import{s as he,o as _e,n as re}from"../chunks/scheduler.8c3d61f6.js";import{S as ge,i as be,g as f,s as d,r as b,A as ye,h as m,f as s,c as l,j as X,u as y,x as Z,k as B,y as _,a as i,v as w,d as $,t as v,w as x}from"../chunks/index.da70eac4.js";import{T as we}from"../chunks/Tip.1d9b8c37.js";import{D as ae}from"../chunks/Docstring.6b390b9a.js";import{C as ue}from"../chunks/CodeBlock.00a903b3.js";import{E as fe}from"../chunks/ExampleCodeBlock.db12be95.js";import{H as me,E as $e}from"../chunks/EditOnGithub.1e64e623.js";function ve(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,a){i(r,o,a)},p:re,d(r){r&&s(o)}}}function xe(L){let o,u="Example:",r,a,c;return a=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(a.$$.fragment)},l(t){o=m(t,"P",{"data-svelte-h":!0}),Z(o)!=="svelte-11lpom8"&&(o.textContent=u),r=l(t),y(a.$$.fragment,t)},m(t,p){i(t,o,p),i(t,r,p),w(a,t,p),c=!0},p:re,i(t){c||($(a.$$.fragment,t),c=!0)},o(t){v(a.$$.fragment,t),c=!1},d(t){t&&(s(o),s(r)),x(a,t)}}}function Me(L){let o,u="Example:",r,a,c;return a=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(a.$$.fragment)},l(t){o=m(t,"P",{"data-svelte-h":!0}),Z(o)!=="svelte-11lpom8"&&(o.textContent=u),r=l(t),y(a.$$.fragment,t)},m(t,p){i(t,o,p),i(t,r,p),w(a,t,p),c=!0},p:re,i(t){c||($(a.$$.fragment,t),c=!0)},o(t){v(a.$$.fragment,t),c=!1},d(t){t&&(s(o),s(r)),x(a,t)}}}function Ue(L){let o,u,r,a,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/pr_10056/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.",A,J,F,G,P,h,I,K,H,le="Load LoRA layers into a <code>UNet2DCondtionModel</code>.",O,M,R,ee,E,ce=`Load pretrained attention processor layers into <a href="/docs/diffusers/pr_10056/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,j,ne,q,pe=`Save attention processor layers to a directory so that it can be reloaded with the
<a href="/docs/diffusers/pr_10056/en/api/loaders/unet#diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs">load_attn_procs()</a> method.`,se,N,z,W,Q,V,Y;return c=new me({props:{title:"UNet",local:"unet",headingTag:"h1"}}),J=new we({props:{$$slots:{default:[ve]},$$scope:{ctx:L}}}),G=new me({props:{title:"UNet2DConditionLoadersMixin",local:"diffusers.loaders.UNet2DConditionLoadersMixin",headingTag:"h2"}}),I=new ae({props:{name:"class diffusers.loaders.UNet2DConditionLoadersMixin",anchor:"diffusers.loaders.UNet2DConditionLoadersMixin",parameters:[],source:"https://github.com/huggingface/diffusers/blob/vr_10056/src/diffusers/loaders/unet.py#L61"}}),R=new ae({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 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/pr_10056/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"},{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs.low_cpu_mem_usage",description:`<strong>low_cpu_mem_usage</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Speed up model loading by only loading the pretrained LoRA weights and not initializing the random
weights.`,name:"low_cpu_mem_usage"}],source:"https://github.com/huggingface/diffusers/blob/vr_10056/src/diffusers/loaders/unet.py#L69"}}),D=new fe({props:{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs.example",$$slots:{default:[xe]},$$scope:{ctx:L}}}),j=new ae({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:"weight_name",val:": str = None"},{name:"save_function",val:": typing.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/vr_10056/src/diffusers/loaders/unet.py#L425"}}),N=new fe({props:{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.save_attn_procs.example",$$slots:{default:[Me]},$$scope:{ctx:L}}}),W=new $e({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"),a=d(),b(c.$$.fragment),t=d(),p=f("p"),p.innerHTML=ie,S=d(),k=f("p"),k.innerHTML=de,A=d(),b(J.$$.fragment),F=d(),b(G.$$.fragment),P=d(),h=f("div"),b(I.$$.fragment),K=d(),H=f("p"),H.innerHTML=le,O=d(),M=f("div"),b(R.$$.fragment),ee=d(),E=f("p"),E.innerHTML=ce,te=d(),b(D.$$.fragment),oe=d(),U=f("div"),b(j.$$.fragment),ne=d(),q=f("p"),q.innerHTML=pe,se=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(s),u=l(e),r=m(e,"P",{}),X(r).forEach(s),a=l(e),y(c.$$.fragment,e),t=l(e),p=m(e,"P",{"data-svelte-h":!0}),Z(p)!=="svelte-5weq7v"&&(p.innerHTML=ie),S=l(e),k=m(e,"P",{"data-svelte-h":!0}),Z(k)!=="svelte-1exfvvi"&&(k.innerHTML=de),A=l(e),y(J.$$.fragment,e),F=l(e),y(G.$$.fragment,e),P=l(e),h=m(e,"DIV",{class:!0});var g=X(h);y(I.$$.fragment,g),K=l(g),H=m(g,"P",{"data-svelte-h":!0}),Z(H)!=="svelte-153rhof"&&(H.innerHTML=le),O=l(g),M=m(g,"DIV",{class:!0});var T=X(M);y(R.$$.fragment,T),ee=l(T),E=m(T,"P",{"data-svelte-h":!0}),Z(E)!=="svelte-7mnq2p"&&(E.innerHTML=ce),te=l(T),y(D.$$.fragment,T),T.forEach(s),oe=l(g),U=m(g,"DIV",{class:!0});var C=X(U);y(j.$$.fragment,C),ne=l(C),q=m(C,"P",{"data-svelte-h":!0}),Z(q)!=="svelte-b1lre8"&&(q.innerHTML=pe),se=l(C),y(N.$$.fragment,C),C.forEach(s),g.forEach(s),z=l(e),y(W.$$.fragment,e),Q=l(e),V=m(e,"P",{}),X(V).forEach(s),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){_(document.head,o),i(e,u,n),i(e,r,n),i(e,a,n),w(c,e,n),i(e,t,n),i(e,p,n),i(e,S,n),i(e,k,n),i(e,A,n),w(J,e,n),i(e,F,n),w(G,e,n),i(e,P,n),i(e,h,n),w(I,h,null),_(h,K),_(h,H),_(h,O),_(h,M),w(R,M,null),_(M,ee),_(M,E),_(M,te),w(D,M,null),_(h,oe),_(h,U),w(j,U,null),_(U,ne),_(U,q),_(U,se),w(N,U,null),i(e,z,n),w(W,e,n),i(e,Q,n),i(e,V,n),Y=!0},p(e,[n]){const g={};n&2&&(g.$$scope={dirty:n,ctx:e}),J.$set(g);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||($(c.$$.fragment,e),$(J.$$.fragment,e),$(G.$$.fragment,e),$(I.$$.fragment,e),$(R.$$.fragment,e),$(D.$$.fragment,e),$(j.$$.fragment,e),$(N.$$.fragment,e),$(W.$$.fragment,e),Y=!0)},o(e){v(c.$$.fragment,e),v(J.$$.fragment,e),v(G.$$.fragment,e),v(I.$$.fragment,e),v(R.$$.fragment,e),v(D.$$.fragment,e),v(j.$$.fragment,e),v(N.$$.fragment,e),v(W.$$.fragment,e),Y=!1},d(e){e&&(s(u),s(r),s(a),s(t),s(p),s(S),s(k),s(A),s(F),s(P),s(h),s(z),s(Q),s(V)),s(o),x(c,e),x(J,e),x(G,e),x(I),x(R),x(D),x(j),x(N),x(W,e)}}}const Te='{"title":"UNet","local":"unet","sections":[{"title":"UNet2DConditionLoadersMixin","local":"diffusers.loaders.UNet2DConditionLoadersMixin","sections":[],"depth":2}],"depth":1}';function Ce(L){return _e(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ie extends ge{constructor(o){super(),be(this,o,Ce,Ue,he,{})}}export{Ie as component};
