import{s as le,n as ie,o as oe}from"../chunks/scheduler.8c3d61f6.js";import{S as pe,i as de,g as i,s as a,r as J,A as me,h as o,f as n,c as l,j as ne,u as _,x as Z,k as se,y as re,a as s,v as $,d as U,t as v,w as C}from"../chunks/index.da70eac4.js";import{C as Y}from"../chunks/CodeBlock.a9c4becf.js";import{H as ae,E as fe}from"../chunks/getInferenceSnippets.cb466318.js";function ue(D){let p,G,W,k,d,x,m,F="Many diffusion systems share the same components, allowing you to adapt a pretrained model for one task to an entirely different task.",B,r,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>.',I,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/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>:',V,c,R,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>:',S,M,X,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.",z,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,L,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,g,H,j,P;return d=new ae({props:{title:"Adapt a model to a new task",local:"adapt-a-model-to-a-new-task",headingTag:"h1"}}),f=new ae({props:{title:"Configure UNet2DConditionModel parameters",local:"configure-unet2dconditionmodel-parameters",headingTag:"h2"}}),c=new Y({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 Y({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 Y({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMEF1dG9Nb2RlbCUwQSUwQW1vZGVsX2lkJTIwJTNEJTIwJTIyc3RhYmxlLWRpZmZ1c2lvbi12MS01JTJGc3RhYmxlLWRpZmZ1c2lvbi12MS01JTIyJTBBdW5ldCUyMCUzRCUyMEF1dG9Nb2RlbC5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwbW9kZWxfaWQlMkMlMEElMjAlMjAlMjAlMjBzdWJmb2xkZXIlM0QlMjJ1bmV0JTIyJTJDJTBBJTIwJTIwJTIwJTIwaW5fY2hhbm5lbHMlM0Q5JTJDJTBBJTIwJTIwJTIwJTIwbG93X2NwdV9tZW1fdXNhZ2UlM0RGYWxzZSUyQyUwQSUyMCUyMCUyMCUyMGlnbm9yZV9taXNtYXRjaGVkX3NpemVzJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMHVzZV9zYWZldGVuc29ycyUzRFRydWUlMkMlMEEp",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> AutoModel

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