import{s as Ta,o as Ua,n as v}from"../chunks/scheduler.8c3d61f6.js";import{S as ga,i as Za,g as o,s as t,r as c,A as _a,h as r,f as l,c as i,j as ba,u as d,x as m,k as wa,y as xa,a as n,v as f,d as u,t as M,w as y}from"../chunks/index.da70eac4.js";import{T as C}from"../chunks/Tip.1d9b8c37.js";import{C as U}from"../chunks/CodeBlock.a9c4becf.js";import{H as I,E as Ia}from"../chunks/getInferenceSnippets.a8672208.js";import{H as Ga,a as ja}from"../chunks/HfOption.6ab18950.js";function va(T){let a,b="Keep in mind these techniques may need to be adjusted depending on the model. For example, a transformer-based diffusion model may not benefit equally from these memory optimizations as a UNet-based model.";return{c(){a=o("p"),a.textContent=b},l(p){a=r(p,"P",{"data-svelte-h":!0}),m(a)!=="svelte-1wzvfzx"&&(a.textContent=b)},m(p,h){n(p,a,h)},p:v,d(p){p&&l(a)}}}function Ca(T){let a,b="Device placement is an experimental feature and the API may change. Only the <code>balanced</code> strategy is supported at the moment. We plan to support additional mapping strategies in the future.";return{c(){a=o("p"),a.innerHTML=b},l(p){a=r(p,"P",{"data-svelte-h":!0}),m(a)!=="svelte-1tuq9h4"&&(a.innerHTML=b)},m(p,h){n(p,a,h)},p:v,d(p){p&&l(a)}}}function Wa(T){let a,b="The <code>balanced</code> device placement strategy evenly splits the pipeline across all available devices.",p,h,w,j,g="You can inspect a pipeline’s device map with <code>hf_device_map</code>.",G,Z,x;return h=new U({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwQXV0b01vZGVsJTJDJTIwU3RhYmxlRGlmZnVzaW9uWExQaXBlbGluZSUwQSUwQXBpcGVsaW5lJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uWExQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIyc3RhYmlsaXR5YWklMkZzdGFibGUtZGlmZnVzaW9uLXhsLWJhc2UtMS4wJTIyJTJDJTBBJTIwJTIwJTIwJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTJDJTBBJTIwJTIwJTIwJTIwZGV2aWNlX21hcCUzRCUyMmJhbGFuY2VkJTIyJTBBKQ==",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> AutoModel, StableDiffusionXLPipeline

pipeline = StableDiffusionXLPipeline.from_pretrained(
    <span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>,
    torch_dtype=torch.float16,
    device_map=<span class="hljs-string">&quot;balanced&quot;</span>
)`,wrap:!1}}),Z=new U({props:{code:"cHJpbnQocGlwZWxpbmUuaGZfZGV2aWNlX21hcCklMEElN0IndW5ldCclM0ElMjAxJTJDJTIwJ3ZhZSclM0ElMjAxJTJDJTIwJ3NhZmV0eV9jaGVja2VyJyUzQSUyMDAlMkMlMjAndGV4dF9lbmNvZGVyJyUzQSUyMDAlN0Q=",highlighted:`<span class="hljs-built_in">print</span>(pipeline.hf_device_map)
{<span class="hljs-string">&#x27;unet&#x27;</span>: <span class="hljs-number">1</span>, <span class="hljs-string">&#x27;vae&#x27;</span>: <span class="hljs-number">1</span>, <span class="hljs-string">&#x27;safety_checker&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;text_encoder&#x27;</span>: <span class="hljs-number">0</span>}`,wrap:!1}}),{c(){a=o("p"),a.innerHTML=b,p=t(),c(h.$$.fragment),w=t(),j=o("p"),j.innerHTML=g,G=t(),c(Z.$$.fragment)},l(J){a=r(J,"P",{"data-svelte-h":!0}),m(a)!=="svelte-13intml"&&(a.innerHTML=b),p=i(J),d(h.$$.fragment,J),w=i(J),j=r(J,"P",{"data-svelte-h":!0}),m(j)!=="svelte-cfrzyx"&&(j.innerHTML=g),G=i(J),d(Z.$$.fragment,J)},m(J,_){n(J,a,_),n(J,p,_),f(h,J,_),n(J,w,_),n(J,j,_),n(J,G,_),f(Z,J,_),x=!0},p:v,i(J){x||(u(h.$$.fragment,J),u(Z.$$.fragment,J),x=!0)},o(J){M(h.$$.fragment,J),M(Z.$$.fragment,J),x=!1},d(J){J&&(l(a),l(p),l(w),l(j),l(G)),y(h,J),y(Z,J)}}}function ka(T){let a,b='The <code>device_map</code> is useful for loading large models, such as the Flux diffusion transformer which has 12.5B parameters. Set it to <code>&quot;auto&quot;</code> to automatically distribute a model across the fastest device first before moving to slower devices. Refer to the <a href="../training/distributed_inference#model-sharding">Model sharding</a> docs for more details.',p,h,w,j,g="You can inspect a model’s device map with <code>hf_device_map</code>.",G,Z,x;return h=new U({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwQXV0b01vZGVsJTBBJTBBdHJhbnNmb3JtZXIlMjAlM0QlMjBBdXRvTW9kZWwuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMmJsYWNrLWZvcmVzdC1sYWJzJTJGRkxVWC4xLWRldiUyMiUyQyUyMCUwQSUyMCUyMCUyMCUyMHN1YmZvbGRlciUzRCUyMnRyYW5zZm9ybWVyJTIyJTJDJTBBJTIwJTIwJTIwJTIwZGV2aWNlX21hcCUzRCUyMmF1dG8lMjIlMkMlMEElMjAlMjAlMjAlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmJmbG9hdDE2JTBBKQ==",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> AutoModel

transformer = AutoModel.from_pretrained(
    <span class="hljs-string">&quot;black-forest-labs/FLUX.1-dev&quot;</span>, 
    subfolder=<span class="hljs-string">&quot;transformer&quot;</span>,
    device_map=<span class="hljs-string">&quot;auto&quot;</span>,
    torch_dtype=torch.bfloat16
)`,wrap:!1}}),Z=new U({props:{code:"cHJpbnQodHJhbnNmb3JtZXIuaGZfZGV2aWNlX21hcCk=",highlighted:'<span class="hljs-built_in">print</span>(transformer.hf_device_map)',wrap:!1}}),{c(){a=o("p"),a.innerHTML=b,p=t(),c(h.$$.fragment),w=t(),j=o("p"),j.innerHTML=g,G=t(),c(Z.$$.fragment)},l(J){a=r(J,"P",{"data-svelte-h":!0}),m(a)!=="svelte-djqsxo"&&(a.innerHTML=b),p=i(J),d(h.$$.fragment,J),w=i(J),j=r(J,"P",{"data-svelte-h":!0}),m(j)!=="svelte-af1u4w"&&(j.innerHTML=g),G=i(J),d(Z.$$.fragment,J)},m(J,_){n(J,a,_),n(J,p,_),f(h,J,_),n(J,w,_),n(J,j,_),n(J,G,_),f(Z,J,_),x=!0},p:v,i(J){x||(u(h.$$.fragment,J),u(Z.$$.fragment,J),x=!0)},o(J){M(h.$$.fragment,J),M(Z.$$.fragment,J),x=!1},d(J){J&&(l(a),l(p),l(w),l(j),l(G)),y(h,J),y(Z,J)}}}function Va(T){let a,b,p,h;return a=new ja({props:{id:"device-map",option:"pipeline level",$$slots:{default:[Wa]},$$scope:{ctx:T}}}),p=new ja({props:{id:"device-map",option:"model level",$$slots:{default:[ka]},$$scope:{ctx:T}}}),{c(){c(a.$$.fragment),b=t(),c(p.$$.fragment)},l(w){d(a.$$.fragment,w),b=i(w),d(p.$$.fragment,w)},m(w,j){f(a,w,j),n(w,b,j),f(p,w,j),h=!0},p(w,j){const g={};j&2&&(g.$$scope={dirty:j,ctx:w}),a.$set(g);const G={};j&2&&(G.$$scope={dirty:j,ctx:w}),p.$set(G)},i(w){h||(u(a.$$.fragment,w),u(p.$$.fragment,w),h=!0)},o(w){M(a.$$.fragment,w),M(p.$$.fragment,w),h=!1},d(w){w&&l(b),y(a,w),y(p,w)}}}function Ba(T){let a,b='The <a href="/docs/diffusers/main/en/api/models/autoencoder_kl_wan#diffusers.AutoencoderKLWan">AutoencoderKLWan</a> and <a href="/docs/diffusers/main/en/api/models/asymmetricautoencoderkl#diffusers.AsymmetricAutoencoderKL">AsymmetricAutoencoderKL</a> classes don’t support slicing.';return{c(){a=o("p"),a.innerHTML=b},l(p){a=r(p,"P",{"data-svelte-h":!0}),m(a)!=="svelte-ouja0u"&&(a.innerHTML=b)},m(p,h){n(p,a,h)},p:v,d(p){p&&l(a)}}}function $a(T){let a,b='Don’t move the pipeline to CUDA before calling <a href="/docs/diffusers/main/en/api/pipelines/overview#diffusers.DiffusionPipeline.enable_sequential_cpu_offload">enable_sequential_cpu_offload()</a>, otherwise the amount of memory saved is only minimal (refer to this <a href="https://github.com/huggingface/diffusers/issues/1934" rel="nofollow">issue</a> for more details). This is a stateful operation that installs hooks on the model.';return{c(){a=o("p"),a.innerHTML=b},l(p){a=r(p,"P",{"data-svelte-h":!0}),m(a)!=="svelte-1d1bxgj"&&(a.innerHTML=b)},m(p,h){n(p,a,h)},p:v,d(p){p&&l(a)}}}function Xa(T){let a,b='Keep in mind that if models are reused outside the pipeline after hookes have been installed (see <a href="https://huggingface.co/docs/accelerate/en/package_reference/big_modeling#accelerate.hooks.remove_hook_from_module" rel="nofollow">Removing Hooks</a> for more details), you need to run the entire pipeline and models in the expected order to properly offload them. This is a stateful operation that installs hooks on the model.';return{c(){a=o("p"),a.innerHTML=b},l(p){a=r(p,"P",{"data-svelte-h":!0}),m(a)!=="svelte-fx1eup"&&(a.innerHTML=b)},m(p,h){n(p,a,h)},p:v,d(p){p&&l(a)}}}function Na(T){let a,b="Group offloading may not work with all models if the forward implementation contains weight-dependent device casting of inputs because it may clash with group offloading’s device casting mechanism.";return{c(){a=o("p"),a.textContent=b},l(p){a=r(p,"P",{"data-svelte-h":!0}),m(a)!=="svelte-78t6ea"&&(a.textContent=b)},m(p,h){n(p,a,h)},p:v,d(p){p&&l(a)}}}function Ya(T){let a,b="When <code>use_stream=True</code> on VAEs with tiling enabled, make sure to do a dummy forward pass (possible with dummy inputs as well) before inference to avoid device mismatch errors. This may not work on all implementations, so feel free to open an issue if you encounter any problems.";return{c(){a=o("p"),a.innerHTML=b},l(p){a=r(p,"P",{"data-svelte-h":!0}),m(a)!=="svelte-1j8tvtw"&&(a.innerHTML=b)},m(p,h){n(p,a,h)},p:v,d(p){p&&l(a)}}}function za(T){let a,b='Combine layerwise casting with <a href="#group-offloading">group offloading</a> for even more memory savings.';return{c(){a=o("p"),a.innerHTML=b},l(p){a=r(p,"P",{"data-svelte-h":!0}),m(a)!=="svelte-1u3ymti"&&(a.innerHTML=b)},m(p,h){n(p,a,h)},p:v,d(p){p&&l(a)}}}function Qa(T){let a,b='Layerwise casting may not work with all models if the forward implementation contains internal typecasting of weights. The current implementation of layerwise casting assumes the forward pass is independent of the weight precision and the input datatypes are always specified in <code>compute_dtype</code> (see <a href="https://github.com/huggingface/transformers/blob/7f5077e53682ca855afc826162b204ebf809f1f9/src/transformers/models/t5/modeling_t5.py#L294-L299" rel="nofollow">here</a> for an incompatible implementation).',p,h,w='Layerwise casting may also fail on custom modeling implementations with <a href="https://huggingface.co/docs/peft/index" rel="nofollow">PEFT</a> layers. There are some checks available but they are not extensively tested or guaranteed to work in all cases.';return{c(){a=o("p"),a.innerHTML=b,p=t(),h=o("p"),h.innerHTML=w},l(j){a=r(j,"P",{"data-svelte-h":!0}),m(a)!=="svelte-nfpqdo"&&(a.innerHTML=b),p=i(j),h=r(j,"P",{"data-svelte-h":!0}),m(h)!=="svelte-5074v9"&&(h.innerHTML=w)},m(j,g){n(j,a,g),n(j,p,g),n(j,h,g)},p:v,d(j){j&&(l(a),l(p),l(h))}}}function Ra(T){let a,b='Memory-efficient attention optimizes for memory usage <em>and</em> <a href="./fp16#scaled-dot-product-attention">inference speed</a>!';return{c(){a=o("p"),a.innerHTML=b},l(p){a=r(p,"P",{"data-svelte-h":!0}),m(a)!=="svelte-fs3wzo"&&(a.innerHTML=b)},m(p,h){n(p,a,h)},p:v,d(p){p&&l(a)}}}function Ha(T){let a,b,p,h,w,j,g,G='Modern diffusion models like <a href="../api/pipelines/flux">Flux</a> and <a href="../api/pipelines/wan">Wan</a> have billions of parameters that take up a lot of memory on your hardware for inference. This is challenging because common GPUs often don’t have sufficient memory. To overcome the memory limitations, you can use more than one GPU (if available), offload some of the pipeline components to the CPU, and more.',Z,x,J="This guide will show you how to reduce your memory usage.",_,W,Te,H,Ue,E,fn='If you have access to more than one GPU, there a few options for efficiently loading and distributing a large model across your hardware. These features are supported by the <a href="https://huggingface.co/docs/accelerate/index" rel="nofollow">Accelerate</a> library, so make sure it is installed first.',ge,S,Ze,F,_e,A,un="Loading large checkpoints in several shards in useful because the shards are loaded one at a time. This keeps memory usage low, only requiring enough memory for the model size and the largest shard size. We recommend sharding when the fp32 checkpoint is greater than 5GB. The default shard size is 5GB.",xe,L,Mn='Shard a checkpoint in <a href="/docs/diffusers/main/en/api/pipelines/overview#diffusers.DiffusionPipeline.save_pretrained">save_pretrained()</a> with the <code>max_shard_size</code> parameter.',Ie,q,Ge,D,yn="Now you can use the sharded checkpoint, instead of the regular checkpoint, to save memory.",ve,P,Ce,K,We,k,ke,O,Jn="The <code>device_map</code> parameter controls how the model components in a pipeline or the layers in an individual model are distributed across devices.",Ve,V,Be,ss,hn="When designing your own <code>device_map</code>, it should be a dictionary of a model’s specific module name or layer and a device identifier (an integer for GPUs, <code>cpu</code> for CPUs, and <code>disk</code> for disk).",$e,es,bn="Call <code>hf_device_map</code> on a model to see how model layers are distributed and then design your own.",Xe,ls,Ne,ns,wn="For example, the <code>device_map</code> below places <code>single_transformer_blocks.10</code> through <code>single_transformer_blocks.20</code> on a second GPU (<code>1</code>).",Ye,as,ze,ts,jn="Pass a dictionary mapping maximum memory usage to each device to enforce a limit. If a device is not in <code>max_memory</code>, it is ignored and pipeline components won’t be distributed to it.",Qe,is,Re,ps,Tn="Diffusers uses the maxmium memory of all devices by default, but if they don’t fit on the GPUs, then you’ll need to use a single GPU and offload to the CPU with the methods below.",He,os,Un='<li><a href="/docs/diffusers/main/en/api/pipelines/overview#diffusers.DiffusionPipeline.enable_model_cpu_offload">enable_model_cpu_offload()</a> only works on a single GPU but a very large model may not fit on it</li> <li><a href="/docs/diffusers/main/en/api/pipelines/overview#diffusers.DiffusionPipeline.enable_sequential_cpu_offload">enable_sequential_cpu_offload()</a> may work but it is extremely slow and also limited to a single GPU</li>',Ee,rs,gn='Use the <a href="/docs/diffusers/main/en/api/pipelines/overview#diffusers.DiffusionPipeline.reset_device_map">reset_device_map()</a> method to reset the <code>device_map</code>. This is necessary if you want to use methods like <code>.to()</code>, <a href="/docs/diffusers/main/en/api/pipelines/overview#diffusers.DiffusionPipeline.enable_sequential_cpu_offload">enable_sequential_cpu_offload()</a>, and <a href="/docs/diffusers/main/en/api/pipelines/overview#diffusers.DiffusionPipeline.enable_model_cpu_offload">enable_model_cpu_offload()</a> on a pipeline that was device-mapped.',Se,ms,Fe,cs,Ae,ds,Zn="VAE slicing saves memory by splitting large batches of inputs into a single batch of data and separately processing them. This method works best when generating more than one image at a time.",Le,fs,_n="For example, if you’re generating 4 images at once, decoding would increase peak activation memory by 4x. VAE slicing reduces this by only decoding 1 image at a time instead of all 4 images at once.",qe,us,xn='Call <a href="/docs/diffusers/main/en/api/pipelines/controlnet#diffusers.StableDiffusionControlNetPipeline.enable_vae_slicing">enable_vae_slicing()</a> to enable sliced VAE. You can expect a small increase in performance when decoding multi-image batches and no performance impact for single-image batches.',De,Ms,Pe,B,Ke,ys,Oe,Js,In="VAE tiling saves memory by dividing an image into smaller overlapping tiles instead of processing the entire image at once. This also reduces peak memory usage because the GPU is only processing a tile at a time.",sl,hs,Gn='Call <a href="/docs/diffusers/main/en/api/pipelines/latent_consistency_models#diffusers.LatentConsistencyModelPipeline.enable_vae_tiling">enable_vae_tiling()</a> to enable VAE tiling. The generated image may have some tone variation from tile-to-tile because they’re decoded separately, but there shouldn’t be any obvious seams between the tiles. Tiling is disabled for resolutions lower than a pre-specified (but configurable) limit. For example, this limit is 512x512 for the VAE in <a href="/docs/diffusers/main/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline">StableDiffusionPipeline</a>.',el,bs,ll,ws,vn='<p>[!WARNING][AutoencoderKLWan](/docs/diffusers/main/en/api/models/autoencoder_kl_wan#diffusers.AutoencoderKLWan) and <a href="/docs/diffusers/main/en/api/models/asymmetricautoencoderkl#diffusers.AsymmetricAutoencoderKL">AsymmetricAutoencoderKL</a> don’t support tiling.</p>',nl,js,al,Ts,Cn="Offloading strategies move not currently active layers or models to the CPU to avoid increasing GPU memory. These strategies can be combined with quantization and torch.compile to balance inference speed and memory usage.",tl,Us,Wn='Refer to the <a href="./speed-memory-optims">Compile and offloading quantized models</a> guide for more details.',il,gs,pl,Zs,kn="CPU offloading selectively moves weights from the GPU to the CPU. When a component is required, it is transferred to the GPU and when it isn’t required, it is moved to the CPU. This method works on submodules rather than whole models. It saves memory by avoiding storing the entire model on the GPU.",ol,_s,Vn="CPU offloading dramatically reduces memory usage, but it is also <strong>extremely slow</strong> because submodules are passed back and forth multiple times between devices. It can often be impractical due to how slow it is.",rl,$,ml,xs,Bn='Call <a href="/docs/diffusers/main/en/api/pipelines/overview#diffusers.DiffusionPipeline.enable_sequential_cpu_offload">enable_sequential_cpu_offload()</a> to enable it on a pipeline.',cl,Is,dl,Gs,fl,vs,$n='Model offloading moves entire models to the GPU instead of selectively moving <em>some</em> layers or model components. One of the main pipeline models, usually the text encoder, UNet, and VAE, is placed on the GPU while the other components are held on the CPU. Components like the UNet that run multiple times stays on the GPU until its completely finished and no longer needed. This eliminates the communication overhead of <a href="#cpu-offloading">CPU offloading</a> and makes model offloading a faster alternative. The tradeoff is memory savings won’t be as large.',ul,X,Ml,Cs,Xn='Call <a href="/docs/diffusers/main/en/api/pipelines/overview#diffusers.DiffusionPipeline.enable_model_cpu_offload">enable_model_cpu_offload()</a> to enable it on a pipeline.',yl,Ws,Jl,ks,Nn='<a href="/docs/diffusers/main/en/api/pipelines/overview#diffusers.DiffusionPipeline.enable_model_cpu_offload">enable_model_cpu_offload()</a> also helps when you’re using the <a href="/docs/diffusers/main/en/api/pipelines/stable_diffusion/stable_diffusion_xl#diffusers.StableDiffusionXLPipeline.encode_prompt">encode_prompt()</a> method on its own to generate the text encoders hidden state.',hl,Vs,bl,Bs,Yn='Group offloading moves groups of internal layers (<a href="https://pytorch.org/docs/stable/generated/torch.nn.ModuleList.html" rel="nofollow">torch.nn.ModuleList</a> or <a href="https://pytorch.org/docs/stable/generated/torch.nn.Sequential.html" rel="nofollow">torch.nn.Sequential</a>) to the CPU. It uses less memory than <a href="#model-offloading">model offloading</a> and it is faster than <a href="#cpu-offloading">CPU offloading</a> because it reduces communication overhead.',wl,N,jl,$s,zn='Call <a href="/docs/diffusers/main/en/api/models/overview#diffusers.ModelMixin.enable_group_offload">enable_group_offload()</a> to enable it for standard Diffusers model components that inherit from <a href="/docs/diffusers/main/en/api/models/overview#diffusers.ModelMixin">ModelMixin</a>. For other model components that don’t inherit from <a href="/docs/diffusers/main/en/api/models/overview#diffusers.ModelMixin">ModelMixin</a>, such as a generic <a href="https://pytorch.org/docs/stable/generated/torch.nn.Module.html" rel="nofollow">torch.nn.Module</a>, use <a href="/docs/diffusers/main/en/api/utilities#diffusers.hooks.apply_group_offloading">apply_group_offloading()</a> instead.',Tl,Xs,Qn="The <code>offload_type</code> parameter can be set to <code>block_level</code> or <code>leaf_level</code>.",Ul,Ns,Rn='<li><code>block_level</code> offloads groups of layers based on the <code>num_blocks_per_group</code> parameter. For example, if <code>num_blocks_per_group=2</code> on a model with 40 layers, 2 layers are onloaded and offloaded at a time (20 total onloads/offloads). This drastically reduces memory requirements.</li> <li><code>leaf_level</code> offloads individual layers at the lowest level and is equivalent to <a href="#cpu-offloading">CPU offloading</a>. But it can be made faster if you use streams without giving up inference speed.</li>',gl,Ys,Zl,zs,_l,Qs,Hn='The <code>use_stream</code> parameter can be activated for CUDA devices that support asynchronous data transfer streams to reduce overall execution time compared to <a href="#cpu-offloading">CPU offloading</a>. It overlaps data transfer and computation by using layer prefetching. The next layer to be executed is loaded onto the GPU while the current layer is still being executed. It can increase CPU memory significantly so ensure you have 2x the amount of memory as the model size.',xl,Rs,En='Set <code>record_stream=True</code> for more of a speedup at the cost of slightly increased memory usage. Refer to the <a href="https://pytorch.org/docs/stable/generated/torch.Tensor.record_stream.html" rel="nofollow">torch.Tensor.record_stream</a> docs to learn more.',Il,Y,Gl,Hs,Sn="If you’re using <code>block_level</code> group offloading with <code>use_stream</code> enabled, the <code>num_blocks_per_group</code> parameter should be set to <code>1</code>, otherwise a warning will be raised.",vl,Es,Cl,Ss,Fn="The <code>low_cpu_mem_usage</code> parameter can be set to <code>True</code> to reduce CPU memory usage when using streams during group offloading. It is best for <code>leaf_level</code> offloading and when CPU memory is bottlenecked. Memory is saved by creating pinned tensors on the fly instead of pre-pinning them. However, this may increase overall execution time.",Wl,Fs,kl,As,An="Group offloading can consume significant system memory depending on the model size. On systems with limited memory, try group offloading onto the disk as a secondary memory.",Vl,Ls,Ln='Set the <code>offload_to_disk_path</code> argument in either <a href="/docs/diffusers/main/en/api/models/overview#diffusers.ModelMixin.enable_group_offload">enable_group_offload()</a> or <a href="/docs/diffusers/main/en/api/utilities#diffusers.hooks.apply_group_offloading">apply_group_offloading()</a> to offload the model to the disk.',Bl,qs,$l,Ds,qn='Refer to these <a href="https://github.com/huggingface/diffusers/pull/11682#issue-3129365363" rel="nofollow">two</a> <a href="https://github.com/huggingface/diffusers/pull/11682#issuecomment-2955715126" rel="nofollow">tables</a> to compare the speed and memory trade-offs.',Xl,Ps,Nl,z,Yl,Ks,Dn="Layerwise casting stores weights in a smaller data format (for example, <code>torch.float8_e4m3fn</code> and <code>torch.float8_e5m2</code>) to use less memory and upcasts those weights to a higher precision like <code>torch.float16</code> or <code>torch.bfloat16</code> for computation. Certain layers (normalization and modulation related weights) are skipped because storing them in fp8 can degrade generation quality.",zl,Q,Ql,Os,Pn='Call <a href="/docs/diffusers/main/en/api/models/overview#diffusers.ModelMixin.enable_layerwise_casting">enable_layerwise_casting()</a> to set the storage and computation datatypes.',Rl,se,Hl,ee,Kn='The <a href="/docs/diffusers/main/en/api/utilities#diffusers.hooks.apply_layerwise_casting">apply_layerwise_casting()</a> method can also be used if you need more control and flexibility. It can be partially applied to model layers by calling it on specific internal modules. Use the <code>skip_modules_pattern</code> or <code>skip_modules_classes</code> parameters to specify modules to avoid, such as the normalization and modulation layers.',El,le,Sl,ne,Fl,ae,On='<a href="https://pytorch.org/tutorials/intermediate/memory_format_tutorial.html" rel="nofollow">torch.channels_last</a> flips how tensors are stored from <code>(batch size, channels, height, width)</code> to <code>(batch size, heigh, width, channels)</code>. This aligns the tensors with how the hardware sequentially accesses the tensors stored in memory and avoids skipping around in memory to access the pixel values.',Al,te,sa="Not all operators currently support the channels-last format and may result in worst performance, but it is still worth trying.",Ll,ie,ql,pe,Dl,oe,ea='<a href="https://pytorch.org/docs/stable/generated/torch.jit.trace.html" rel="nofollow">torch.jit.trace</a> records the operations a model performs on a sample input and creates a new, optimized representation of the model based on the recorded execution path. During tracing, the model is optimized to reduce overhead from Python and dynamic control flows and operations are fused together for more efficiency. The returned executable or <a href="https://pytorch.org/docs/stable/generated/torch.jit.ScriptFunction.html" rel="nofollow">ScriptFunction</a> can be compiled.',Pl,re,Kl,me,la="Replace the pipeline’s UNet with the traced version.",Ol,ce,sn,de,en,R,ln,fe,na="The Transformers attention mechanism is memory-intensive, especially for long sequences, so you can try using different and more memory-efficient attention types.",nn,ue,aa='By default, if PyTorch &gt;= 2.0 is installed, <a href="https://pytorch.org/docs/stable/generated/torch.nn.functional.scaled_dot_product_attention.html" rel="nofollow">scaled dot-product attention (SDPA)</a> is used. You don’t need to make any additional changes to your code.',an,Me,ta='SDPA supports <a href="https://github.com/Dao-AILab/flash-attention" rel="nofollow">FlashAttention</a> and <a href="https://github.com/facebookresearch/xformers" rel="nofollow">xFormers</a> as well as a native C++ PyTorch implementation. It automatically selects the most optimal implementation based on your input.',tn,ye,ia='You can explicitly use xFormers with the <a href="/docs/diffusers/main/en/api/models/overview#diffusers.ModelMixin.enable_xformers_memory_efficient_attention">enable_xformers_memory_efficient_attention()</a> method.',pn,Je,on,he,pa='Call <a href="/docs/diffusers/main/en/api/models/overview#diffusers.ModelMixin.disable_xformers_memory_efficient_attention">disable_xformers_memory_efficient_attention()</a> to disable it.',rn,be,mn,we,cn,je,dn;return w=new I({props:{title:"Reduce memory usage",local:"reduce-memory-usage",headingTag:"h1"}}),W=new C({props:{warning:!1,$$slots:{default:[va]},$$scope:{ctx:T}}}),H=new I({props:{title:"Multiple GPUs",local:"multiple-gpus",headingTag:"h2"}}),S=new U({props:{code:"cGlwJTIwaW5zdGFsbCUyMC1VJTIwYWNjZWxlcmF0ZQ==",highlighted:"pip install -U accelerate",wrap:!1}}),F=new I({props:{title:"Sharded checkpoints",local:"sharded-checkpoints",headingTag:"h3"}}),q=new U({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMEF1dG9Nb2RlbCUwQSUwQXVuZXQlMjAlM0QlMjBBdXRvTW9kZWwuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMnN0YWJpbGl0eWFpJTJGc3RhYmxlLWRpZmZ1c2lvbi14bC1iYXNlLTEuMCUyMiUyQyUyMHN1YmZvbGRlciUzRCUyMnVuZXQlMjIlMEEpJTBBdW5ldC5zYXZlX3ByZXRyYWluZWQoJTIyc2R4bC11bmV0LXNoYXJkZWQlMjIlMkMlMjBtYXhfc2hhcmRfc2l6ZSUzRCUyMjVHQiUyMik=",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> AutoModel

unet = AutoModel.from_pretrained(
    <span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>, subfolder=<span class="hljs-string">&quot;unet&quot;</span>
)
unet.save_pretrained(<span class="hljs-string">&quot;sdxl-unet-sharded&quot;</span>, max_shard_size=<span class="hljs-string">&quot;5GB&quot;</span>)`,wrap:!1}}),P=new U({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwQXV0b01vZGVsJTJDJTIwU3RhYmxlRGlmZnVzaW9uWExQaXBlbGluZSUwQSUwQXVuZXQlMjAlM0QlMjBBdXRvTW9kZWwuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMnVzZXJuYW1lJTJGc2R4bC11bmV0LXNoYXJkZWQlMjIlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYlMEEpJTBBcGlwZWxpbmUlMjAlM0QlMjBTdGFibGVEaWZmdXNpb25YTFBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJzdGFiaWxpdHlhaSUyRnN0YWJsZS1kaWZmdXNpb24teGwtYmFzZS0xLjAlMjIlMkMlMEElMjAlMjAlMjAlMjB1bmV0JTNEdW5ldCUyQyUwQSUyMCUyMCUyMCUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiUwQSkudG8oJTIyY3VkYSUyMik=",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> AutoModel, StableDiffusionXLPipeline

unet = AutoModel.from_pretrained(
    <span class="hljs-string">&quot;username/sdxl-unet-sharded&quot;</span>, torch_dtype=torch.float16
)
pipeline = StableDiffusionXLPipeline.from_pretrained(
    <span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>,
    unet=unet,
    torch_dtype=torch.float16
).to(<span class="hljs-string">&quot;cuda&quot;</span>)`,wrap:!1}}),K=new I({props:{title:"Device placement",local:"device-placement",headingTag:"h3"}}),k=new C({props:{warning:!0,$$slots:{default:[Ca]},$$scope:{ctx:T}}}),V=new Ga({props:{id:"device-map",options:["pipeline level","model level"],$$slots:{default:[Va]},$$scope:{ctx:T}}}),ls=new U({props:{code:"cHJpbnQodHJhbnNmb3JtZXIuaGZfZGV2aWNlX21hcCklMEElN0IncG9zX2VtYmVkJyUzQSUyMDAlMkMlMjAndGltZV90ZXh0X2VtYmVkJyUzQSUyMDAlMkMlMjAnY29udGV4dF9lbWJlZGRlciclM0ElMjAw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cmFuc2Zvcm1lcl9ibG9ja3MuMzInJTNBJTIwJ2NwdSclMkMlMjAnc2luZ2xlX3RyYW5zZm9ybWVyX2Jsb2Nrcy4zMyclM0ElMjAnY3B1JyUyQyUyMCdzaW5nbGVfdHJhbnNmb3JtZXJfYmxvY2tzLjM0JyUzQSUyMCdjcHUnJTJDJTIwJ3NpbmdsZV90cmFuc2Zvcm1lcl9ibG9ja3MuMzUnJTNBJTIwJ2NwdSclMkMlMjAnc2luZ2xlX3RyYW5zZm9ybWVyX2Jsb2Nrcy4zNiclM0ElMjAnY3B1JyUyQyUyMCdzaW5nbGVfdHJhbnNmb3JtZXJfYmxvY2tzLjM3JyUzQSUyMCdjcHUnJTJDJTIwJ25vcm1fb3V0JyUzQSUyMCdjcHUnJTJDJTIwJ3Byb2pfb3V0JyUzQSUyMCdjcHUnJTdE",highlighted:`<span class="hljs-built_in">print</span>(transformer.hf_device_map)
{<span class="hljs-string">&#x27;pos_embed&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;time_text_embed&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;context_embedder&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;x_embedder&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;transformer_blocks&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;single_transformer_blocks.0&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;single_transformer_blocks.1&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;single_transformer_blocks.2&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;single_transformer_blocks.3&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;single_transformer_blocks.4&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;single_transformer_blocks.5&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;single_transformer_blocks.6&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;single_transformer_blocks.7&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;single_transformer_blocks.8&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;single_transformer_blocks.9&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;single_transformer_blocks.10&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.11&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.12&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.13&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.14&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.15&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.16&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.17&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.18&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.19&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.20&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.21&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.22&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.23&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.24&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.25&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.26&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.27&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.28&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.29&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.30&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.31&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.32&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.33&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.34&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.35&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.36&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.37&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;norm_out&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;proj_out&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>}`,wrap:!1}}),as=new U({props:{code:"aW1wb3J0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TIwJ2NwdSclMkMlMjAnc2luZ2xlX3RyYW5zZm9ybWVyX2Jsb2Nrcy4zMCclM0ElMjAnY3B1JyUyQyUyMCdzaW5nbGVfdHJhbnNmb3JtZXJfYmxvY2tzLjMxJyUzQSUyMCdjcHUnJTJDJTIwJ3NpbmdsZV90cmFuc2Zvcm1lcl9ibG9ja3MuMzInJTNBJTIwJ2NwdSclMkMlMjAnc2luZ2xlX3RyYW5zZm9ybWVyX2Jsb2Nrcy4zMyclM0ElMjAnY3B1JyUyQyUyMCdzaW5nbGVfdHJhbnNmb3JtZXJfYmxvY2tzLjM0JyUzQSUyMCdjcHUnJTJDJTIwJ3NpbmdsZV90cmFuc2Zvcm1lcl9ibG9ja3MuMzUnJTNBJTIwJ2NwdSclMkMlMjAnc2luZ2xlX3RyYW5zZm9ybWVyX2Jsb2Nrcy4zNiclM0ElMjAnY3B1JyUyQyUyMCdzaW5nbGVfdHJhbnNmb3JtZXJfYmxvY2tzLjM3JyUzQSUyMCdjcHUnJTJDJTIwJ25vcm1fb3V0JyUzQSUyMCdjcHUnJTJDJTIwJ3Byb2pfb3V0JyUzQSUyMCdjcHUnJTBBJTdEJTBBJTBBdHJhbnNmb3JtZXIlMjAlM0QlMjBBdXRvTW9kZWwuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMmJsYWNrLWZvcmVzdC1sYWJzJTJGRkxVWC4xLWRldiUyMiUyQyUyMCUwQSUyMCUyMCUyMCUyMHN1YmZvbGRlciUzRCUyMnRyYW5zZm9ybWVyJTIyJTJDJTBBJTIwJTIwJTIwJTIwZGV2aWNlX21hcCUzRGRldmljZV9tYXAlMkMlMEElMjAlMjAlMjAlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmJmbG9hdDE2JTBBKQ==",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> AutoModel

device_map = {
    <span class="hljs-string">&#x27;pos_embed&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;time_text_embed&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;context_embedder&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;x_embedder&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;transformer_blocks&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;single_transformer_blocks.0&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;single_transformer_blocks.1&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;single_transformer_blocks.2&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;single_transformer_blocks.3&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;single_transformer_blocks.4&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;single_transformer_blocks.5&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;single_transformer_blocks.6&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;single_transformer_blocks.7&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;single_transformer_blocks.8&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;single_transformer_blocks.9&#x27;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&#x27;single_transformer_blocks.10&#x27;</span>: <span class="hljs-number">1</span>, <span class="hljs-string">&#x27;single_transformer_blocks.11&#x27;</span>: <span class="hljs-number">1</span>, <span class="hljs-string">&#x27;single_transformer_blocks.12&#x27;</span>: <span class="hljs-number">1</span>, <span class="hljs-string">&#x27;single_transformer_blocks.13&#x27;</span>: <span class="hljs-number">1</span>, <span class="hljs-string">&#x27;single_transformer_blocks.14&#x27;</span>: <span class="hljs-number">1</span>, <span class="hljs-string">&#x27;single_transformer_blocks.15&#x27;</span>: <span class="hljs-number">1</span>, <span class="hljs-string">&#x27;single_transformer_blocks.16&#x27;</span>: <span class="hljs-number">1</span>, <span class="hljs-string">&#x27;single_transformer_blocks.17&#x27;</span>: <span class="hljs-number">1</span>, <span class="hljs-string">&#x27;single_transformer_blocks.18&#x27;</span>: <span class="hljs-number">1</span>, <span class="hljs-string">&#x27;single_transformer_blocks.19&#x27;</span>: <span class="hljs-number">1</span>, <span class="hljs-string">&#x27;single_transformer_blocks.20&#x27;</span>: <span class="hljs-number">1</span>, <span class="hljs-string">&#x27;single_transformer_blocks.21&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.22&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.23&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.24&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.25&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.26&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.27&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.28&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.29&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.30&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.31&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.32&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.33&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.34&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.35&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.36&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;single_transformer_blocks.37&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;norm_out&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>, <span class="hljs-string">&#x27;proj_out&#x27;</span>: <span class="hljs-string">&#x27;cpu&#x27;</span>
}

transformer = AutoModel.from_pretrained(
    <span class="hljs-string">&quot;black-forest-labs/FLUX.1-dev&quot;</span>, 
    subfolder=<span class="hljs-string">&quot;transformer&quot;</span>,
    device_map=device_map,
    torch_dtype=torch.bfloat16
)`,wrap:!1}}),is=new U({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwQXV0b01vZGVsJTJDJTIwU3RhYmxlRGlmZnVzaW9uWExQaXBlbGluZSUwQSUwQW1heF9tZW1vcnklMjAlM0QlMjAlN0IwJTNBJTIyMUdCJTIyJTJDJTIwMSUzQSUyMjFHQiUyMiU3RCUwQXBpcGVsaW5lJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uWExQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIyc3RhYmlsaXR5YWklMkZzdGFibGUtZGlmZnVzaW9uLXhsLWJhc2UtMS4wJTIyJTJDJTBBJTIwJTIwJTIwJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTJDJTBBJTIwJTIwJTIwJTIwZGV2aWNlX21hcCUzRCUyMmJhbGFuY2VkJTIyJTJDJTBBJTIwJTIwJTIwJTIwbWF4X21lbW9yeSUzRG1heF9tZW1vcnklMEEp",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> AutoModel, StableDiffusionXLPipeline

max_memory = {<span class="hljs-number">0</span>:<span class="hljs-string">&quot;1GB&quot;</span>, <span class="hljs-number">1</span>:<span class="hljs-string">&quot;1GB&quot;</span>}
pipeline = StableDiffusionXLPipeline.from_pretrained(
    <span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>,
    torch_dtype=torch.float16,
    device_map=<span class="hljs-string">&quot;balanced&quot;</span>,
    max_memory=max_memory
)`,wrap:!1}}),ms=new U({props:{code:"cGlwZWxpbmUucmVzZXRfZGV2aWNlX21hcCgp",highlighted:"pipeline.reset_device_map()",wrap:!1}}),cs=new I({props:{title:"VAE slicing",local:"vae-slicing",headingTag:"h2"}}),Ms=new U({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwQXV0b01vZGVsJTJDJTIwU3RhYmxlRGlmZnVzaW9uWExQaXBlbGluZSUwQSUwQXBpcGVsaW5lJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uWExQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIyc3RhYmlsaXR5YWklMkZzdGFibGUtZGlmZnVzaW9uLXhsLWJhc2UtMS4wJTIyJTJDJTBBJTIwJTIwJTIwJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTJDJTBBKS50byglMjJjdWRhJTIyKSUwQXBpcGVsaW5lLmVuYWJsZV92YWVfc2xpY2luZygpJTBBcGlwZWxpbmUoJTVCJTIyQW4lMjBhc3Ryb25hdXQlMjByaWRpbmclMjBhJTIwaG9yc2UlMjBvbiUyME1hcnMlMjIlNUQqMzIpLmltYWdlcyU1QjAlNUQlMEFwcmludChmJTIyTWF4JTIwbWVtb3J5JTIwcmVzZXJ2ZWQlM0ElMjAlN0J0b3JjaC5jdWRhLm1heF9tZW1vcnlfYWxsb2NhdGVkKCklMjAlMkYlMjAxMDI0KiozJTNBLjJmJTdEJTIwR0IlMjIp",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> AutoModel, StableDiffusionXLPipeline

pipeline = StableDiffusionXLPipeline.from_pretrained(
    <span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>,
    torch_dtype=torch.float16,
).to(<span class="hljs-string">&quot;cuda&quot;</span>)
pipeline.enable_vae_slicing()
pipeline([<span class="hljs-string">&quot;An astronaut riding a horse on Mars&quot;</span>]*<span class="hljs-number">32</span>).images[<span class="hljs-number">0</span>]
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Max memory reserved: <span class="hljs-subst">{torch.cuda.max_memory_allocated() / <span class="hljs-number">1024</span>**<span class="hljs-number">3</span>:<span class="hljs-number">.2</span>f}</span> GB&quot;</span>)`,wrap:!1}}),B=new C({props:{warning:!0,$$slots:{default:[Ba]},$$scope:{ctx:T}}}),ys=new I({props:{title:"VAE tiling",local:"vae-tiling",headingTag:"h2"}}),bs=new U({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwQXV0b1BpcGVsaW5lRm9ySW1hZ2UySW1hZ2UlMEFmcm9tJTIwZGlmZnVzZXJzLnV0aWxzJTIwaW1wb3J0JTIwbG9hZF9pbWFnZSUwQSUwQXBpcGVsaW5lJTIwJTNEJTIwQXV0b1BpcGVsaW5lRm9ySW1hZ2UySW1hZ2UuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMnN0YWJpbGl0eWFpJTJGc3RhYmxlLWRpZmZ1c2lvbi14bC1iYXNlLTEuMCUyMiUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiUwQSkudG8oJTIyY3VkYSUyMiklMEFwaXBlbGluZS5lbmFibGVfdmFlX3RpbGluZygpJTBBJTBBaW5pdF9pbWFnZSUyMCUzRCUyMGxvYWRfaW1hZ2UoJTIyaHR0cHMlM0ElMkYlMkZodWdnaW5nZmFjZS5jbyUyRmRhdGFzZXRzJTJGaHVnZ2luZ2ZhY2UlMkZkb2N1bWVudGF0aW9uLWltYWdlcyUyRnJlc29sdmUlMkZtYWluJTJGZGlmZnVzZXJzJTJGaW1nMmltZy1zZHhsLWluaXQucG5nJTIyKSUwQXByb21wdCUyMCUzRCUyMCUyMkFzdHJvbmF1dCUyMGluJTIwYSUyMGp1bmdsZSUyQyUyMGNvbGQlMjBjb2xvciUyMHBhbGV0dGUlMkMlMjBtdXRlZCUyMGNvbG9ycyUyQyUyMGRldGFpbGVkJTJDJTIwOGslMjIlMEFwaXBlbGluZShwcm9tcHQlMkMlMjBpbWFnZSUzRGluaXRfaW1hZ2UlMkMlMjBzdHJlbmd0aCUzRDAuNSkuaW1hZ2VzJTVCMCU1RCUwQXByaW50KGYlMjJNYXglMjBtZW1vcnklMjByZXNlcnZlZCUzQSUyMCU3QnRvcmNoLmN1ZGEubWF4X21lbW9yeV9hbGxvY2F0ZWQoKSUyMCUyRiUyMDEwMjQqKjMlM0EuMmYlN0QlMjBHQiUyMik=",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> AutoPipelineForImage2Image
<span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> load_image

pipeline = AutoPipelineForImage2Image.from_pretrained(
    <span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>, torch_dtype=torch.float16
).to(<span class="hljs-string">&quot;cuda&quot;</span>)
pipeline.enable_vae_tiling()

init_image = load_image(<span class="hljs-string">&quot;https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/img2img-sdxl-init.png&quot;</span>)
prompt = <span class="hljs-string">&quot;Astronaut in a jungle, cold color palette, muted colors, detailed, 8k&quot;</span>
pipeline(prompt, image=init_image, strength=<span class="hljs-number">0.5</span>).images[<span class="hljs-number">0</span>]
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Max memory reserved: <span class="hljs-subst">{torch.cuda.max_memory_allocated() / <span class="hljs-number">1024</span>**<span class="hljs-number">3</span>:<span class="hljs-number">.2</span>f}</span> GB&quot;</span>)`,wrap:!1}}),js=new I({props:{title:"Offloading",local:"offloading",headingTag:"h2"}}),gs=new I({props:{title:"CPU offloading",local:"cpu-offloading",headingTag:"h3"}}),$=new C({props:{warning:!0,$$slots:{default:[$a]},$$scope:{ctx:T}}}),Is=new U({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRGlmZnVzaW9uUGlwZWxpbmUlMEElMEFwaXBlbGluZSUyMCUzRCUyMERpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJibGFjay1mb3Jlc3QtbGFicyUyRkZMVVguMS1zY2huZWxsJTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5iZmxvYXQxNiUwQSklMEFwaXBlbGluZS5lbmFibGVfc2VxdWVudGlhbF9jcHVfb2ZmbG9hZCgpJTBBJTBBcGlwZWxpbmUoJTBBJTIwJTIwJTIwJTIwcHJvbXB0JTNEJTIyQW4lMjBhc3Ryb25hdXQlMjByaWRpbmclMjBhJTIwaG9yc2UlMjBvbiUyME1hcnMlMjIlMkMlMEElMjAlMjAlMjAlMjBndWlkYW5jZV9zY2FsZSUzRDAuJTJDJTBBJTIwJTIwJTIwJTIwaGVpZ2h0JTNENzY4JTJDJTBBJTIwJTIwJTIwJTIwd2lkdGglM0QxMzYwJTJDJTBBJTIwJTIwJTIwJTIwbnVtX2luZmVyZW5jZV9zdGVwcyUzRDQlMkMlMEElMjAlMjAlMjAlMjBtYXhfc2VxdWVuY2VfbGVuZ3RoJTNEMjU2JTJDJTBBKS5pbWFnZXMlNUIwJTVEJTBBcHJpbnQoZiUyMk1heCUyMG1lbW9yeSUyMHJlc2VydmVkJTNBJTIwJTdCdG9yY2guY3VkYS5tYXhfbWVtb3J5X2FsbG9jYXRlZCgpJTIwJTJGJTIwMTAyNCoqMyUzQS4yZiU3RCUyMEdCJTIyKQ==",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline

pipeline = DiffusionPipeline.from_pretrained(
    <span class="hljs-string">&quot;black-forest-labs/FLUX.1-schnell&quot;</span>, torch_dtype=torch.bfloat16
)
pipeline.enable_sequential_cpu_offload()

pipeline(
    prompt=<span class="hljs-string">&quot;An astronaut riding a horse on Mars&quot;</span>,
    guidance_scale=<span class="hljs-number">0.</span>,
    height=<span class="hljs-number">768</span>,
    width=<span class="hljs-number">1360</span>,
    num_inference_steps=<span class="hljs-number">4</span>,
    max_sequence_length=<span class="hljs-number">256</span>,
).images[<span class="hljs-number">0</span>]
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Max memory reserved: <span class="hljs-subst">{torch.cuda.max_memory_allocated() / <span class="hljs-number">1024</span>**<span class="hljs-number">3</span>:<span class="hljs-number">.2</span>f}</span> GB&quot;</span>)`,wrap:!1}}),Gs=new I({props:{title:"Model offloading",local:"model-offloading",headingTag:"h3"}}),X=new C({props:{warning:!0,$$slots:{default:[Xa]},$$scope:{ctx:T}}}),Ws=new U({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRGlmZnVzaW9uUGlwZWxpbmUlMEElMEFwaXBlbGluZSUyMCUzRCUyMERpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJibGFjay1mb3Jlc3QtbGFicyUyRkZMVVguMS1zY2huZWxsJTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5iZmxvYXQxNiUwQSklMEFwaXBlbGluZS5lbmFibGVfbW9kZWxfY3B1X29mZmxvYWQoKSUwQSUwQXBpcGVsaW5lKCUwQSUyMCUyMCUyMCUyMHByb21wdCUzRCUyMkFuJTIwYXN0cm9uYXV0JTIwcmlkaW5nJTIwYSUyMGhvcnNlJTIwb24lMjBNYXJzJTIyJTJDJTBBJTIwJTIwJTIwJTIwZ3VpZGFuY2Vfc2NhbGUlM0QwLiUyQyUwQSUyMCUyMCUyMCUyMGhlaWdodCUzRDc2OCUyQyUwQSUyMCUyMCUyMCUyMHdpZHRoJTNEMTM2MCUyQyUwQSUyMCUyMCUyMCUyMG51bV9pbmZlcmVuY2Vfc3RlcHMlM0Q0JTJDJTBBJTIwJTIwJTIwJTIwbWF4X3NlcXVlbmNlX2xlbmd0aCUzRDI1NiUyQyUwQSkuaW1hZ2VzJTVCMCU1RCUwQXByaW50KGYlMjJNYXglMjBtZW1vcnklMjByZXNlcnZlZCUzQSUyMCU3QnRvcmNoLmN1ZGEubWF4X21lbW9yeV9hbGxvY2F0ZWQoKSUyMCUyRiUyMDEwMjQqKjMlM0EuMmYlN0QlMjBHQiUyMik=",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline

pipeline = DiffusionPipeline.from_pretrained(
    <span class="hljs-string">&quot;black-forest-labs/FLUX.1-schnell&quot;</span>, torch_dtype=torch.bfloat16
)
pipeline.enable_model_cpu_offload()

pipeline(
    prompt=<span class="hljs-string">&quot;An astronaut riding a horse on Mars&quot;</span>,
    guidance_scale=<span class="hljs-number">0.</span>,
    height=<span class="hljs-number">768</span>,
    width=<span class="hljs-number">1360</span>,
    num_inference_steps=<span class="hljs-number">4</span>,
    max_sequence_length=<span class="hljs-number">256</span>,
).images[<span class="hljs-number">0</span>]
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Max memory reserved: <span class="hljs-subst">{torch.cuda.max_memory_allocated() / <span class="hljs-number">1024</span>**<span class="hljs-number">3</span>:<span class="hljs-number">.2</span>f}</span> GB&quot;</span>)`,wrap:!1}}),Vs=new I({props:{title:"Group offloading",local:"group-offloading",headingTag:"h3"}}),N=new C({props:{warning:!0,$$slots:{default:[Na]},$$scope:{ctx:T}}}),Ys=new U({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwQ29nVmlkZW9YUGlwZWxpbmUlMEFmcm9tJTIwZGlmZnVzZXJzLmhvb2tzJTIwaW1wb3J0JTIwYXBwbHlfZ3JvdXBfb2ZmbG9hZGluZyUwQWZyb20lMjBkaWZmdXNlcnMudXRpbHMlMjBpbXBvcnQlMjBleHBvcnRfdG9fdmlkZW8lMEElMEFvbmxvYWRfZGV2aWNlJTIwJTNEJTIwdG9yY2guZGV2aWNlKCUyMmN1ZGElMjIpJTBBb2ZmbG9hZF9kZXZpY2UlMjAlM0QlMjB0b3JjaC5kZXZpY2UoJTIyY3B1JTIyKSUwQXBpcGVsaW5lJTIwJTNEJTIwQ29nVmlkZW9YUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUyMlRIVURNJTJGQ29nVmlkZW9YLTViJTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5iZmxvYXQxNiklMEElMEElMjMlMjBVc2UlMjB0aGUlMjBlbmFibGVfZ3JvdXBfb2ZmbG9hZCUyMG1ldGhvZCUyMGZvciUyMERpZmZ1c2VycyUyMG1vZGVsJTIwaW1wbGVtZW50YXRpb25zJTBBcGlwZWxpbmUudHJhbnNmb3JtZXIuZW5hYmxlX2dyb3VwX29mZmxvYWQob25sb2FkX2RldmljZSUzRG9ubG9hZF9kZXZpY2UlMkMlMjBvZmZsb2FkX2RldmljZSUzRG9mZmxvYWRfZGV2aWNlJTJDJTIwb2ZmbG9hZF90eXBlJTNEJTIybGVhZl9sZXZlbCUyMiklMEFwaXBlbGluZS52YWUuZW5hYmxlX2dyb3VwX29mZmxvYWQob25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hljs-keyword">import</span> CogVideoXPipeline
<span class="hljs-keyword">from</span> diffusers.hooks <span class="hljs-keyword">import</span> apply_group_offloading
<span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> export_to_video

onload_device = torch.device(<span class="hljs-string">&quot;cuda&quot;</span>)
offload_device = torch.device(<span class="hljs-string">&quot;cpu&quot;</span>)
pipeline = CogVideoXPipeline.from_pretrained(<span class="hljs-string">&quot;THUDM/CogVideoX-5b&quot;</span>, torch_dtype=torch.bfloat16)

<span class="hljs-comment"># Use the enable_group_offload method for Diffusers model implementations</span>
pipeline.transformer.enable_group_offload(onload_device=onload_device, offload_device=offload_device, offload_type=<span class="hljs-string">&quot;leaf_level&quot;</span>)
pipeline.vae.enable_group_offload(onload_device=onload_device, offload_type=<span class="hljs-string">&quot;leaf_level&quot;</span>)

<span class="hljs-comment"># Use the apply_group_offloading method for other model components</span>
apply_group_offloading(pipeline.text_encoder, onload_device=onload_device, offload_type=<span class="hljs-string">&quot;block_level&quot;</span>, num_blocks_per_group=<span class="hljs-number">2</span>)

prompt = (
    <span class="hljs-string">&quot;A panda, dressed in a small, red jacket and a tiny hat, sits on a wooden stool in a serene bamboo forest. &quot;</span>
    <span class="hljs-string">&quot;The panda&#x27;s fluffy paws strum a miniature acoustic guitar, producing soft, melodic tunes. Nearby, a few other &quot;</span>
    <span class="hljs-string">&quot;pandas gather, watching curiously and some clapping in rhythm. Sunlight filters through the tall bamboo, &quot;</span>
    <span class="hljs-string">&quot;casting a gentle glow on the scene. The panda&#x27;s face is expressive, showing concentration and joy as it plays. &quot;</span>
    <span class="hljs-string">&quot;The background includes a small, flowing stream and vibrant green foliage, enhancing the peaceful and magical &quot;</span>
    <span class="hljs-string">&quot;atmosphere of this unique musical performance.&quot;</span>
)
video = pipeline(prompt=prompt, guidance_scale=<span class="hljs-number">6</span>, num_inference_steps=<span class="hljs-number">50</span>).frames[<span class="hljs-number">0</span>]
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Max memory reserved: <span class="hljs-subst">{torch.cuda.max_memory_allocated() / <span class="hljs-number">1024</span>**<span class="hljs-number">3</span>:<span class="hljs-number">.2</span>f}</span> GB&quot;</span>)
export_to_video(video, <span class="hljs-string">&quot;output.mp4&quot;</span>, fps=<span class="hljs-number">8</span>)`,wrap:!1}}),zs=new I({props:{title:"CUDA stream",local:"cuda-stream",headingTag:"h4"}}),Y=new C({props:{warning:!1,$$slots:{default:[Ya]},$$scope:{ctx:T}}}),Es=new U({props:{code:"cGlwZWxpbmUudHJhbnNmb3JtZXIuZW5hYmxlX2dyb3VwX29mZmxvYWQob25sb2FkX2RldmljZSUzRG9ubG9hZF9kZXZpY2UlMkMlMjBvZmZsb2FkX2RldmljZSUzRG9mZmxvYWRfZGV2aWNlJTJDJTIwb2ZmbG9hZF90eXBlJTNEJTIybGVhZl9sZXZlbCUyMiUyQyUyMHVzZV9zdHJlYW0lM0RUcnVlJTJDJTIwcmVjb3JkX3N0cmVhbSUzRFRydWUp",highlighted:'pipeline.transformer.enable_group_offload(onload_device=onload_device, offload_device=offload_device, offload_type=<span class="hljs-string">&quot;leaf_level&quot;</span>, use_stream=<span class="hljs-literal">True</span>, record_stream=<span class="hljs-literal">True</span>)',wrap:!1}}),Fs=new I({props:{title:"Offloading to disk",local:"offloading-to-disk",headingTag:"h4"}}),qs=new U({props:{code:"cGlwZWxpbmUudHJhbnNmb3JtZXIuZW5hYmxlX2dyb3VwX29mZmxvYWQob25sb2FkX2RldmljZSUzRG9ubG9hZF9kZXZpY2UlMkMlMjBvZmZsb2FkX2RldmljZSUzRG9mZmxvYWRfZGV2aWNlJTJDJTIwb2ZmbG9hZF90eXBlJTNEJTIybGVhZl9sZXZlbCUyMiUyQyUyMG9mZmxvYWRfdG9fZGlza19wYXRoJTNEJTIycGF0aCUyRnRvJTJGZGlzayUyMiklMEElMEFhcHBseV9ncm91cF9vZmZsb2FkaW5nKHBpcGVsaW5lLnRleHRfZW5jb2RlciUyQyUyMG9ubG9hZF9kZXZpY2UlM0RvbmxvYWRfZGV2aWNlJTJDJTIwb2ZmbG9hZF90eXBlJTNEJTIyYmxvY2tfbGV2ZWwlMjIlMkMlMjBudW1fYmxvY2tzX3Blcl9ncm91cCUzRDIlMkMlMjBvZmZsb2FkX3RvX2Rpc2tfcGF0aCUzRCUyMnBhdGglMkZ0byUyRmRpc2slMjIp",highlighted:`pipeline.transformer.enable_group_offload(onload_device=onload_device, offload_device=offload_device, offload_type=<span class="hljs-string">&quot;leaf_level&quot;</span>, offload_to_disk_path=<span class="hljs-string">&quot;path/to/disk&quot;</span>)

apply_group_offloading(pipeline.text_encoder, onload_device=onload_device, offload_type=<span class="hljs-string">&quot;block_level&quot;</span>, num_blocks_per_group=<span class="hljs-number">2</span>, offload_to_disk_path=<span class="hljs-string">&quot;path/to/disk&quot;</span>)`,wrap:!1}}),Ps=new I({props:{title:"Layerwise casting",local:"layerwise-casting",headingTag:"h2"}}),z=new C({props:{warning:!1,$$slots:{default:[za]},$$scope:{ctx:T}}}),Q=new C({props:{warning:!0,$$slots:{default:[Qa]},$$scope:{ctx:T}}}),se=new U({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwQ29nVmlkZW9YUGlwZWxpbmUlMkMlMjBDb2dWaWRlb1hUcmFuc2Zvcm1lcjNETW9kZWwlMEFmcm9tJTIwZGlmZnVzZXJzLnV0aWxzJTIwaW1wb3J0JTIwZXhwb3J0X3RvX3ZpZGVvJTBBJTBBdHJhbnNmb3JtZXIlMjAlM0QlMjBDb2dWaWRlb1hUcmFuc2Zvcm1lcjNETW9kZWwuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMlRIVURNJTJGQ29nVmlkZW9YLTViJTIyJTJDJTBBJTIwJTIwJTIwJTIwc3ViZm9sZGVyJTNEJTIydHJhbnNmb3JtZXIlMjIlMkMlMEElMjAlMjAlMjAlMjB0b3JjaF9kdHlwZSUzRHRv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word">from</span> diffusers <span class="hljs-keyword">import</span> CogVideoXPipeline, CogVideoXTransformer3DModel
<span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> export_to_video

transformer = CogVideoXTransformer3DModel.from_pretrained(
    <span class="hljs-string">&quot;THUDM/CogVideoX-5b&quot;</span>,
    subfolder=<span class="hljs-string">&quot;transformer&quot;</span>,
    torch_dtype=torch.bfloat16
)
transformer.enable_layerwise_casting(storage_dtype=torch.float8_e4m3fn, compute_dtype=torch.bfloat16)

pipeline = CogVideoXPipeline.from_pretrained(<span class="hljs-string">&quot;THUDM/CogVideoX-5b&quot;</span>,
    transformer=transformer,
    torch_dtype=torch.bfloat16
).to(<span class="hljs-string">&quot;cuda&quot;</span>)
prompt = (
    <span class="hljs-string">&quot;A panda, dressed in a small, red jacket and a tiny hat, sits on a wooden stool in a serene bamboo forest. &quot;</span>
    <span class="hljs-string">&quot;The panda&#x27;s fluffy paws strum a miniature acoustic guitar, producing soft, melodic tunes. Nearby, a few other &quot;</span>
    <span class="hljs-string">&quot;pandas gather, watching curiously and some clapping in rhythm. Sunlight filters through the tall bamboo, &quot;</span>
    <span class="hljs-string">&quot;casting a gentle glow on the scene. The panda&#x27;s face is expressive, showing concentration and joy as it plays. &quot;</span>
    <span class="hljs-string">&quot;The background includes a small, flowing stream and vibrant green foliage, enhancing the peaceful and magical &quot;</span>
    <span class="hljs-string">&quot;atmosphere of this unique musical performance.&quot;</span>
)
video = pipeline(prompt=prompt, guidance_scale=<span class="hljs-number">6</span>, num_inference_steps=<span class="hljs-number">50</span>).frames[<span class="hljs-number">0</span>]
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Max memory reserved: <span class="hljs-subst">{torch.cuda.max_memory_allocated() / <span class="hljs-number">1024</span>**<span class="hljs-number">3</span>:<span class="hljs-number">.2</span>f}</span> GB&quot;</span>)
export_to_video(video, <span class="hljs-string">&quot;output.mp4&quot;</span>, fps=<span class="hljs-number">8</span>)`,wrap:!1}}),le=new U({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwQ29nVmlkZW9YVHJhbnNmb3JtZXIzRE1vZGVsJTBBZnJvbSUyMGRpZmZ1c2Vycy5ob29rcyUyMGltcG9ydCUyMGFwcGx5X2xheWVyd2lzZV9jYXN0aW5nJTBBJTBBdHJhbnNmb3JtZXIlMjAlM0QlMjBDb2dWaWRlb1hUcmFuc2Zvcm1lcjNETW9kZWwuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMlRIVURNJTJGQ29nVmlkZW9YLTViJTIyJTJDJTBBJTIwJTIwJTIwJTIwc3ViZm9sZGVyJTNEJTIydHJhbnNmb3JtZXIlMjIlMkMlMEElMjAlMjAlMjAlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmJmbG9hdDE2JTBBKSUwQSUwQSUyMyUyMHNraXAlMjB0aGUlMjBub3JtYWxpemF0aW9uJTIwbGF5ZXIlMEFhcHBseV9sYXllcndpc2VfY2FzdGluZyglMEElMjAlMjAlMjAlMjB0cmFuc2Zvcm1lciUyQyUwQSUyMCUyMCUyMCUyMHN0b3JhZ2VfZHR5cGUlM0R0b3JjaC5mbG9hdDhfZTRtM2ZuJTJDJTBBJTIwJTIwJTIwJTIwY29tcHV0ZV9kdHlwZSUzRHRvcmNoLmJmbG9hdDE2JTJDJTBBJTIwJTIwJTIwJTIwc2tpcF9tb2R1bGVzX2NsYXNzZXMlM0QlNUIlMjJub3JtJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwbm9uX2Jsb2NraW5nJTNEVHJ1ZSUyQyUwQSk=",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> CogVideoXTransformer3DModel
<span class="hljs-keyword">from</span> diffusers.hooks <span class="hljs-keyword">import</span> apply_layerwise_casting

transformer = CogVideoXTransformer3DModel.from_pretrained(
    <span class="hljs-string">&quot;THUDM/CogVideoX-5b&quot;</span>,
    subfolder=<span class="hljs-string">&quot;transformer&quot;</span>,
    torch_dtype=torch.bfloat16
)

<span class="hljs-comment"># skip the normalization layer</span>
apply_layerwise_casting(
    transformer,
    storage_dtype=torch.float8_e4m3fn,
    compute_dtype=torch.bfloat16,
    skip_modules_classes=[<span class="hljs-string">&quot;norm&quot;</span>],
    non_blocking=<span class="hljs-literal">True</span>,
)`,wrap:!1}}),ne=new I({props:{title:"torch.channels_last",local:"torchchannelslast",headingTag:"h2"}}),ie=new U({props:{code:"cHJpbnQocGlwZWxpbmUudW5ldC5jb252X291dC5zdGF0ZV9kaWN0KCklNUIlMjJ3ZWlnaHQlMjIlNUQuc3RyaWRlKCkpJTIwJTIwJTIzJTIwKDI4ODAlMkMlMjA5JTJDJTIwMyUyQyUyMDEpJTBBcGlwZWxpbmUudW5ldC50byhtZW1vcnlfZm9ybWF0JTNEdG9yY2guY2hhbm5lbHNfbGFzdCklMjAlMjAlMjMlMjBpbi1wbGFjZSUyMG9wZXJhdGlvbiUwQXByaW50KCUwQSUyMCUyMCUyMCUyMHBpcGVsaW5lLnVuZXQuY29udl9vdXQuc3RhdGVfZGljdCgpJTVCJTIyd2VpZ2h0JTIyJTVELnN0cmlkZSgpJTBBKSUyMCUyMCUyMyUyMCgyODgwJTJDJTIwMSUyQyUyMDk2MCUyQyUyMDMyMCklMjBoYXZpbmclMjBhJTIwc3RyaWRlJTIwb2YlMjAxJTIwZm9yJTIwdGhlJTIwMm5kJTIwZGltZW5zaW9uJTIwcHJvdmVzJTIwdGhhdCUyMGl0JTIwd29ya3M=",highlighted:`<span class="hljs-built_in">print</span>(pipeline.unet.conv_out.state_dict()[<span class="hljs-string">&quot;weight&quot;</span>].stride())  <span class="hljs-comment"># (2880, 9, 3, 1)</span>
pipeline.unet.to(memory_format=torch.channels_last)  <span class="hljs-comment"># in-place operation</span>
<span class="hljs-built_in">print</span>(
    pipeline.unet.conv_out.state_dict()[<span class="hljs-string">&quot;weight&quot;</span>].stride()
)  <span class="hljs-comment"># (2880, 1, 960, 320) having a stride of 1 for the 2nd dimension proves that it works</span>`,wrap:!1}}),pe=new I({props:{title:"torch.jit.trace",local:"torchjittrace",headingTag:"h2"}}),re=new U({props:{code:"aW1wb3J0JTIwdGltZSUwQWltcG9ydCUyMHRvcmNoJTBBZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBaW1wb3J0JTIwZnVuY3Rvb2xzJTBBJTBBJTIzJTIwdG9yY2glMjBkaXNhYmxlJTIwZ3JhZCUwQXRvcmNoLnNldF9ncmFkX2VuYWJsZWQoRmFsc2UpJTBBJTBBJTIzJTIwc2V0JTIwdmFyaWFibGVzJTBBbl9leHBlcmltZW50cyUyMCUzRCUyMDIlMEF1bmV0X3J1bnNfcGVyX2V4cGVyaW1lbnQlMjAlM0QlMjA1MCUwQSUwQSUyMyUyMGxvYWQlMjBzYW1wbGUlMjBpbnB1dHMlMEFkZWYlMjBnZW5lcmF0ZV9pbnB1dHMoKSUzQSUwQSUyMCUyMCUyMCUyMHNhbXBsZSUyMCUzRCUyMHRvcmNoLnJhbmRuKCgyJTJDJTIwNCUyQyUyMDY0JTJDJTIwNjQpJTJDJTIwZGV2aWNlJTNEJTIyY3VkYSUyMiUyQyUyMGR0eXBlJTNEdG9yY2guZmxvYXQxNiklMEElMjAlMjAlMjAlMjB0aW1lc3RlcCUyMCUzRCUyMHRvcmNoLnJhbmQoMSUyQyUyMGRldmljZSUzRCUyMmN1ZGElMjIlMkMlMjBkdHlwZSUzRHRvcmNoLmZsb2F0MTYpJTIwKiUyMDk5OSUwQSUyMCUyMCUyMCUyMGVuY29kZXJfaGlkZGVuX3N0YXRlcyUyMCUzRCUyMHRvcmNoLnJhbmRuKCgyJTJDJTIwNzclMkMlMjA3NjgpJTJDJTIwZGV2aWNlJTNEJTIyY3VkYSUyMiUyQyUyMGR0eXBlJTNEdG9yY2guZmxvYXQxNiklMEEl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AlMjAlMjAlMjAlMjB0b3JjaC5jdWRhLnN5bmNocm9uaXplKCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBwcmludChmJTIydW5ldCUyMHRyYWNlZCUyMGluZmVyZW5jZSUyMHRvb2slMjAlN0J0aW1lLnRpbWUoKSUyMC0lMjBzdGFydF90aW1lJTNBLjJmJTdEJTIwc2Vjb25kcyUyMiklMEElMjAlMjAlMjAlMjBmb3IlMjBfJTIwaW4lMjByYW5nZShuX2V4cGVyaW1lbnRzKSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHRvcmNoLmN1ZGEuc3luY2hyb25pemUoKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHN0YXJ0X3RpbWUlMjAlM0QlMjB0aW1lLnRpbWUoKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZvciUyMF8lMjBpbiUyMHJhbmdlKHVuZXRfcnVuc19wZXJfZXhwZXJpbWVudCklM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBvcmlnX291dHB1dCUyMCUzRCUyMHVuZXQoKmlucHV0cyklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjB0b3JjaC5jdWRhLnN5bmNocm9uaXplKCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBwcmludChmJTIydW5ldCUyMGluZmVyZW5jZSUyMHRvb2slMjAlN0J0aW1lLnRpbWUoKSUyMC0lMjBzdGFydF90aW1lJTNBLjJmJTdEJTIwc2Vjb25kcyUyMiklMEElMEElMjMlMjBzYXZlJTIwdGhlJTIwbW9kZWwlMEF1bmV0X3RyYWNlZC5zYXZlKCUyMnVuZXRfdHJhY2VkLnB0JTIyKQ==",highlighted:`<span class="hljs-keyword">import</span> time
<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline
<span class="hljs-keyword">import</span> functools

<span class="hljs-comment"># torch disable grad</span>
torch.set_grad_enabled(<span class="hljs-literal">False</span>)

<span class="hljs-comment"># set variables</span>
n_experiments = <span class="hljs-number">2</span>
unet_runs_per_experiment = <span class="hljs-number">50</span>

<span class="hljs-comment"># load sample inputs</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">generate_inputs</span>():
    sample = torch.randn((<span class="hljs-number">2</span>, <span class="hljs-number">4</span>, <span class="hljs-number">64</span>, <span class="hljs-number">64</span>), device=<span class="hljs-string">&quot;cuda&quot;</span>, dtype=torch.float16)
    timestep = torch.rand(<span class="hljs-number">1</span>, device=<span class="hljs-string">&quot;cuda&quot;</span>, dtype=torch.float16) * <span class="hljs-number">999</span>
    encoder_hidden_states = torch.randn((<span class="hljs-number">2</span>, <span class="hljs-number">77</span>, <span class="hljs-number">768</span>), device=<span class="hljs-string">&quot;cuda&quot;</span>, dtype=torch.float16)
    <span class="hljs-keyword">return</span> sample, timestep, encoder_hidden_states


pipeline = StableDiffusionPipeline.from_pretrained(
    <span class="hljs-string">&quot;stable-diffusion-v1-5/stable-diffusion-v1-5&quot;</span>,
    torch_dtype=torch.float16,
    use_safetensors=<span class="hljs-literal">True</span>,
).to(<span class="hljs-string">&quot;cuda&quot;</span>)
unet = pipeline.unet
unet.<span class="hljs-built_in">eval</span>()
unet.to(memory_format=torch.channels_last)  <span class="hljs-comment"># use channels_last memory format</span>
unet.forward = functools.partial(unet.forward, return_dict=<span class="hljs-literal">False</span>)  <span class="hljs-comment"># set return_dict=False as default</span>

<span class="hljs-comment"># warmup</span>
<span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">3</span>):
    <span class="hljs-keyword">with</span> torch.inference_mode():
        inputs = generate_inputs()
        orig_output = unet(*inputs)

<span class="hljs-comment"># trace</span>
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;tracing..&quot;</span>)
unet_traced = torch.jit.trace(unet, inputs)
unet_traced.<span class="hljs-built_in">eval</span>()
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;done tracing&quot;</span>)

