import{S as es,i as ts,s as ns,e as s,k as p,w as P,t as i,M as ss,c as a,d as n,m as c,a as o,x,h as r,b as f,G as e,g as _,y as D,q as S,o as E,B as k,v as as,L as Yn}from"../../../../chunks/vendor-hf-doc-builder.js";import{D as W}from"../../../../chunks/Docstring-hf-doc-builder.js";import{C as Zn}from"../../../../chunks/CodeBlock-hf-doc-builder.js";import{I as Qn}from"../../../../chunks/IconCopyLink-hf-doc-builder.js";import{E as Xn}from"../../../../chunks/ExampleCodeBlock-hf-doc-builder.js";function os(fe){let h,U,b,u,y;return u=new Zn({props:{code:`import requests
from PIL import Image
from io import BytesIO
from diffusers import StableDiffusionUpscalePipeline
import torch

# load model and scheduler
model_id = "stabilityai/stable-diffusion-x4-upscaler"
pipeline = StableDiffusionUpscalePipeline.from_pretrained(
    model_id, revision="fp16", torch_dtype=torch.float16
)
pipeline = pipeline.to("cuda")

# let's download an  image
url = "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd2-upscale/low_res_cat.png"
response = requests.get(url)
low_res_img = Image.open(BytesIO(response.content)).convert("RGB")
low_res_img = low_res_img.resize((128, 128))
prompt = "a white cat"

upscaled_image = pipeline(prompt=prompt, image=low_res_img).images[0]
upscaled_image.save("upsampled_cat.png")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> requests
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> io <span class="hljs-keyword">import</span> BytesIO
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionUpscalePipeline
<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-comment"># load model and scheduler</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model_id = <span class="hljs-string">&quot;stabilityai/stable-diffusion-x4-upscaler&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline = StableDiffusionUpscalePipeline.from_pretrained(
<span class="hljs-meta">... </span>    model_id, revision=<span class="hljs-string">&quot;fp16&quot;</span>, torch_dtype=torch.float16
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline = pipeline.to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># let&#x27;s download an  image</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>url = <span class="hljs-string">&quot;https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd2-upscale/low_res_cat.png&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>response = requests.get(url)
<span class="hljs-meta">&gt;&gt;&gt; </span>low_res_img = Image.<span class="hljs-built_in">open</span>(BytesIO(response.content)).convert(<span class="hljs-string">&quot;RGB&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>low_res_img = low_res_img.resize((<span class="hljs-number">128</span>, <span class="hljs-number">128</span>))
<span class="hljs-meta">&gt;&gt;&gt; </span>prompt = <span class="hljs-string">&quot;a white cat&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>upscaled_image = pipeline(prompt=prompt, image=low_res_img).images[<span class="hljs-number">0</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>upscaled_image.save(<span class="hljs-string">&quot;upsampled_cat.png&quot;</span>)`}}),{c(){h=s("p"),U=i("Examples:"),b=p(),P(u.$$.fragment)},l(l){h=a(l,"P",{});var v=o(h);U=r(v,"Examples:"),v.forEach(n),b=c(l),x(u.$$.fragment,l)},m(l,v){_(l,h,v),e(h,U),_(l,b,v),D(u,l,v),y=!0},p:Yn,i(l){y||(S(u.$$.fragment,l),y=!0)},o(l){E(u.$$.fragment,l),y=!1},d(l){l&&n(h),l&&n(b),k(u,l)}}}function is(fe){let h,U,b,u,y;return u=new Zn({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(){h=s("p"),U=i("Examples:"),b=p(),P(u.$$.fragment)},l(l){h=a(l,"P",{});var v=o(h);U=r(v,"Examples:"),v.forEach(n),b=c(l),x(u.$$.fragment,l)},m(l,v){_(l,h,v),e(h,U),_(l,b,v),D(u,l,v),y=!0},p:Yn,i(l){y||(S(u.$$.fragment,l),y=!0)},o(l){E(u.$$.fragment,l),y=!1},d(l){l&&n(h),l&&n(b),k(u,l)}}}function rs(fe){let h,U,b,u,y,l,v,ye,at,Fe,T,M,we,B,ot,$e,it,Ge,w,rt,R,lt,pt,K,ct,ft,H,dt,ut,de,mt,ht,ze,ue,gt,Ve,me,J,Pe,_t,bt,Q,vt,We,he,yt,Be,ge,X,xe,wt,$t,Y,Pt,Re,d,Z,xt,De,Dt,St,ee,Et,_e,kt,It,Ut,j,te,jt,Se,Ct,At,O,Lt,C,ne,qt,Ee,Tt,Mt,ke,Ot,Nt,N,se,Ft,ae,Gt,Ie,zt,Vt,Wt,$,oe,Bt,Ue,Rt,Kt,je,Ht,Jt,Ce,Qt,Xt,F,Yt,G,ie,Zt,Ae,en,tn,z,re,nn,I,sn,Le,an,on,qe,rn,ln,Te,pn,cn,Me,fn,dn,un,V,le,mn,pe,hn,Oe,gn,_n,Ke;return l=new Qn({}),B=new Qn({}),Z=new W({props:{name:"class diffusers.StableDiffusionUpscalePipeline",anchor:"diffusers.StableDiffusionUpscalePipeline",parameters:[{name:"vae",val:": AutoencoderKL"},{name:"text_encoder",val:": CLIPTextModel"},{name:"tokenizer",val:": CLIPTokenizer"},{name:"unet",val:": UNet2DConditionModel"},{name:"low_res_scheduler",val:": DDPMScheduler"},{name:"scheduler",val:": KarrasDiffusionSchedulers"},{name:"safety_checker",val:": typing.Optional[typing.Any] = None"},{name:"feature_extractor",val:": typing.Optional[transformers.models.clip.image_processing_clip.CLIPImageProcessor] = None"},{name:"watermarker",val:": typing.Optional[typing.Any] = None"},{name:"max_noise_level",val:": int = 350"}],parametersDescription:[{anchor:"diffusers.StableDiffusionUpscalePipeline.vae",description:`<strong>vae</strong> (<a href="/docs/diffusers/v0.16.0/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.StableDiffusionUpscalePipeline.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.StableDiffusionUpscalePipeline.tokenizer",description:`<strong>tokenizer</strong> (<code>CLIPTokenizer</code>) &#x2014;
Tokenizer of class
<a href="https://huggingface.co/docs/transformers/v4.21.0/en/model_doc/clip#transformers.CLIPTokenizer" rel="nofollow">CLIPTokenizer</a>.`,name:"tokenizer"},{anchor:"diffusers.StableDiffusionUpscalePipeline.unet",description:'<strong>unet</strong> (<a href="/docs/diffusers/v0.16.0/en/api/models#diffusers.UNet2DConditionModel">UNet2DConditionModel</a>) &#x2014; Conditional U-Net architecture to denoise the encoded image latents.',name:"unet"},{anchor:"diffusers.StableDiffusionUpscalePipeline.low_res_scheduler",description:`<strong>low_res_scheduler</strong> (<a href="/docs/diffusers/v0.16.0/en/api/schedulers/overview#diffusers.SchedulerMixin">SchedulerMixin</a>) &#x2014;
A scheduler used to add initial noise to the low res conditioning image. It must be an instance of
<a href="/docs/diffusers/v0.16.0/en/api/schedulers/ddpm#diffusers.DDPMScheduler">DDPMScheduler</a>.`,name:"low_res_scheduler"},{anchor:"diffusers.StableDiffusionUpscalePipeline.scheduler",description:`<strong>scheduler</strong> (<a href="/docs/diffusers/v0.16.0/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.16.0/en/api/schedulers/ddim#diffusers.DDIMScheduler">DDIMScheduler</a>, <a href="/docs/diffusers/v0.16.0/en/api/schedulers/lms_discrete#diffusers.LMSDiscreteScheduler">LMSDiscreteScheduler</a>, or <a href="/docs/diffusers/v0.16.0/en/api/schedulers/pndm#diffusers.PNDMScheduler">PNDMScheduler</a>.`,name:"scheduler"}],source:"https://github.com/huggingface/diffusers/blob/v0.16.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py#L56"}}),te=new W({props:{name:"__call__",anchor:"diffusers.StableDiffusionUpscalePipeline.__call__",parameters:[{name:"prompt",val:": typing.Union[str, typing.List[str]] = None"},{name:"image",val:": typing.Union[torch.FloatTensor, PIL.Image.Image, typing.List[PIL.Image.Image]] = None"},{name:"num_inference_steps",val:": int = 75"},{name:"guidance_scale",val:": float = 9.0"},{name:"noise_level",val:": int = 20"},{name:"negative_prompt",val:": typing.Union[str, typing.List[str], NoneType] = None"},{name:"num_images_per_prompt",val:": typing.Optional[int] = 1"},{name:"eta",val:": float = 0.0"},{name:"generator",val:": typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None"},{name:"latents",val:": typing.Optional[torch.FloatTensor] = None"},{name:"prompt_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"negative_prompt_embeds",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.StableDiffusionUpscalePipeline.__call__.prompt",description:`<strong>prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
The prompt or prompts to guide the image generation. If not defined, one has to pass <code>prompt_embeds</code>.
instead.`,name:"prompt"},{anchor:"diffusers.StableDiffusionUpscalePipeline.__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. *`,name:"image"},{anchor:"diffusers.StableDiffusionUpscalePipeline.__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.StableDiffusionUpscalePipeline.__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.StableDiffusionUpscalePipeline.__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. If not defined, one has to pass
<code>negative_prompt_embeds</code>. instead. Ignored when not using guidance (i.e., ignored if <code>guidance_scale</code>
is less than <code>1</code>).`,name:"negative_prompt"},{anchor:"diffusers.StableDiffusionUpscalePipeline.__call__.num_images_per_prompt",description:`<strong>num_images_per_prompt</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The number of images to generate per prompt.`,name:"num_images_per_prompt"},{anchor:"diffusers.StableDiffusionUpscalePipeline.__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.16.0/en/api/schedulers/ddim#diffusers.DDIMScheduler">schedulers.DDIMScheduler</a>, will be ignored for others.`,name:"eta"},{anchor:"diffusers.StableDiffusionUpscalePipeline.__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.StableDiffusionUpscalePipeline.__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.StableDiffusionUpscalePipeline.__call__.prompt_embeds",description:`<strong>prompt_embeds</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated text embeddings. Can be used to easily tweak text inputs, <em>e.g.</em> prompt weighting. If not
provided, text embeddings will be generated from <code>prompt</code> input argument.`,name:"prompt_embeds"},{anchor:"diffusers.StableDiffusionUpscalePipeline.__call__.negative_prompt_embeds",description:`<strong>negative_prompt_embeds</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated negative text embeddings. Can be used to easily tweak text inputs, <em>e.g.</em> prompt
weighting. If not provided, negative_prompt_embeds will be generated from <code>negative_prompt</code> input
argument.`,name:"negative_prompt_embeds"},{anchor:"diffusers.StableDiffusionUpscalePipeline.__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.StableDiffusionUpscalePipeline.__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.16.0/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput">StableDiffusionPipelineOutput</a> instead of a
plain tuple.`,name:"return_dict"},{anchor:"diffusers.StableDiffusionUpscalePipeline.__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.StableDiffusionUpscalePipeline.__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.16.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py#L476",returnDescription:`
<p><a
  href="/docs/diffusers/v0.16.0/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.16.0/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> or <code>tuple</code></p>
`}}),O=new Xn({props:{anchor:"diffusers.StableDiffusionUpscalePipeline.__call__.example",$$slots:{default:[os]},$$scope:{ctx:fe}}}),ne=new W({props:{name:"enable_attention_slicing",anchor:"diffusers.StableDiffusionUpscalePipeline.enable_attention_slicing",parameters:[{name:"slice_size",val:": typing.Union[str, int, NoneType] = 'auto'"}],parametersDescription:[{anchor:"diffusers.StableDiffusionUpscalePipeline.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.16.0/src/diffusers/pipelines/pipeline_utils.py#L1476"}}),se=new W({props:{name:"disable_attention_slicing",anchor:"diffusers.StableDiffusionUpscalePipeline.disable_attention_slicing",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.16.0/src/diffusers/pipelines/pipeline_utils.py#L1492"}}),oe=new W({props:{name:"enable_xformers_memory_efficient_attention",anchor:"diffusers.StableDiffusionUpscalePipeline.enable_xformers_memory_efficient_attention",parameters:[{name:"attention_op",val:": typing.Optional[typing.Callable] = None"}],parametersDescription:[{anchor:"diffusers.StableDiffusionUpscalePipeline.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.16.0/src/diffusers/pipelines/pipeline_utils.py#L1418"}}),F=new Xn({props:{anchor:"diffusers.StableDiffusionUpscalePipeline.enable_xformers_memory_efficient_attention.example",$$slots:{default:[is]},$$scope:{ctx:fe}}}),ie=new W({props:{name:"disable_xformers_memory_efficient_attention",anchor:"diffusers.StableDiffusionUpscalePipeline.disable_xformers_memory_efficient_attention",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.16.0/src/diffusers/pipelines/pipeline_utils.py#L1450"}}),re=new W({props:{name:"enable_model_cpu_offload",anchor:"diffusers.StableDiffusionUpscalePipeline.enable_model_cpu_offload",parameters:[{name:"gpu_id",val:" = 0"}],source:"https://github.com/huggingface/diffusers/blob/v0.16.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py#L146"}}),le=new W({props:{name:"enable_sequential_cpu_offload",anchor:"diffusers.StableDiffusionUpscalePipeline.enable_sequential_cpu_offload",parameters:[{name:"gpu_id",val:" = 0"}],source:"https://github.com/huggingface/diffusers/blob/v0.16.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py#L129"}}),{c(){h=s("meta"),U=p(),b=s("h1"),u=s("a"),y=s("span"),P(l.$$.fragment),v=p(),ye=s("span"),at=i("Super-Resolution"),Fe=p(),T=s("h2"),M=s("a"),we=s("span"),P(B.$$.fragment),ot=p(),$e=s("span"),it=i("StableDiffusionUpscalePipeline"),Ge=p(),w=s("p"),rt=i("The upscaler diffusion model was created by the researchers and engineers from "),R=s("a"),lt=i("CompVis"),pt=i(", "),K=s("a"),ct=i("Stability AI"),ft=i(", and "),H=s("a"),dt=i("LAION"),ut=i(", as part of Stable Diffusion 2.0. "),de=s("a"),mt=i("StableDiffusionUpscalePipeline"),ht=i(" can be used to enhance the resolution of input images by a factor of 4."),ze=p(),ue=s("p"),gt=i("The original codebase can be found here:"),Ve=p(),me=s("ul"),J=s("li"),Pe=s("em"),_t=i("Stable Diffusion v2"),bt=i(": "),Q=s("a"),vt=i("Stability-AI/stablediffusion"),We=p(),he=s("p"),yt=i("Available Checkpoints are:"),Be=p(),ge=s("ul"),X=s("li"),xe=s("em"),wt=i("stabilityai/stable-diffusion-x4-upscaler (x4 resolution resolution)"),$t=i(": "),Y=s("a"),Pt=i("stable-diffusion-x4-upscaler"),Re=p(),d=s("div"),P(Z.$$.fragment),xt=p(),De=s("p"),Dt=i("Pipeline for text-guided image super-resolution using Stable Diffusion 2."),St=p(),ee=s("p"),Et=i("This model inherits from "),_e=s("a"),kt=i("DiffusionPipeline"),It=i(`. 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.)`),Ut=p(),j=s("div"),P(te.$$.fragment),jt=p(),Se=s("p"),Ct=i("Function invoked when calling the pipeline for generation."),At=p(),P(O.$$.fragment),Lt=p(),C=s("div"),P(ne.$$.fragment),qt=p(),Ee=s("p"),Tt=i("Enable sliced attention computation."),Mt=p(),ke=s("p"),Ot=i(`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.`),Nt=p(),N=s("div"),P(se.$$.fragment),Ft=p(),ae=s("p"),Gt=i("Disable sliced attention computation. If "),Ie=s("code"),zt=i("enable_attention_slicing"),Vt=i(` was previously invoked, this method will go
back to computing attention in one step.`),Wt=p(),$=s("div"),P(oe.$$.fragment),Bt=p(),Ue=s("p"),Rt=i("Enable memory efficient attention as implemented in xformers."),Kt=p(),je=s("p"),Ht=i(`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.`),Jt=p(),Ce=s("p"),Qt=i(`Warning: When Memory Efficient Attention and Sliced attention are both enabled, the Memory Efficient Attention
is used.`),Xt=p(),P(F.$$.fragment),Yt=p(),G=s("div"),P(ie.$$.fragment),Zt=p(),Ae=s("p"),en=i("Disable memory efficient attention as implemented in xformers."),tn=p(),z=s("div"),P(re.$$.fragment),nn=p(),I=s("p"),sn=i(`Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared
to `),Le=s("code"),an=i("enable_sequential_cpu_offload"),on=i(", this method moves one whole model at a time to the GPU when its "),qe=s("code"),rn=i("forward"),ln=i(`
method is called, and the model remains in GPU until the next model runs. Memory savings are lower than with
`),Te=s("code"),pn=i("enable_sequential_cpu_offload"),cn=i(", but performance is much better due to the iterative execution of the "),Me=s("code"),fn=i("unet"),dn=i("."),un=p(),V=s("div"),P(le.$$.fragment),mn=p(),pe=s("p"),hn=i(`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
`),Oe=s("code"),gn=i("torch.device('meta') and loaded to GPU only when their specific submodule has its "),_n=i("forward` method called."),this.h()},l(t){const m=ss('[data-svelte="svelte-1phssyn"]',document.head);h=a(m,"META",{name:!0,content:!0}),m.forEach(n),U=c(t),b=a(t,"H1",{class:!0});var ce=o(b);u=a(ce,"A",{id:!0,class:!0,href:!0});var Ne=o(u);y=a(Ne,"SPAN",{});var bn=o(y);x(l.$$.fragment,bn),bn.forEach(n),Ne.forEach(n),v=c(ce),ye=a(ce,"SPAN",{});var vn=o(ye);at=r(vn,"Super-Resolution"),vn.forEach(n),ce.forEach(n),Fe=c(t),T=a(t,"H2",{class:!0});var He=o(T);M=a(He,"A",{id:!0,class:!0,href:!0});var yn=o(M);we=a(yn,"SPAN",{});var wn=o(we);x(B.$$.fragment,wn),wn.forEach(n),yn.forEach(n),ot=c(He),$e=a(He,"SPAN",{});var $n=o($e);it=r($n,"StableDiffusionUpscalePipeline"),$n.forEach(n),He.forEach(n),Ge=c(t),w=a(t,"P",{});var A=o(w);rt=r(A,"The upscaler diffusion model was created by the researchers and engineers from "),R=a(A,"A",{href:!0,rel:!0});var Pn=o(R);lt=r(Pn,"CompVis"),Pn.forEach(n),pt=r(A,", "),K=a(A,"A",{href:!0,rel:!0});var xn=o(K);ct=r(xn,"Stability AI"),xn.forEach(n),ft=r(A,", and "),H=a(A,"A",{href:!0,rel:!0});var Dn=o(H);dt=r(Dn,"LAION"),Dn.forEach(n),ut=r(A,", as part of Stable Diffusion 2.0. "),de=a(A,"A",{href:!0});var Sn=o(de);mt=r(Sn,"StableDiffusionUpscalePipeline"),Sn.forEach(n),ht=r(A," can be used to enhance the resolution of input images by a factor of 4."),A.forEach(n),ze=c(t),ue=a(t,"P",{});var En=o(ue);gt=r(En,"The original codebase can be found here:"),En.forEach(n),Ve=c(t),me=a(t,"UL",{});var kn=o(me);J=a(kn,"LI",{});var Je=o(J);Pe=a(Je,"EM",{});var In=o(Pe);_t=r(In,"Stable Diffusion v2"),In.forEach(n),bt=r(Je,": "),Q=a(Je,"A",{href:!0,rel:!0});var Un=o(Q);vt=r(Un,"Stability-AI/stablediffusion"),Un.forEach(n),Je.forEach(n),kn.forEach(n),We=c(t),he=a(t,"P",{});var jn=o(he);yt=r(jn,"Available Checkpoints are:"),jn.forEach(n),Be=c(t),ge=a(t,"UL",{});var Cn=o(ge);X=a(Cn,"LI",{});var Qe=o(X);xe=a(Qe,"EM",{});var An=o(xe);wt=r(An,"stabilityai/stable-diffusion-x4-upscaler (x4 resolution resolution)"),An.forEach(n),$t=r(Qe,": "),Y=a(Qe,"A",{href:!0,rel:!0});var Ln=o(Y);Pt=r(Ln,"stable-diffusion-x4-upscaler"),Ln.forEach(n),Qe.forEach(n),Cn.forEach(n),Re=c(t),d=a(t,"DIV",{class:!0});var g=o(d);x(Z.$$.fragment,g),xt=c(g),De=a(g,"P",{});var qn=o(De);Dt=r(qn,"Pipeline for text-guided image super-resolution using Stable Diffusion 2."),qn.forEach(n),St=c(g),ee=a(g,"P",{});var Xe=o(ee);Et=r(Xe,"This model inherits from "),_e=a(Xe,"A",{href:!0});var Tn=o(_e);kt=r(Tn,"DiffusionPipeline"),Tn.forEach(n),It=r(Xe,`. 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.)`),Xe.forEach(n),Ut=c(g),j=a(g,"DIV",{class:!0});var be=o(j);x(te.$$.fragment,be),jt=c(be),Se=a(be,"P",{});var Mn=o(Se);Ct=r(Mn,"Function invoked when calling the pipeline for generation."),Mn.forEach(n),At=c(be),x(O.$$.fragment,be),be.forEach(n),Lt=c(g),C=a(g,"DIV",{class:!0});var ve=o(C);x(ne.$$.fragment,ve),qt=c(ve),Ee=a(ve,"P",{});var On=o(Ee);Tt=r(On,"Enable sliced attention computation."),On.forEach(n),Mt=c(ve),ke=a(ve,"P",{});var Nn=o(ke);Ot=r(Nn,`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.`),Nn.forEach(n),ve.forEach(n),Nt=c(g),N=a(g,"DIV",{class:!0});var Ye=o(N);x(se.$$.fragment,Ye),Ft=c(Ye),ae=a(Ye,"P",{});var Ze=o(ae);Gt=r(Ze,"Disable sliced attention computation. If "),Ie=a(Ze,"CODE",{});var Fn=o(Ie);zt=r(Fn,"enable_attention_slicing"),Fn.forEach(n),Vt=r(Ze,` was previously invoked, this method will go
back to computing attention in one step.`),Ze.forEach(n),Ye.forEach(n),Wt=c(g),$=a(g,"DIV",{class:!0});var L=o($);x(oe.$$.fragment,L),Bt=c(L),Ue=a(L,"P",{});var Gn=o(Ue);Rt=r(Gn,"Enable memory efficient attention as implemented in xformers."),Gn.forEach(n),Kt=c(L),je=a(L,"P",{});var zn=o(je);Ht=r(zn,`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.`),zn.forEach(n),Jt=c(L),Ce=a(L,"P",{});var Vn=o(Ce);Qt=r(Vn,`Warning: When Memory Efficient Attention and Sliced attention are both enabled, the Memory Efficient Attention
is used.`),Vn.forEach(n),Xt=c(L),x(F.$$.fragment,L),L.forEach(n),Yt=c(g),G=a(g,"DIV",{class:!0});var et=o(G);x(ie.$$.fragment,et),Zt=c(et),Ae=a(et,"P",{});var Wn=o(Ae);en=r(Wn,"Disable memory efficient attention as implemented in xformers."),Wn.forEach(n),et.forEach(n),tn=c(g),z=a(g,"DIV",{class:!0});var tt=o(z);x(re.$$.fragment,tt),nn=c(tt),I=a(tt,"P",{});var q=o(I);sn=r(q,`Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared
to `),Le=a(q,"CODE",{});var Bn=o(Le);an=r(Bn,"enable_sequential_cpu_offload"),Bn.forEach(n),on=r(q,", this method moves one whole model at a time to the GPU when its "),qe=a(q,"CODE",{});var Rn=o(qe);rn=r(Rn,"forward"),Rn.forEach(n),ln=r(q,`
method is called, and the model remains in GPU until the next model runs. Memory savings are lower than with
`),Te=a(q,"CODE",{});var Kn=o(Te);pn=r(Kn,"enable_sequential_cpu_offload"),Kn.forEach(n),cn=r(q,", but performance is much better due to the iterative execution of the "),Me=a(q,"CODE",{});var Hn=o(Me);fn=r(Hn,"unet"),Hn.forEach(n),dn=r(q,"."),q.forEach(n),tt.forEach(n),un=c(g),V=a(g,"DIV",{class:!0});var nt=o(V);x(le.$$.fragment,nt),mn=c(nt),pe=a(nt,"P",{});var st=o(pe);hn=r(st,`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
`),Oe=a(st,"CODE",{});var Jn=o(Oe);gn=r(Jn,"torch.device('meta') and loaded to GPU only when their specific submodule has its "),Jn.forEach(n),_n=r(st,"forward` method called."),st.forEach(n),nt.forEach(n),g.forEach(n),this.h()},h(){f(h,"name","hf:doc:metadata"),f(h,"content",JSON.stringify(ls)),f(u,"id","superresolution"),f(u,"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(u,"href","#superresolution"),f(b,"class","relative group"),f(M,"id","diffusers.StableDiffusionUpscalePipeline"),f(M,"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(M,"href","#diffusers.StableDiffusionUpscalePipeline"),f(T,"class","relative group"),f(R,"href","https://github.com/CompVis"),f(R,"rel","nofollow"),f(K,"href","https://stability.ai/"),f(K,"rel","nofollow"),f(H,"href","https://laion.ai/"),f(H,"rel","nofollow"),f(de,"href","/docs/diffusers/v0.16.0/en/api/pipelines/stable_diffusion/upscale#diffusers.StableDiffusionUpscalePipeline"),f(Q,"href","https://github.com/Stability-AI/stablediffusion#image-upscaling-with-stable-diffusion"),f(Q,"rel","nofollow"),f(Y,"href","https://huggingface.co/stabilityai/stable-diffusion-x4-upscaler"),f(Y,"rel","nofollow"),f(_e,"href","/docs/diffusers/v0.16.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),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(C,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),f(N,"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(G,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),f(z,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),f(V,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),f(d,"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,m){e(document.head,h),_(t,U,m),_(t,b,m),e(b,u),e(u,y),D(l,y,null),e(b,v),e(b,ye),e(ye,at),_(t,Fe,m),_(t,T,m),e(T,M),e(M,we),D(B,we,null),e(T,ot),e(T,$e),e($e,it),_(t,Ge,m),_(t,w,m),e(w,rt),e(w,R),e(R,lt),e(w,pt),e(w,K),e(K,ct),e(w,ft),e(w,H),e(H,dt),e(w,ut),e(w,de),e(de,mt),e(w,ht),_(t,ze,m),_(t,ue,m),e(ue,gt),_(t,Ve,m),_(t,me,m),e(me,J),e(J,Pe),e(Pe,_t),e(J,bt),e(J,Q),e(Q,vt),_(t,We,m),_(t,he,m),e(he,yt),_(t,Be,m),_(t,ge,m),e(ge,X),e(X,xe),e(xe,wt),e(X,$t),e(X,Y),e(Y,Pt),_(t,Re,m),_(t,d,m),D(Z,d,null),e(d,xt),e(d,De),e(De,Dt),e(d,St),e(d,ee),e(ee,Et),e(ee,_e),e(_e,kt),e(ee,It),e(d,Ut),e(d,j),D(te,j,null),e(j,jt),e(j,Se),e(Se,Ct),e(j,At),D(O,j,null),e(d,Lt),e(d,C),D(ne,C,null),e(C,qt),e(C,Ee),e(Ee,Tt),e(C,Mt),e(C,ke),e(ke,Ot),e(d,Nt),e(d,N),D(se,N,null),e(N,Ft),e(N,ae),e(ae,Gt),e(ae,Ie),e(Ie,zt),e(ae,Vt),e(d,Wt),e(d,$),D(oe,$,null),e($,Bt),e($,Ue),e(Ue,Rt),e($,Kt),e($,je),e(je,Ht),e($,Jt),e($,Ce),e(Ce,Qt),e($,Xt),D(F,$,null),e(d,Yt),e(d,G),D(ie,G,null),e(G,Zt),e(G,Ae),e(Ae,en),e(d,tn),e(d,z),D(re,z,null),e(z,nn),e(z,I),e(I,sn),e(I,Le),e(Le,an),e(I,on),e(I,qe),e(qe,rn),e(I,ln),e(I,Te),e(Te,pn),e(I,cn),e(I,Me),e(Me,fn),e(I,dn),e(d,un),e(d,V),D(le,V,null),e(V,mn),e(V,pe),e(pe,hn),e(pe,Oe),e(Oe,gn),e(pe,_n),Ke=!0},p(t,[m]){const ce={};m&2&&(ce.$$scope={dirty:m,ctx:t}),O.$set(ce);const Ne={};m&2&&(Ne.$$scope={dirty:m,ctx:t}),F.$set(Ne)},i(t){Ke||(S(l.$$.fragment,t),S(B.$$.fragment,t),S(Z.$$.fragment,t),S(te.$$.fragment,t),S(O.$$.fragment,t),S(ne.$$.fragment,t),S(se.$$.fragment,t),S(oe.$$.fragment,t),S(F.$$.fragment,t),S(ie.$$.fragment,t),S(re.$$.fragment,t),S(le.$$.fragment,t),Ke=!0)},o(t){E(l.$$.fragment,t),E(B.$$.fragment,t),E(Z.$$.fragment,t),E(te.$$.fragment,t),E(O.$$.fragment,t),E(ne.$$.fragment,t),E(se.$$.fragment,t),E(oe.$$.fragment,t),E(F.$$.fragment,t),E(ie.$$.fragment,t),E(re.$$.fragment,t),E(le.$$.fragment,t),Ke=!1},d(t){n(h),t&&n(U),t&&n(b),k(l),t&&n(Fe),t&&n(T),k(B),t&&n(Ge),t&&n(w),t&&n(ze),t&&n(ue),t&&n(Ve),t&&n(me),t&&n(We),t&&n(he),t&&n(Be),t&&n(ge),t&&n(Re),t&&n(d),k(Z),k(te),k(O),k(ne),k(se),k(oe),k(F),k(ie),k(re),k(le)}}}const ls={local:"superresolution",sections:[{local:"diffusers.StableDiffusionUpscalePipeline",title:"StableDiffusionUpscalePipeline"}],title:"Super-Resolution"};function ps(fe){return as(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class hs extends es{constructor(h){super();ts(this,h,ps,rs,ns,{})}}export{hs as default,ls as metadata};
