Buckets:
| import"../chunks/DsnmJJEf.js";import{i as Q,h as q,C as X,H as l,a,E as C,s as x}from"../chunks/Bqo1LwON.js";import{p as R,o as Y,s as e,f as V,a as W,b as F,d as v,n as P}from"../chunks/DK803DsY.js";const N='{"title":"DiffusionPipeline","local":"diffusionpipeline","sections":[{"title":"Loading a pipeline","local":"loading-a-pipeline","sections":[{"title":"Local pipelines","local":"local-pipelines","sections":[],"depth":3}],"depth":2},{"title":"Pipeline data types","local":"pipeline-data-types","sections":[],"depth":2},{"title":"Device placement","local":"device-placement","sections":[],"depth":2},{"title":"Parallel loading","local":"parallel-loading","sections":[],"depth":2},{"title":"Replacing models in a pipeline","local":"replacing-models-in-a-pipeline","sections":[],"depth":2},{"title":"Reusing models in multiple pipelines","local":"reusing-models-in-multiple-pipelines","sections":[],"depth":2},{"title":"Next steps","local":"next-steps","sections":[],"depth":2}],"depth":1}';var S=v('<meta name="hf:doc:metadata"/>'),D=v('<p></p> <!> <!> <p>Diffusion models consist of multiple components like UNets or diffusion transformers (DiTs), text encoders, variational autoencoders (VAEs), and schedulers. The <a href="/docs/diffusers/pr_15151/en/api/pipelines/overview#diffusers.DiffusionPipeline">DiffusionPipeline</a> wraps all of these components into a single easy-to-use API without giving up the flexibility to modify its components.</p> <p>This guide will show you how to load a <a href="/docs/diffusers/pr_15151/en/api/pipelines/overview#diffusers.DiffusionPipeline">DiffusionPipeline</a>.</p> <!> <p><a href="/docs/diffusers/pr_15151/en/api/pipelines/overview#diffusers.DiffusionPipeline">DiffusionPipeline</a> is a base pipeline class that automatically selects and returns an instance of a model’s pipeline subclass, like <a href="/docs/diffusers/pr_15151/en/api/pipelines/qwenimage#diffusers.QwenImagePipeline">QwenImagePipeline</a>, by scanning the <code>model_index.json</code> file for the class name.</p> <p>Pass a model id to <a href="/docs/diffusers/pr_15151/en/api/pipelines/overview#diffusers.DiffusionPipeline.from_pretrained">from_pretrained()</a> to load a pipeline.</p> <!> <p>Every model has a specific pipeline subclass that inherits from <a href="/docs/diffusers/pr_15151/en/api/pipelines/overview#diffusers.DiffusionPipeline">DiffusionPipeline</a>. A subclass usually has a narrow focus and is task-specific. See the table below for an example.</p> <table><thead><tr><th>pipeline subclass</th><th>task</th></tr></thead><tbody><tr><td><a href="/docs/diffusers/pr_15151/en/api/pipelines/qwenimage#diffusers.QwenImagePipeline">QwenImagePipeline</a></td><td>text-to-image</td></tr><tr><td><a href="/docs/diffusers/pr_15151/en/api/pipelines/qwenimage#diffusers.QwenImageImg2ImgPipeline">QwenImageImg2ImgPipeline</a></td><td>image-to-image</td></tr><tr><td><a href="/docs/diffusers/pr_15151/en/api/pipelines/qwenimage#diffusers.QwenImageInpaintPipeline">QwenImageInpaintPipeline</a></td><td>inpaint</td></tr></tbody></table> <p>You could use the subclass directly by passing a model id to <a href="/docs/diffusers/pr_15151/en/api/pipelines/overview#diffusers.DiffusionPipeline.from_pretrained">from_pretrained()</a>.</p> <!> <blockquote class="tip"><p>Refer to the <a href="./other-formats#single-file-format">Single file format</a> docs to learn how to load single file models.</p></blockquote> <!> <p>Pipelines can also be run locally. Use <a href="https://huggingface.co/docs/huggingface_hub/main/en/package_reference/file_download#huggingface_hub.snapshot_download" rel="nofollow">snapshot_download</a> to download a model repository.</p> <!> <p>Pass that path to <a href="/docs/diffusers/pr_15151/en/api/pipelines/overview#diffusers.DiffusionPipeline.from_pretrained">from_pretrained()</a> to load it.</p> <!> <p>The <a href="/docs/diffusers/pr_15151/en/api/pipelines/overview#diffusers.DiffusionPipeline.from_pretrained">from_pretrained()</a> method won’t download files from the Hub when it detects a local path. But this also means it won’t download and cache any updates that have been made to the model either.</p> <!> <p>Use the <code>dtype</code> argument in <a href="/docs/diffusers/pr_15151/en/api/pipelines/overview#diffusers.DiffusionPipeline.from_pretrained">from_pretrained()</a> to load a model with a specific data type. This allows you to load different models in different precisions. For example, loading a large transformer model in half-precision reduces the memory required.</p> <p>Pass the data type for each model as a dictionary to <code>dtype</code>. Use the <code>default</code> key to set the default data type. If a model isn’t in the dictionary and <code>default</code> isn’t provided, it is loaded in full precision (<code>torch.float32</code>).</p> <!> <p>You don’t need to use a dictionary if you’re loading all the models in the same data type.</p> <!> <!> <p>The <code>device_map</code> argument places a pipeline on devices. At runtime, Diffusers accepts <code>"balanced"</code>, <code>"cpu"</code>, and the accelerator string for the machine you are on (typically <code>"cuda"</code>, <code>"mps"</code>, or <code>"xpu"</code>).</p> <table><thead><tr><th>parameter</th><th>description</th></tr></thead><tbody><tr><td>accelerator string</td><td>Places the pipeline on that device. Pass the accelerator your machine supports, such as <code>"cuda"</code>, <code>"mps"</code>, or <code>"xpu"</code>.</td></tr><tr><td><code>"balanced"</code></td><td>Spreads pipeline components across visible GPUs. Use with <code>max_memory</code> when you need per-device caps.</td></tr><tr><td><code>"cpu"</code></td><td>Places the pipeline on CPU.</td></tr></tbody></table> <p>Use the <code>max_memory</code> argument in <a href="/docs/diffusers/pr_15151/en/api/pipelines/overview#diffusers.DiffusionPipeline.from_pretrained">from_pretrained()</a> to allocate a maximum amount of memory to use on each device. By default, Diffusers uses the maximum amount available.</p> <!> <p>The <code>hf_device_map</code> attribute allows you to access and view the <code>device_map</code>.</p> <!> <p>Reset a pipeline’s <code>device_map</code> with the <a href="/docs/diffusers/pr_15151/en/api/pipelines/overview#diffusers.DiffusionPipeline.reset_device_map">reset_device_map()</a> method. This is necessary if you want to use methods such as <code>.to()</code>, <a href="/docs/diffusers/pr_15151/en/api/pipelines/overview#diffusers.DiffusionPipeline.enable_sequential_cpu_offload">enable_sequential_cpu_offload()</a>, and <a href="/docs/diffusers/pr_15151/en/api/pipelines/overview#diffusers.DiffusionPipeline.enable_model_cpu_offload">enable_model_cpu_offload()</a>.</p> <!> <!> <p>Large models are often <a href="../optimization/memory#sharded-checkpoints">sharded</a> into smaller files so that they are easier to load. Diffusers supports loading shards in parallel to speed up the loading process.</p> <p>Set <code>HF_ENABLE_PARALLEL_LOADING</code> to <code>"YES"</code> to enable parallel loading of shards.</p> <p>The <code>device_map</code> argument should be set to <code>"cuda"</code> to pre-allocate a large chunk of memory based on the model size. This substantially reduces model load time because warming up the memory allocator now avoids many smaller calls to the allocator later.</p> <!> <!> <p><a href="/docs/diffusers/pr_15151/en/api/pipelines/overview#diffusers.DiffusionPipeline">DiffusionPipeline</a> is flexible and accommodates loading other models or schedulers. You can experiment with different schedulers to optimize for generation speed or quality, and you can replace models with more performant ones.</p> <p>The example below uses a more stable VAE version.</p> <!> <!> <p>When working with multiple pipelines that use the same model, the <a href="/docs/diffusers/pr_15151/en/api/pipelines/overview#diffusers.DiffusionPipeline.from_pipe">from_pipe()</a> method enables reusing a model instead of reloading it each time. This allows you to use multiple pipelines without increasing memory usage.</p> <p>Memory usage is determined by the pipeline with the highest memory requirement regardless of the number of pipelines.</p> <p>The example below loads a pipeline and then loads a second pipeline with <a href="/docs/diffusers/pr_15151/en/api/pipelines/overview#diffusers.DiffusionPipeline.from_pipe">from_pipe()</a> to use <a href="../api/pipelines/pag">perturbed-attention guidance (PAG)</a> to improve generation quality.</p> <blockquote class="warning"><p>Use <a href="/docs/diffusers/pr_15151/en/api/pipelines/auto_pipeline#diffusers.AutoPipelineForText2Image">AutoPipelineForText2Image</a> because <a href="/docs/diffusers/pr_15151/en/api/pipelines/overview#diffusers.DiffusionPipeline">DiffusionPipeline</a> doesn’t support PAG. Refer to the <a href="../tutorials/autopipeline">AutoPipeline</a> docs to learn more.</p></blockquote> <!> <p>Set <code>enable_pag=True</code> in the second pipeline to enable PAG. The second pipeline uses the same amount of memory because it shares model weights with the first one.</p> <!> <blockquote class="warning"><p>Pipelines created by <a href="/docs/diffusers/pr_15151/en/api/pipelines/overview#diffusers.DiffusionPipeline.from_pipe">from_pipe()</a> share the same models and <em>state</em>. Modifying the state of a model in one pipeline affects all the other pipelines that share the same model.</p></blockquote> <p>Some methods may not work correctly on pipelines created with <a href="/docs/diffusers/pr_15151/en/api/pipelines/overview#diffusers.DiffusionPipeline.from_pipe">from_pipe()</a>. For example, <a href="/docs/diffusers/pr_15151/en/api/pipelines/overview#diffusers.DiffusionPipeline.enable_model_cpu_offload">enable_model_cpu_offload()</a> relies on a unique model execution order, which may differ in the new pipeline. To ensure proper functionality, reapply these methods on the new pipeline.</p> <!> <p>Once a pipeline loads, you usually tune the denoising schedule, swap weight formats, or attach adapters.</p> <ul><li><a href="./schedulers">Schedulers</a> covers swapping and configuring the denoising algorithm.</li> <li><a href="./other-formats">Model formats</a> covers GGUF, single-file checkpoints, and other weight layouts.</li> <li><a href="../optimization/memory">Reduce memory usage</a> covers offloading and other memory tools.</li> <li><a href="../tutorials/using_peft_for_inference">LoRA</a> covers loading adapters on a pipeline.</li> <li><a href="./legacy_checkpoints#safety-checker">Legacy checkpoints</a> covers the safety checker for older Stable Diffusion checkpoints.</li></ul> <!> <p></p>',1);function L(G,E){R(E,!1),Y(()=>{new URLSearchParams(window.location.search).get("fw")}),Q();var s=D();q("5lyivs",B=>{var _=S();x(_,"content",N),W(B,_)});var i=e(V(s),2);X(i,{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"});var o=e(i,2);l(o,{title:"DiffusionPipeline",local:"diffusionpipeline",headingTag:"h1"});var n=e(o,6);l(n,{title:"Loading a pipeline",local:"loading-a-pipeline",headingTag:"h2"});var p=e(n,6);a(p,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRGlmZnVzaW9uUGlwZWxpbmUlMEElMEFwaXBlbGluZSUyMCUzRCUyMERpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjJRd2VuJTJGUXdlbi1JbWFnZSUyMiUyQyUyMGR0eXBlJTNEdG9yY2guYmZsb2F0MTYlMkMlMjBkZXZpY2VfbWFwJTNEJTIyY3VkYSUyMiUyMCUyMCUyMyUyMG9yJTIwJTIybXBzJTIyJTJDJTIwJTIyeHB1JTIyJTJDJTIwJTIyY3B1JTIyJTBBKQ==",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">"Qwen/Qwen-Image"</span>, dtype=torch.bfloat16, device_map=<span class="hljs-string">"cuda"</span> <span class="hljs-comment"># or "mps", "xpu", "cpu"</span> | |
| )`,lang:"py",wrap:!1});var t=e(p,8);a(t,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwUXdlbkltYWdlUGlwZWxpbmUlMEElMEFwaXBlbGluZSUyMCUzRCUyMFF3ZW5JbWFnZVBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjJRd2VuJTJGUXdlbi1JbWFnZSUyMiUyQyUyMGR0eXBlJTNEdG9yY2guYmZsb2F0MTYlMkMlMjBkZXZpY2VfbWFwJTNEJTIyY3VkYSUyMiUyMCUyMCUyMyUyMG9yJTIwJTIybXBzJTIyJTJDJTIwJTIyeHB1JTIyJTJDJTIwJTIyY3B1JTIyJTBBKQ==",highlighted:`<span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> QwenImagePipeline | |
| pipeline = QwenImagePipeline.from_pretrained( | |
| <span class="hljs-string">"Qwen/Qwen-Image"</span>, dtype=torch.bfloat16, device_map=<span class="hljs-string">"cuda"</span> <span class="hljs-comment"># or "mps", "xpu", "cpu"</span> | |
| )`,lang:"py",wrap:!1});var r=e(t,4);l(r,{title:"Local pipelines",local:"local-pipelines",headingTag:"h3"});var d=e(r,4);a(d,{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMHNuYXBzaG90X2Rvd25sb2FkJTBBJTBBbG9jYWxfZGlyJTIwJTNEJTIwc25hcHNob3RfZG93bmxvYWQocmVwb19pZCUzRCUyMlF3ZW4lMkZRd2VuLUltYWdlJTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> snapshot_download | |
| local_dir = snapshot_download(repo_id=<span class="hljs-string">"Qwen/Qwen-Image"</span>)`,lang:"py",wrap:!1});var c=e(d,4);a(c,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwUXdlbkltYWdlUGlwZWxpbmUlMEElMEFwaXBlbGluZSUyMCUzRCUyMFF3ZW5JbWFnZVBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjBsb2NhbF9kaXIlMkMlMjBkdHlwZSUzRHRvcmNoLmJmbG9hdDE2JTJDJTIwZGV2aWNlX21hcCUzRCUyMmN1ZGElMjIlMjAlMjAlMjMlMjBvciUyMCUyMm1wcyUyMiUyQyUyMCUyMnhwdSUyMiUyQyUyMCUyMmNwdSUyMiUwQSk=",highlighted:`<span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> QwenImagePipeline | |
| pipeline = QwenImagePipeline.from_pretrained( | |
| local_dir, dtype=torch.bfloat16, device_map=<span class="hljs-string">"cuda"</span> <span class="hljs-comment"># or "mps", "xpu", "cpu"</span> | |
| )`,lang:"py",wrap:!1});var m=e(c,4);l(m,{title:"Pipeline data types",local:"pipeline-data-types",headingTag:"h2"});var u=e(m,6);a(u,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwUXdlbkltYWdlUGlwZWxpbmUlMEElMEFwaXBlbGluZSUyMCUzRCUyMFF3ZW5JbWFnZVBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjJRd2VuJTJGUXdlbi1JbWFnZSUyMiUyQyUwQSUyMCUyMGR0eXBlJTNEJTdCJTIydHJhbnNmb3JtZXIlMjIlM0ElMjB0b3JjaC5iZmxvYXQxNiUyQyUyMCUyMmRlZmF1bHQlMjIlM0ElMjB0b3JjaC5mbG9hdDE2JTdEJTJDJTBBKSUwQXByaW50KHBpcGVsaW5lLnRyYW5zZm9ybWVyLmR0eXBlJTJDJTIwcGlwZWxpbmUudmFlLmR0eXBlKQ==",highlighted:`<span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> QwenImagePipeline | |
| pipeline = QwenImagePipeline.from_pretrained( | |
| <span class="hljs-string">"Qwen/Qwen-Image"</span>, | |
| dtype={<span class="hljs-string">"transformer"</span>: torch.bfloat16, <span class="hljs-string">"default"</span>: torch.float16}, | |
| ) | |
| <span class="hljs-built_in">print</span>(pipeline.transformer.dtype, pipeline.vae.dtype)`,lang:"py",wrap:!1});var h=e(u,4);a(h,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwUXdlbkltYWdlUGlwZWxpbmUlMEElMEFwaXBlbGluZSUyMCUzRCUyMFF3ZW5JbWFnZVBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjJRd2VuJTJGUXdlbi1JbWFnZSUyMiUyQyUyMGR0eXBlJTNEdG9yY2guYmZsb2F0MTYlMEEpJTBBcHJpbnQocGlwZWxpbmUudHJhbnNmb3JtZXIuZHR5cGUlMkMlMjBwaXBlbGluZS52YWUuZHR5cGUp",highlighted:`<span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> QwenImagePipeline | |
| pipeline = QwenImagePipeline.from_pretrained( | |
| <span class="hljs-string">"Qwen/Qwen-Image"</span>, dtype=torch.bfloat16 | |
| ) | |
| <span class="hljs-built_in">print</span>(pipeline.transformer.dtype, pipeline.vae.dtype)`,lang:"py",wrap:!1});var f=e(h,2);l(f,{title:"Device placement",local:"device-placement",headingTag:"h2"});var y=e(f,8);a(y,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRGlmZnVzaW9uUGlwZWxpbmUlMEElMEFtYXhfbWVtb3J5JTIwJTNEJTIwJTdCMCUzQSUyMCUyMjE2R0IlMjIlMkMlMjAxJTNBJTIwJTIyMTZHQiUyMiU3RCUwQXBpcGVsaW5lJTIwJTNEJTIwRGlmZnVzaW9uUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMlF3ZW4lMkZRd2VuLUltYWdlJTIyJTJDJTBBJTIwJTIwZHR5cGUlM0R0b3JjaC5iZmxvYXQxNiUyQyUwQSUyMCUyMGRldmljZV9tYXAlM0QlMjJiYWxhbmNlZCUyMiUyQyUwQSUyMCUyMG1heF9tZW1vcnklM0RtYXhfbWVtb3J5JTJDJTBBKQ==",highlighted:`<span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline | |
| max_memory = {<span class="hljs-number">0</span>: <span class="hljs-string">"16GB"</span>, <span class="hljs-number">1</span>: <span class="hljs-string">"16GB"</span>} | |
| pipeline = DiffusionPipeline.from_pretrained( | |
| <span class="hljs-string">"Qwen/Qwen-Image"</span>, | |
| dtype=torch.bfloat16, | |
| device_map=<span class="hljs-string">"balanced"</span>, | |
| max_memory=max_memory, | |
| )`,lang:"py",wrap:!1});var M=e(y,4);a(M,{code:"cHJpbnQocGlwZWxpbmUuaGZfZGV2aWNlX21hcCklMEElMjMlMjAlN0IndHJhbnNmb3JtZXInJTNBJTIwMSUyQyUyMCd2YWUnJTNBJTIwMSUyQyUyMCd0ZXh0X2VuY29kZXInJTNBJTIwMCU3RA==",highlighted:`<span class="hljs-built_in">print</span>(pipeline.hf_device_map) | |
| <span class="hljs-comment"># {'transformer': 1, 'vae': 1, 'text_encoder': 0}</span>`,lang:"py",wrap:!1});var w=e(M,4);a(w,{code:"cGlwZWxpbmUucmVzZXRfZGV2aWNlX21hcCgp",highlighted:"pipeline.reset_device_map()",lang:"py",wrap:!1});var J=e(w,2);l(J,{title:"Parallel loading",local:"parallel-loading",headingTag:"h2"});var b=e(J,8);a(b,{code:"aW1wb3J0JTIwb3MlMEFpbXBvcnQlMjB0b3JjaCUwQWZyb20lMjBkaWZmdXNlcnMlMjBpbXBvcnQlMjBEaWZmdXNpb25QaXBlbGluZSUwQSUwQW9zLmVudmlyb24lNUIlMjJIRl9FTkFCTEVfUEFSQUxMRUxfTE9BRElORyUyMiU1RCUyMCUzRCUyMCUyMllFUyUyMiUwQSUwQXBpcGVsaW5lJTIwJTNEJTIwRGlmZnVzaW9uUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMldhbi1BSSUyRldhbjIuMi1JMlYtQTE0Qi1EaWZmdXNlcnMlMjIlMkMlMjBkdHlwZSUzRHRvcmNoLmJmbG9hdDE2JTJDJTIwZGV2aWNlX21hcCUzRCUyMmN1ZGElMjIlMjAlMjAlMjMlMjBvciUyMCUyMm1wcyUyMiUyQyUyMCUyMnhwdSUyMiUyQyUyMCUyMmNwdSUyMiUwQSk=",highlighted:`<span class="hljs-keyword">import</span> os | |
| <span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline | |
| os.environ[<span class="hljs-string">"HF_ENABLE_PARALLEL_LOADING"</span>] = <span class="hljs-string">"YES"</span> | |
| pipeline = DiffusionPipeline.from_pretrained( | |
| <span class="hljs-string">"Wan-AI/Wan2.2-I2V-A14B-Diffusers"</span>, dtype=torch.bfloat16, device_map=<span class="hljs-string">"cuda"</span> <span class="hljs-comment"># or "mps", "xpu", "cpu"</span> | |
| )`,lang:"py",wrap:!1});var U=e(b,2);l(U,{title:"Replacing models in a pipeline",local:"replacing-models-in-a-pipeline",headingTag:"h2"});var g=e(U,6);a(g,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRGlmZnVzaW9uUGlwZWxpbmUlMkMlMjBBdXRvTW9kZWwlMEElMEF2YWUlMjAlM0QlMjBBdXRvTW9kZWwuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMm1hZGVieW9sbGluJTJGc2R4bC12YWUtZnAxNi1maXglMjIlMkMlMjBkdHlwZSUzRHRvcmNoLmZsb2F0MTYlMEEpJTBBJTBBcGlwZWxpbmUlMjAlM0QlMjBEaWZmdXNpb25QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIyc3RhYmlsaXR5YWklMkZzdGFibGUtZGlmZnVzaW9uLXhsLWJhc2UtMS4wJTIyJTJDJTBBJTIwJTIwdmFlJTNEdmFlJTJDJTBBJTIwJTIwZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTJDJTBBJTIwJTIwZGV2aWNlX21hcCUzRCUyMmN1ZGElMjIlMjAlMjAlMjMlMjBvciUyMCUyMm1wcyUyMiUyQyUyMCUyMnhwdSUyMiUyQyUyMCUyMmNwdSUyMiUwQSk=",highlighted:`<span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline, AutoModel | |
| vae = AutoModel.from_pretrained( | |
| <span class="hljs-string">"madebyollin/sdxl-vae-fp16-fix"</span>, dtype=torch.float16 | |
| ) | |
| pipeline = DiffusionPipeline.from_pretrained( | |
| <span class="hljs-string">"stabilityai/stable-diffusion-xl-base-1.0"</span>, | |
| vae=vae, | |
| dtype=torch.float16, | |
| device_map=<span class="hljs-string">"cuda"</span> <span class="hljs-comment"># or "mps", "xpu", "cpu"</span> | |
| )`,lang:"py",wrap:!1});var T=e(g,2);l(T,{title:"Reusing models in multiple pipelines",local:"reusing-models-in-multiple-pipelines",headingTag:"h2"});var j=e(T,10);a(j,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwQXV0b1BpcGVsaW5lRm9yVGV4dDJJbWFnZSUwQSUwQXBpcGVsaW5lX3NkeGwlMjAlM0QlMjBBdXRvUGlwZWxpbmVGb3JUZXh0MkltYWdlLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjJzdGFiaWxpdHlhaSUyRnN0YWJsZS1kaWZmdXNpb24teGwtYmFzZS0xLjAlMjIlMkMlMjBkdHlwZSUzRHRvcmNoLmZsb2F0MTYlMkMlMjBkZXZpY2VfbWFwJTNEJTIyY3VkYSUyMiUyMCUyMCUyMyUyMG9yJTIwJTIybXBzJTIyJTJDJTIwJTIyeHB1JTIyJTJDJTIwJTIyY3B1JTIyJTBBKSUwQXByb21wdCUyMCUzRCUyMCUyMiUyMiUyMiUwQWNpbmVtYXRpYyUyMGZpbG0lMjBzdGlsbCUyMG9mJTIwYSUyMGNhdCUyMHNpcHBpbmclMjBhJTIwbWFyZ2FyaXRhJTIwaW4lMjBhJTIwcG9vbCUyMGluJTIwUGFsbSUyMFNwcmluZ3MlMkMlMjBDYWxpZm9ybmlhJTBBaGlnaGx5JTIwZGV0YWlsZWQlMkMlMjBoaWdoJTIwYnVkZ2V0JTIwaG9sbHl3b29kJTIwbW92aWUlMkMlMjBjaW5lbWFzY29wZSUyQyUyMG1vb2R5JTJDJTIwZXBpYyUyQyUyMGdvcmdlb3VzJTJDJTIwZmlsbSUyMGdyYWluJTBBJTIyJTIyJTIyJTBBaW1hZ2UlMjAlM0QlMjBwaXBlbGluZV9zZHhsKHByb21wdCkuaW1hZ2VzJTVCMCU1RCUwQXByaW50KGYlMjJNYXglMjBtZW1vcnklMjByZXNlcnZlZCUzQSUyMCU3QnRvcmNoLmN1ZGEubWF4X21lbW9yeV9hbGxvY2F0ZWQoKSUyMCUyRiUyMDEwMjQqKjMlM0EuMmYlN0QlMjBHQiUyMiklMEElMjMlMjBNYXglMjBtZW1vcnklMjByZXNlcnZlZCUzQSUyMDEwLjQ3JTIwR0I=",highlighted:`<span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> AutoPipelineForText2Image | |
| pipeline_sdxl = AutoPipelineForText2Image.from_pretrained( | |
| <span class="hljs-string">"stabilityai/stable-diffusion-xl-base-1.0"</span>, dtype=torch.float16, device_map=<span class="hljs-string">"cuda"</span> <span class="hljs-comment"># or "mps", "xpu", "cpu"</span> | |
| ) | |
| prompt = <span class="hljs-string">""" | |
| cinematic film still of a cat sipping a margarita in a pool in Palm Springs, California | |
| highly detailed, high budget hollywood movie, cinemascope, moody, epic, gorgeous, film grain | |
| """</span> | |
| image = pipeline_sdxl(prompt).images[<span class="hljs-number">0</span>] | |
| <span class="hljs-built_in">print</span>(<span class="hljs-string">f"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"</span>) | |
| <span class="hljs-comment"># Max memory reserved: 10.47 GB</span>`,lang:"py",wrap:!1});var Z=e(j,4);a(Z,{code:"cGlwZWxpbmUlMjAlM0QlMjBBdXRvUGlwZWxpbmVGb3JUZXh0MkltYWdlLmZyb21fcGlwZSglMEElMjAlMjBwaXBlbGluZV9zZHhsJTJDJTIwZW5hYmxlX3BhZyUzRFRydWUlMEEpJTBBcHJvbXB0JTIwJTNEJTIwJTIyJTIyJTIyJTBBY2luZW1hdGljJTIwZmlsbSUyMHN0aWxsJTIwb2YlMjBhJTIwY2F0JTIwc2lwcGluZyUyMGElMjBtYXJnYXJpdGElMjBpbiUyMGElMjBwb29sJTIwaW4lMjBQYWxtJTIwU3ByaW5ncyUyQyUyMENhbGlmb3JuaWElMEFoaWdobHklMjBkZXRhaWxlZCUyQyUyMGhpZ2glMjBidWRnZXQlMjBob2xseXdvb2QlMjBtb3ZpZSUyQyUyMGNpbmVtYXNjb3BlJTJDJTIwbW9vZHklMkMlMjBlcGljJTJDJTIwZ29yZ2VvdXMlMkMlMjBmaWxtJTIwZ3JhaW4lMEElMjIlMjIlMjIlMEFpbWFnZSUyMCUzRCUyMHBpcGVsaW5lKHByb21wdCkuaW1hZ2VzJTVCMCU1RCUwQXByaW50KGYlMjJNYXglMjBtZW1vcnklMjByZXNlcnZlZCUzQSUyMCU3QnRvcmNoLmN1ZGEubWF4X21lbW9yeV9hbGxvY2F0ZWQoKSUyMCUyRiUyMDEwMjQqKjMlM0EuMmYlN0QlMjBHQiUyMiklMEElMjMlMjBNYXglMjBtZW1vcnklMjByZXNlcnZlZCUzQSUyMDEwLjQ3JTIwR0I=",highlighted:`pipeline = AutoPipelineForText2Image.from_pipe( | |
| pipeline_sdxl, enable_pag=<span class="hljs-literal">True</span> | |
| ) | |
| prompt = <span class="hljs-string">""" | |
| cinematic film still of a cat sipping a margarita in a pool in Palm Springs, California | |
| highly detailed, high budget hollywood movie, cinemascope, moody, epic, gorgeous, film grain | |
| """</span> | |
| image = pipeline(prompt).images[<span class="hljs-number">0</span>] | |
| <span class="hljs-built_in">print</span>(<span class="hljs-string">f"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"</span>) | |
| <span class="hljs-comment"># Max memory reserved: 10.47 GB</span>`,lang:"py",wrap:!1});var I=e(Z,6);l(I,{title:"Next steps",local:"next-steps",headingTag:"h2"});var k=e(I,6);C(k,{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/using-diffusers/loading.md"}),P(2),W(G,s),F()}export{L as component}; | |
Xet Storage Details
- Size:
- 24.8 kB
- Xet hash:
- 4eea767d94ff2fdb823335beea6dc891451cd06b9b1d0cd865007243020a4e39
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.