Buckets:
| import"../chunks/DsnmJJEf.js";import{i as N,h as Z,C as j,H as w,D as d,E as G,s as W,a as M}from"../chunks/BtE7mKSK.js";import{p as I,o as R,s as e,f as l,a as s,b as q,c,d as f,r as p,n as E}from"../chunks/jDjavuwI.js";import{E as x}from"../chunks/SrSJA0zO.js";const A='{"title":"UNet","local":"unet","sections":[{"title":"UNet2DConditionLoadersMixin","local":"diffusers.loaders.UNet2DConditionLoadersMixin","sections":[],"depth":2}],"depth":1}';var H=f('<meta name="hf:doc:metadata"/>'),J=f("<p>Example:</p> <!>",1),k=f(`<p></p> <!> <!> <p>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_14261/en/api/loaders/lora#diffusers.loaders.StableDiffusionLoraLoaderMixin.load_lora_weights">load_lora_weights()</a> function instead.</p> <p>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.</p> <blockquote class="tip"><p>To learn more about how to load LoRA weights, see the <a href="../../tutorials/using_peft_for_inference">LoRA</a> guide.</p></blockquote> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Load LoRA layers into a <code>UNet2DCondtionModel</code>.</p> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Load pretrained Custom Diffusion attention processor layers into <a href="/docs/diffusers/pr_14261/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. To load LoRA layers, use <a href="/docs/diffusers/pr_14261/en/api/loaders/peft#diffusers.loaders.PeftAdapterMixin.load_lora_adapter">load_lora_adapter()</a> instead.</p> <!></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Save Custom Diffusion attention processor layers to a directory so that it can be reloaded with the <a href="/docs/diffusers/pr_14261/en/api/loaders/unet#diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs">load_attn_procs()</a> method. To save LoRA layers, use <a href="/docs/diffusers/pr_14261/en/api/loaders/peft#diffusers.loaders.PeftAdapterMixin.save_lora_adapter">save_lora_adapter()</a> instead.</p> <!></div></div> <!> <p></p>`,1);function S(U,T){I(T,!1),R(()=>{new URLSearchParams(window.location.search).get("fw")}),N();var u=k();Z("buy5q7",o=>{var t=H();W(t,"content",A),s(o,t)});var h=e(l(u),2);j(h,{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"});var m=e(h,2);w(m,{title:"UNet",local:"unet",headingTag:"h1"});var _=e(m,8);w(_,{title:"UNet2DConditionLoadersMixin",local:"diffusers.loaders.UNet2DConditionLoadersMixin",headingTag:"h2"});var n=e(_,2),g=c(n);d(g,{name:"class diffusers.loaders.UNet2DConditionLoadersMixin",anchor:"diffusers.loaders.UNet2DConditionLoadersMixin",source:"https://github.com/huggingface/diffusers/blob/vr_14261/src/diffusers/loaders/unet.py#L54",parameters:[]});var i=e(g,4),b=c(i);d(b,{name:"load_attn_procs",anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs",source:"https://github.com/huggingface/diffusers/blob/vr_14261/src/diffusers/loaders/unet.py#L62",parameters:[{name:"pretrained_model_name_or_path_or_dict",val:": str | 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_14261/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>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.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"}]});var C=e(b,4);x(C,{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs.example",children:(o,t)=>{var a=J(),r=e(l(a),2);M(r,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRGlmZnVzaW9uUGlwZWxpbmUlMEElMEFwaXBlbGluZSUyMCUzRCUyMERpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJDb21wVmlzJTJGc3RhYmxlLWRpZmZ1c2lvbi12MS00JTIyJTJDJTBBJTIwJTIwJTIwJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTJDJTBBKS50byglMjJjdWRhJTIyKSUwQXBpcGVsaW5lLnVuZXQubG9hZF9hdHRuX3Byb2NzKCUyMnBhdGgtdG8tc2F2ZS1tb2RlbCUyMiUyQyUyMHdlaWdodF9uYW1lJTNEJTIycHl0b3JjaF9jdXN0b21fZGlmZnVzaW9uX3dlaWdodHMuYmluJTIyKQ==",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>)`,lang:"py",wrap:!1}),s(o,a)},$$slots:{default:!0}}),p(i);var y=e(i,2),v=c(y);d(v,{name:"save_attn_procs",anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.save_attn_procs",source:"https://github.com/huggingface/diffusers/blob/vr_14261/src/diffusers/loaders/unet.py#L253",parameters:[{name:"save_directory",val:": 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"}]});var L=e(v,4);x(L,{anchor:"diffusers.loaders.UNet2DConditionLoadersMixin.save_attn_procs.example",children:(o,t)=>{var a=J(),r=e(l(a),2);M(r,{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>)`,lang:"py",wrap:!1}),s(o,a)},$$slots:{default:!0}}),p(y),p(n);var D=e(n,2);G(D,{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/loaders/unet.md"}),E(2),s(U,u),q()}export{S as component}; | |
Xet Storage Details
- Size:
- 12.8 kB
- Xet hash:
- 6099ff8ba098d032324ebcc31933a42d61f3e08b1b14553eaf7076d3123a97fd
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.