import{S as wn,i as Pn,s as Dn,e as a,k as p,w,t as l,M as xn,c as s,d as n,m as c,a as i,x as P,h as r,b as f,G as e,g,y as D,q as x,o as L,B as S,v as Ln,L as yn}from"../../../../chunks/vendor-hf-doc-builder.js";import{D as se}from"../../../../chunks/Docstring-hf-doc-builder.js";import{C as $n}from"../../../../chunks/CodeBlock-hf-doc-builder.js";import{I as bn}from"../../../../chunks/IconCopyLink-hf-doc-builder.js";import{E as vn}from"../../../../chunks/ExampleCodeBlock-hf-doc-builder.js";function Sn(ie){let m,E,_,d,y;return d=new $n({props:{code:`from diffusers import StableDiffusionLatentUpscalePipeline, StableDiffusionPipeline
import torch


pipeline = StableDiffusionPipeline.from_pretrained(
    "CompVis/stable-diffusion-v1-4", torch_dtype=torch.float16
)
pipeline.to("cuda")

model_id = "stabilityai/sd-x2-latent-upscaler"
upscaler = StableDiffusionLatentUpscalePipeline.from_pretrained(model_id, torch_dtype=torch.float16)
upscaler.to("cuda")

prompt = "a photo of an astronaut high resolution, unreal engine, ultra realistic"
generator = torch.manual_seed(33)

low_res_latents = pipeline(prompt, generator=generator, output_type="latent").images

with torch.no_grad():
    image = pipeline.decode_latents(low_res_latents)
image = pipeline.numpy_to_pil(image)[0]

image.save("../images/a1.png")

upscaled_image = upscaler(
    prompt=prompt,
    image=low_res_latents,
    num_inference_steps=20,
    guidance_scale=0,
    generator=generator,
).images[0]

upscaled_image.save("../images/a2.png")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionLatentUpscalePipeline, StableDiffusionPipeline
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch


<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline = StableDiffusionPipeline.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>, torch_dtype=torch.float16
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline.to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>model_id = <span class="hljs-string">&quot;stabilityai/sd-x2-latent-upscaler&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>upscaler = StableDiffusionLatentUpscalePipeline.from_pretrained(model_id, torch_dtype=torch.float16)
<span class="hljs-meta">&gt;&gt;&gt; </span>upscaler.to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>prompt = <span class="hljs-string">&quot;a photo of an astronaut high resolution, unreal engine, ultra realistic&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>generator = torch.manual_seed(<span class="hljs-number">33</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>low_res_latents = pipeline(prompt, generator=generator, output_type=<span class="hljs-string">&quot;latent&quot;</span>).images

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> torch.no_grad():
<span class="hljs-meta">... </span>    image = pipeline.decode_latents(low_res_latents)
<span class="hljs-meta">&gt;&gt;&gt; </span>image = pipeline.numpy_to_pil(image)[<span class="hljs-number">0</span>]

<span class="hljs-meta">&gt;&gt;&gt; </span>image.save(<span class="hljs-string">&quot;../images/a1.png&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>upscaled_image = upscaler(
<span class="hljs-meta">... </span>    prompt=prompt,
<span class="hljs-meta">... </span>    image=low_res_latents,
<span class="hljs-meta">... </span>    num_inference_steps=<span class="hljs-number">20</span>,
<span class="hljs-meta">... </span>    guidance_scale=<span class="hljs-number">0</span>,
<span class="hljs-meta">... </span>    generator=generator,
<span class="hljs-meta">... </span>).images[<span class="hljs-number">0</span>]

<span class="hljs-meta">&gt;&gt;&gt; </span>upscaled_image.save(<span class="hljs-string">&quot;../images/a2.png&quot;</span>)`}}),{c(){m=a("p"),E=l("Examples:"),_=p(),w(d.$$.fragment)},l(o){m=s(o,"P",{});var v=i(m);E=r(v,"Examples:"),v.forEach(n),_=c(o),P(d.$$.fragment,o)},m(o,v){g(o,m,v),e(m,E),g(o,_,v),D(d,o,v),y=!0},p:yn,i(o){y||(x(d.$$.fragment,o),y=!0)},o(o){L(d.$$.fragment,o),y=!1},d(o){o&&n(m),o&&n(_),S(d,o)}}}function En(ie){let m,E,_,d,y;return d=new $n({props:{code:`import torch
from diffusers import DiffusionPipeline
from xformers.ops import MemoryEfficientAttentionFlashAttentionOp

pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1", torch_dtype=torch.float16)
pipe = pipe.to("cuda")
pipe.enable_xformers_memory_efficient_attention(attention_op=MemoryEfficientAttentionFlashAttentionOp)
# Workaround for not accepting attention shape using VAE for Flash Attention
pipe.vae.enable_xformers_memory_efficient_attention(attention_op=None)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> xformers.ops <span class="hljs-keyword">import</span> MemoryEfficientAttentionFlashAttentionOp

<span class="hljs-meta">&gt;&gt;&gt; </span>pipe = DiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;stabilityai/stable-diffusion-2-1&quot;</span>, torch_dtype=torch.float16)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipe = pipe.to(<span class="hljs-string">&quot;cuda&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipe.enable_xformers_memory_efficient_attention(attention_op=MemoryEfficientAttentionFlashAttentionOp)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Workaround for not accepting attention shape using VAE for Flash Attention</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>pipe.vae.enable_xformers_memory_efficient_attention(attention_op=<span class="hljs-literal">None</span>)`}}),{c(){m=a("p"),E=l("Examples:"),_=p(),w(d.$$.fragment)},l(o){m=s(o,"P",{});var v=i(m);E=r(v,"Examples:"),v.forEach(n),_=c(o),P(d.$$.fragment,o)},m(o,v){g(o,m,v),e(m,E),g(o,_,v),D(d,o,v),y=!0},p:yn,i(o){y||(x(d.$$.fragment,o),y=!0)},o(o){L(d.$$.fragment,o),y=!1},d(o){o&&n(m),o&&n(_),S(d,o)}}}function kn(ie){let m,E,_,d,y,o,v,me,Be,Ue,C,A,he,z,He,ge,Je,je,k,Re,W,Ye,Ze,G,Qe,Xe,oe,et,tt,Ie,le,nt,Ce,re,_e,V,at,Ae,pe,st,qe,ce,K,be,it,ot,B,lt,Te,h,H,rt,ve,pt,ct,J,ft,fe,dt,ut,mt,U,R,ht,ye,gt,_t,q,bt,T,Y,vt,Z,yt,$e,$t,wt,Pt,j,Q,Dt,we,xt,Lt,Pe,St,Et,M,X,kt,ee,Ut,De,jt,It,Ct,$,te,At,xe,qt,Tt,Le,Mt,Nt,Se,Ot,Ft,N,zt,O,ne,Wt,Ee,Gt,Me;return o=new bn({}),z=new bn({}),H=new se({props:{name:"class diffusers.StableDiffusionLatentUpscalePipeline",anchor:"diffusers.StableDiffusionLatentUpscalePipeline",parameters:[{name:"vae",val:": AutoencoderKL"},{name:"text_encoder",val:": CLIPTextModel"},{name:"tokenizer",val:": CLIPTokenizer"},{name:"unet",val:": UNet2DConditionModel"},{name:"scheduler",val:": EulerDiscreteScheduler"}],parametersDescription:[{anchor:"diffusers.StableDiffusionLatentUpscalePipeline.vae",description:`<strong>vae</strong> (<a href="/docs/diffusers/main/en/api/models#diffusers.AutoencoderKL">AutoencoderKL</a>) &#x2014;
Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations.`,name:"vae"},{anchor:"diffusers.StableDiffusionLatentUpscalePipeline.text_encoder",description:`<strong>text_encoder</strong> (<code>CLIPTextModel</code>) &#x2014;
Frozen text-encoder. Stable Diffusion uses the text portion of
<a href="https://huggingface.co/docs/transformers/model_doc/clip#transformers.CLIPTextModel" rel="nofollow">CLIP</a>, specifically
the <a href="https://huggingface.co/openai/clip-vit-large-patch14" rel="nofollow">clip-vit-large-patch14</a> variant.`,name:"text_encoder"},{anchor:"diffusers.StableDiffusionLatentUpscalePipeline.tokenizer",description:`<strong>tokenizer</strong> (<code>CLIPTokenizer</code>) &#x2014;
Tokenizer of class
<a href="https://huggingface.co/docs/transformers/main/en/model_doc/clip#transformers.CLIPTokenizer" rel="nofollow">CLIPTokenizer</a>.`,name:"tokenizer"},{anchor:"diffusers.StableDiffusionLatentUpscalePipeline.unet",description:'<strong>unet</strong> (<a href="/docs/diffusers/main/en/api/models#diffusers.UNet2DConditionModel">UNet2DConditionModel</a>) &#x2014; Conditional U-Net architecture to denoise the encoded image latents.',name:"unet"},{anchor:"diffusers.StableDiffusionLatentUpscalePipeline.scheduler",description:`<strong>scheduler</strong> (<a href="/docs/diffusers/main/en/api/schedulers/overview#diffusers.SchedulerMixin">SchedulerMixin</a>) &#x2014;
A scheduler to be used in combination with <code>unet</code> to denoise the encoded image latents. Can be one of
<a href="/docs/diffusers/main/en/api/schedulers/euler#diffusers.EulerDiscreteScheduler">EulerDiscreteScheduler</a>.`,name:"scheduler"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py#L54"}}),R=new se({props:{name:"__call__",anchor:"diffusers.StableDiffusionLatentUpscalePipeline.__call__",parameters:[{name:"prompt",val:": typing.Union[str, typing.List[str]]"},{name:"image",val:": typing.Union[torch.FloatTensor, PIL.Image.Image, typing.List[PIL.Image.Image]]"},{name:"num_inference_steps",val:": int = 75"},{name:"guidance_scale",val:": float = 9.0"},{name:"negative_prompt",val:": typing.Union[str, typing.List[str], NoneType] = None"},{name:"generator",val:": typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None"},{name:"latents",val:": typing.Optional[torch.FloatTensor] = None"},{name:"output_type",val:": typing.Optional[str] = 'pil'"},{name:"return_dict",val:": bool = True"},{name:"callback",val:": typing.Union[typing.Callable[[int, int, torch.FloatTensor], NoneType], NoneType] = None"},{name:"callback_steps",val:": int = 1"}],parametersDescription:[{anchor:"diffusers.StableDiffusionLatentUpscalePipeline.__call__.prompt",description:`<strong>prompt</strong> (<code>str</code> or <code>List[str]</code>) &#x2014;
The prompt or prompts to guide the image upscaling.`,name:"prompt"},{anchor:"diffusers.StableDiffusionLatentUpscalePipeline.__call__.image",description:`<strong>image</strong> (<code>PIL.Image.Image</code> or List<code>PIL.Image.Image</code> or <code>torch.FloatTensor</code>) &#x2014;
<code>Image</code>, or tensor representing an image batch which will be upscaled. If it&#x2019;s a tensor, it can be
either a latent output from a stable diffusion model, or an image tensor in the range <code>[-1, 1]</code>. It
will be considered a <code>latent</code> if <code>image.shape[1]</code> is <code>4</code>; otherwise, it will be considered to be an
image representation and encoded using this pipeline&#x2019;s <code>vae</code> encoder.`,name:"image"},{anchor:"diffusers.StableDiffusionLatentUpscalePipeline.__call__.num_inference_steps",description:`<strong>num_inference_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 50) &#x2014;
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
expense of slower inference.`,name:"num_inference_steps"},{anchor:"diffusers.StableDiffusionLatentUpscalePipeline.__call__.guidance_scale",description:`<strong>guidance_scale</strong> (<code>float</code>, <em>optional</em>, defaults to 7.5) &#x2014;
Guidance scale as defined in <a href="https://arxiv.org/abs/2207.12598" rel="nofollow">Classifier-Free Diffusion Guidance</a>.
<code>guidance_scale</code> is defined as <code>w</code> of equation 2. of <a href="https://arxiv.org/pdf/2205.11487.pdf" rel="nofollow">Imagen
Paper</a>. Guidance scale is enabled by setting <code>guidance_scale &gt; 1</code>. Higher guidance scale encourages to generate images that are closely linked to the text <code>prompt</code>,
usually at the expense of lower image quality.`,name:"guidance_scale"},{anchor:"diffusers.StableDiffusionLatentUpscalePipeline.__call__.negative_prompt",description:`<strong>negative_prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
The prompt or prompts not to guide the image generation. Ignored when not using guidance (i.e., ignored
if <code>guidance_scale</code> is less than <code>1</code>).`,name:"negative_prompt"},{anchor:"diffusers.StableDiffusionLatentUpscalePipeline.__call__.eta",description:`<strong>eta</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
Corresponds to parameter eta (&#x3B7;) in the DDIM paper: <a href="https://arxiv.org/abs/2010.02502" rel="nofollow">https://arxiv.org/abs/2010.02502</a>. Only applies to
<a href="/docs/diffusers/main/en/api/schedulers/ddim#diffusers.DDIMScheduler">schedulers.DDIMScheduler</a>, will be ignored for others.`,name:"eta"},{anchor:"diffusers.StableDiffusionLatentUpscalePipeline.__call__.generator",description:`<strong>generator</strong> (<code>torch.Generator</code>, <em>optional</em>) &#x2014;
One or a list of <a href="https://pytorch.org/docs/stable/generated/torch.Generator.html" rel="nofollow">torch generator(s)</a>
to make generation deterministic.`,name:"generator"},{anchor:"diffusers.StableDiffusionLatentUpscalePipeline.__call__.latents",description:`<strong>latents</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for image
generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
tensor will ge generated by sampling using the supplied random <code>generator</code>.`,name:"latents"},{anchor:"diffusers.StableDiffusionLatentUpscalePipeline.__call__.output_type",description:`<strong>output_type</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;pil&quot;</code>) &#x2014;
The output format of the generate image. Choose between
<a href="https://pillow.readthedocs.io/en/stable/" rel="nofollow">PIL</a>: <code>PIL.Image.Image</code> or <code>np.array</code>.`,name:"output_type"},{anchor:"diffusers.StableDiffusionLatentUpscalePipeline.__call__.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not to return a <a href="/docs/diffusers/main/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput">StableDiffusionPipelineOutput</a> instead of a
plain tuple.`,name:"return_dict"},{anchor:"diffusers.StableDiffusionLatentUpscalePipeline.__call__.callback",description:`<strong>callback</strong> (<code>Callable</code>, <em>optional</em>) &#x2014;
A function that will be called every <code>callback_steps</code> steps during inference. The function will be
called with the following arguments: <code>callback(step: int, timestep: int, latents: torch.FloatTensor)</code>.`,name:"callback"},{anchor:"diffusers.StableDiffusionLatentUpscalePipeline.__call__.callback_steps",description:`<strong>callback_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The frequency at which the <code>callback</code> function will be called. If not specified, the callback will be
called at every step.`,name:"callback_steps"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py#L281",returnDescription:`
<p><a
  href="/docs/diffusers/main/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> if <code>return_dict</code> is True, otherwise a <code>tuple. When returning a tuple, the first element is a list with the generated images, and the second element is a list of </code>bool<code>s denoting whether the corresponding generated image likely represents "not-safe-for-work" (nsfw) content, according to the </code>safety_checker\`.</p>
`,returnType:`
<p><a
  href="/docs/diffusers/main/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> or <code>tuple</code></p>
`}}),q=new vn({props:{anchor:"diffusers.StableDiffusionLatentUpscalePipeline.__call__.example",$$slots:{default:[Sn]},$$scope:{ctx:ie}}}),Y=new se({props:{name:"enable_sequential_cpu_offload",anchor:"diffusers.StableDiffusionLatentUpscalePipeline.enable_sequential_cpu_offload",parameters:[{name:"gpu_id",val:" = 0"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py#L95"}}),Q=new se({props:{name:"enable_attention_slicing",anchor:"diffusers.StableDiffusionLatentUpscalePipeline.enable_attention_slicing",parameters:[{name:"slice_size",val:": typing.Union[str, int, NoneType] = 'auto'"}],parametersDescription:[{anchor:"diffusers.StableDiffusionLatentUpscalePipeline.enable_attention_slicing.slice_size",description:`<strong>slice_size</strong> (<code>str</code> or <code>int</code>, <em>optional</em>, defaults to <code>&quot;auto&quot;</code>) &#x2014;
When <code>&quot;auto&quot;</code>, halves the input to the attention heads, so attention will be computed in two steps. If
<code>&quot;max&quot;</code>, maxium amount of memory will be saved by running only one slice at a time. If a number is
provided, uses as many slices as <code>attention_head_dim // slice_size</code>. In this case, <code>attention_head_dim</code>
must be a multiple of <code>slice_size</code>.`,name:"slice_size"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/pipeline_utils.py#L1033"}}),X=new se({props:{name:"disable_attention_slicing",anchor:"diffusers.StableDiffusionLatentUpscalePipeline.disable_attention_slicing",parameters:[],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/pipeline_utils.py#L1049"}}),te=new se({props:{name:"enable_xformers_memory_efficient_attention",anchor:"diffusers.StableDiffusionLatentUpscalePipeline.enable_xformers_memory_efficient_attention",parameters:[{name:"attention_op",val:": typing.Optional[typing.Callable] = None"}],parametersDescription:[{anchor:"diffusers.StableDiffusionLatentUpscalePipeline.enable_xformers_memory_efficient_attention.attention_op",description:`<strong>attention_op</strong> (<code>Callable</code>, <em>optional</em>) &#x2014;
Override the default <code>None</code> operator for use as <code>op</code> argument to the
<a href="https://facebookresearch.github.io/xformers/components/ops.html#xformers.ops.memory_efficient_attention" rel="nofollow"><code>memory_efficient_attention()</code></a>
function of xFormers.`,name:"attention_op"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/pipeline_utils.py#L976"}}),N=new vn({props:{anchor:"diffusers.StableDiffusionLatentUpscalePipeline.enable_xformers_memory_efficient_attention.example",$$slots:{default:[En]},$$scope:{ctx:ie}}}),ne=new se({props:{name:"disable_xformers_memory_efficient_attention",anchor:"diffusers.StableDiffusionLatentUpscalePipeline.disable_xformers_memory_efficient_attention",parameters:[],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/pipeline_utils.py#L1008"}}),{c(){m=a("meta"),E=p(),_=a("h1"),d=a("a"),y=a("span"),w(o.$$.fragment),v=p(),me=a("span"),Be=l("Stable Diffusion Latent Upscaler"),Ue=p(),C=a("h2"),A=a("a"),he=a("span"),w(z.$$.fragment),He=p(),ge=a("span"),Je=l("StableDiffusionLatentUpscalePipeline"),je=p(),k=a("p"),Re=l("The Stable Diffusion Latent Upscaler model was created by "),W=a("a"),Ye=l("Katherine Crowson"),Ze=l(" in collaboration with "),G=a("a"),Qe=l("Stability AI"),Xe=l(". It can be used on top of any "),oe=a("a"),et=l("StableDiffusionUpscalePipeline"),tt=l(" checkpoint to enhance its output image resolution by a factor of 2."),Ie=p(),le=a("p"),nt=l("A notebook that demonstrates the original implementation can be found here:"),Ce=p(),re=a("ul"),_e=a("li"),V=a("a"),at=l("Stable Diffusion Upscaler Demo"),Ae=p(),pe=a("p"),st=l("Available Checkpoints are:"),qe=p(),ce=a("ul"),K=a("li"),be=a("em"),it=l("stabilityai/latent-upscaler"),ot=l(": "),B=a("a"),lt=l("stabilityai/sd-x2-latent-upscaler"),Te=p(),h=a("div"),w(H.$$.fragment),rt=p(),ve=a("p"),pt=l("Pipeline to upscale the resolution of Stable Diffusion output images by a factor of 2."),ct=p(),J=a("p"),ft=l("This model inherits from "),fe=a("a"),dt=l("DiffusionPipeline"),ut=l(`. Check the superclass documentation for the generic methods the
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)`),mt=p(),U=a("div"),w(R.$$.fragment),ht=p(),ye=a("p"),gt=l("Function invoked when calling the pipeline for generation."),_t=p(),w(q.$$.fragment),bt=p(),T=a("div"),w(Y.$$.fragment),vt=p(),Z=a("p"),yt=l(`Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae and safety checker have their state dicts saved to CPU and then are moved to a
`),$e=a("code"),$t=l("torch.device('meta') and loaded to GPU only when their specific submodule has its "),wt=l("forward` method called."),Pt=p(),j=a("div"),w(Q.$$.fragment),Dt=p(),we=a("p"),xt=l("Enable sliced attention computation."),Lt=p(),Pe=a("p"),St=l(`When this option is enabled, the attention module will split the input tensor in slices, to compute attention
in several steps. This is useful to save some memory in exchange for a small speed decrease.`),Et=p(),M=a("div"),w(X.$$.fragment),kt=p(),ee=a("p"),Ut=l("Disable sliced attention computation. If "),De=a("code"),jt=l("enable_attention_slicing"),It=l(` was previously invoked, this method will go
back to computing attention in one step.`),Ct=p(),$=a("div"),w(te.$$.fragment),At=p(),xe=a("p"),qt=l("Enable memory efficient attention as implemented in xformers."),Tt=p(),Le=a("p"),Mt=l(`When this option is enabled, you should observe lower GPU memory usage and a potential speed up at inference
time. Speed up at training time is not guaranteed.`),Nt=p(),Se=a("p"),Ot=l(`Warning: When Memory Efficient Attention and Sliced attention are both enabled, the Memory Efficient Attention
is used.`),Ft=p(),w(N.$$.fragment),zt=p(),O=a("div"),w(ne.$$.fragment),Wt=p(),Ee=a("p"),Gt=l("Disable memory efficient attention as implemented in xformers."),this.h()},l(t){const u=xn('[data-svelte="svelte-1phssyn"]',document.head);m=s(u,"META",{name:!0,content:!0}),u.forEach(n),E=c(t),_=s(t,"H1",{class:!0});var ae=i(_);d=s(ae,"A",{id:!0,class:!0,href:!0});var ke=i(d);y=s(ke,"SPAN",{});var Vt=i(y);P(o.$$.fragment,Vt),Vt.forEach(n),ke.forEach(n),v=c(ae),me=s(ae,"SPAN",{});var Kt=i(me);Be=r(Kt,"Stable Diffusion Latent Upscaler"),Kt.forEach(n),ae.forEach(n),Ue=c(t),C=s(t,"H2",{class:!0});var Ne=i(C);A=s(Ne,"A",{id:!0,class:!0,href:!0});var Bt=i(A);he=s(Bt,"SPAN",{});var Ht=i(he);P(z.$$.fragment,Ht),Ht.forEach(n),Bt.forEach(n),He=c(Ne),ge=s(Ne,"SPAN",{});var Jt=i(ge);Je=r(Jt,"StableDiffusionLatentUpscalePipeline"),Jt.forEach(n),Ne.forEach(n),je=c(t),k=s(t,"P",{});var F=i(k);Re=r(F,"The Stable Diffusion Latent Upscaler model was created by "),W=s(F,"A",{href:!0,rel:!0});var Rt=i(W);Ye=r(Rt,"Katherine Crowson"),Rt.forEach(n),Ze=r(F," in collaboration with "),G=s(F,"A",{href:!0,rel:!0});var Yt=i(G);Qe=r(Yt,"Stability AI"),Yt.forEach(n),Xe=r(F,". It can be used on top of any "),oe=s(F,"A",{href:!0});var Zt=i(oe);et=r(Zt,"StableDiffusionUpscalePipeline"),Zt.forEach(n),tt=r(F," checkpoint to enhance its output image resolution by a factor of 2."),F.forEach(n),Ie=c(t),le=s(t,"P",{});var Qt=i(le);nt=r(Qt,"A notebook that demonstrates the original implementation can be found here:"),Qt.forEach(n),Ce=c(t),re=s(t,"UL",{});var Xt=i(re);_e=s(Xt,"LI",{});var en=i(_e);V=s(en,"A",{href:!0,rel:!0});var tn=i(V);at=r(tn,"Stable Diffusion Upscaler Demo"),tn.forEach(n),en.forEach(n),Xt.forEach(n),Ae=c(t),pe=s(t,"P",{});var nn=i(pe);st=r(nn,"Available Checkpoints are:"),nn.forEach(n),qe=c(t),ce=s(t,"UL",{});var an=i(ce);K=s(an,"LI",{});var Oe=i(K);be=s(Oe,"EM",{});var sn=i(be);it=r(sn,"stabilityai/latent-upscaler"),sn.forEach(n),ot=r(Oe,": "),B=s(Oe,"A",{href:!0,rel:!0});var on=i(B);lt=r(on,"stabilityai/sd-x2-latent-upscaler"),on.forEach(n),Oe.forEach(n),an.forEach(n),Te=c(t),h=s(t,"DIV",{class:!0});var b=i(h);P(H.$$.fragment,b),rt=c(b),ve=s(b,"P",{});var ln=i(ve);pt=r(ln,"Pipeline to upscale the resolution of Stable Diffusion output images by a factor of 2."),ln.forEach(n),ct=c(b),J=s(b,"P",{});var Fe=i(J);ft=r(Fe,"This model inherits from "),fe=s(Fe,"A",{href:!0});var rn=i(fe);dt=r(rn,"DiffusionPipeline"),rn.forEach(n),ut=r(Fe,`. Check the superclass documentation for the generic methods the
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)`),Fe.forEach(n),mt=c(b),U=s(b,"DIV",{class:!0});var de=i(U);P(R.$$.fragment,de),ht=c(de),ye=s(de,"P",{});var pn=i(ye);gt=r(pn,"Function invoked when calling the pipeline for generation."),pn.forEach(n),_t=c(de),P(q.$$.fragment,de),de.forEach(n),bt=c(b),T=s(b,"DIV",{class:!0});var ze=i(T);P(Y.$$.fragment,ze),vt=c(ze),Z=s(ze,"P",{});var We=i(Z);yt=r(We,`Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae and safety checker have their state dicts saved to CPU and then are moved to a
`),$e=s(We,"CODE",{});var cn=i($e);$t=r(cn,"torch.device('meta') and loaded to GPU only when their specific submodule has its "),cn.forEach(n),wt=r(We,"forward` method called."),We.forEach(n),ze.forEach(n),Pt=c(b),j=s(b,"DIV",{class:!0});var ue=i(j);P(Q.$$.fragment,ue),Dt=c(ue),we=s(ue,"P",{});var fn=i(we);xt=r(fn,"Enable sliced attention computation."),fn.forEach(n),Lt=c(ue),Pe=s(ue,"P",{});var dn=i(Pe);St=r(dn,`When this option is enabled, the attention module will split the input tensor in slices, to compute attention
in several steps. This is useful to save some memory in exchange for a small speed decrease.`),dn.forEach(n),ue.forEach(n),Et=c(b),M=s(b,"DIV",{class:!0});var Ge=i(M);P(X.$$.fragment,Ge),kt=c(Ge),ee=s(Ge,"P",{});var Ve=i(ee);Ut=r(Ve,"Disable sliced attention computation. If "),De=s(Ve,"CODE",{});var un=i(De);jt=r(un,"enable_attention_slicing"),un.forEach(n),It=r(Ve,` was previously invoked, this method will go
back to computing attention in one step.`),Ve.forEach(n),Ge.forEach(n),Ct=c(b),$=s(b,"DIV",{class:!0});var I=i($);P(te.$$.fragment,I),At=c(I),xe=s(I,"P",{});var mn=i(xe);qt=r(mn,"Enable memory efficient attention as implemented in xformers."),mn.forEach(n),Tt=c(I),Le=s(I,"P",{});var hn=i(Le);Mt=r(hn,`When this option is enabled, you should observe lower GPU memory usage and a potential speed up at inference
time. Speed up at training time is not guaranteed.`),hn.forEach(n),Nt=c(I),Se=s(I,"P",{});var gn=i(Se);Ot=r(gn,`Warning: When Memory Efficient Attention and Sliced attention are both enabled, the Memory Efficient Attention
is used.`),gn.forEach(n),Ft=c(I),P(N.$$.fragment,I),I.forEach(n),zt=c(b),O=s(b,"DIV",{class:!0});var Ke=i(O);P(ne.$$.fragment,Ke),Wt=c(Ke),Ee=s(Ke,"P",{});var _n=i(Ee);Gt=r(_n,"Disable memory efficient attention as implemented in xformers."),_n.forEach(n),Ke.forEach(n),b.forEach(n),this.h()},h(){f(m,"name","hf:doc:metadata"),f(m,"content",JSON.stringify(Un)),f(d,"id","stable-diffusion-latent-upscaler"),f(d,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(d,"href","#stable-diffusion-latent-upscaler"),f(_,"class","relative group"),f(A,"id","diffusers.StableDiffusionLatentUpscalePipeline"),f(A,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(A,"href","#diffusers.StableDiffusionLatentUpscalePipeline"),f(C,"class","relative group"),f(W,"href","https://github.com/crowsonkb/k-diffusion"),f(W,"rel","nofollow"),f(G,"href","https://stability.ai/"),f(G,"rel","nofollow"),f(oe,"href","/docs/diffusers/main/en/api/pipelines/stable_diffusion/upscale#diffusers.StableDiffusionUpscalePipeline"),f(V,"href","https://colab.research.google.com/drive/1o1qYJcFeywzCIdkfKJy7cTpgZTCM2EI4"),f(V,"rel","nofollow"),f(B,"href","https://huggingface.co/stabilityai/sd-x2-latent-upscaler"),f(B,"rel","nofollow"),f(fe,"href","/docs/diffusers/main/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),f(U,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),f(T,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),f(j,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),f(M,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),f($,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),f(O,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),f(h,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(t,u){e(document.head,m),g(t,E,u),g(t,_,u),e(_,d),e(d,y),D(o,y,null),e(_,v),e(_,me),e(me,Be),g(t,Ue,u),g(t,C,u),e(C,A),e(A,he),D(z,he,null),e(C,He),e(C,ge),e(ge,Je),g(t,je,u),g(t,k,u),e(k,Re),e(k,W),e(W,Ye),e(k,Ze),e(k,G),e(G,Qe),e(k,Xe),e(k,oe),e(oe,et),e(k,tt),g(t,Ie,u),g(t,le,u),e(le,nt),g(t,Ce,u),g(t,re,u),e(re,_e),e(_e,V),e(V,at),g(t,Ae,u),g(t,pe,u),e(pe,st),g(t,qe,u),g(t,ce,u),e(ce,K),e(K,be),e(be,it),e(K,ot),e(K,B),e(B,lt),g(t,Te,u),g(t,h,u),D(H,h,null),e(h,rt),e(h,ve),e(ve,pt),e(h,ct),e(h,J),e(J,ft),e(J,fe),e(fe,dt),e(J,ut),e(h,mt),e(h,U),D(R,U,null),e(U,ht),e(U,ye),e(ye,gt),e(U,_t),D(q,U,null),e(h,bt),e(h,T),D(Y,T,null),e(T,vt),e(T,Z),e(Z,yt),e(Z,$e),e($e,$t),e(Z,wt),e(h,Pt),e(h,j),D(Q,j,null),e(j,Dt),e(j,we),e(we,xt),e(j,Lt),e(j,Pe),e(Pe,St),e(h,Et),e(h,M),D(X,M,null),e(M,kt),e(M,ee),e(ee,Ut),e(ee,De),e(De,jt),e(ee,It),e(h,Ct),e(h,$),D(te,$,null),e($,At),e($,xe),e(xe,qt),e($,Tt),e($,Le),e(Le,Mt),e($,Nt),e($,Se),e(Se,Ot),e($,Ft),D(N,$,null),e(h,zt),e(h,O),D(ne,O,null),e(O,Wt),e(O,Ee),e(Ee,Gt),Me=!0},p(t,[u]){const ae={};u&2&&(ae.$$scope={dirty:u,ctx:t}),q.$set(ae);const ke={};u&2&&(ke.$$scope={dirty:u,ctx:t}),N.$set(ke)},i(t){Me||(x(o.$$.fragment,t),x(z.$$.fragment,t),x(H.$$.fragment,t),x(R.$$.fragment,t),x(q.$$.fragment,t),x(Y.$$.fragment,t),x(Q.$$.fragment,t),x(X.$$.fragment,t),x(te.$$.fragment,t),x(N.$$.fragment,t),x(ne.$$.fragment,t),Me=!0)},o(t){L(o.$$.fragment,t),L(z.$$.fragment,t),L(H.$$.fragment,t),L(R.$$.fragment,t),L(q.$$.fragment,t),L(Y.$$.fragment,t),L(Q.$$.fragment,t),L(X.$$.fragment,t),L(te.$$.fragment,t),L(N.$$.fragment,t),L(ne.$$.fragment,t),Me=!1},d(t){n(m),t&&n(E),t&&n(_),S(o),t&&n(Ue),t&&n(C),S(z),t&&n(je),t&&n(k),t&&n(Ie),t&&n(le),t&&n(Ce),t&&n(re),t&&n(Ae),t&&n(pe),t&&n(qe),t&&n(ce),t&&n(Te),t&&n(h),S(H),S(R),S(q),S(Y),S(Q),S(X),S(te),S(N),S(ne)}}}const Un={local:"stable-diffusion-latent-upscaler",sections:[{local:"diffusers.StableDiffusionLatentUpscalePipeline",title:"StableDiffusionLatentUpscalePipeline"}],title:"Stable Diffusion Latent Upscaler"};function jn(ie){return Ln(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Mn extends wn{constructor(m){super();Pn(this,m,jn,kn,Dn,{})}}export{Mn as default,Un as metadata};
