import{S as Un,i as Jn,s as Tn,e as a,k as c,w as U,t as l,M as $n,c as s,d as n,m as p,a as o,x as J,h as r,b as d,G as e,g,y as T,q as $,o as M,B as x,v as Mn,L as vn}from"../../../../chunks/vendor-hf-doc-builder.js";import{D as se}from"../../../../chunks/Docstring-hf-doc-builder.js";import{C as wn}from"../../../../chunks/CodeBlock-hf-doc-builder.js";import{I as _n}from"../../../../chunks/IconCopyLink-hf-doc-builder.js";import{E as yn}from"../../../../chunks/ExampleCodeBlock-hf-doc-builder.js";function xn(oe){let m,E,b,f,v;return f=new wn({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvbkxhdGVudFVwc2NhbGVQaXBlbGluZSUyQyUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBaW1wb3J0JTIwdG9yY2glMEElMEElMEFwaXBlbGluZSUyMCUzRCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJDb21wVmlzJTJGc3RhYmxlLWRpZmZ1c2lvbi12MS00JTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTBBKSUwQXBpcGVsaW5lLnRvKCUyMmN1ZGElMjIpJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJzdGFiaWxpdHlhaSUyRnNkLXgyLWxhdGVudC11cHNjYWxlciUyMiUwQXVwc2NhbGVyJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uTGF0ZW50VXBzY2FsZVBpcGVsaW5lLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiklMEF1cHNjYWxlci50byglMjJjdWRhJTIyKSUwQSUwQXByb21wdCUyMCUzRCUyMCUyMmElMjBwaG90byUyMG9mJTIwYW4lMjBhc3Ryb25hdXQlMjBoaWdoJTIwcmVzb2x1dGlvbiUyQyUyMHVucmVhbCUyMGVuZ2luZSUyQyUyMHVsdHJhJTIwcmVhbGlzdGljJTIyJTBBZ2VuZXJhdG9yJTIwJTNEJTIwdG9yY2gubWFudWFsX3NlZWQoMzMpJTBBJTBBbG93X3Jlc19sYXRlbnRzJTIwJTNEJTIwcGlwZWxpbmUocHJvbXB0JTJDJTIwZ2VuZXJhdG9yJTNEZ2VuZXJhdG9yJTJDJTIwb3V0cHV0X3R5cGUlM0QlMjJsYXRlbnQlMjIpLmltYWdlcyUwQSUwQXdpdGglMjB0b3JjaC5ub19ncmFkKCklM0ElMEElMjAlMjAlMjAlMjBpbWFnZSUyMCUzRCUyMHBpcGVsaW5lLmRlY29kZV9sYXRlbnRzKGxvd19yZXNfbGF0ZW50cyklMEFpbWFnZSUyMCUzRCUyMHBpcGVsaW5lLm51bXB5X3RvX3BpbChpbWFnZSklNUIwJTVEJTBBJTBBaW1hZ2Uuc2F2ZSglMjIuLiUyRmltYWdlcyUyRmExLnBuZyUyMiklMEElMEF1cHNjYWxlZF9pbWFnZSUyMCUzRCUyMHVwc2NhbGVyKCUwQSUyMCUyMCUyMCUyMHByb21wdCUzRHByb21wdCUyQyUwQSUyMCUyMCUyMCUyMGltYWdlJTNEbG93X3Jlc19sYXRlbnRzJTJDJTBBJTIwJTIwJTIwJTIwbnVtX2luZmVyZW5jZV9zdGVwcyUzRDIwJTJDJTBBJTIwJTIwJTIwJTIwZ3VpZGFuY2Vfc2NhbGUlM0QwJTJDJTBBJTIwJTIwJTIwJTIwZ2VuZXJhdG9yJTNEZ2VuZXJhdG9yJTJDJTBBKS5pbWFnZXMlNUIwJTVEJTBBJTBBdXBzY2FsZWRfaW1hZ2Uuc2F2ZSglMjIuLiUyRmltYWdlcyUyRmEyLnBuZyUyMik=",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:"),b=c(),U(f.$$.fragment)},l(i){m=s(i,"P",{});var y=o(m);E=r(y,"Examples:"),y.forEach(n),b=p(i),J(f.$$.fragment,i)},m(i,y){g(i,m,y),e(m,E),g(i,b,y),T(f,i,y),v=!0},p:vn,i(i){v||($(f.$$.fragment,i),v=!0)},o(i){M(f.$$.fragment,i),v=!1},d(i){i&&n(m),i&&n(b),x(f,i)}}}function En(oe){let m,E,b,f,v;return f=new wn({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRGlmZnVzaW9uUGlwZWxpbmUlMEFmcm9tJTIweGZvcm1lcnMub3BzJTIwaW1wb3J0JTIwTWVtb3J5RWZmaWNpZW50QXR0ZW50aW9uRmxhc2hBdHRlbnRpb25PcCUwQSUwQXBpcGUlMjAlM0QlMjBEaWZmdXNpb25QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIyc3RhYmlsaXR5YWklMkZzdGFibGUtZGlmZnVzaW9uLTItMSUyMiUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiklMEFwaXBlJTIwJTNEJTIwcGlwZS50byglMjJjdWRhJTIyKSUwQXBpcGUuZW5hYmxlX3hmb3JtZXJzX21lbW9yeV9lZmZpY2llbnRfYXR0ZW50aW9uKGF0dGVudGlvbl9vcCUzRE1lbW9yeUVmZmljaWVudEF0dGVudGlvbkZsYXNoQXR0ZW50aW9uT3ApJTBBJTIzJTIwV29ya2Fyb3VuZCUyMGZvciUyMG5vdCUyMGFjY2VwdGluZyUyMGF0dGVudGlvbiUyMHNoYXBlJTIwdXNpbmclMjBWQUUlMjBmb3IlMjBGbGFzaCUyMEF0dGVudGlvbiUwQXBpcGUudmFlLmVuYWJsZV94Zm9ybWVyc19tZW1vcnlfZWZmaWNpZW50X2F0dGVudGlvbihhdHRlbnRpb25fb3AlM0ROb25lKQ==",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:"),b=c(),U(f.$$.fragment)},l(i){m=s(i,"P",{});var y=o(m);E=r(y,"Examples:"),y.forEach(n),b=p(i),J(f.$$.fragment,i)},m(i,y){g(i,m,y),e(m,E),g(i,b,y),T(f,i,y),v=!0},p:vn,i(i){v||($(f.$$.fragment,i),v=!0)},o(i){M(f.$$.fragment,i),v=!1},d(i){i&&n(m),i&&n(b),x(f,i)}}}function Dn(oe){let m,E,b,f,v,i,y,me,Ae,Ie,L,Z,he,V,ze,ge,Ye,Pe,D,qe,R,Qe,He,N,Oe,Ke,ie,et,tt,Se,le,nt,Le,re,be,F,at,Ze,ce,st,je,pe,X,_e,ot,it,A,lt,Ge,h,z,rt,ye,ct,pt,Y,dt,de,ft,ut,mt,I,q,ht,ve,gt,bt,j,_t,G,Q,yt,H,vt,we,wt,Ut,Jt,P,O,Tt,Ue,$t,Mt,Je,xt,Et,W,K,Dt,ee,It,Te,Pt,St,Lt,w,te,Zt,$e,jt,Gt,Me,Wt,kt,xe,Ct,Bt,k,Vt,C,ne,Rt,Ee,Nt,We;return i=new _n({}),V=new _n({}),z=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/v0.17.1/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/v0.17.1/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/v0.17.1/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/v0.17.1/en/api/schedulers/euler#diffusers.EulerDiscreteScheduler">EulerDiscreteScheduler</a>.`,name:"scheduler"}],source:"https://github.com/huggingface/diffusers/blob/v0.17.1/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py#L61"}}),q=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, numpy.ndarray, typing.List[torch.FloatTensor], typing.List[PIL.Image.Image], typing.List[numpy.ndarray]] = None"},{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>torch.FloatTensor</code>, <code>PIL.Image.Image</code>, <code>np.ndarray</code>, <code>List[torch.FloatTensor]</code>, <code>List[PIL.Image.Image]</code>, or <code>List[np.ndarray]</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/v0.17.1/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/v0.17.1/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/v0.17.1/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py#L295",returnDescription:`
<p><a
  href="/docs/diffusers/v0.17.1/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/v0.17.1/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> or <code>tuple</code></p>
`}}),j=new yn({props:{anchor:"diffusers.StableDiffusionLatentUpscalePipeline.__call__.example",$$slots:{default:[xn]},$$scope:{ctx:oe}}}),Q=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/v0.17.1/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py#L104"}}),O=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>, maximum 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/v0.17.1/src/diffusers/pipelines/pipeline_utils.py#L1492"}}),K=new se({props:{name:"disable_attention_slicing",anchor:"diffusers.StableDiffusionLatentUpscalePipeline.disable_attention_slicing",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.17.1/src/diffusers/pipelines/pipeline_utils.py#L1508"}}),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/v0.17.1/src/diffusers/pipelines/pipeline_utils.py#L1434"}}),k=new yn({props:{anchor:"diffusers.StableDiffusionLatentUpscalePipeline.enable_xformers_memory_efficient_attention.example",$$slots:{default:[En]},$$scope:{ctx:oe}}}),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/v0.17.1/src/diffusers/pipelines/pipeline_utils.py#L1466"}}),{c(){m=a("meta"),E=c(),b=a("h1"),f=a("a"),v=a("span"),U(i.$$.fragment),y=c(),me=a("span"),Ae=l("Stable Diffusion Latent Upscaler"),Ie=c(),L=a("h2"),Z=a("a"),he=a("span"),U(V.$$.fragment),ze=c(),ge=a("span"),Ye=l("StableDiffusionLatentUpscalePipeline"),Pe=c(),D=a("p"),qe=l("The Stable Diffusion Latent Upscaler model was created by "),R=a("a"),Qe=l("Katherine Crowson"),He=l(" in collaboration with "),N=a("a"),Oe=l("Stability AI"),Ke=l(". It can be used on top of any "),ie=a("a"),et=l("StableDiffusionUpscalePipeline"),tt=l(" checkpoint to enhance its output image resolution by a factor of 2."),Se=c(),le=a("p"),nt=l("A notebook that demonstrates the original implementation can be found here:"),Le=c(),re=a("ul"),be=a("li"),F=a("a"),at=l("Stable Diffusion Upscaler Demo"),Ze=c(),ce=a("p"),st=l("Available Checkpoints are:"),je=c(),pe=a("ul"),X=a("li"),_e=a("em"),ot=l("stabilityai/latent-upscaler"),it=l(": "),A=a("a"),lt=l("stabilityai/sd-x2-latent-upscaler"),Ge=c(),h=a("div"),U(z.$$.fragment),rt=c(),ye=a("p"),ct=l("Pipeline to upscale the resolution of Stable Diffusion output images by a factor of 2."),pt=c(),Y=a("p"),dt=l("This model inherits from "),de=a("a"),ft=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=c(),I=a("div"),U(q.$$.fragment),ht=c(),ve=a("p"),gt=l("Function invoked when calling the pipeline for generation."),bt=c(),U(j.$$.fragment),_t=c(),G=a("div"),U(Q.$$.fragment),yt=c(),H=a("p"),vt=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
`),we=a("code"),wt=l("torch.device('meta') and loaded to GPU only when their specific submodule has its "),Ut=l("forward` method called."),Jt=c(),P=a("div"),U(O.$$.fragment),Tt=c(),Ue=a("p"),$t=l("Enable sliced attention computation."),Mt=c(),Je=a("p"),xt=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=c(),W=a("div"),U(K.$$.fragment),Dt=c(),ee=a("p"),It=l("Disable sliced attention computation. If "),Te=a("code"),Pt=l("enable_attention_slicing"),St=l(` was previously invoked, this method will go
back to computing attention in one step.`),Lt=c(),w=a("div"),U(te.$$.fragment),Zt=c(),$e=a("p"),jt=l("Enable memory efficient attention as implemented in xformers."),Gt=c(),Me=a("p"),Wt=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.`),kt=c(),xe=a("p"),Ct=l(`Warning: When Memory Efficient Attention and Sliced attention are both enabled, the Memory Efficient Attention
is used.`),Bt=c(),U(k.$$.fragment),Vt=c(),C=a("div"),U(ne.$$.fragment),Rt=c(),Ee=a("p"),Nt=l("Disable memory efficient attention as implemented in xformers."),this.h()},l(t){const u=$n('[data-svelte="svelte-1phssyn"]',document.head);m=s(u,"META",{name:!0,content:!0}),u.forEach(n),E=p(t),b=s(t,"H1",{class:!0});var ae=o(b);f=s(ae,"A",{id:!0,class:!0,href:!0});var De=o(f);v=s(De,"SPAN",{});var Ft=o(v);J(i.$$.fragment,Ft),Ft.forEach(n),De.forEach(n),y=p(ae),me=s(ae,"SPAN",{});var Xt=o(me);Ae=r(Xt,"Stable Diffusion Latent Upscaler"),Xt.forEach(n),ae.forEach(n),Ie=p(t),L=s(t,"H2",{class:!0});var ke=o(L);Z=s(ke,"A",{id:!0,class:!0,href:!0});var At=o(Z);he=s(At,"SPAN",{});var zt=o(he);J(V.$$.fragment,zt),zt.forEach(n),At.forEach(n),ze=p(ke),ge=s(ke,"SPAN",{});var Yt=o(ge);Ye=r(Yt,"StableDiffusionLatentUpscalePipeline"),Yt.forEach(n),ke.forEach(n),Pe=p(t),D=s(t,"P",{});var B=o(D);qe=r(B,"The Stable Diffusion Latent Upscaler model was created by "),R=s(B,"A",{href:!0,rel:!0});var qt=o(R);Qe=r(qt,"Katherine Crowson"),qt.forEach(n),He=r(B," in collaboration with "),N=s(B,"A",{href:!0,rel:!0});var Qt=o(N);Oe=r(Qt,"Stability AI"),Qt.forEach(n),Ke=r(B,". It can be used on top of any "),ie=s(B,"A",{href:!0});var Ht=o(ie);et=r(Ht,"StableDiffusionUpscalePipeline"),Ht.forEach(n),tt=r(B," checkpoint to enhance its output image resolution by a factor of 2."),B.forEach(n),Se=p(t),le=s(t,"P",{});var Ot=o(le);nt=r(Ot,"A notebook that demonstrates the original implementation can be found here:"),Ot.forEach(n),Le=p(t),re=s(t,"UL",{});var Kt=o(re);be=s(Kt,"LI",{});var en=o(be);F=s(en,"A",{href:!0,rel:!0});var tn=o(F);at=r(tn,"Stable Diffusion Upscaler Demo"),tn.forEach(n),en.forEach(n),Kt.forEach(n),Ze=p(t),ce=s(t,"P",{});var nn=o(ce);st=r(nn,"Available Checkpoints are:"),nn.forEach(n),je=p(t),pe=s(t,"UL",{});var an=o(pe);X=s(an,"LI",{});var Ce=o(X);_e=s(Ce,"EM",{});var sn=o(_e);ot=r(sn,"stabilityai/latent-upscaler"),sn.forEach(n),it=r(Ce,": "),A=s(Ce,"A",{href:!0,rel:!0});var on=o(A);lt=r(on,"stabilityai/sd-x2-latent-upscaler"),on.forEach(n),Ce.forEach(n),an.forEach(n),Ge=p(t),h=s(t,"DIV",{class:!0});var _=o(h);J(z.$$.fragment,_),rt=p(_),ye=s(_,"P",{});var ln=o(ye);ct=r(ln,"Pipeline to upscale the resolution of Stable Diffusion output images by a factor of 2."),ln.forEach(n),pt=p(_),Y=s(_,"P",{});var Be=o(Y);dt=r(Be,"This model inherits from "),de=s(Be,"A",{href:!0});var rn=o(de);ft=r(rn,"DiffusionPipeline"),rn.forEach(n),ut=r(Be,`. 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.)`),Be.forEach(n),mt=p(_),I=s(_,"DIV",{class:!0});var fe=o(I);J(q.$$.fragment,fe),ht=p(fe),ve=s(fe,"P",{});var cn=o(ve);gt=r(cn,"Function invoked when calling the pipeline for generation."),cn.forEach(n),bt=p(fe),J(j.$$.fragment,fe),fe.forEach(n),_t=p(_),G=s(_,"DIV",{class:!0});var Ve=o(G);J(Q.$$.fragment,Ve),yt=p(Ve),H=s(Ve,"P",{});var Re=o(H);vt=r(Re,`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
`),we=s(Re,"CODE",{});var pn=o(we);wt=r(pn,"torch.device('meta') and loaded to GPU only when their specific submodule has its "),pn.forEach(n),Ut=r(Re,"forward` method called."),Re.forEach(n),Ve.forEach(n),Jt=p(_),P=s(_,"DIV",{class:!0});var ue=o(P);J(O.$$.fragment,ue),Tt=p(ue),Ue=s(ue,"P",{});var dn=o(Ue);$t=r(dn,"Enable sliced attention computation."),dn.forEach(n),Mt=p(ue),Je=s(ue,"P",{});var fn=o(Je);xt=r(fn,`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.`),fn.forEach(n),ue.forEach(n),Et=p(_),W=s(_,"DIV",{class:!0});var Ne=o(W);J(K.$$.fragment,Ne),Dt=p(Ne),ee=s(Ne,"P",{});var Fe=o(ee);It=r(Fe,"Disable sliced attention computation. If "),Te=s(Fe,"CODE",{});var un=o(Te);Pt=r(un,"enable_attention_slicing"),un.forEach(n),St=r(Fe,` was previously invoked, this method will go
back to computing attention in one step.`),Fe.forEach(n),Ne.forEach(n),Lt=p(_),w=s(_,"DIV",{class:!0});var S=o(w);J(te.$$.fragment,S),Zt=p(S),$e=s(S,"P",{});var mn=o($e);jt=r(mn,"Enable memory efficient attention as implemented in xformers."),mn.forEach(n),Gt=p(S),Me=s(S,"P",{});var hn=o(Me);Wt=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),kt=p(S),xe=s(S,"P",{});var gn=o(xe);Ct=r(gn,`Warning: When Memory Efficient Attention and Sliced attention are both enabled, the Memory Efficient Attention
is used.`),gn.forEach(n),Bt=p(S),J(k.$$.fragment,S),S.forEach(n),Vt=p(_),C=s(_,"DIV",{class:!0});var Xe=o(C);J(ne.$$.fragment,Xe),Rt=p(Xe),Ee=s(Xe,"P",{});var bn=o(Ee);Nt=r(bn,"Disable memory efficient attention as implemented in xformers."),bn.forEach(n),Xe.forEach(n),_.forEach(n),this.h()},h(){d(m,"name","hf:doc:metadata"),d(m,"content",JSON.stringify(In)),d(f,"id","stable-diffusion-latent-upscaler"),d(f,"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"),d(f,"href","#stable-diffusion-latent-upscaler"),d(b,"class","relative group"),d(Z,"id","diffusers.StableDiffusionLatentUpscalePipeline"),d(Z,"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"),d(Z,"href","#diffusers.StableDiffusionLatentUpscalePipeline"),d(L,"class","relative group"),d(R,"href","https://github.com/crowsonkb/k-diffusion"),d(R,"rel","nofollow"),d(N,"href","https://stability.ai/"),d(N,"rel","nofollow"),d(ie,"href","/docs/diffusers/v0.17.1/en/api/pipelines/stable_diffusion/upscale#diffusers.StableDiffusionUpscalePipeline"),d(F,"href","https://colab.research.google.com/drive/1o1qYJcFeywzCIdkfKJy7cTpgZTCM2EI4"),d(F,"rel","nofollow"),d(A,"href","https://huggingface.co/stabilityai/sd-x2-latent-upscaler"),d(A,"rel","nofollow"),d(de,"href","/docs/diffusers/v0.17.1/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),d(I,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(G,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(P,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(W,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(w,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(C,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(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,b,u),e(b,f),e(f,v),T(i,v,null),e(b,y),e(b,me),e(me,Ae),g(t,Ie,u),g(t,L,u),e(L,Z),e(Z,he),T(V,he,null),e(L,ze),e(L,ge),e(ge,Ye),g(t,Pe,u),g(t,D,u),e(D,qe),e(D,R),e(R,Qe),e(D,He),e(D,N),e(N,Oe),e(D,Ke),e(D,ie),e(ie,et),e(D,tt),g(t,Se,u),g(t,le,u),e(le,nt),g(t,Le,u),g(t,re,u),e(re,be),e(be,F),e(F,at),g(t,Ze,u),g(t,ce,u),e(ce,st),g(t,je,u),g(t,pe,u),e(pe,X),e(X,_e),e(_e,ot),e(X,it),e(X,A),e(A,lt),g(t,Ge,u),g(t,h,u),T(z,h,null),e(h,rt),e(h,ye),e(ye,ct),e(h,pt),e(h,Y),e(Y,dt),e(Y,de),e(de,ft),e(Y,ut),e(h,mt),e(h,I),T(q,I,null),e(I,ht),e(I,ve),e(ve,gt),e(I,bt),T(j,I,null),e(h,_t),e(h,G),T(Q,G,null),e(G,yt),e(G,H),e(H,vt),e(H,we),e(we,wt),e(H,Ut),e(h,Jt),e(h,P),T(O,P,null),e(P,Tt),e(P,Ue),e(Ue,$t),e(P,Mt),e(P,Je),e(Je,xt),e(h,Et),e(h,W),T(K,W,null),e(W,Dt),e(W,ee),e(ee,It),e(ee,Te),e(Te,Pt),e(ee,St),e(h,Lt),e(h,w),T(te,w,null),e(w,Zt),e(w,$e),e($e,jt),e(w,Gt),e(w,Me),e(Me,Wt),e(w,kt),e(w,xe),e(xe,Ct),e(w,Bt),T(k,w,null),e(h,Vt),e(h,C),T(ne,C,null),e(C,Rt),e(C,Ee),e(Ee,Nt),We=!0},p(t,[u]){const ae={};u&2&&(ae.$$scope={dirty:u,ctx:t}),j.$set(ae);const De={};u&2&&(De.$$scope={dirty:u,ctx:t}),k.$set(De)},i(t){We||($(i.$$.fragment,t),$(V.$$.fragment,t),$(z.$$.fragment,t),$(q.$$.fragment,t),$(j.$$.fragment,t),$(Q.$$.fragment,t),$(O.$$.fragment,t),$(K.$$.fragment,t),$(te.$$.fragment,t),$(k.$$.fragment,t),$(ne.$$.fragment,t),We=!0)},o(t){M(i.$$.fragment,t),M(V.$$.fragment,t),M(z.$$.fragment,t),M(q.$$.fragment,t),M(j.$$.fragment,t),M(Q.$$.fragment,t),M(O.$$.fragment,t),M(K.$$.fragment,t),M(te.$$.fragment,t),M(k.$$.fragment,t),M(ne.$$.fragment,t),We=!1},d(t){n(m),t&&n(E),t&&n(b),x(i),t&&n(Ie),t&&n(L),x(V),t&&n(Pe),t&&n(D),t&&n(Se),t&&n(le),t&&n(Le),t&&n(re),t&&n(Ze),t&&n(ce),t&&n(je),t&&n(pe),t&&n(Ge),t&&n(h),x(z),x(q),x(j),x(Q),x(O),x(K),x(te),x(k),x(ne)}}}const In={local:"stable-diffusion-latent-upscaler",sections:[{local:"diffusers.StableDiffusionLatentUpscalePipeline",title:"StableDiffusionLatentUpscalePipeline"}],title:"Stable Diffusion Latent Upscaler"};function Pn(oe){return Mn(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Wn extends Un{constructor(m){super();Jn(this,m,Pn,Dn,Tn,{})}}export{Wn as default,In as metadata};
