Buckets:

download
raw
10.5 kB
import"../chunks/DsnmJJEf.js";import{i as g,h as I,C as U,H as d,a as i,E as w,s as T}from"../chunks/Bqo1LwON.js";import{p as b,o as j,s as e,f as Z,a as f,b as W,d as M,n as A}from"../chunks/DK803DsY.js";const G='{"title":"AutoPipeline","local":"autopipeline","sections":[{"title":"Switch tasks with from_pipe","local":"switch-tasks-with-frompipe","sections":[],"depth":2}],"depth":1}';var _=M('<meta name="hf:doc:metadata"/>'),k=M('<p></p> <!> <!> <p><a href="../api/pipelines/auto_pipeline">AutoPipeline</a> is a <em>task-and-model</em> pipeline that automatically selects the correct pipeline subclass based on the task. It handles the complexity of loading different pipeline subclasses without needing to know the specific pipeline subclass name.</p> <p>This is unlike <a href="/docs/diffusers/pr_15151/en/api/pipelines/overview#diffusers.DiffusionPipeline">DiffusionPipeline</a>, a <em>model-only</em> pipeline that automatically selects the pipeline subclass based on the model.</p> <!> <p><a href="/docs/diffusers/pr_15151/en/api/pipelines/auto_pipeline#diffusers.AutoPipelineForImage2Image">AutoPipelineForImage2Image</a> returns the task-specific subclass (for example, <a href="/docs/diffusers/pr_15151/en/api/pipelines/stable_diffusion/stable_diffusion_xl#diffusers.StableDiffusionXLImg2ImgPipeline">StableDiffusionXLImg2ImgPipeline</a>), which can only be used for image-to-image tasks.</p> <!> <p>Loading the same model with <a href="/docs/diffusers/pr_15151/en/api/pipelines/overview#diffusers.DiffusionPipeline">DiffusionPipeline</a> returns the default text-to-image subclass, <a href="/docs/diffusers/pr_15151/en/api/pipelines/stable_diffusion/stable_diffusion_xl#diffusers.StableDiffusionXLPipeline">StableDiffusionXLPipeline</a>. That pipeline is for text-to-image. For image-to-image or inpainting, load a task AutoPipeline such as <a href="/docs/diffusers/pr_15151/en/api/pipelines/auto_pipeline#diffusers.AutoPipelineForImage2Image">AutoPipelineForImage2Image</a> or <a href="/docs/diffusers/pr_15151/en/api/pipelines/auto_pipeline#diffusers.AutoPipelineForInpainting">AutoPipelineForInpainting</a>, or the matching task-specific subclass.</p> <!> <!> <p>Load a task AutoPipeline once, then switch tasks with <a href="/docs/diffusers/pr_15151/en/api/pipelines/auto_pipeline#diffusers.AutoPipelineForImage2Image.from_pipe">from_pipe()</a> without downloading the weights again. Components are reused from the source pipeline.</p> <!> <p>See <a href="../using-diffusers/loading#reusing-models-in-multiple-pipelines">Reusing models in multiple pipelines</a> for more details.</p> <p>Check the <a href="https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/auto_pipeline.py" rel="nofollow">mappings</a> to see whether a model is supported or not. Trying to load an unsupported model returns an error.</p> <!> <p>There are four types of <a href="../api/pipelines/auto_pipeline">AutoPipeline</a> classes:</p> <ul><li><a href="/docs/diffusers/pr_15151/en/api/pipelines/auto_pipeline#diffusers.AutoPipelineForText2Image">AutoPipelineForText2Image</a></li> <li><a href="/docs/diffusers/pr_15151/en/api/pipelines/auto_pipeline#diffusers.AutoPipelineForImage2Image">AutoPipelineForImage2Image</a></li> <li><a href="/docs/diffusers/pr_15151/en/api/pipelines/auto_pipeline#diffusers.AutoPipelineForInpainting">AutoPipelineForInpainting</a></li> <li><a href="/docs/diffusers/pr_15151/en/api/pipelines/auto_pipeline#diffusers.AutoPipelineForText2Audio">AutoPipelineForText2Audio</a></li></ul> <p>Each of these classes has a predefined mapping, linking a pipeline to their task-specific subclass.</p> <p>When <a href="/docs/diffusers/pr_15151/en/api/pipelines/auto_pipeline#diffusers.AutoPipelineForText2Image.from_pretrained">from_pretrained()</a> is called, it extracts the class name from the <code>model_index.json</code> file and selects the appropriate pipeline subclass for the task based on the mapping.</p> <!> <p></p>',1);function S(h,y){b(y,!1),j(()=>{new URLSearchParams(window.location.search).get("fw")}),g();var l=k();I("4ifgl2",m=>{var c=_();T(c,"content",G),f(m,c)});var s=e(Z(l),2);U(s,{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"});var a=e(s,2);d(a,{title:"AutoPipeline",local:"autopipeline",headingTag:"h1"});var p=e(a,6);i(p,{code:"QXV0b1BpcGVsaW5lRm9ySW1hZ2UySW1hZ2UuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2lkKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU3QyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyQi0tJTIwcmVhZCUyMG1vZGVsX2luZGV4Lmpzb24lMjAlMjAoZS5nLiUyMFN0YWJsZURpZmZ1c2lvblhMUGlwZWxpbmUpJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTJCLS0lMjB0YXNrJTIwbWFwcGluZyUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMChpbWFnZS10by1pbWFnZSklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlN0MlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjB2JTBBU3RhYmxlRGlmZnVzaW9uWExJbWcySW1nUGlwZWxpbmUlMjAlMjAlMjAlMkYlMkYlMjByZXR1cm5lZCUyMGluc3RhbmNl",highlighted:`AutoPipelineForImage2Image.from_pretrained(model_id)
|
+-- read model_index.json (e.g. StableDiffusionXLPipeline)
+-- task mapping (image-to-image)
|
v
StableDiffusionXLImg2ImgPipeline // returned instance`,lang:"text",wrap:!1});var n=e(p,4);i(n,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwQXV0b1BpcGVsaW5lRm9ySW1hZ2UySW1hZ2UlMEElMEFwaXBlbGluZSUyMCUzRCUyMEF1dG9QaXBlbGluZUZvckltYWdlMkltYWdlLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjJSdW5EaWZmdXNpb24lMkZKdWdnZXJuYXV0LVhMLXY5JTIyJTJDJTIwZHR5cGUlM0R0b3JjaC5iZmxvYXQxNiUyQyUyMGRldmljZV9tYXAlM0QlMjJjdWRhJTIyJTJDJTIwJTIwJTIzJTIwb3IlMjAlMjJtcHMlMjIlMkMlMjAlMjJ4cHUlMjIlMkMlMjAlMjJjcHUlMjIlMEEpJTBBcHJpbnQocGlwZWxpbmUpJTBBJTIzJTIwU3RhYmxlRGlmZnVzaW9uWExJbWcySW1nUGlwZWxpbmUlMjAlN0IlMEElMjMlMjAlMjAlMjAlMjJfY2xhc3NfbmFtZSUyMiUzQSUyMCUyMlN0YWJsZURpZmZ1c2lvblhMSW1nMkltZ1BpcGVsaW5lJTIyJTJDJTBBJTIzJTIwJTIwJTIwLi4uJTBBJTIzJTIwJTdE",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> AutoPipelineForImage2Image
pipeline = AutoPipelineForImage2Image.from_pretrained(
<span class="hljs-string">&quot;RunDiffusion/Juggernaut-XL-v9&quot;</span>, dtype=torch.bfloat16, device_map=<span class="hljs-string">&quot;cuda&quot;</span>, <span class="hljs-comment"># or &quot;mps&quot;, &quot;xpu&quot;, &quot;cpu&quot;</span>
)
<span class="hljs-built_in">print</span>(pipeline)
<span class="hljs-comment"># StableDiffusionXLImg2ImgPipeline {</span>
<span class="hljs-comment"># &quot;_class_name&quot;: &quot;StableDiffusionXLImg2ImgPipeline&quot;,</span>
<span class="hljs-comment"># ...</span>
<span class="hljs-comment"># }</span>`,lang:"py",wrap:!1});var t=e(n,4);i(t,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRGlmZnVzaW9uUGlwZWxpbmUlMEElMEFwaXBlbGluZSUyMCUzRCUyMERpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjJSdW5EaWZmdXNpb24lMkZKdWdnZXJuYXV0LVhMLXY5JTIyJTJDJTIwZHR5cGUlM0R0b3JjaC5iZmxvYXQxNiUyQyUyMGRldmljZV9tYXAlM0QlMjJjdWRhJTIyJTJDJTIwJTIwJTIzJTIwb3IlMjAlMjJtcHMlMjIlMkMlMjAlMjJ4cHUlMjIlMkMlMjAlMjJjcHUlMjIlMEEpJTBBcHJpbnQocGlwZWxpbmUpJTBBJTIzJTIwU3RhYmxlRGlmZnVzaW9uWExQaXBlbGluZSUyMCU3QiUwQSUyMyUyMCUyMCUyMCUyMl9jbGFzc19uYW1lJTIyJTNBJTIwJTIyU3RhYmxlRGlmZnVzaW9uWExQaXBlbGluZSUyMiUyQyUwQSUyMyUyMCUyMCUyMC4uLiUwQSUyMyUyMCU3RA==",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;RunDiffusion/Juggernaut-XL-v9&quot;</span>, dtype=torch.bfloat16, device_map=<span class="hljs-string">&quot;cuda&quot;</span>, <span class="hljs-comment"># or &quot;mps&quot;, &quot;xpu&quot;, &quot;cpu&quot;</span>
)
<span class="hljs-built_in">print</span>(pipeline)
<span class="hljs-comment"># StableDiffusionXLPipeline {</span>
<span class="hljs-comment"># &quot;_class_name&quot;: &quot;StableDiffusionXLPipeline&quot;,</span>
<span class="hljs-comment"># ...</span>
<span class="hljs-comment"># }</span>`,lang:"py",wrap:!1});var o=e(t,2);d(o,{title:"Switch tasks with from_pipe",local:"switch-tasks-with-frompipe",headingTag:"h2"});var r=e(o,4);i(r,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwQXV0b1BpcGVsaW5lRm9yVGV4dDJJbWFnZSUyQyUyMEF1dG9QaXBlbGluZUZvckltYWdlMkltYWdlJTBBJTBBcGlwZWxpbmVfdDJpJTIwJTNEJTIwQXV0b1BpcGVsaW5lRm9yVGV4dDJJbWFnZS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIyUnVuRGlmZnVzaW9uJTJGSnVnZ2VybmF1dC1YTC12OSUyMiUyQyUyMGR0eXBlJTNEdG9yY2guYmZsb2F0MTYlMkMlMjBkZXZpY2VfbWFwJTNEJTIyY3VkYSUyMiUyQyUyMCUyMCUyMyUyMG9yJTIwJTIybXBzJTIyJTJDJTIwJTIyeHB1JTIyJTJDJTIwJTIyY3B1JTIyJTBBKSUwQXBpcGVsaW5lX2kyaSUyMCUzRCUyMEF1dG9QaXBlbGluZUZvckltYWdlMkltYWdlLmZyb21fcGlwZShwaXBlbGluZV90Mmkp",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> AutoPipelineForText2Image, AutoPipelineForImage2Image
pipeline_t2i = AutoPipelineForText2Image.from_pretrained(
<span class="hljs-string">&quot;RunDiffusion/Juggernaut-XL-v9&quot;</span>, dtype=torch.bfloat16, device_map=<span class="hljs-string">&quot;cuda&quot;</span>, <span class="hljs-comment"># or &quot;mps&quot;, &quot;xpu&quot;, &quot;cpu&quot;</span>
)
pipeline_i2i = AutoPipelineForImage2Image.from_pipe(pipeline_t2i)`,lang:"py",wrap:!1});var u=e(r,6);i(u,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwQXV0b1BpcGVsaW5lRm9ySW1hZ2UySW1hZ2UlMEElMEFwaXBlbGluZSUyMCUzRCUyMEF1dG9QaXBlbGluZUZvckltYWdlMkltYWdlLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJvcGVuYWklMkZzaGFwLWUtaW1nMmltZyUyMiUyQyUyMGR0eXBlJTNEdG9yY2guZmxvYXQxNiUyQyUwQSklMEElMjJWYWx1ZUVycm9yJTNBJTIwQXV0b1BpcGVsaW5lJTIwY2FuJ3QlMjBmaW5kJTIwYSUyMHBpcGVsaW5lJTIwbGlua2VkJTIwdG8lMjBTaGFwRUltZzJJbWdQaXBlbGluZSUyMGZvciUyME5vbmUlMjI=",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> AutoPipelineForImage2Image
pipeline = AutoPipelineForImage2Image.from_pretrained(
<span class="hljs-string">&quot;openai/shap-e-img2img&quot;</span>, dtype=torch.float16,
)
<span class="hljs-string">&quot;ValueError: AutoPipeline can&#x27;t find a pipeline linked to ShapEImg2ImgPipeline for None&quot;</span>`,lang:"py",wrap:!1});var J=e(u,10);w(J,{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/tutorials/autopipeline.md"}),A(2),f(h,l),W()}export{S as component};

Xet Storage Details

Size:
10.5 kB
·
Xet hash:
b9ce0ae78bf4b8d744bbc645610414240c5d9ed34ba02d26c47e8152d22ca648

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.