import{s as oe,n as pe,o as me}from"../chunks/scheduler.53228c21.js";import{S as de,i as re,e as l,s as i,c as Z,h as fe,a as o,d as n,b as a,f as ie,g as $,j as _,k as ae,l as ue,m as s,n as v,t as U,o as x,p as C}from"../chunks/index.100fac89.js";import{C as ce}from"../chunks/CopyLLMTxtMenu.fb2ec027.js";import{C as q}from"../chunks/CodeBlock.d30a6509.js";import{H as le,E as he}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.09d4dba9.js";function be(A){let p,k,W,G,m,j,d,N,r,F="Many diffusion systems share the same components, allowing you to adapt a pretrained model for one task to an entirely different task.",I,f,O='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>.',R,u,S,c,K='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,h,X,b,ee='Inpainting requires 9 channels in the input sample. You can check this value in a pretrained inpainting model like <a href="https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-inpainting" rel="nofollow"><code>stable-diffusion-v1-5/stable-diffusion-inpainting</code></a>:',z,y,L,M,te="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.",E,T,ne='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.',H,g,Q,J,se="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.",Y,w,D,B,P;return m=new ce({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),d=new le({props:{title:"Adapt a model to a new task",local:"adapt-a-model-to-a-new-task",headingTag:"h1"}}),u=new le({props:{title:"Configure UNet2DConditionModel parameters",local:"configure-unet2dconditionmodel-parameters",headingTag:"h2"}}),h=new q({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}}),y=new q({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBJTBBcGlwZWxpbmUlMjAlM0QlMjBTdGFibGVEaWZmdXNpb25QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIyc3RhYmxlLWRpZmZ1c2lvbi12MS01JTJGc3RhYmxlLWRpZmZ1c2lvbi1pbnBhaW50aW5nJTIyJTJDJTIwdXNlX3NhZmV0ZW5zb3JzJTNEVHJ1ZSklMEFwaXBlbGluZS51bmV0LmNvbmZpZyU1QiUyMmluX2NoYW5uZWxzJTIyJTVEJTBBOQ==",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-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 q({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}}),w=new he({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/training/adapt_a_model.md"}}),{c(){p=l("meta"),k=i(),W=l("p"),G=i(),Z(m.$$.fragment),j=i(),Z(d.$$.fragment),N=i(),r=l("p"),r.textContent=F,I=i(),f=l("p"),f.innerHTML=O,R=i(),Z(u.$$.fragment),S=i(),c=l("p"),c.innerHTML=K,V=i(),Z(h.$$.fragment),X=i(),b=l("p"),b.innerHTML=ee,z=i(),Z(y.$$.fragment),L=i(),M=l("p"),M.innerHTML=te,E=i(),T=l("p"),T.innerHTML=ne,H=i(),Z(g.$$.fragment),Q=i(),J=l("p"),J.innerHTML=se,Y=i(),Z(w.$$.fragment),D=i(),B=l("p"),this.h()},l(e){const t=fe("svelte-u9bgzb",document.head);p=o(t,"META",{name:!0,content:!0}),t.forEach(n),k=a(e),W=o(e,"P",{}),ie(W).forEach(n),G=a(e),$(m.$$.fragment,e),j=a(e),$(d.$$.fragment,e),N=a(e),r=o(e,"P",{"data-svelte-h":!0}),_(r)!=="svelte-3om45r"&&(r.textContent=F),I=a(e),f=o(e,"P",{"data-svelte-h":!0}),_(f)!=="svelte-plxekm"&&(f.innerHTML=O),R=a(e),$(u.$$.fragment,e),S=a(e),c=o(e,"P",{"data-svelte-h":!0}),_(c)!=="svelte-s4tzh5"&&(c.innerHTML=K),V=a(e),$(h.$$.fragment,e),X=a(e),b=o(e,"P",{"data-svelte-h":!0}),_(b)!=="svelte-h01zxl"&&(b.innerHTML=ee),z=a(e),$(y.$$.fragment,e),L=a(e),M=o(e,"P",{"data-svelte-h":!0}),_(M)!=="svelte-1p1x44t"&&(M.innerHTML=te),E=a(e),T=o(e,"P",{"data-svelte-h":!0}),_(T)!=="svelte-1k8u2s"&&(T.innerHTML=ne),H=a(e),$(g.$$.fragment,e),Q=a(e),J=o(e,"P",{"data-svelte-h":!0}),_(J)!=="svelte-6j6lxu"&&(J.innerHTML=se),Y=a(e),$(w.$$.fragment,e),D=a(e),B=o(e,"P",{}),ie(B).forEach(n),this.h()},h(){ae(p,"name","hf:doc:metadata"),ae(p,"content",ye)},m(e,t){ue(document.head,p),s(e,k,t),s(e,W,t),s(e,G,t),v(m,e,t),s(e,j,t),v(d,e,t),s(e,N,t),s(e,r,t),s(e,I,t),s(e,f,t),s(e,R,t),v(u,e,t),s(e,S,t),s(e,c,t),s(e,V,t),v(h,e,t),s(e,X,t),s(e,b,t),s(e,z,t),v(y,e,t),s(e,L,t),s(e,M,t),s(e,E,t),s(e,T,t),s(e,H,t),v(g,e,t),s(e,Q,t),s(e,J,t),s(e,Y,t),v(w,e,t),s(e,D,t),s(e,B,t),P=!0},p:pe,i(e){P||(U(m.$$.fragment,e),U(d.$$.fragment,e),U(u.$$.fragment,e),U(h.$$.fragment,e),U(y.$$.fragment,e),U(g.$$.fragment,e),U(w.$$.fragment,e),P=!0)},o(e){x(m.$$.fragment,e),x(d.$$.fragment,e),x(u.$$.fragment,e),x(h.$$.fragment,e),x(y.$$.fragment,e),x(g.$$.fragment,e),x(w.$$.fragment,e),P=!1},d(e){e&&(n(k),n(W),n(G),n(j),n(N),n(r),n(I),n(f),n(R),n(S),n(c),n(V),n(X),n(b),n(z),n(L),n(M),n(E),n(T),n(H),n(Q),n(J),n(Y),n(D),n(B)),n(p),C(m,e),C(d,e),C(u,e),C(h,e),C(y,e),C(g,e),C(w,e)}}}const ye='{"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 Me(A){return me(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class $e extends de{constructor(p){super(),re(this,p,Me,be,oe,{})}}export{$e as component};
