import{s as he,o as ge,n as re}from"../chunks/scheduler.8c3d61f6.js";import{S as _e,i as be,g as f,s as d,r as b,A as ye,h as m,f as a,c as l,j as X,u as y,x as Z,k as B,y as g,a as i,v as $,d as w,t as x,w as v}from"../chunks/index.da70eac4.js";import{T as $e}from"../chunks/Tip.1d9b8c37.js";import{D as se}from"../chunks/Docstring.ee4b6913.js";import{C as ue}from"../chunks/CodeBlock.00a903b3.js";import{E as fe}from"../chunks/ExampleCodeBlock.f7bd2c1f.js";import{H as me,E as we}from"../chunks/EditOnGithub.1e64e623.js";function xe(L){let o,u='To learn more about how to load LoRA weights, see the <a href="../../using-diffusers/loading_adapters#lora">LoRA</a> loading guide.';return{c(){o=f("p"),o.innerHTML=u},l(r){o=m(r,"P",{"data-svelte-h":!0}),Z(o)!=="svelte-1fw6lx1"&&(o.innerHTML=u)},m(r,s){i(r,o,s)},p:re,d(r){r&&a(o)}}}function ve(L){let o,u="Example:",r,s,c;return s=new ue({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMEF1dG9QaXBlbGluZUZvclRleHQySW1hZ2UlMEFpbXBvcnQlMjB0b3JjaCUwQSUwQXBpcGVsaW5lJTIwJTNEJTIwQXV0b1BpcGVsaW5lRm9yVGV4dDJJbWFnZS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIyc3RhYmlsaXR5YWklMkZzdGFibGUtZGlmZnVzaW9uLXhsLWJhc2UtMS4wJTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTBBKS50byglMjJjdWRhJTIyKSUwQXBpcGVsaW5lLnVuZXQubG9hZF9hdHRuX3Byb2NzKCUwQSUyMCUyMCUyMCUyMCUyMmpiaWxja2UtaGYlMkZzZHhsLWNpbmVtYXRpYy0xJTIyJTJDJTIwd2VpZ2h0X25hbWUlM0QlMjJweXRvcmNoX2xvcmFfd2VpZ2h0cy5zYWZldGVuc29ycyUyMiUyQyUyMGFkYXB0ZXJfbmFtZSUzRCUyMmNpbmVtYXRpYyUyMiUwQSk=",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> AutoPipelineForText2Image
<span class="hljs-keyword">import</span> torch

pipeline = AutoPipelineForText2Image.from_pretrained(
    <span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>, torch_dtype=torch.float16
).to(<span class="hljs-string">&quot;cuda&quot;</span>)
pipeline.unet.load_attn_procs(
    <span class="hljs-string">&quot;jbilcke-hf/sdxl-cinematic-1&quot;</span>, weight_name=<span class="hljs-string">&quot;pytorch_lora_weights.safetensors&quot;</span>, adapter_name=<span class="hljs-string">&quot;cinematic&quot;</span>
)`,wrap:!1}}),{c(){o=f("p"),o.textContent=u,r=d(),b(s.$$.fragment)},l(t){o=m(t,"P",{"data-svelte-h":!0}),Z(o)!=="svelte-11lpom8"&&(o.textContent=u),r=l(t),y(s.$$.fragment,t)},m(t,p){i(t,o,p),i(t,r,p),$(s,t,p),c=!0},p:re,i(t){c||(w(s.$$.fragment,t),c=!0)},o(t){x(s.$$.fragment,t),c=!1},d(t){t&&(a(o),a(r)),v(s,t)}}}function Me(L){let o,u="Example:",r,s,c;return s=new ue({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRGlmZnVzaW9uUGlwZWxpbmUlMEElMEFwaXBlbGluZSUyMCUzRCUyMERpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJDb21wVmlzJTJGc3RhYmxlLWRpZmZ1c2lvbi12MS00JTIyJTJDJTBBJTIwJTIwJTIwJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTJDJTBBKS50byglMjJjdWRhJTIyKSUwQXBpcGVsaW5lLnVuZXQubG9hZF9hdHRuX3Byb2NzKCUyMnBhdGgtdG8tc2F2ZS1tb2RlbCUyMiUyQyUyMHdlaWdodF9uYW1lJTNEJTIycHl0b3JjaF9jdXN0b21fZGlmZnVzaW9uX3dlaWdodHMuYmluJTIyKSUwQXBpcGVsaW5lLnVuZXQuc2F2ZV9hdHRuX3Byb2NzKCUyMnBhdGgtdG8tc2F2ZS1tb2RlbCUyMiUyQyUyMHdlaWdodF9uYW1lJTNEJTIycHl0b3JjaF9jdXN0b21fZGlmZnVzaW9uX3dlaWdodHMuYmluJTIyKQ==",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline

pipeline = DiffusionPipeline.from_pretrained(
    <span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>,
    torch_dtype=torch.float16,
).to(<span class="hljs-string">&quot;cuda&quot;</span>)
pipeline.unet.load_attn_procs(<span class="hljs-string">&quot;path-to-save-model&quot;</span>, weight_name=<span class="hljs-string">&quot;pytorch_custom_diffusion_weights.bin&quot;</span>)
pipeline.unet.save_attn_procs(<span class="hljs-string">&quot;path-to-save-model&quot;</span>, weight_name=<span class="hljs-string">&quot;pytorch_custom_diffusion_weights.bin&quot;</span>)`,wrap:!1}}),{c(){o=f("p"),o.textContent=u,r=d(),b(s.$$.fragment)},l(t){o=m(t,"P",{"data-svelte-h":!0}),Z(o)!=="svelte-11lpom8"&&(o.textContent=u),r=l(t),y(s.$$.fragment,t)},m(t,p){i(t,o,p),i(t,r,p),$(s,t,p),c=!0},p:re,i(t){c||(w(s.$$.fragment,t),c=!0)},o(t){x(s.$$.fragment,t),c=!1},d(t){t&&(a(o),a(r)),v(s,t)}}}function Ue(L){let o,u,r,s,c,t,p,ie='Some training methods - like LoRA and Custom Diffusion - typically target the UNet’s attention layers, but these training methods can also target other non-attention layers. Instead of training all of a model’s parameters, only a subset of the parameters are trained, which is faster and more efficient. This class is useful if you’re <em>only</em> loading weights into a UNet. If you need to load weights into the text encoder or a text encoder and UNet, try using the <a href="/docs/diffusers/main/en/api/loaders/lora#diffusers.loaders.StableDiffusionLoraLoaderMixin.load_lora_weights">load_lora_weights()</a> function instead.',S,k,de="The <code>UNet2DConditionLoadersMixin</code> class provides functions for loading and saving weights, fusing and unfusing LoRAs, disabling and enabling LoRAs, and setting and deleting adapters.",F,J,A,G,P,h,j,K,H,le="Load LoRA layers into a <code>UNet2DCondtionModel</code>.",O,M,I,ee,E,ce=`Load pretrained attention processor layers into <a href="/docs/diffusers/main/en/api/models/unet2d-cond#diffusers.UNet2DConditionModel">UNet2DConditionModel</a>. Attention processor layers have to be
defined in
<a href="https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py" rel="nofollow"><code>attention_processor.py</code></a>
and be a <code>torch.nn.Module</code> class. Currently supported: LoRA, Custom Diffusion. For LoRA, one must install
<code>peft</code>: <code>pip install -U peft</code>.`,te,D,oe,U,R,ne,q,pe=`Save attention processor layers to a directory so that it can be reloaded with the
<a href="/docs/diffusers/main/en/api/loaders/unet#diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs">load_attn_procs()</a> method.`,ae,N,z,W,Q,V,Y;return c=new me({props:{title:"UNet",local:"unet",headingTag:"h1"}}),J=new $e({props:{$$slots:{default:[xe]},$$scope:{ctx:L}}}),G=new me({props:{title:"UNet2DConditionLoadersMixin",local:"diffusers.loaders.UNet2DConditionLoadersMixin",headingTag:"h2"}}),j=new se({props:{name:"class diffusers.loaders.UNet2DConditionLoadersMixin",anchor:"diffusers.loaders.UNet2DConditionLoadersMixin",parameters:[],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/loaders/unet.py#L60"}}),I=new se({props:{name:"load_attn_procs",anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs",parameters:[{name:"pretrained_model_name_or_path_or_dict",val:": Union"},{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 model id (for example <code>google/ddpm-celebahq-256</code>) of a pretrained model hosted on
the Hub.</li>
<li>A path to a directory (for example <code>./my_model_directory</code>) containing the model weights saved
with <a href="/docs/diffusers/main/en/api/models/overview#diffusers.ModelMixin.save_pretrained">ModelMixin.save_pretrained()</a>.</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 where a downloaded pretrained model configuration is cached if the standard cache
is not 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.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, for example, <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",description:`<strong>local_files_only</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether to only load local model weights and configuration files or not. If set to <code>True</code>, the model
won&#x2019;t be downloaded from the Hub.`,name:"local_files_only"},{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs.token",description:`<strong>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>, the token generated from
<code>diffusers-cli login</code> (stored in <code>~/.huggingface</code>) is used.`,name:"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, a commit id, or 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;
The subfolder location of a model file within a larger model repository on the Hub or locally.`,name:"subfolder"},{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs.network_alphas",description:`<strong>network_alphas</strong> (<code>Dict[str, float]</code>) &#x2014;
The value of the network alpha used for stable learning and preventing underflow. This value has the
same meaning as the <code>--network_alpha</code> option in the kohya-ss trainer script. Refer to <a href="https://github.com/darkstorm2150/sd-scripts/blob/main/docs/train_network_README-en.md#execute-learning" rel="nofollow">this
link</a>.`,name:"network_alphas"},{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs.adapter_name",description:`<strong>adapter_name</strong> (<code>str</code>, <em>optional</em>, defaults to None) &#x2014;
Adapter name to be used for referencing the loaded adapter model. If not specified, it will use
<code>default_{i}</code> where i is the total number of adapters being loaded.`,name:"adapter_name"},{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs.weight_name",description:`<strong>weight_name</strong> (<code>str</code>, <em>optional</em>, defaults to None) &#x2014;
Name of the serialized state dict file.`,name:"weight_name"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/loaders/unet.py#L68"}}),D=new fe({props:{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs.example",$$slots:{default:[ve]},$$scope:{ctx:L}}}),R=new se({props:{name:"save_attn_procs",anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.save_attn_procs",parameters:[{name:"save_directory",val:": Union"},{name:"is_main_process",val:": bool = True"},{name:"weight_name",val:": str = None"},{name:"save_function",val:": Callable = None"},{name:"safe_serialization",val:": bool = True"},{name:"**kwargs",val:""}],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 save an attention processor to (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 during distributed training and you
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 during distributed training when you need to
replace <code>torch.save</code> with another method. Can be configured with the environment variable
<code>DIFFUSERS_SAVE_MODE</code>.`,name:"save_function"},{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.save_attn_procs.safe_serialization",description:`<strong>safe_serialization</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to save the model using <code>safetensors</code> or with <code>pickle</code>.`,name:"safe_serialization"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/loaders/unet.py#L389"}}),N=new fe({props:{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.save_attn_procs.example",$$slots:{default:[Me]},$$scope:{ctx:L}}}),W=new we({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/loaders/unet.md"}}),{c(){o=f("meta"),u=d(),r=f("p"),s=d(),b(c.$$.fragment),t=d(),p=f("p"),p.innerHTML=ie,S=d(),k=f("p"),k.innerHTML=de,F=d(),b(J.$$.fragment),A=d(),b(G.$$.fragment),P=d(),h=f("div"),b(j.$$.fragment),K=d(),H=f("p"),H.innerHTML=le,O=d(),M=f("div"),b(I.$$.fragment),ee=d(),E=f("p"),E.innerHTML=ce,te=d(),b(D.$$.fragment),oe=d(),U=f("div"),b(R.$$.fragment),ne=d(),q=f("p"),q.innerHTML=pe,ae=d(),b(N.$$.fragment),z=d(),b(W.$$.fragment),Q=d(),V=f("p"),this.h()},l(e){const n=ye("svelte-u9bgzb",document.head);o=m(n,"META",{name:!0,content:!0}),n.forEach(a),u=l(e),r=m(e,"P",{}),X(r).forEach(a),s=l(e),y(c.$$.fragment,e),t=l(e),p=m(e,"P",{"data-svelte-h":!0}),Z(p)!=="svelte-12aq0rb"&&(p.innerHTML=ie),S=l(e),k=m(e,"P",{"data-svelte-h":!0}),Z(k)!=="svelte-1exfvvi"&&(k.innerHTML=de),F=l(e),y(J.$$.fragment,e),A=l(e),y(G.$$.fragment,e),P=l(e),h=m(e,"DIV",{class:!0});var _=X(h);y(j.$$.fragment,_),K=l(_),H=m(_,"P",{"data-svelte-h":!0}),Z(H)!=="svelte-153rhof"&&(H.innerHTML=le),O=l(_),M=m(_,"DIV",{class:!0});var T=X(M);y(I.$$.fragment,T),ee=l(T),E=m(T,"P",{"data-svelte-h":!0}),Z(E)!=="svelte-1j94dhx"&&(E.innerHTML=ce),te=l(T),y(D.$$.fragment,T),T.forEach(a),oe=l(_),U=m(_,"DIV",{class:!0});var C=X(U);y(R.$$.fragment,C),ne=l(C),q=m(C,"P",{"data-svelte-h":!0}),Z(q)!=="svelte-17c800g"&&(q.innerHTML=pe),ae=l(C),y(N.$$.fragment,C),C.forEach(a),_.forEach(a),z=l(e),y(W.$$.fragment,e),Q=l(e),V=m(e,"P",{}),X(V).forEach(a),this.h()},h(){B(o,"name","hf:doc:metadata"),B(o,"content",Te),B(M,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),B(U,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),B(h,"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,n){g(document.head,o),i(e,u,n),i(e,r,n),i(e,s,n),$(c,e,n),i(e,t,n),i(e,p,n),i(e,S,n),i(e,k,n),i(e,F,n),$(J,e,n),i(e,A,n),$(G,e,n),i(e,P,n),i(e,h,n),$(j,h,null),g(h,K),g(h,H),g(h,O),g(h,M),$(I,M,null),g(M,ee),g(M,E),g(M,te),$(D,M,null),g(h,oe),g(h,U),$(R,U,null),g(U,ne),g(U,q),g(U,ae),$(N,U,null),i(e,z,n),$(W,e,n),i(e,Q,n),i(e,V,n),Y=!0},p(e,[n]){const _={};n&2&&(_.$$scope={dirty:n,ctx:e}),J.$set(_);const T={};n&2&&(T.$$scope={dirty:n,ctx:e}),D.$set(T);const C={};n&2&&(C.$$scope={dirty:n,ctx:e}),N.$set(C)},i(e){Y||(w(c.$$.fragment,e),w(J.$$.fragment,e),w(G.$$.fragment,e),w(j.$$.fragment,e),w(I.$$.fragment,e),w(D.$$.fragment,e),w(R.$$.fragment,e),w(N.$$.fragment,e),w(W.$$.fragment,e),Y=!0)},o(e){x(c.$$.fragment,e),x(J.$$.fragment,e),x(G.$$.fragment,e),x(j.$$.fragment,e),x(I.$$.fragment,e),x(D.$$.fragment,e),x(R.$$.fragment,e),x(N.$$.fragment,e),x(W.$$.fragment,e),Y=!1},d(e){e&&(a(u),a(r),a(s),a(t),a(p),a(S),a(k),a(F),a(A),a(P),a(h),a(z),a(Q),a(V)),a(o),v(c,e),v(J,e),v(G,e),v(j),v(I),v(D),v(R),v(N),v(W,e)}}}const Te='{"title":"UNet","local":"unet","sections":[{"title":"UNet2DConditionLoadersMixin","local":"diffusers.loaders.UNet2DConditionLoadersMixin","sections":[],"depth":2}],"depth":1}';function Ce(L){return ge(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class je extends _e{constructor(o){super(),be(this,o,Ce,Ue,he,{})}}export{je as component};
