import{S as Oo,i as Ho,s as Wo,e as r,k as u,w as k,t as i,M as Fo,c as n,d as t,m,a,x as A,h as d,b as l,G as o,g as _,y as P,q as T,o as I,B as S,v as Ro}from"../../chunks/vendor-hf-doc-builder.js";import{T as mo}from"../../chunks/Tip-hf-doc-builder.js";import{D as _o}from"../../chunks/Docstring-hf-doc-builder.js";import{I as go}from"../../chunks/IconCopyLink-hf-doc-builder.js";function Vo(q){let s,g;return{c(){s=r("p"),g=i("This function is experimental and might change in the future")},l(c){s=n(c,"P",{});var h=a(s);g=d(h,"This function is experimental and might change in the future"),h.forEach(t)},m(c,h){_(c,s,h),o(s,g)},d(c){c&&t(s)}}}function zo(q){let s,g,c,h,b,p,v,w;return{c(){s=r("p"),g=i("It is required to be logged in ("),c=r("code"),h=i("huggingface-cli login"),b=i(") when you want to use private or "),p=r("a"),v=i(`gated
models`),w=i("."),this.h()},l(C){s=n(C,"P",{});var y=a(s);g=d(y,"It is required to be logged in ("),c=n(y,"CODE",{});var M=a(c);h=d(M,"huggingface-cli login"),M.forEach(t),b=d(y,") when you want to use private or "),p=n(y,"A",{href:!0,rel:!0});var ne=a(p);v=d(ne,`gated
models`),ne.forEach(t),w=d(y,"."),y.forEach(t),this.h()},h(){l(p,"href","https://huggingface.co/docs/hub/models-gated#gated-models"),l(p,"rel","nofollow")},m(C,y){_(C,s,y),o(s,g),o(s,c),o(c,h),o(s,b),o(s,p),o(p,v),o(s,w)},d(C){C&&t(s)}}}function Go(q){let s,g,c,h,b;return{c(){s=r("p"),g=i("Activate the special "),c=r("a"),h=i("\u201Coffline-mode\u201D"),b=i(` to use
this method in a firewalled environment.`),this.h()},l(p){s=n(p,"P",{});var v=a(s);g=d(v,"Activate the special "),c=n(v,"A",{href:!0,rel:!0});var w=a(c);h=d(w,"\u201Coffline-mode\u201D"),w.forEach(t),b=d(v,` to use
this method in a firewalled environment.`),v.forEach(t),this.h()},h(){l(c,"href","https://huggingface.co/diffusers/installation.html#offline-mode"),l(c,"rel","nofollow")},m(p,v){_(p,s,v),o(s,g),o(s,c),o(c,h),o(s,b)},d(p){p&&t(s)}}}function Bo(q){let s,g,c,h,b,p,v,w,C,y,M,ne,we,L,de,ae,Te,Ie,le,J,Se,qe,ce,j,Oe,xe,O,He,H,fe,We,Fe,Re,Ee,K,he,Ve,ze,Le,N,W,pe,Q,Ge,ue,Be,De,U,F,me,X,Je,_e,je,Ce,x,Y,Ke,$,Z,Qe,E,Xe,ge,Ye,Ze,ee,eo,oo,ve,to,ro,no,R,ao,V,so,z,io,G,oe,lo,te,co,$e,fo,ho,Me;return p=new go({}),Q=new go({}),X=new go({}),Y=new _o({props:{name:"class diffusers.loaders.UNet2DConditionLoadersMixin",anchor:"diffusers.loaders.UNet2DConditionLoadersMixin",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.12.0/src/diffusers/loaders.py#L61"}}),Z=new _o({props:{name:"load_attn_procs",anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs",parameters:[{name:"pretrained_model_name_or_path_or_dict",val:": typing.Union[str, typing.Dict[str, torch.Tensor]]"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs.pretrained_model_name_or_path_or_dict",description:`<strong>pretrained_model_name_or_path_or_dict</strong> (<code>str</code> or <code>os.PathLike</code> or <code>dict</code>) &#x2014;
Can be either:</p>
<ul>
<li>A string, the <em>model id</em> of a pretrained model hosted inside a model repo on huggingface.co.
Valid model ids should have an organization name, like <code>google/ddpm-celebahq-256</code>.</li>
<li>A path to a <em>directory</em> containing model weights saved using <code>~ModelMixin.save_config</code>, e.g.,
<code>./my_model_directory/</code>.</li>
<li>A <a href="https://pytorch.org/tutorials/beginner/saving_loading_models.html#what-is-a-state-dict" rel="nofollow">torch state
dict</a>.</li>
</ul>`,name:"pretrained_model_name_or_path_or_dict"},{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs.cache_dir",description:`<strong>cache_dir</strong> (<code>Union[str, os.PathLike]</code>, <em>optional</em>) &#x2014;
Path to a directory in which a downloaded pretrained model configuration should be cached if the
standard cache should not be used.`,name:"cache_dir"},{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs.force_download",description:`<strong>force_download</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
cached versions if they exist.`,name:"force_download"},{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs.resume_download",description:`<strong>resume_download</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether or not to delete incompletely received files. Will attempt to resume the download if such a
file exists.`,name:"resume_download"},{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs.proxies",description:`<strong>proxies</strong> (<code>Dict[str, str]</code>, <em>optional</em>) &#x2014;
A dictionary of proxy servers to use by protocol or endpoint, e.g., <code>{&apos;http&apos;: &apos;foo.bar:3128&apos;, &apos;http://hostname&apos;: &apos;foo.bar:4012&apos;}</code>. The proxies are used on each request.`,name:"proxies"},{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs.local_files_only(bool,",description:`<strong>local_files_only(<code>bool</code>,</strong> <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether or not to only look at local files (i.e., do not try to download the model).`,name:"local_files_only(bool,"},{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs.use_auth_token",description:`<strong>use_auth_token</strong> (<code>str</code> or <em>bool</em>, <em>optional</em>) &#x2014;
The token to use as HTTP bearer authorization for remote files. If <code>True</code>, will use the token generated
when running <code>diffusers-cli login</code> (stored in <code>~/.huggingface</code>).`,name:"use_auth_token"},{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs.revision",description:`<strong>revision</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;main&quot;</code>) &#x2014;
The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
git-based system for storing models and other artifacts on huggingface.co, so <code>revision</code> can be any
identifier allowed by git.`,name:"revision"},{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs.subfolder",description:`<strong>subfolder</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&quot;</code>) &#x2014;
In case the relevant files are located inside a subfolder of the model repo (either remote in
huggingface.co or downloaded locally), you can specify the folder name here.`,name:"subfolder"},{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs.mirror",description:`<strong>mirror</strong> (<code>str</code>, <em>optional</em>) &#x2014;
Mirror source to accelerate downloads in China. If you are from China and have an accessibility
problem, you can set this option to resolve it. Note that we do not guarantee the timeliness or safety.
Please refer to the mirror site for more information.`,name:"mirror"}],source:"https://github.com/huggingface/diffusers/blob/v0.12.0/src/diffusers/loaders.py#L62"}}),R=new mo({props:{warning:!0,$$slots:{default:[Vo]},$$scope:{ctx:q}}}),V=new mo({props:{$$slots:{default:[zo]},$$scope:{ctx:q}}}),z=new mo({props:{$$slots:{default:[Go]},$$scope:{ctx:q}}}),oe=new _o({props:{name:"save_attn_procs",anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.save_attn_procs",parameters:[{name:"save_directory",val:": typing.Union[str, os.PathLike]"},{name:"is_main_process",val:": bool = True"},{name:"weights_name",val:": str = 'pytorch_lora_weights.bin'"},{name:"save_function",val:": typing.Callable = None"}],parametersDescription:[{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.save_attn_procs.save_directory",description:`<strong>save_directory</strong> (<code>str</code> or <code>os.PathLike</code>) &#x2014;
Directory to which to save. Will be created if it doesn&#x2019;t exist.`,name:"save_directory"},{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.save_attn_procs.is_main_process",description:`<strong>is_main_process</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether the process calling this is the main process or not. Useful when in distributed training like
TPUs and need to call this function on all processes. In this case, set <code>is_main_process=True</code> only on
the main process to avoid race conditions.`,name:"is_main_process"},{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.save_attn_procs.save_function",description:`<strong>save_function</strong> (<code>Callable</code>) &#x2014;
The function to use to save the state dictionary. Useful on distributed training like TPUs when one
need to replace <code>torch.save</code> by another method. Can be configured with the environment variable
<code>DIFFUSERS_SAVE_MODE</code>.`,name:"save_function"}],source:"https://github.com/huggingface/diffusers/blob/v0.12.0/src/diffusers/loaders.py#L194"}}),{c(){s=r("meta"),g=u(),c=r("h1"),h=r("a"),b=r("span"),k(p.$$.fragment),v=u(),w=r("span"),C=i("Loaders"),y=u(),M=r("p"),ne=i("There are many weights to train adapter neural networks for diffusion models, such as"),we=u(),L=r("ul"),de=r("li"),ae=r("a"),Te=i("Textual Inversion"),Ie=u(),le=r("li"),J=r("a"),Se=i("LoRA"),qe=u(),ce=r("li"),j=r("a"),Oe=i("Hypernetworks"),xe=u(),O=r("p"),He=i(`Such adapter neural networks often only consist of a fraction of the number of weights compared
to the pretrained model and as such are very portable. The Diffusers library offers an easy-to-use
API to load such adapter neural networks via the `),H=r("a"),fe=r("code"),We=i("loaders.py"),Fe=i(" module"),Re=i("."),Ee=u(),K=r("p"),he=r("strong"),Ve=i("Note"),ze=i(": This module is still highly experimental and prone to future changes."),Le=u(),N=r("h2"),W=r("a"),pe=r("span"),k(Q.$$.fragment),Ge=u(),ue=r("span"),Be=i("LoaderMixins"),De=u(),U=r("h3"),F=r("a"),me=r("span"),k(X.$$.fragment),Je=u(),_e=r("span"),je=i("UNet2DConditionLoadersMixin"),Ce=u(),x=r("div"),k(Y.$$.fragment),Ke=u(),$=r("div"),k(Z.$$.fragment),Qe=u(),E=r("p"),Xe=i("Load pretrained attention processor layers into "),ge=r("code"),Ye=i("UNet2DConditionModel"),Ze=i(`. Attention processor layers have to be
defined in
`),ee=r("a"),eo=i("cross_attention.py"),oo=i(`
and be a `),ve=r("code"),to=i("torch.nn.Module"),ro=i(" class."),no=u(),k(R.$$.fragment),ao=u(),k(V.$$.fragment),so=u(),k(z.$$.fragment),io=u(),G=r("div"),k(oe.$$.fragment),lo=u(),te=r("p"),co=i(`Save an attention procesor to a directory, so that it can be re-loaded using the
`),$e=r("code"),fo=i("[load_attn_procs()](/docs/diffusers/v0.12.0/en/api/loaders#diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs)"),ho=i(" method."),this.h()},l(e){const f=Fo('[data-svelte="svelte-1phssyn"]',document.head);s=n(f,"META",{name:!0,content:!0}),f.forEach(t),g=m(e),c=n(e,"H1",{class:!0});var re=a(c);h=n(re,"A",{id:!0,class:!0,href:!0});var be=a(h);b=n(be,"SPAN",{});var ye=a(b);A(p.$$.fragment,ye),ye.forEach(t),be.forEach(t),v=m(re),w=n(re,"SPAN",{});var vo=a(w);C=d(vo,"Loaders"),vo.forEach(t),re.forEach(t),y=m(e),M=n(e,"P",{});var $o=a(M);ne=d($o,"There are many weights to train adapter neural networks for diffusion models, such as"),$o.forEach(t),we=m(e),L=n(e,"UL",{});var se=a(L);de=n(se,"LI",{});var bo=a(de);ae=n(bo,"A",{href:!0});var yo=a(ae);Te=d(yo,"Textual Inversion"),yo.forEach(t),bo.forEach(t),Ie=m(se),le=n(se,"LI",{});var wo=a(le);J=n(wo,"A",{href:!0,rel:!0});var xo=a(J);Se=d(xo,"LoRA"),xo.forEach(t),wo.forEach(t),qe=m(se),ce=n(se,"LI",{});var Eo=a(ce);j=n(Eo,"A",{href:!0,rel:!0});var Lo=a(j);Oe=d(Lo,"Hypernetworks"),Lo.forEach(t),Eo.forEach(t),se.forEach(t),xe=m(e),O=n(e,"P",{});var Ne=a(O);He=d(Ne,`Such adapter neural networks often only consist of a fraction of the number of weights compared
to the pretrained model and as such are very portable. The Diffusers library offers an easy-to-use
API to load such adapter neural networks via the `),H=n(Ne,"A",{href:!0,rel:!0});var po=a(H);fe=n(po,"CODE",{});var Do=a(fe);We=d(Do,"loaders.py"),Do.forEach(t),Fe=d(po," module"),po.forEach(t),Re=d(Ne,"."),Ne.forEach(t),Ee=m(e),K=n(e,"P",{});var uo=a(K);he=n(uo,"STRONG",{});var Co=a(he);Ve=d(Co,"Note"),Co.forEach(t),ze=d(uo,": This module is still highly experimental and prone to future changes."),uo.forEach(t),Le=m(e),N=n(e,"H2",{class:!0});var Ue=a(N);W=n(Ue,"A",{id:!0,class:!0,href:!0});var Mo=a(W);pe=n(Mo,"SPAN",{});var No=a(pe);A(Q.$$.fragment,No),No.forEach(t),Mo.forEach(t),Ge=m(Ue),ue=n(Ue,"SPAN",{});var Uo=a(ue);Be=d(Uo,"LoaderMixins"),Uo.forEach(t),Ue.forEach(t),De=m(e),U=n(e,"H3",{class:!0});var ke=a(U);F=n(ke,"A",{id:!0,class:!0,href:!0});var ko=a(F);me=n(ko,"SPAN",{});var Ao=a(me);A(X.$$.fragment,Ao),Ao.forEach(t),ko.forEach(t),Je=m(ke),_e=n(ke,"SPAN",{});var Po=a(_e);je=d(Po,"UNet2DConditionLoadersMixin"),Po.forEach(t),ke.forEach(t),Ce=m(e),x=n(e,"DIV",{class:!0});var ie=a(x);A(Y.$$.fragment,ie),Ke=m(ie),$=n(ie,"DIV",{class:!0});var D=a($);A(Z.$$.fragment,D),Qe=m(D),E=n(D,"P",{});var B=a(E);Xe=d(B,"Load pretrained attention processor layers into "),ge=n(B,"CODE",{});var To=a(ge);Ye=d(To,"UNet2DConditionModel"),To.forEach(t),Ze=d(B,`. Attention processor layers have to be
defined in
`),ee=n(B,"A",{href:!0,rel:!0});var Io=a(ee);eo=d(Io,"cross_attention.py"),Io.forEach(t),oo=d(B,`
and be a `),ve=n(B,"CODE",{});var So=a(ve);to=d(So,"torch.nn.Module"),So.forEach(t),ro=d(B," class."),B.forEach(t),no=m(D),A(R.$$.fragment,D),ao=m(D),A(V.$$.fragment,D),so=m(D),A(z.$$.fragment,D),D.forEach(t),io=m(ie),G=n(ie,"DIV",{class:!0});var Ae=a(G);A(oe.$$.fragment,Ae),lo=m(Ae),te=n(Ae,"P",{});var Pe=a(te);co=d(Pe,`Save an attention procesor to a directory, so that it can be re-loaded using the
`),$e=n(Pe,"CODE",{});var qo=a($e);fo=d(qo,"[load_attn_procs()](/docs/diffusers/v0.12.0/en/api/loaders#diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs)"),qo.forEach(t),ho=d(Pe," method."),Pe.forEach(t),Ae.forEach(t),ie.forEach(t),this.h()},h(){l(s,"name","hf:doc:metadata"),l(s,"content",JSON.stringify(Jo)),l(h,"id","loaders"),l(h,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(h,"href","#loaders"),l(c,"class","relative group"),l(ae,"href","./training/text_inversion.mdx"),l(J,"href","https://github.com/cloneofsimo/lora"),l(J,"rel","nofollow"),l(j,"href","https://arxiv.org/abs/1609.09106"),l(j,"rel","nofollow"),l(H,"href","https://github.com/huggingface/diffusers/blob/main/src/diffusers/loaders.py"),l(H,"rel","nofollow"),l(W,"id","loadermixins"),l(W,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(W,"href","#loadermixins"),l(N,"class","relative group"),l(F,"id","diffusers.loaders.UNet2DConditionLoadersMixin"),l(F,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(F,"href","#diffusers.loaders.UNet2DConditionLoadersMixin"),l(U,"class","relative group"),l(ee,"href","https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/cross_attention.py"),l(ee,"rel","nofollow"),l($,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(G,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(x,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,f){o(document.head,s),_(e,g,f),_(e,c,f),o(c,h),o(h,b),P(p,b,null),o(c,v),o(c,w),o(w,C),_(e,y,f),_(e,M,f),o(M,ne),_(e,we,f),_(e,L,f),o(L,de),o(de,ae),o(ae,Te),o(L,Ie),o(L,le),o(le,J),o(J,Se),o(L,qe),o(L,ce),o(ce,j),o(j,Oe),_(e,xe,f),_(e,O,f),o(O,He),o(O,H),o(H,fe),o(fe,We),o(H,Fe),o(O,Re),_(e,Ee,f),_(e,K,f),o(K,he),o(he,Ve),o(K,ze),_(e,Le,f),_(e,N,f),o(N,W),o(W,pe),P(Q,pe,null),o(N,Ge),o(N,ue),o(ue,Be),_(e,De,f),_(e,U,f),o(U,F),o(F,me),P(X,me,null),o(U,Je),o(U,_e),o(_e,je),_(e,Ce,f),_(e,x,f),P(Y,x,null),o(x,Ke),o(x,$),P(Z,$,null),o($,Qe),o($,E),o(E,Xe),o(E,ge),o(ge,Ye),o(E,Ze),o(E,ee),o(ee,eo),o(E,oo),o(E,ve),o(ve,to),o(E,ro),o($,no),P(R,$,null),o($,ao),P(V,$,null),o($,so),P(z,$,null),o(x,io),o(x,G),P(oe,G,null),o(G,lo),o(G,te),o(te,co),o(te,$e),o($e,fo),o(te,ho),Me=!0},p(e,[f]){const re={};f&2&&(re.$$scope={dirty:f,ctx:e}),R.$set(re);const be={};f&2&&(be.$$scope={dirty:f,ctx:e}),V.$set(be);const ye={};f&2&&(ye.$$scope={dirty:f,ctx:e}),z.$set(ye)},i(e){Me||(T(p.$$.fragment,e),T(Q.$$.fragment,e),T(X.$$.fragment,e),T(Y.$$.fragment,e),T(Z.$$.fragment,e),T(R.$$.fragment,e),T(V.$$.fragment,e),T(z.$$.fragment,e),T(oe.$$.fragment,e),Me=!0)},o(e){I(p.$$.fragment,e),I(Q.$$.fragment,e),I(X.$$.fragment,e),I(Y.$$.fragment,e),I(Z.$$.fragment,e),I(R.$$.fragment,e),I(V.$$.fragment,e),I(z.$$.fragment,e),I(oe.$$.fragment,e),Me=!1},d(e){t(s),e&&t(g),e&&t(c),S(p),e&&t(y),e&&t(M),e&&t(we),e&&t(L),e&&t(xe),e&&t(O),e&&t(Ee),e&&t(K),e&&t(Le),e&&t(N),S(Q),e&&t(De),e&&t(U),S(X),e&&t(Ce),e&&t(x),S(Y),S(Z),S(R),S(V),S(z),S(oe)}}}const Jo={local:"loaders",sections:[{local:"loadermixins",sections:[{local:"diffusers.loaders.UNet2DConditionLoadersMixin",title:"UNet2DConditionLoadersMixin"}],title:"LoaderMixins"}],title:"Loaders"};function jo(q){return Ro(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Zo extends Oo{constructor(s){super();Ho(this,s,jo,Bo,Wo,{})}}export{Zo as default,Jo as metadata};
