Buckets:
| 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 q,u as y,x as Z,k as B,y as _,a as i,v as w,d as $,t as x,w as v}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 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,a){i(r,o,a)},p:re,d(r){r&&s(o)}}}function ve(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">"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(){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){x(a.$$.fragment,t),c=!1},d(t){t&&(s(o),s(r)),v(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">"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(){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){x(a.$$.fragment,t),c=!1},d(t){t&&(s(o),s(r)),v(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_10312/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.",z,J,A,G,F,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/pr_10312/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,V,pe=`Save attention processor layers to a directory so that it can be reloaded with the | |
| <a href="/docs/diffusers/pr_10312/en/api/loaders/unet#diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs">load_attn_procs()</a> method.`,se,N,P,W,Q,X,Y;return c=new me({props:{title:"UNet",local:"unet",headingTag:"h1"}}),J=new we({props:{$$slots:{default:[xe]},$$scope:{ctx:L}}}),G=new me({props:{title:"UNet2DConditionLoadersMixin",local:"diffusers.loaders.UNet2DConditionLoadersMixin",headingTag:"h2"}}),j=new ae({props:{name:"class diffusers.loaders.UNet2DConditionLoadersMixin",anchor:"diffusers.loaders.UNet2DConditionLoadersMixin",parameters:[],source:"https://github.com/huggingface/diffusers/blob/vr_10312/src/diffusers/loaders/unet.py#L61"}}),I=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>) — | |
| 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_10312/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_10312/src/diffusers/loaders/unet.py#L69"}}),D=new fe({props:{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs.example",$$slots:{default:[ve]},$$scope:{ctx:L}}}),R=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>) — | |
| 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_10312/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,z=d(),b(J.$$.fragment),A=d(),b(G.$$.fragment),F=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(),V=f("p"),V.innerHTML=pe,se=d(),b(N.$$.fragment),P=d(),b(W.$$.fragment),Q=d(),X=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",{}),q(r).forEach(s),a=l(e),y(c.$$.fragment,e),t=l(e),p=m(e,"P",{"data-svelte-h":!0}),Z(p)!=="svelte-ewzdjm"&&(p.innerHTML=ie),S=l(e),k=m(e,"P",{"data-svelte-h":!0}),Z(k)!=="svelte-1exfvvi"&&(k.innerHTML=de),z=l(e),y(J.$$.fragment,e),A=l(e),y(G.$$.fragment,e),F=l(e),h=m(e,"DIV",{class:!0});var g=q(h);y(j.$$.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=q(M);y(I.$$.fragment,T),ee=l(T),E=m(T,"P",{"data-svelte-h":!0}),Z(E)!=="svelte-tzsl2o"&&(E.innerHTML=ce),te=l(T),y(D.$$.fragment,T),T.forEach(s),oe=l(g),U=m(g,"DIV",{class:!0});var C=q(U);y(R.$$.fragment,C),ne=l(C),V=m(C,"P",{"data-svelte-h":!0}),Z(V)!=="svelte-1axr3yz"&&(V.innerHTML=pe),se=l(C),y(N.$$.fragment,C),C.forEach(s),g.forEach(s),P=l(e),y(W.$$.fragment,e),Q=l(e),X=m(e,"P",{}),q(X).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,z,n),w(J,e,n),i(e,A,n),w(G,e,n),i(e,F,n),i(e,h,n),w(j,h,null),_(h,K),_(h,H),_(h,O),_(h,M),w(I,M,null),_(M,ee),_(M,E),_(M,te),w(D,M,null),_(h,oe),_(h,U),w(R,U,null),_(U,ne),_(U,V),_(U,se),w(N,U,null),i(e,P,n),w(W,e,n),i(e,Q,n),i(e,X,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),$(j.$$.fragment,e),$(I.$$.fragment,e),$(D.$$.fragment,e),$(R.$$.fragment,e),$(N.$$.fragment,e),$(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&&(s(u),s(r),s(a),s(t),s(p),s(S),s(k),s(z),s(A),s(F),s(h),s(P),s(Q),s(X)),s(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 _e(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class je extends ge{constructor(o){super(),be(this,o,Ce,Ue,he,{})}}export{je as component}; | |
Xet Storage Details
- Size:
- 17.5 kB
- Xet hash:
- 3df1696042d9110c3488f18e092e0476201077e288303294b270f05ac9197a2d
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.