import{s as se,n as ie,o as oe}from"../chunks/scheduler.182ea377.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 s,j as ne,u as _,x as Z,k as ae,y as me,a,v as $,d as j,t as J,w as k}from"../chunks/index.abf12888.js";import{C as P}from"../chunks/CodeBlock.57fe6e13.js";import{H as le,E as fe}from"../chunks/EditOnGithub.9b8e78e4.js";function ue(Y){let p,v,C,G,d,V,r,F="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/main/en/api/models/unet2d-cond#diffusers.UNet2DConditionModel">UNet2DConditionModel</a>.',x,f,N,u,A='A <a href="/docs/diffusers/main/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/runwayml/stable-diffusion-v1-5" rel="nofollow"><code>runwayml/stable-diffusion-v1-5</code></a> and take a look at the number of <code>in_channels</code>:',X,c,Q,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>:',I,M,R,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.",S,b,ee='Initialize a <a href="/docs/diffusers/main/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.',E,w,H,g,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.",z,T,D,W,L;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 P({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBJTBBcGlwZWxpbmUlMjAlM0QlMjBTdGFibGVEaWZmdXNpb25QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIycnVud2F5bWwlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTUlMjIlMkMlMjB1c2Vfc2FmZXRlbnNvcnMlM0RUcnVlKSUwQXBpcGVsaW5lLnVuZXQuY29uZmlnJTVCJTIyaW5fY2hhbm5lbHMlMjIlNUQlMEE0",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-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 P({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}}),w=new P({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFVOZXQyRENvbmRpdGlvbk1vZGVsJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJydW53YXltbCUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNSUyMiUwQXVuZXQlMjAlM0QlMjBVTmV0MkRDb25kaXRpb25Nb2RlbC5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwbW9kZWxfaWQlMkMlMEElMjAlMjAlMjAlMjBzdWJmb2xkZXIlM0QlMjJ1bmV0JTIyJTJDJTBBJTIwJTIwJTIwJTIwaW5fY2hhbm5lbHMlM0Q5JTJDJTBBJTIwJTIwJTIwJTIwbG93X2NwdV9tZW1fdXNhZ2UlM0RGYWxzZSUyQyUwQSUyMCUyMCUyMCUyMGlnbm9yZV9taXNtYXRjaGVkX3NpemVzJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMHVzZV9zYWZldGVuc29ycyUzRFRydWUlMkMlMEEp",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> UNet2DConditionModel

model_id = <span class="hljs-string">&quot;runwayml/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}}),T=new fe({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/training/adapt_a_model.md"}}),{c(){p=i("meta"),v=l(),C=i("p"),G=l(),U(d.$$.fragment),V=l(),r=i("p"),r.textContent=F,B=l(),m=i("p"),m.innerHTML=q,x=l(),U(f.$$.fragment),N=l(),u=i("p"),u.innerHTML=A,X=l(),U(c.$$.fragment),Q=l(),h=i("p"),h.innerHTML=K,I=l(),U(M.$$.fragment),R=l(),y=i("p"),y.innerHTML=O,S=l(),b=i("p"),b.innerHTML=ee,E=l(),U(w.$$.fragment),H=l(),g=i("p"),g.innerHTML=te,z=l(),U(T.$$.fragment),D=l(),W=i("p"),this.h()},l(e){const t=re("svelte-u9bgzb",document.head);p=o(t,"META",{name:!0,content:!0}),t.forEach(n),v=s(e),C=o(e,"P",{}),ne(C).forEach(n),G=s(e),_(d.$$.fragment,e),V=s(e),r=o(e,"P",{"data-svelte-h":!0}),Z(r)!=="svelte-3om45r"&&(r.textContent=F),B=s(e),m=o(e,"P",{"data-svelte-h":!0}),Z(m)!=="svelte-plxekm"&&(m.innerHTML=q),x=s(e),_(f.$$.fragment,e),N=s(e),u=o(e,"P",{"data-svelte-h":!0}),Z(u)!=="svelte-17kub3x"&&(u.innerHTML=A),X=s(e),_(c.$$.fragment,e),Q=s(e),h=o(e,"P",{"data-svelte-h":!0}),Z(h)!=="svelte-ph2jy1"&&(h.innerHTML=K),I=s(e),_(M.$$.fragment,e),R=s(e),y=o(e,"P",{"data-svelte-h":!0}),Z(y)!=="svelte-15mkgo9"&&(y.innerHTML=O),S=s(e),b=o(e,"P",{"data-svelte-h":!0}),Z(b)!=="svelte-1k8u2s"&&(b.innerHTML=ee),E=s(e),_(w.$$.fragment,e),H=s(e),g=o(e,"P",{"data-svelte-h":!0}),Z(g)!=="svelte-6j6lxu"&&(g.innerHTML=te),z=s(e),_(T.$$.fragment,e),D=s(e),W=o(e,"P",{}),ne(W).forEach(n),this.h()},h(){ae(p,"name","hf:doc:metadata"),ae(p,"content",ce)},m(e,t){me(document.head,p),a(e,v,t),a(e,C,t),a(e,G,t),$(d,e,t),a(e,V,t),a(e,r,t),a(e,B,t),a(e,m,t),a(e,x,t),$(f,e,t),a(e,N,t),a(e,u,t),a(e,X,t),$(c,e,t),a(e,Q,t),a(e,h,t),a(e,I,t),$(M,e,t),a(e,R,t),a(e,y,t),a(e,S,t),a(e,b,t),a(e,E,t),$(w,e,t),a(e,H,t),a(e,g,t),a(e,z,t),$(T,e,t),a(e,D,t),a(e,W,t),L=!0},p:ie,i(e){L||(j(d.$$.fragment,e),j(f.$$.fragment,e),j(c.$$.fragment,e),j(M.$$.fragment,e),j(w.$$.fragment,e),j(T.$$.fragment,e),L=!0)},o(e){J(d.$$.fragment,e),J(f.$$.fragment,e),J(c.$$.fragment,e),J(M.$$.fragment,e),J(w.$$.fragment,e),J(T.$$.fragment,e),L=!1},d(e){e&&(n(v),n(C),n(G),n(V),n(r),n(B),n(m),n(x),n(N),n(u),n(X),n(Q),n(h),n(I),n(R),n(y),n(S),n(b),n(E),n(H),n(g),n(z),n(D),n(W)),n(p),k(d,e),k(f,e),k(c,e),k(M,e),k(w,e),k(T,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(Y){return oe(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ge extends pe{constructor(p){super(),de(this,p,he,ue,se,{})}}export{ge as component};
