import{s as be,o as ye,n as ge}from"../chunks/scheduler.53228c21.js";import{S as we,i as xe,e as f,s as r,c as _,h as $e,a as m,d as n,b as d,f as S,g as b,j as D,k as X,l as h,m as i,n as y,t as w,o as x,p as $}from"../chunks/index.100fac89.js";import{C as Me}from"../chunks/CopyLLMTxtMenu.b0ff86f3.js";import{D as re}from"../chunks/Docstring.db856a1e.js";import{C as _e}from"../chunks/CodeBlock.d30a6509.js";import{E as ue}from"../chunks/ExampleCodeBlock.3eb26ae1.js";import{H as he,E as ve}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.136ef3fd.js";function Ue(W){let a,M="Example:",c,s,l;return s=new _e({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(){a=f("p"),a.textContent=M,c=r(),_(s.$$.fragment)},l(t){a=m(t,"P",{"data-svelte-h":!0}),D(a)!=="svelte-11lpom8"&&(a.textContent=M),c=d(t),b(s.$$.fragment,t)},m(t,p){i(t,a,p),i(t,c,p),y(s,t,p),l=!0},p:ge,i(t){l||(w(s.$$.fragment,t),l=!0)},o(t){x(s.$$.fragment,t),l=!1},d(t){t&&(n(a),n(c)),$(s,t)}}}function Te(W){let a,M="Example:",c,s,l;return s=new _e({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(){a=f("p"),a.textContent=M,c=r(),_(s.$$.fragment)},l(t){a=m(t,"P",{"data-svelte-h":!0}),D(a)!=="svelte-11lpom8"&&(a.textContent=M),c=d(t),b(s.$$.fragment,t)},m(t,p){i(t,a,p),i(t,c,p),y(s,t,p),l=!0},p:ge,i(t){l||(w(s.$$.fragment,t),l=!0)},o(t){x(s.$$.fragment,t),l=!1},d(t){t&&(n(a),n(c)),$(s,t)}}}function Ce(W){let a,M,c,s,l,t,p,F,N,de='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.',z,k,le="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,C,ce='<p>To learn more about how to load LoRA weights, see the <a href="../../using-diffusers/loading_adapters#lora">LoRA</a> loading guide.</p>',P,Z,Q,u,G,ee,E,pe="Load LoRA layers into a <code>UNet2DCondtionModel</code>.",te,v,j,oe,H,fe=`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>.`,ne,L,ae,U,I,se,q,me=`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.`,ie,J,Y,R,K,B,O;return l=new Me({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),p=new he({props:{title:"UNet",local:"unet",headingTag:"h1"}}),Z=new he({props:{title:"UNet2DConditionLoadersMixin",local:"diffusers.loaders.UNet2DConditionLoadersMixin",headingTag:"h2"}}),G=new re({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"}}),j=new re({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/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"},{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/main/src/diffusers/loaders/unet.py#L68"}}),L=new ue({props:{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs.example",$$slots:{default:[Ue]},$$scope:{ctx:W}}}),I=new re({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/main/src/diffusers/loaders/unet.py#L413"}}),J=new ue({props:{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.save_attn_procs.example",$$slots:{default:[Te]},$$scope:{ctx:W}}}),R=new ve({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/loaders/unet.md"}}),{c(){a=f("meta"),M=r(),c=f("p"),s=r(),_(l.$$.fragment),t=r(),_(p.$$.fragment),F=r(),N=f("p"),N.innerHTML=de,z=r(),k=f("p"),k.innerHTML=le,A=r(),C=f("blockquote"),C.innerHTML=ce,P=r(),_(Z.$$.fragment),Q=r(),u=f("div"),_(G.$$.fragment),ee=r(),E=f("p"),E.innerHTML=pe,te=r(),v=f("div"),_(j.$$.fragment),oe=r(),H=f("p"),H.innerHTML=fe,ne=r(),_(L.$$.fragment),ae=r(),U=f("div"),_(I.$$.fragment),se=r(),q=f("p"),q.innerHTML=me,ie=r(),_(J.$$.fragment),Y=r(),_(R.$$.fragment),K=r(),B=f("p"),this.h()},l(e){const o=$e("svelte-u9bgzb",document.head);a=m(o,"META",{name:!0,content:!0}),o.forEach(n),M=d(e),c=m(e,"P",{}),S(c).forEach(n),s=d(e),b(l.$$.fragment,e),t=d(e),b(p.$$.fragment,e),F=d(e),N=m(e,"P",{"data-svelte-h":!0}),D(N)!=="svelte-12aq0rb"&&(N.innerHTML=de),z=d(e),k=m(e,"P",{"data-svelte-h":!0}),D(k)!=="svelte-1exfvvi"&&(k.innerHTML=le),A=d(e),C=m(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),D(C)!=="svelte-1tdc15y"&&(C.innerHTML=ce),P=d(e),b(Z.$$.fragment,e),Q=d(e),u=m(e,"DIV",{class:!0});var g=S(u);b(G.$$.fragment,g),ee=d(g),E=m(g,"P",{"data-svelte-h":!0}),D(E)!=="svelte-153rhof"&&(E.innerHTML=pe),te=d(g),v=m(g,"DIV",{class:!0});var T=S(v);b(j.$$.fragment,T),oe=d(T),H=m(T,"P",{"data-svelte-h":!0}),D(H)!=="svelte-1j94dhx"&&(H.innerHTML=fe),ne=d(T),b(L.$$.fragment,T),T.forEach(n),ae=d(g),U=m(g,"DIV",{class:!0});var V=S(U);b(I.$$.fragment,V),se=d(V),q=m(V,"P",{"data-svelte-h":!0}),D(q)!=="svelte-17c800g"&&(q.innerHTML=me),ie=d(V),b(J.$$.fragment,V),V.forEach(n),g.forEach(n),Y=d(e),b(R.$$.fragment,e),K=d(e),B=m(e,"P",{}),S(B).forEach(n),this.h()},h(){X(a,"name","hf:doc:metadata"),X(a,"content",Le),X(C,"class","tip"),X(v,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),X(U,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),X(u,"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,o){h(document.head,a),i(e,M,o),i(e,c,o),i(e,s,o),y(l,e,o),i(e,t,o),y(p,e,o),i(e,F,o),i(e,N,o),i(e,z,o),i(e,k,o),i(e,A,o),i(e,C,o),i(e,P,o),y(Z,e,o),i(e,Q,o),i(e,u,o),y(G,u,null),h(u,ee),h(u,E),h(u,te),h(u,v),y(j,v,null),h(v,oe),h(v,H),h(v,ne),y(L,v,null),h(u,ae),h(u,U),y(I,U,null),h(U,se),h(U,q),h(U,ie),y(J,U,null),i(e,Y,o),y(R,e,o),i(e,K,o),i(e,B,o),O=!0},p(e,[o]){const g={};o&2&&(g.$$scope={dirty:o,ctx:e}),L.$set(g);const T={};o&2&&(T.$$scope={dirty:o,ctx:e}),J.$set(T)},i(e){O||(w(l.$$.fragment,e),w(p.$$.fragment,e),w(Z.$$.fragment,e),w(G.$$.fragment,e),w(j.$$.fragment,e),w(L.$$.fragment,e),w(I.$$.fragment,e),w(J.$$.fragment,e),w(R.$$.fragment,e),O=!0)},o(e){x(l.$$.fragment,e),x(p.$$.fragment,e),x(Z.$$.fragment,e),x(G.$$.fragment,e),x(j.$$.fragment,e),x(L.$$.fragment,e),x(I.$$.fragment,e),x(J.$$.fragment,e),x(R.$$.fragment,e),O=!1},d(e){e&&(n(M),n(c),n(s),n(t),n(F),n(N),n(z),n(k),n(A),n(C),n(P),n(Q),n(u),n(Y),n(K),n(B)),n(a),$(l,e),$(p,e),$(Z,e),$(G),$(j),$(L),$(I),$(J),$(R,e)}}}const Le='{"title":"UNet","local":"unet","sections":[{"title":"UNet2DConditionLoadersMixin","local":"diffusers.loaders.UNet2DConditionLoadersMixin","sections":[],"depth":2}],"depth":1}';function Je(W){return ye(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Re extends we{constructor(a){super(),xe(this,a,Je,Ce,be,{})}}export{Re as component};
