import{s as ae,n as ie,o as oe}from"../chunks/scheduler.8c3d61f6.js";import{S as pe,i as de,g as i,s as l,r as U,A as re,h as o,f as n,c as a,j as ne,u as _,x as Z,k as se,y as me,a as s,v as $,d as v,t as J,w as j}from"../chunks/index.da70eac4.js";import{C as H}from"../chunks/CodeBlock.00a903b3.js";import{H as le,E as fe}from"../chunks/EditOnGithub.1e64e623.js";function ue(P){let p,W,C,V,d,k,r,A="Many diffusion systems share the same components, allowing you to adapt a pretrained model for one task to an entirely different task.",B,m,q='This guide will show you how to adapt a pretrained text-to-image model for inpainting by initializing and modifying the architecture of a pretrained <a href="/docs/diffusers/pr_7067/en/api/models/unet2d-cond#diffusers.UNet2DConditionModel">UNet2DConditionModel</a>.',x,f,N,u,Y='A <a href="/docs/diffusers/pr_7067/en/api/models/unet2d-cond#diffusers.UNet2DConditionModel">UNet2DConditionModel</a> by default accepts 4 channels in the <a href="https://huggingface.co/docs/diffusers/v0.16.0/en/api/models#diffusers.UNet2DConditionModel.in_channels" rel="nofollow">input sample</a>. For example, load a pretrained text-to-image model like <a href="https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5" rel="nofollow"><code>stable-diffusion-v1-5/stable-diffusion-v1-5</code></a> and take a look at the number of <code>in_channels</code>:',z,c,E,h,K='Inpainting requires 9 channels in the input sample. You can check this value in a pretrained inpainting model like <a href="https://huggingface.co/runwayml/stable-diffusion-inpainting" rel="nofollow"><code>runwayml/stable-diffusion-inpainting</code></a>:',X,M,F,y,O="To adapt your text-to-image model for inpainting, you’ll need to change the number of <code>in_channels</code> from 4 to 9.",L,b,ee='Initialize a <a href="/docs/diffusers/pr_7067/en/api/models/unet2d-cond#diffusers.UNet2DConditionModel">UNet2DConditionModel</a> with the pretrained text-to-image model weights, and change <code>in_channels</code> to 9. Changing the number of <code>in_channels</code> means you need to set <code>ignore_mismatched_sizes=True</code> and <code>low_cpu_mem_usage=False</code> to avoid a size mismatch error because the shape is different now.',R,g,S,T,te="The pretrained weights of the other components from the text-to-image model are initialized from their checkpoints, but the input channel weights (<code>conv_in.weight</code>) of the <code>unet</code> are randomly initialized. It is important to finetune the model for inpainting because otherwise the model returns noise.",Q,w,D,G,I;return d=new le({props:{title:"Adapt a model to a new task",local:"adapt-a-model-to-a-new-task",headingTag:"h1"}}),f=new le({props:{title:"Configure UNet2DConditionModel parameters",local:"configure-unet2dconditionmodel-parameters",headingTag:"h2"}}),c=new H({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBJTBBcGlwZWxpbmUlMjAlM0QlMjBTdGFibGVEaWZmdXNpb25QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIyc3RhYmxlLWRpZmZ1c2lvbi12MS01JTJGc3RhYmxlLWRpZmZ1c2lvbi12MS01JTIyJTJDJTIwdXNlX3NhZmV0ZW5zb3JzJTNEVHJ1ZSklMEFwaXBlbGluZS51bmV0LmNvbmZpZyU1QiUyMmluX2NoYW5uZWxzJTIyJTVEJTBBNA==",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline

pipeline = StableDiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;stable-diffusion-v1-5/stable-diffusion-v1-5&quot;</span>, use_safetensors=<span class="hljs-literal">True</span>)
pipeline.unet.config[<span class="hljs-string">&quot;in_channels&quot;</span>]
<span class="hljs-number">4</span>`,wrap:!1}}),M=new H({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBJTBBcGlwZWxpbmUlMjAlM0QlMjBTdGFibGVEaWZmdXNpb25QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIycnVud2F5bWwlMkZzdGFibGUtZGlmZnVzaW9uLWlucGFpbnRpbmclMjIlMkMlMjB1c2Vfc2FmZXRlbnNvcnMlM0RUcnVlKSUwQXBpcGVsaW5lLnVuZXQuY29uZmlnJTVCJTIyaW5fY2hhbm5lbHMlMjIlNUQlMEE5",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline

pipeline = StableDiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;runwayml/stable-diffusion-inpainting&quot;</span>, use_safetensors=<span class="hljs-literal">True</span>)
pipeline.unet.config[<span class="hljs-string">&quot;in_channels&quot;</span>]
<span class="hljs-number">9</span>`,wrap:!1}}),g=new H({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFVOZXQyRENvbmRpdGlvbk1vZGVsJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJzdGFibGUtZGlmZnVzaW9uLXYxLTUlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTUlMjIlMEF1bmV0JTIwJTNEJTIwVU5ldDJEQ29uZGl0aW9uTW9kZWwuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMG1vZGVsX2lkJTJDJTBBJTIwJTIwJTIwJTIwc3ViZm9sZGVyJTNEJTIydW5ldCUyMiUyQyUwQSUyMCUyMCUyMCUyMGluX2NoYW5uZWxzJTNEOSUyQyUwQSUyMCUyMCUyMCUyMGxvd19jcHVfbWVtX3VzYWdlJTNERmFsc2UlMkMlMEElMjAlMjAlMjAlMjBpZ25vcmVfbWlzbWF0Y2hlZF9zaXplcyUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjB1c2Vfc2FmZXRlbnNvcnMlM0RUcnVlJTJDJTBBKQ==",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> UNet2DConditionModel

model_id = <span class="hljs-string">&quot;stable-diffusion-v1-5/stable-diffusion-v1-5&quot;</span>
unet = UNet2DConditionModel.from_pretrained(
    model_id,
    subfolder=<span class="hljs-string">&quot;unet&quot;</span>,
    in_channels=<span class="hljs-number">9</span>,
    low_cpu_mem_usage=<span class="hljs-literal">False</span>,
    ignore_mismatched_sizes=<span class="hljs-literal">True</span>,
    use_safetensors=<span class="hljs-literal">True</span>,
)`,wrap:!1}}),w=new fe({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/training/adapt_a_model.md"}}),{c(){p=i("meta"),W=l(),C=i("p"),V=l(),U(d.$$.fragment),k=l(),r=i("p"),r.textContent=A,B=l(),m=i("p"),m.innerHTML=q,x=l(),U(f.$$.fragment),N=l(),u=i("p"),u.innerHTML=Y,z=l(),U(c.$$.fragment),E=l(),h=i("p"),h.innerHTML=K,X=l(),U(M.$$.fragment),F=l(),y=i("p"),y.innerHTML=O,L=l(),b=i("p"),b.innerHTML=ee,R=l(),U(g.$$.fragment),S=l(),T=i("p"),T.innerHTML=te,Q=l(),U(w.$$.fragment),D=l(),G=i("p"),this.h()},l(e){const t=re("svelte-u9bgzb",document.head);p=o(t,"META",{name:!0,content:!0}),t.forEach(n),W=a(e),C=o(e,"P",{}),ne(C).forEach(n),V=a(e),_(d.$$.fragment,e),k=a(e),r=o(e,"P",{"data-svelte-h":!0}),Z(r)!=="svelte-3om45r"&&(r.textContent=A),B=a(e),m=o(e,"P",{"data-svelte-h":!0}),Z(m)!=="svelte-1ujeqe2"&&(m.innerHTML=q),x=a(e),_(f.$$.fragment,e),N=a(e),u=o(e,"P",{"data-svelte-h":!0}),Z(u)!=="svelte-zhas8n"&&(u.innerHTML=Y),z=a(e),_(c.$$.fragment,e),E=a(e),h=o(e,"P",{"data-svelte-h":!0}),Z(h)!=="svelte-ph2jy1"&&(h.innerHTML=K),X=a(e),_(M.$$.fragment,e),F=a(e),y=o(e,"P",{"data-svelte-h":!0}),Z(y)!=="svelte-1p1x44t"&&(y.innerHTML=O),L=a(e),b=o(e,"P",{"data-svelte-h":!0}),Z(b)!=="svelte-vsuyzo"&&(b.innerHTML=ee),R=a(e),_(g.$$.fragment,e),S=a(e),T=o(e,"P",{"data-svelte-h":!0}),Z(T)!=="svelte-6j6lxu"&&(T.innerHTML=te),Q=a(e),_(w.$$.fragment,e),D=a(e),G=o(e,"P",{}),ne(G).forEach(n),this.h()},h(){se(p,"name","hf:doc:metadata"),se(p,"content",ce)},m(e,t){me(document.head,p),s(e,W,t),s(e,C,t),s(e,V,t),$(d,e,t),s(e,k,t),s(e,r,t),s(e,B,t),s(e,m,t),s(e,x,t),$(f,e,t),s(e,N,t),s(e,u,t),s(e,z,t),$(c,e,t),s(e,E,t),s(e,h,t),s(e,X,t),$(M,e,t),s(e,F,t),s(e,y,t),s(e,L,t),s(e,b,t),s(e,R,t),$(g,e,t),s(e,S,t),s(e,T,t),s(e,Q,t),$(w,e,t),s(e,D,t),s(e,G,t),I=!0},p:ie,i(e){I||(v(d.$$.fragment,e),v(f.$$.fragment,e),v(c.$$.fragment,e),v(M.$$.fragment,e),v(g.$$.fragment,e),v(w.$$.fragment,e),I=!0)},o(e){J(d.$$.fragment,e),J(f.$$.fragment,e),J(c.$$.fragment,e),J(M.$$.fragment,e),J(g.$$.fragment,e),J(w.$$.fragment,e),I=!1},d(e){e&&(n(W),n(C),n(V),n(k),n(r),n(B),n(m),n(x),n(N),n(u),n(z),n(E),n(h),n(X),n(F),n(y),n(L),n(b),n(R),n(S),n(T),n(Q),n(D),n(G)),n(p),j(d,e),j(f,e),j(c,e),j(M,e),j(g,e),j(w,e)}}}const ce='{"title":"Adapt a model to a new task","local":"adapt-a-model-to-a-new-task","sections":[{"title":"Configure UNet2DConditionModel parameters","local":"configure-unet2dconditionmodel-parameters","sections":[],"depth":2}],"depth":1}';function he(P){return oe(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Te extends pe{constructor(p){super(),de(this,p,he,ue,ae,{})}}export{Te as component};
