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