<span class="hljs-comment"># warmup and optimize graph</span>
<span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">5</span>):
    <span class="hljs-keyword">with</span> torch.inference_mode():
        inputs = generate_inputs()
        orig_output = unet_traced(*inputs)

<span class="hljs-comment"># benchmarking</span>
<span class="hljs-keyword">with</span> torch.inference_mode():
    <span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(n_experiments):
        torch.cuda.synchronize()
        start_time = time.time()
        <span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(unet_runs_per_experiment):
            orig_output = unet_traced(*inputs)
        torch.cuda.synchronize()
        <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;unet traced inference took <span class="hljs-subst">{time.time() - start_time:<span class="hljs-number">.2</span>f}</span> seconds&quot;</span>)
    <span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(n_experiments):
        torch.cuda.synchronize()
        start_time = time.time()
        <span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(unet_runs_per_experiment):
            orig_output = unet(*inputs)
        torch.cuda.synchronize()
        <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;unet inference took <span class="hljs-subst">{time.time() - start_time:<span class="hljs-number">.2</span>f}</span> seconds&quot;</span>)

<span class="hljs-comment"># save the model</span>
unet_traced.save(<span class="hljs-string">&quot;unet_traced.pt&quot;</span>)`,wrap:!1}}),ce=new U({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwU3RhYmxlRGlmZnVzaW9uUGlwZWxpbmUlMEFmcm9tJTIwZGF0YWNsYXNzZXMlMjBpbXBvcnQlMjBkYXRhY2xhc3MlMEElMEElNDB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bl9zdGF0ZXMpJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwc2FtcGxlJTIwJTNEJTIwdW5ldF90cmFjZWQobGF0ZW50X21vZGVsX2lucHV0JTJDJTIwdCUyQyUyMGVuY29kZXJfaGlkZGVuX3N0YXRlcyklNUIwJTVEJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcmV0dXJuJTIwVU5ldDJEQ29uZGl0aW9uT3V0cHV0KHNhbXBsZSUzRHNhbXBsZSklMEElMEFwaXBlbGluZS51bmV0JTIwJTNEJTIwVHJhY2VkVU5ldCgpJTBBJTBBd2l0aCUyMHRvcmNoLmluZmVyZW5jZV9tb2RlKCklM0ElMEElMjAlMjAlMjAlMjBpbWFnZSUyMCUzRCUyMHBpcGUoJTVCcHJvbXB0JTVEJTIwKiUyMDElMkMlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNENTApLmltYWdlcyU1QjAlNUQ=",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline
<span class="hljs-keyword">from</span> dataclasses <span class="hljs-keyword">import</span> dataclass

<span class="hljs-meta">@dataclass</span>
<span class="hljs-keyword">class</span> <span class="hljs-title class_">UNet2DConditionOutput</span>:
    sample: torch.Tensor

pipeline = StableDiffusionPipeline.from_pretrained(
    <span class="hljs-string">&quot;stable-diffusion-v1-5/stable-diffusion-v1-5&quot;</span>,
    torch_dtype=torch.float16,
    use_safetensors=<span class="hljs-literal">True</span>,
).to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-comment"># use jitted unet</span>
unet_traced = torch.jit.load(<span class="hljs-string">&quot;unet_traced.pt&quot;</span>)

<span class="hljs-comment"># del pipeline.unet</span>
<span class="hljs-keyword">class</span> <span class="hljs-title class_">TracedUNet</span>(torch.nn.Module):
    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self</span>):
        <span class="hljs-built_in">super</span>().__init__()
        self.in_channels = pipe.unet.config.in_channels
        self.device = pipe.unet.device

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">forward</span>(<span class="hljs-params">self, latent_model_input, t, encoder_hidden_states</span>):
        sample = unet_traced(latent_model_input, t, encoder_hidden_states)[<span class="hljs-number">0</span>]
        <span class="hljs-keyword">return</span> UNet2DConditionOutput(sample=sample)

pipeline.unet = TracedUNet()

<span class="hljs-keyword">with</span> torch.inference_mode():
    image = pipe([prompt] * <span class="hljs-number">1</span>, num_inference_steps=<span class="hljs-number">50</span>).images[<span class="hljs-number">0</span>]`,wrap:!1}}),de=new I({props:{title:"Memory-efficient attention",local:"memory-efficient-attention",headingTag:"h2"}}),R=new C({props:{warning:!1,$$slots:{default:[Ra]},$$scope:{ctx:T}}}),Je=new U({props:{code:"JTIzJTIwcGlwJTIwaW5zdGFsbCUyMHhmb3JtZXJzJTBBaW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwU3RhYmxlRGlmZnVzaW9uWExQaXBlbGluZSUwQSUwQXBpcGVsaW5lJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uWExQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIyc3RhYmlsaXR5YWklMkZzdGFibGUtZGlmZnVzaW9uLXhsLWJhc2UtMS4wJTIyJTJDJTBBJTIwJTIwJTIwJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTJDJTBBKS50byglMjJjdWRhJTIyKSUwQXBpcGVsaW5lLmVuYWJsZV94Zm9ybWVyc19tZW1vcnlfZWZmaWNpZW50X2F0dGVudGlvbigp",highlighted:`<span class="hljs-comment"># pip install xformers</span>
<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionXLPipeline

pipeline = StableDiffusionXLPipeline.from_pretrained(
    <span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>,
    torch_dtype=torch.float16,
).to(<span class="hljs-string">&quot;cuda&quot;</span>)
pipeline.enable_xformers_memory_efficient_attention()`,wrap:!1}}),be=new U({props:{code:"cGlwZWxpbmUuZGlzYWJsZV94Zm9ybWVyc19tZW1vcnlfZWZmaWNpZW50X2F0dGVudGlvbigp",highlighted:"pipeline.disable_xformers_memory_efficient_attention()",wrap:!1}}),we=new Ia({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/optimization/memory.md"}}),{c(){a=o("meta"),b=t(),p=o("p"),h=t(),c(w.$$.fragment),j=t(),g=o("p"),g.innerHTML=G,Z=t(),x=o("p"),x.textContent=J,_=t(),c(W.$$.fragment),Te=t(),c(H.$$.fragment),Ue=t(),E=o("p"),E.innerHTML=fn,ge=t(),c(S.$$.fragment),Ze=t(),c(F.$$.fragment),_e=t(),A=o("p"),A.textContent=un,xe=t(),L=o("p"),L.innerHTML=Mn,Ie=t(),c(q.$$.fragment),Ge=t(),D=o("p"),D.textContent=yn,ve=t(),c(P.$$.fragment),Ce=t(),c(K.$$.fragment),We=t(),c(k.$$.fragment),ke=t(),O=o("p"),O.innerHTML=Jn,Ve=t(),c(V.$$.fragment),Be=t(),ss=o("p"),ss.innerHTML=hn,$e=t(),es=o("p"),es.innerHTML=bn,Xe=t(),c(ls.$$.fragment),Ne=t(),ns=o("p"),ns.innerHTML=wn,Ye=t(),c(as.$$.fragment),ze=t(),ts=o("p"),ts.innerHTML=jn,Qe=t(),c(is.$$.fragment),Re=t(),ps=o("p"),ps.textContent=Tn,He=t(),os=o("ul"),os.innerHTML=Un,Ee=t(),rs=o("p"),rs.innerHTML=gn,Se=t(),c(ms.$$.fragment),Fe=t(),c(cs.$$.fragment),Ae=t(),ds=o("p"),ds.textContent=Zn,Le=t(),fs=o("p"),fs.textContent=_n,qe=t(),us=o("p"),us.innerHTML=xn,De=t(),c(Ms.$$.fragment),Pe=t(),c(B.$$.fragment),Ke=t(),c(ys.$$.fragment),Oe=t(),Js=o("p"),Js.textContent=In,sl=t(),hs=o("p"),hs.innerHTML=Gn,el=t(),c(bs.$$.fragment),ll=t(),ws=o("blockquote"),ws.innerHTML=vn,nl=t(),c(js.$$.fragment),al=t(),Ts=o("p"),Ts.textContent=Cn,tl=t(),Us=o("p"),Us.innerHTML=Wn,il=t(),c(gs.$$.fragment),pl=t(),Zs=o("p"),Zs.textContent=kn,ol=t(),_s=o("p"),_s.innerHTML=Vn,rl=t(),c($.$$.fragment),ml=t(),xs=o("p"),xs.innerHTML=Bn,cl=t(),c(Is.$$.fragment),dl=t(),c(Gs.$$.fragment),fl=t(),vs=o("p"),vs.innerHTML=$n,ul=t(),c(X.$$.fragment),Ml=t(),Cs=o("p"),Cs.innerHTML=Xn,yl=t(),c(Ws.$$.fragment),Jl=t(),ks=o("p"),ks.innerHTML=Nn,hl=t(),c(Vs.$$.fragment),bl=t(),Bs=o("p"),Bs.innerHTML=Yn,wl=t(),c(N.$$.fragment),jl=t(),$s=o("p"),$s.innerHTML=zn,Tl=t(),Xs=o("p"),Xs.innerHTML=Qn,Ul=t(),Ns=o("ul"),Ns.innerHTML=Rn,gl=t(),c(Ys.$$.fragment),Zl=t(),c(zs.$$.fragment),_l=t(),Qs=o("p"),Qs.innerHTML=Hn,xl=t(),Rs=o("p"),Rs.innerHTML=En,Il=t(),c(Y.$$.fragment),Gl=t(),Hs=o("p"),Hs.innerHTML=Sn,vl=t(),c(Es.$$.fragment),Cl=t(),Ss=o("p"),Ss.innerHTML=Fn,Wl=t(),c(Fs.$$.fragment),kl=t(),As=o("p"),As.textContent=An,Vl=t(),Ls=o("p"),Ls.innerHTML=Ln,Bl=t(),c(qs.$$.fragment),$l=t(),Ds=o("p"),Ds.innerHTML=qn,Xl=t(),c(Ps.$$.fragment),Nl=t(),c(z.$$.fragment),Yl=t(),Ks=o("p"),Ks.innerHTML=Dn,zl=t(),c(Q.$$.fragment),Ql=t(),Os=o("p"),Os.innerHTML=Pn,Rl=t(),c(se.$$.fragment),Hl=t(),ee=o("p"),ee.innerHTML=Kn,El=t(),c(le.$$.fragment),Sl=t(),c(ne.$$.fragment),Fl=t(),ae=o("p"),ae.innerHTML=On,Al=t(),te=o("p"),te.textContent=sa,Ll=t(),c(ie.$$.fragment),ql=t(),c(pe.$$.fragment),Dl=t(),oe=o("p"),oe.innerHTML=ea,Pl=t(),c(re.$$.fragment),Kl=t(),me=o("p"),me.textContent=la,Ol=t(),c(ce.$$.fragment),sn=t(),c(de.$$.fragment),en=t(),c(R.$$.fragment),ln=t(),fe=o("p"),fe.textContent=na,nn=t(),ue=o("p"),ue.innerHTML=aa,an=t(),Me=o("p"),Me.innerHTML=ta,tn=t(),ye=o("p"),ye.innerHTML=ia,pn=t(),c(Je.$$.fragment),on=t(),he=o("p"),he.innerHTML=pa,rn=t(),c(be.$$.fragment),mn=t(),c(we.$$.fragment),cn=t(),je=o("p"),this.h()},l(s){const e=_a("svelte-u9bgzb",document.head);a=r(e,"META",{name:!0,content:!0}),e.forEach(l),b=i(s),p=r(s,"P",{}),ba(p).forEach(l),h=i(s),d(w.$$.fragment,s),j=i(s),g=r(s,"P",{"data-svelte-h":!0}),m(g)!=="svelte-11rtgo9"&&(g.innerHTML=G),Z=i(s),x=r(s,"P",{"data-svelte-h":!0}),m(x)!=="svelte-vxpcfq"&&(x.textContent=J),_=i(s),d(W.$$.fragment,s),Te=i(s),d(H.$$.fragment,s),Ue=i(s),E=r(s,"P",{"data-svelte-h":!0}),m(E)!=="svelte-646d08"&&(E.innerHTML=fn),ge=i(s),d(S.$$.fragment,s),Ze=i(s),d(F.$$.fragment,s),_e=i(s),A=r(s,"P",{"data-svelte-h":!0}),m(A)!=="svelte-z6beln"&&(A.textContent=un),xe=i(s),L=r(s,"P",{"data-svelte-h":!0}),m(L)!=="svelte-115ttl4"&&(L.innerHTML=Mn),Ie=i(s),d(q.$$.fragment,s),Ge=i(s),D=r(s,"P",{"data-svelte-h":!0}),m(D)!=="svelte-1f9wrc7"&&(D.textContent=yn),ve=i(s),d(P.$$.fragment,s),Ce=i(s),d(K.$$.fragment,s),We=i(s),d(k.$$.fragment,s),ke=i(s),O=r(s,"P",{"data-svelte-h":!0}),m(O)!=="svelte-1n4q4np"&&(O.innerHTML=Jn),Ve=i(s),d(V.$$.fragment,s),Be=i(s),ss=r(s,"P",{"data-svelte-h":!0}),m(ss)!=="svelte-2a94z6"&&(ss.innerHTML=hn),$e=i(s),es=r(s,"P",{"data-svelte-h":!0}),m(es)!=="svelte-c7w8iz"&&(es.innerHTML=bn),Xe=i(s),d(ls.$$.fragment,s),Ne=i(s),ns=r(s,"P",{"data-svelte-h":!0}),m(ns)!=="svelte-1ut2jly"&&(ns.innerHTML=wn),Ye=i(s),d(as.$$.fragment,s),ze=i(s),ts=r(s,"P",{"data-svelte-h":!0}),m(ts)!=="svelte-1oxgib7"&&(ts.innerHTML=jn),Qe=i(s),d(is.$$.fragment,s),Re=i(s),ps=r(s,"P",{"data-svelte-h":!0}),m(ps)!=="svelte-whoqae"&&(ps.textContent=Tn),He=i(s),os=r(s,"UL",{"data-svelte-h":!0}),m(os)!=="svelte-5cwvqn"&&(os.innerHTML=Un),Ee=i(s),rs=r(s,"P",{"data-svelte-h":!0}),m(rs)!=="svelte-6e1s7a"&&(rs.innerHTML=gn),Se=i(s),d(ms.$$.fragment,s),Fe=i(s),d(cs.$$.fragment,s),Ae=i(s),ds=r(s,"P",{"data-svelte-h":!0}),m(ds)!=="svelte-d36gg7"&&(ds.textContent=Zn),Le=i(s),fs=r(s,"P",{"data-svelte-h":!0}),m(fs)!=="svelte-5ay0zr"&&(fs.textContent=_n),qe=i(s),us=r(s,"P",{"data-svelte-h":!0}),m(us)!=="svelte-jm20t4"&&(us.innerHTML=xn),De=i(s),d(Ms.$$.fragment,s),Pe=i(s),d(B.$$.fragment,s),Ke=i(s),d(ys.$$.fragment,s),Oe=i(s),Js=r(s,"P",{"data-svelte-h":!0}),m(Js)!=="svelte-vsq5zh"&&(Js.textContent=In),sl=i(s),hs=r(s,"P",{"data-svelte-h":!0}),m(hs)!=="svelte-a79yk8"&&(hs.innerHTML=Gn),el=i(s),d(bs.$$.fragment,s),ll=i(s),ws=r(s,"BLOCKQUOTE",{"data-svelte-h":!0}),m(ws)!=="svelte-1ch13xh"&&(ws.innerHTML=vn),nl=i(s),d(js.$$.fragment,s),al=i(s),Ts=r(s,"P",{"data-svelte-h":!0}),m(Ts)!=="svelte-1lghmz8"&&(Ts.textContent=Cn),tl=i(s),Us=r(s,"P",{"data-svelte-h":!0}),m(Us)!=="svelte-sey8xy"&&(Us.innerHTML=Wn),il=i(s),d(gs.$$.fragment,s),pl=i(s),Zs=r(s,"P",{"data-svelte-h":!0}),m(Zs)!=="svelte-nwk8qi"&&(Zs.textContent=kn),ol=i(s),_s=r(s,"P",{"data-svelte-h":!0}),m(_s)!=="svelte-1jssif2"&&(_s.innerHTML=Vn),rl=i(s),d($.$$.fragment,s),ml=i(s),xs=r(s,"P",{"data-svelte-h":!0}),m(xs)!=="svelte-vdp76n"&&(xs.innerHTML=Bn),cl=i(s),d(Is.$$.fragment,s),dl=i(s),d(Gs.$$.fragment,s),fl=i(s),vs=r(s,"P",{"data-svelte-h":!0}),m(vs)!=="svelte-lwbzkf"&&(vs.innerHTML=$n),ul=i(s),d(X.$$.fragment,s),Ml=i(s),Cs=r(s,"P",{"data-svelte-h":!0}),m(Cs)!=="svelte-t552fb"&&(Cs.innerHTML=Xn),yl=i(s),d(Ws.$$.fragment,s),Jl=i(s),ks=r(s,"P",{"data-svelte-h":!0}),m(ks)!=="svelte-1ic7r11"&&(ks.innerHTML=Nn),hl=i(s),d(Vs.$$.fragment,s),bl=i(s),Bs=r(s,"P",{"data-svelte-h":!0}),m(Bs)!=="svelte-6x5rs4"&&(Bs.innerHTML=Yn),wl=i(s),d(N.$$.fragment,s),jl=i(s),$s=r(s,"P",{"data-svelte-h":!0}),m($s)!=="svelte-u1fru0"&&($s.innerHTML=zn),Tl=i(s),Xs=r(s,"P",{"data-svelte-h":!0}),m(Xs)!=="svelte-1agvgw7"&&(Xs.innerHTML=Qn),Ul=i(s),Ns=r(s,"UL",{"data-svelte-h":!0}),m(Ns)!=="svelte-8dkla6"&&(Ns.innerHTML=Rn),gl=i(s),d(Ys.$$.fragment,s),Zl=i(s),d(zs.$$.fragment,s),_l=i(s),Qs=r(s,"P",{"data-svelte-h":!0}),m(Qs)!=="svelte-1ik3m1u"&&(Qs.innerHTML=Hn),xl=i(s),Rs=r(s,"P",{"data-svelte-h":!0}),m(Rs)!=="svelte-f4wc5s"&&(Rs.innerHTML=En),Il=i(s),d(Y.$$.fragment,s),Gl=i(s),Hs=r(s,"P",{"data-svelte-h":!0}),m(Hs)!=="svelte-17oamma"&&(Hs.innerHTML=Sn),vl=i(s),d(Es.$$.fragment,s),Cl=i(s),Ss=r(s,"P",{"data-svelte-h":!0}),m(Ss)!=="svelte-1ixqgvf"&&(Ss.innerHTML=Fn),Wl=i(s),d(Fs.$$.fragment,s),kl=i(s),As=r(s,"P",{"data-svelte-h":!0}),m(As)!=="svelte-mq1z2c"&&(As.textContent=An),Vl=i(s),Ls=r(s,"P",{"data-svelte-h":!0}),m(Ls)!=="svelte-1p1tymo"&&(Ls.innerHTML=Ln),Bl=i(s),d(qs.$$.fragment,s),$l=i(s),Ds=r(s,"P",{"data-svelte-h":!0}),m(Ds)!=="svelte-1ugmkgt"&&(Ds.innerHTML=qn),Xl=i(s),d(Ps.$$.fragment,s),Nl=i(s),d(z.$$.fragment,s),Yl=i(s),Ks=r(s,"P",{"data-svelte-h":!0}),m(Ks)!=="svelte-1boiobn"&&(Ks.innerHTML=Dn),zl=i(s),d(Q.$$.fragment,s),Ql=i(s),Os=r(s,"P",{"data-svelte-h":!0}),m(Os)!=="svelte-19ytv0"&&(Os.innerHTML=Pn),Rl=i(s),d(se.$$.fragment,s),Hl=i(s),ee=r(s,"P",{"data-svelte-h":!0}),m(ee)!=="svelte-1hmx68j"&&(ee.innerHTML=Kn),El=i(s),d(le.$$.fragment,s),Sl=i(s),d(ne.$$.fragment,s),Fl=i(s),ae=r(s,"P",{"data-svelte-h":!0}),m(ae)!=="svelte-1tu261v"&&(ae.innerHTML=On),Al=i(s),te=r(s,"P",{"data-svelte-h":!0}),m(te)!=="svelte-dfwok5"&&(te.textContent=sa),Ll=i(s),d(ie.$$.fragment,s),ql=i(s),d(pe.$$.fragment,s),Dl=i(s),oe=r(s,"P",{"data-svelte-h":!0}),m(oe)!=="svelte-15jhfav"&&(oe.innerHTML=ea),Pl=i(s),d(re.$$.fragment,s),Kl=i(s),me=r(s,"P",{"data-svelte-h":!0}),m(me)!=="svelte-16t9h37"&&(me.textContent=la),Ol=i(s),d(ce.$$.fragment,s),sn=i(s),d(de.$$.fragment,s),en=i(s),d(R.$$.fragment,s),ln=i(s),fe=r(s,"P",{"data-svelte-h":!0}),m(fe)!=="svelte-8q1sue"&&(fe.textContent=na),nn=i(s),ue=r(s,"P",{"data-svelte-h":!0}),m(ue)!=="svelte-1idpc42"&&(ue.innerHTML=aa),an=i(s),Me=r(s,"P",{"data-svelte-h":!0}),m(Me)!=="svelte-4p44md"&&(Me.innerHTML=ta),tn=i(s),ye=r(s,"P",{"data-svelte-h":!0}),m(ye)!=="svelte-u62ci7"&&(ye.innerHTML=ia),pn=i(s),d(Je.$$.fragment,s),on=i(s),he=r(s,"P",{"data-svelte-h":!0}),m(he)!=="svelte-p2p9rw"&&(he.innerHTML=pa),rn=i(s),d(be.$$.fragment,s),mn=i(s),d(we.$$.fragment,s),cn=i(s),je=r(s,"P",{}),ba(je).forEach(l),this.h()},h(){wa(a,"name","hf:doc:metadata"),wa(a,"content",Ea)},m(s,e){xa(document.head,a),n(s,b,e),n(s,p,e),n(s,h,e),f(w,s,e),n(s,j,e),n(s,g,e),n(s,Z,e),n(s,x,e),n(s,_,e),f(W,s,e),n(s,Te,e),f(H,s,e),n(s,Ue,e),n(s,E,e),n(s,ge,e),f(S,s,e),n(s,Ze,e),f(F,s,e),n(s,_e,e),n(s,A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l,e),n(s,Hs,e),n(s,vl,e),f(Es,s,e),n(s,Cl,e),n(s,Ss,e),n(s,Wl,e),f(Fs,s,e),n(s,kl,e),n(s,As,e),n(s,Vl,e),n(s,Ls,e),n(s,Bl,e),f(qs,s,e),n(s,$l,e),n(s,Ds,e),n(s,Xl,e),f(Ps,s,e),n(s,Nl,e),f(z,s,e),n(s,Yl,e),n(s,Ks,e),n(s,zl,e),f(Q,s,e),n(s,Ql,e),n(s,Os,e),n(s,Rl,e),f(se,s,e),n(s,Hl,e),n(s,ee,e),n(s,El,e),f(le,s,e),n(s,Sl,e),f(ne,s,e),n(s,Fl,e),n(s,ae,e),n(s,Al,e),n(s,te,e),n(s,Ll,e),f(ie,s,e),n(s,ql,e),f(pe,s,e),n(s,Dl,e),n(s,oe,e),n(s,Pl,e),f(re,s,e),n(s,Kl,e),n(s,me,e),n(s,Ol,e),f(ce,s,e),n(s,sn,e),f(de,s,e),n(s,en,e),f(R,s,e),n(s,ln,e),n(s,fe,e),n(s,nn,e),n(s,ue,e),n(s,an,e),n(s,Me,e),n(s,tn,e),n(s,ye,e),n(s,pn,e),f(Je,s,e),n(s,on,e),n(s,he,e),n(s,rn,e),f(be,s,e),n(s,mn,e),f(we,s,e),n(s,cn,e),n(s,je,e),dn=!0},p(s,[e]){const oa={};e&2&&(oa.$$scope={dirty:e,ctx:s}),W.$set(oa);const ra={};e&2&&(ra.$$scope={dirty:e,ctx:s}),k.$set(ra);const ma={};e&2&&(ma.$$scope={dirty:e,ctx:s}),V.$set(ma);const ca={};e&2&&(ca.$$scope={dirty:e,ctx:s}),B.$set(ca);const da={};e&2&&(da.$$scope={dirty:e,ctx:s}),$.$set(da);const fa={};e&2&&(fa.$$scope={dirty:e,ctx:s}),X.$set(fa);const ua={};e&2&&(ua.$$scope={dirty:e,ctx:s}),N.$set(ua);const Ma={};e&2&&(Ma.$$scope={dirty:e,ctx:s}),Y.$set(Ma);const ya={};e&2&&(ya.$$scope={dirty:e,ctx:s}),z.$set(ya);const Ja={};e&2&&(Ja.$$scope={dirty:e,ctx:s}),Q.$set(Ja);const ha={};e&2&&(ha.$$scope={dirty:e,ctx:s}),R.$set(ha)},i(s){dn||(u(w.$$.fragment,s),u(W.$$.fragment,s),u(H.$$.fragment,s),u(S.$$.fragment,s),u(F.$$.fragment,s),u(q.$$.fragment,s),u(P.$$.fragment,s),u(K.$$.fragment,s),u(k.$$.fragment,s),u(V.$$.fragment,s),u(ls.$$.fragment,s),u(as.$$.fragment,s),u(is.$$.fragment,s),u(ms.$$.fragment,s),u(cs.$$.fragment,s),u(Ms.$$.fragment,s),u(B.$$.fragment,s),u(ys.$$.fragment,s),u(bs.$$.fragment,s),u(js.$$.fragment,s),u(gs.$$.fragment,s),u($.$$.fragment,s),u(Is.$$.fragment,s),u(Gs.$$.fragment,s),u(X.$$.fragment,s),u(Ws.$$.fragment,s),u(Vs.$$.fragment,s),u(N.$$.fragment,s),u(Ys.$$.fragment,s),u(zs.$$.fragment,s),u(Y.$$.fragment,s),u(Es.$$.fragment,s),u(Fs.$$.fragment,s),u(qs.$$.fragment,s),u(Ps.$$.fragment,s),u(z.$$.fragment,s),u(Q.$$.fragment,s),u(se.$$.fragment,s),u(le.$$.fragment,s),u(ne.$$.fragment,s),u(ie.$$.fragment,s),u(pe.$$.fragment,s),u(re.$$.fragment,s),u(ce.$$.fragment,s),u(de.$$.fragment,s),u(R.$$.fragment,s),u(Je.$$.fragment,s),u(be.$$.fragment,s),u(we.$$.fragment,s),dn=!0)},o(s){M(w.$$.fragment,s),M(W.$$.fragment,s),M(H.$$.fragment,s),M(S.$$.fragment,s),M(F.$$.fragment,s),M(q.$$.fragment,s),M(P.$$.fragment,s),M(K.$$.fragment,s),M(k.$$.fragment,s),M(V.$$.fragment,s),M(ls.$$.fragment,s),M(as.$$.fragment,s),M(is.$$.fragment,s),M(ms.$$.fragment,s),M(cs.$$.fragment,s),M(Ms.$$.fragment,s),M(B.$$.fragment,s),M(ys.$$.fragment,s),M(bs.$$.fragment,s),M(js.$$.fragment,s),M(gs.$$.fragment,s),M($.$$.fragment,s),M(Is.$$.fragment,s),M(Gs.$$.fragment,s),M(X.$$.fragment,s),M(Ws.$$.fragment,s),M(Vs.$$.fragment,s),M(N.$$.fragment,s),M(Ys.$$.fragment,s),M(zs.$$.fragment,s),M(Y.$$.fragment,s),M(Es.$$.fragment,s),M(Fs.$$.fragment,s),M(qs.$$.fragment,s),M(Ps.$$.fragment,s),M(z.$$.fragment,s),M(Q.$$.fragment,s),M(se.$$.fragment,s),M(le.$$.fragment,s),M(ne.$$.fragment,s),M(ie.$$.fragment,s),M(pe.$$.fragment,s),M(re.$$.fragment,s),M(ce.$$.fragment,s),M(de.$$.fragment,s),M(R.$$.fragment,s),M(Je.$$.fragment,s),M(be.$$.fragment,s),M(we.$$.fragment,s),dn=!1},d(s){s&&(l(b),l(p),l(h),l(j),l(g),l(Z),l(x),l(_),l(Te),l(Ue),l(E),l(ge),l(Ze),l(_e),l(A),l(xe),l(L),l(Ie),l(Ge),l(D),l(ve),l(Ce),l(We),l(ke),l(O),l(Ve),l(Be),l(ss),l($e),l(es),l(Xe),l(Ne),l(ns),l(Ye),l(ze),l(ts),l(Qe),l(Re),l(ps),l(He),l(os),l(Ee),l(rs),l(Se),l(Fe),l(Ae),l(ds),l(Le),l(fs),l(qe),l(us),l(De),l(Pe),l(Ke),l(Oe),l(Js),l(sl),l(hs),l(el),l(ll),l(ws),l(nl),l(al),l(Ts),l(tl),l(Us),l(il),l(pl),l(Zs),l(ol),l(_s),l(rl),l(ml),l(xs),l(cl),l(dl),l(fl),l(vs),l(ul),l(Ml),l(Cs),l(yl),l(Jl),l(ks),l(hl),l(bl),l(Bs),l(wl),l(jl),l($s),l(Tl),l(Xs),l(Ul),l(Ns),l(gl),l(Zl),l(_l),l(Qs),l(xl),l(Rs),l(Il),l(Gl),l(Hs),l(vl),l(Cl),l(Ss),l(Wl),l(kl),l(As),l(Vl),l(Ls),l(Bl),l($l),l(Ds),l(Xl),l(Nl),l(Yl),l(Ks),l(zl),l(Ql),l(Os),l(Rl),l(Hl),l(ee),l(El),l(Sl),l(Fl),l(ae),l(Al),l(te),l(Ll),l(ql),l(Dl),l(oe),l(Pl),l(Kl),l(me),l(Ol),l(sn),l(en),l(ln),l(fe),l(nn),l(ue),l(an),l(Me),l(tn),l(ye),l(pn),l(on),l(he),l(rn),l(mn),l(cn),l(je)),l(a),y(w,s),y(W,s),y(H,s),y(S,s),y(F,s),y(q,s),y(P,s),y(K,s),y(k,s),y(V,s),y(ls,s),y(as,s),y(is,s),y(ms,s),y(cs,s),y(Ms,s),y(B,s),y(ys,s),y(bs,s),y(js,s),y(gs,s),y($,s),y(Is,s),y(Gs,s),y(X,s),y(Ws,s),y(Vs,s),y(N,s),y(Ys,s),y(zs,s),y(Y,s),y(Es,s),y(Fs,s),y(qs,s),y(Ps,s),y(z,s),y(Q,s),y(se,s),y(le,s),y(ne,s),y(ie,s),y(pe,s),y(re,s),y(ce,s),y(de,s),y(R,s),y(Je,s),y(be,s),y(we,s)}}}const Ea='{"title":"Reduce memory usage","local":"reduce-memory-usage","sections":[{"title":"Multiple GPUs","local":"multiple-gpus","sections":[{"title":"Sharded checkpoints","local":"sharded-checkpoints","sections":[],"depth":3},{"title":"Device placement","local":"device-placement","sections":[],"depth":3}],"depth":2},{"title":"VAE slicing","local":"vae-slicing","sections":[],"depth":2},{"title":"VAE tiling","local":"vae-tiling","sections":[],"depth":2},{"title":"Offloading","local":"offloading","sections":[{"title":"CPU offloading","local":"cpu-offloading","sections":[],"depth":3},{"title":"Model offloading","local":"model-offloading","sections":[],"depth":3},{"title":"Group offloading","local":"group-offloading","sections":[{"title":"CUDA stream","local":"cuda-stream","sections":[],"depth":4},{"title":"Offloading to disk","local":"offloading-to-disk","sections":[],"depth":4}],"depth":3}],"depth":2},{"title":"Layerwise casting","local":"layerwise-casting","sections":[],"depth":2},{"title":"torch.channels_last","local":"torchchannelslast","sections":[],"depth":2},{"title":"torch.jit.trace","local":"torchjittrace","sections":[],"depth":2},{"title":"Memory-efficient attention","local":"memory-efficient-attention","sections":[],"depth":2}],"depth":1}';function Sa(T){return Ua(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ka extends ga{constructor(a){super(),Za(this,a,Sa,Ha,Ta,{})}}export{Ka as component};
