Buckets:
| import{s as be,o as ye,n as _e}from"../chunks/scheduler.53228c21.js";import{S as we,i as $e,e as f,s as i,c as g,h as xe,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 r,n as y,t as w,o as $,p as x}from"../chunks/index.100fac89.js";import{C as ve}from"../chunks/CopyLLMTxtMenu.969c168d.js";import{D as ie}from"../chunks/Docstring.8eea0d47.js";import{C as ge}from"../chunks/CodeBlock.d30a6509.js";import{E as ue}from"../chunks/ExampleCodeBlock.5e9b5749.js";import{H as he,E as Me}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.92f39b94.js";function Ue(W){let s,v="Example:",c,a,l;return a=new ge({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">"stabilityai/stable-diffusion-xl-base-1.0"</span>, torch_dtype=torch.float16 | |
| ).to(<span class="hljs-string">"cuda"</span>) | |
| pipeline.unet.load_attn_procs( | |
| <span class="hljs-string">"jbilcke-hf/sdxl-cinematic-1"</span>, weight_name=<span class="hljs-string">"pytorch_lora_weights.safetensors"</span>, adapter_name=<span class="hljs-string">"cinematic"</span> | |
| )`,wrap:!1}}),{c(){s=f("p"),s.textContent=v,c=i(),g(a.$$.fragment)},l(t){s=m(t,"P",{"data-svelte-h":!0}),D(s)!=="svelte-11lpom8"&&(s.textContent=v),c=d(t),b(a.$$.fragment,t)},m(t,p){r(t,s,p),r(t,c,p),y(a,t,p),l=!0},p:_e,i(t){l||(w(a.$$.fragment,t),l=!0)},o(t){$(a.$$.fragment,t),l=!1},d(t){t&&(n(s),n(c)),x(a,t)}}}function Te(W){let s,v="Example:",c,a,l;return a=new ge({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">"CompVis/stable-diffusion-v1-4"</span>, | |
| torch_dtype=torch.float16, | |
| ).to(<span class="hljs-string">"cuda"</span>) | |
| pipeline.unet.load_attn_procs(<span class="hljs-string">"path-to-save-model"</span>, weight_name=<span class="hljs-string">"pytorch_custom_diffusion_weights.bin"</span>) | |
| pipeline.unet.save_attn_procs(<span class="hljs-string">"path-to-save-model"</span>, weight_name=<span class="hljs-string">"pytorch_custom_diffusion_weights.bin"</span>)`,wrap:!1}}),{c(){s=f("p"),s.textContent=v,c=i(),g(a.$$.fragment)},l(t){s=m(t,"P",{"data-svelte-h":!0}),D(s)!=="svelte-11lpom8"&&(s.textContent=v),c=d(t),b(a.$$.fragment,t)},m(t,p){r(t,s,p),r(t,c,p),y(a,t,p),l=!0},p:_e,i(t){l||(w(a.$$.fragment,t),l=!0)},o(t){$(a.$$.fragment,t),l=!1},d(t){t&&(n(s),n(c)),x(a,t)}}}function Ce(W){let s,v,c,a,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/pr_12762/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="../../tutorials/using_peft_for_inference">LoRA</a> guide.</p>',P,Z,Q,u,G,ee,E,pe="Load LoRA layers into a <code>UNet2DCondtionModel</code>.",te,M,j,oe,H,fe=`Load pretrained attention processor layers into <a href="/docs/diffusers/pr_12762/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,se,U,I,ae,q,me=`Save attention processor layers to a directory so that it can be reloaded with the | |
| <a href="/docs/diffusers/pr_12762/en/api/loaders/unet#diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs">load_attn_procs()</a> method.`,re,J,Y,R,K,B,O;return l=new ve({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 ie({props:{name:"class diffusers.loaders.UNet2DConditionLoadersMixin",anchor:"diffusers.loaders.UNet2DConditionLoadersMixin",parameters:[],source:"https://github.com/huggingface/diffusers/blob/vr_12762/src/diffusers/loaders/unet.py#L60"}}),j=new ie({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>) — | |
| 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_12762/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>) — | |
| 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>) — | |
| 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>) — | |
| A dictionary of proxy servers to use by protocol or endpoint, for example, <code>{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}</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>) — | |
| Whether to only load local model weights and configuration files or not. If set to <code>True</code>, the model | |
| won’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>) — | |
| 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>"main"</code>) — | |
| 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>""</code>) — | |
| 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>) — | |
| 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) — | |
| 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) — | |
| 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>) — | |
| 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_12762/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 ie({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>) — | |
| Directory to save an attention processor to (will be created if it doesn’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>) — | |
| 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>) — | |
| 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>) — | |
| 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_12762/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 Me({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/loaders/unet.md"}}),{c(){s=f("meta"),v=i(),c=f("p"),a=i(),g(l.$$.fragment),t=i(),g(p.$$.fragment),F=i(),N=f("p"),N.innerHTML=de,z=i(),k=f("p"),k.innerHTML=le,A=i(),C=f("blockquote"),C.innerHTML=ce,P=i(),g(Z.$$.fragment),Q=i(),u=f("div"),g(G.$$.fragment),ee=i(),E=f("p"),E.innerHTML=pe,te=i(),M=f("div"),g(j.$$.fragment),oe=i(),H=f("p"),H.innerHTML=fe,ne=i(),g(L.$$.fragment),se=i(),U=f("div"),g(I.$$.fragment),ae=i(),q=f("p"),q.innerHTML=me,re=i(),g(J.$$.fragment),Y=i(),g(R.$$.fragment),K=i(),B=f("p"),this.h()},l(e){const o=xe("svelte-u9bgzb",document.head);s=m(o,"META",{name:!0,content:!0}),o.forEach(n),v=d(e),c=m(e,"P",{}),S(c).forEach(n),a=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-150fahf"&&(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-or7eaj"&&(C.innerHTML=ce),P=d(e),b(Z.$$.fragment,e),Q=d(e),u=m(e,"DIV",{class:!0});var _=S(u);b(G.$$.fragment,_),ee=d(_),E=m(_,"P",{"data-svelte-h":!0}),D(E)!=="svelte-153rhof"&&(E.innerHTML=pe),te=d(_),M=m(_,"DIV",{class:!0});var T=S(M);b(j.$$.fragment,T),oe=d(T),H=m(T,"P",{"data-svelte-h":!0}),D(H)!=="svelte-10ybik5"&&(H.innerHTML=fe),ne=d(T),b(L.$$.fragment,T),T.forEach(n),se=d(_),U=m(_,"DIV",{class:!0});var V=S(U);b(I.$$.fragment,V),ae=d(V),q=m(V,"P",{"data-svelte-h":!0}),D(q)!=="svelte-17tkr8k"&&(q.innerHTML=me),re=d(V),b(J.$$.fragment,V),V.forEach(n),_.forEach(n),Y=d(e),b(R.$$.fragment,e),K=d(e),B=m(e,"P",{}),S(B).forEach(n),this.h()},h(){X(s,"name","hf:doc:metadata"),X(s,"content",Le),X(C,"class","tip"),X(M,"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,s),r(e,v,o),r(e,c,o),r(e,a,o),y(l,e,o),r(e,t,o),y(p,e,o),r(e,F,o),r(e,N,o),r(e,z,o),r(e,k,o),r(e,A,o),r(e,C,o),r(e,P,o),y(Z,e,o),r(e,Q,o),r(e,u,o),y(G,u,null),h(u,ee),h(u,E),h(u,te),h(u,M),y(j,M,null),h(M,oe),h(M,H),h(M,ne),y(L,M,null),h(u,se),h(u,U),y(I,U,null),h(U,ae),h(U,q),h(U,re),y(J,U,null),r(e,Y,o),y(R,e,o),r(e,K,o),r(e,B,o),O=!0},p(e,[o]){const _={};o&2&&(_.$$scope={dirty:o,ctx:e}),L.$set(_);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){$(l.$$.fragment,e),$(p.$$.fragment,e),$(Z.$$.fragment,e),$(G.$$.fragment,e),$(j.$$.fragment,e),$(L.$$.fragment,e),$(I.$$.fragment,e),$(J.$$.fragment,e),$(R.$$.fragment,e),O=!1},d(e){e&&(n(v),n(c),n(a),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(s),x(l,e),x(p,e),x(Z,e),x(G),x(j),x(L),x(I),x(J),x(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(s){super(),$e(this,s,Je,Ce,be,{})}}export{Re as component}; | |
Xet Storage Details
- Size:
- 17.5 kB
- Xet hash:
- e5a0d65d85f6ad5f49c6afc3c2de00a60f5f97e210aca31147b41b4ffb232e36
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.