Buckets:
| import"../chunks/DsnmJJEf.js";import{i as O,h as ee,C as ae,H as F,D as a,E as te,s as oe,a as c}from"../chunks/BtE7mKSK.js";import{p as re,o as se,s as e,f as p,a as l,b as de,c as t,d as U,n as d,r as o}from"../chunks/jDjavuwI.js";import{E as f}from"../chunks/SrSJA0zO.js";const ne='{"title":"PEFT","local":"peft","sections":[{"title":"PeftAdapterMixin","local":"diffusers.loaders.PeftAdapterMixin","sections":[],"depth":2}],"depth":1}';var ie=U('<meta name="hf:doc:metadata"/>'),h=U("<p>Example:</p> <!>",1),le=U(`<p></p> <!> <!> <p>Diffusers supports loading adapters such as <a href="../../tutorials/using_peft_for_inference">LoRA</a> with the <a href="https://huggingface.co/docs/peft/index" rel="nofollow">PEFT</a> library with the <a href="/docs/diffusers/pr_13966/en/api/loaders/peft#diffusers.loaders.PeftAdapterMixin">PeftAdapterMixin</a> class. This allows modeling classes in Diffusers like <a href="/docs/diffusers/pr_13966/en/api/models/unet2d-cond#diffusers.UNet2DConditionModel">UNet2DConditionModel</a>, <a href="/docs/diffusers/pr_13966/en/api/models/sd3_transformer2d#diffusers.SD3Transformer2DModel">SD3Transformer2DModel</a> to operate with an adapter.</p> <blockquote class="tip"><p>Refer to the <a href="../../tutorials/using_peft_for_inference">Inference with PEFT</a> tutorial for an overview of how to use PEFT in Diffusers for inference.</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>A class containing all functions for loading and using adapters weights that are supported in PEFT library. For | |
| more details about adapters and injecting them in a base model, check out the PEFT <a href="https://huggingface.co/docs/peft/index" rel="nofollow">documentation</a>.</p> <p>Install the latest version of PEFT, and use this mixin to:</p> <ul><li>Attach new adapters in the model.</li> <li>Attach multiple adapters and iteratively activate/deactivate them.</li> <li>Activate/deactivate all adapters from the model.</li> <li>Get a list of the active adapters.</li></ul> <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>Gets the current list of active adapters of the model.</p> <p>If you are not familiar with adapters and PEFT methods, we invite you to read more about them on the PEFT <a href="https://huggingface.co/docs/peft" rel="nofollow">documentation</a>.</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>Adds a new adapter to the current model for training. If no adapter name is passed, a default name is assigned | |
| to the adapter to follow the convention of the PEFT library.</p> <p>If you are not familiar with adapters and PEFT methods, we invite you to read more about them in the PEFT <a href="https://huggingface.co/docs/peft" rel="nofollow">documentation</a>.</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>Delete an adapter’s LoRA layers from the underlying model.</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>Disable all adapters attached to the model and fallback to inference with the base model only.</p> <p>If you are not familiar with adapters and PEFT methods, we invite you to read more about them on the PEFT <a href="https://huggingface.co/docs/peft" rel="nofollow">documentation</a>.</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>Disables the active LoRA layers of the underlying model.</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>Enable adapters that are attached to the model. The model uses <code>self.active_adapters()</code> to retrieve the list of | |
| adapters to enable.</p> <p>If you are not familiar with adapters and PEFT methods, we invite you to read more about them on the PEFT <a href="https://huggingface.co/docs/peft" rel="nofollow">documentation</a>.</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>Enables the active LoRA layers of the underlying model.</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>Enables the possibility to hotswap LoRA adapters.</p> <p>Calling this method is only required when hotswapping adapters and if the model is compiled or if the ranks of | |
| the loaded adapters differ.</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>Loads a LoRA adapter into the underlying model.</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 the LoRA parameters corresponding to the underlying model.</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>Sets a specific adapter by forcing the model to only use that adapter and disables the other adapters.</p> <p>If you are not familiar with adapters and PEFT methods, we invite you to read more about them on the PEFT <a href="https://huggingface.co/docs/peft" rel="nofollow">documentation</a>.</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>Set the currently active adapters for use in the diffusion network (e.g. unet, transformer, etc.).</p> <!></div></div> <!> <p></p>`,1);function me(V,q){re(q,!1),se(()=>{new URLSearchParams(window.location.search).get("fw")}),O();var Z=le();ee("15jpsxu",s=>{var i=ie();oe(i,"content",ne),l(s,i)});var G=e(p(Z),2);ae(G,{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"});var P=e(G,2);F(P,{title:"PEFT",local:"peft",headingTag:"h1"});var W=e(P,6);F(W,{title:"PeftAdapterMixin",local:"diffusers.loaders.PeftAdapterMixin",headingTag:"h2"});var m=e(W,2),j=t(m);a(j,{name:"class diffusers.loaders.PeftAdapterMixin",anchor:"diffusers.loaders.PeftAdapterMixin",source:"https://github.com/huggingface/diffusers/blob/vr_13966/src/diffusers/loaders/peft.py#L57",parameters:[]});var u=e(j,8),B=t(u);a(B,{name:"active_adapters",anchor:"diffusers.loaders.PeftAdapterMixin.active_adapters",source:"https://github.com/huggingface/diffusers/blob/vr_13966/src/diffusers/loaders/peft.py#L640",parameters:[]}),d(4),o(u);var g=e(u,2),C=t(g);a(C,{name:"add_adapter",anchor:"diffusers.loaders.PeftAdapterMixin.add_adapter",source:"https://github.com/huggingface/diffusers/blob/vr_13966/src/diffusers/loaders/peft.py#L508",parameters:[{name:"adapter_config",val:""},{name:"adapter_name",val:": str = 'default'"}],parametersDescription:[{anchor:"diffusers.loaders.PeftAdapterMixin.add_adapter.adapter_config",description:`<strong>adapter_config</strong> (<code>[~peft.PeftConfig]</code>) — | |
| The configuration of the adapter to add; supported adapters are non-prefix tuning and adaption prompt | |
| methods.`,name:"adapter_config"},{anchor:"diffusers.loaders.PeftAdapterMixin.add_adapter.adapter_name",description:`<strong>adapter_name</strong> (<code>str</code>, <em>optional</em>, defaults to <code>"default"</code>) — | |
| The name of the adapter to add. If no name is passed, a default name is assigned to the adapter.`,name:"adapter_name"}]}),d(4),o(g);var _=e(g,2),k=t(_);a(k,{name:"delete_adapters",anchor:"diffusers.loaders.PeftAdapterMixin.delete_adapters",source:"https://github.com/huggingface/diffusers/blob/vr_13966/src/diffusers/loaders/peft.py#L763",parameters:[{name:"adapter_names",val:": list[str] | str"}],parametersDescription:[{anchor:"diffusers.loaders.PeftAdapterMixin.delete_adapters.adapter_names",description:`<strong>adapter_names</strong> (<code>list[str, str]</code>) — | |
| The names (single string or list of strings) of the adapter to delete.`,name:"adapter_names"}]});var Y=e(k,4);f(Y,{anchor:"diffusers.loaders.PeftAdapterMixin.delete_adapters.example",children:(s,i)=>{var r=h(),n=e(p(r),2);c(n,{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMEF1dG9QaXBlbGluZUZvclRleHQySW1hZ2UlMEFpbXBvcnQlMjB0b3JjaCUwQSUwQXBpcGVsaW5lJTIwJTNEJTIwQXV0b1BpcGVsaW5lRm9yVGV4dDJJbWFnZS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIyc3RhYmlsaXR5YWklMkZzdGFibGUtZGlmZnVzaW9uLXhsLWJhc2UtMS4wJTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTBBKS50byglMjJjdWRhJTIyKSUwQXBpcGVsaW5lLmxvYWRfbG9yYV93ZWlnaHRzKCUwQSUyMCUyMCUyMCUyMCUyMmpiaWxja2UtaGYlMkZzZHhsLWNpbmVtYXRpYy0xJTIyJTJDJTIwd2VpZ2h0X25hbWUlM0QlMjJweXRvcmNoX2xvcmFfd2VpZ2h0cy5zYWZldGVuc29ycyUyMiUyQyUyMGFkYXB0ZXJfbmFtZXMlM0QlMjJjaW5lbWF0aWMlMjIlMEEpJTBBcGlwZWxpbmUudW5ldC5kZWxldGVfYWRhcHRlcnMoJTIyY2luZW1hdGljJTIyKQ==",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.load_lora_weights( | |
| <span class="hljs-string">"jbilcke-hf/sdxl-cinematic-1"</span>, weight_name=<span class="hljs-string">"pytorch_lora_weights.safetensors"</span>, adapter_names=<span class="hljs-string">"cinematic"</span> | |
| ) | |
| pipeline.unet.delete_adapters(<span class="hljs-string">"cinematic"</span>)`,lang:"py",wrap:!1}),l(s,r)},$$slots:{default:!0}}),o(_);var y=e(_,2),Q=t(y);a(Q,{name:"disable_adapters",anchor:"diffusers.loaders.PeftAdapterMixin.disable_adapters",source:"https://github.com/huggingface/diffusers/blob/vr_13966/src/diffusers/loaders/peft.py#L595",parameters:[]}),d(4),o(y);var b=e(y,2),R=t(b);a(R,{name:"disable_lora",anchor:"diffusers.loaders.PeftAdapterMixin.disable_lora",source:"https://github.com/huggingface/diffusers/blob/vr_13966/src/diffusers/loaders/peft.py#L717",parameters:[]});var S=e(R,4);f(S,{anchor:"diffusers.loaders.PeftAdapterMixin.disable_lora.example",children:(s,i)=>{var r=h(),n=e(p(r),2);c(n,{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMEF1dG9QaXBlbGluZUZvclRleHQySW1hZ2UlMEFpbXBvcnQlMjB0b3JjaCUwQSUwQXBpcGVsaW5lJTIwJTNEJTIwQXV0b1BpcGVsaW5lRm9yVGV4dDJJbWFnZS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIyc3RhYmlsaXR5YWklMkZzdGFibGUtZGlmZnVzaW9uLXhsLWJhc2UtMS4wJTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTBBKS50byglMjJjdWRhJTIyKSUwQXBpcGVsaW5lLmxvYWRfbG9yYV93ZWlnaHRzKCUwQSUyMCUyMCUyMCUyMCUyMmpiaWxja2UtaGYlMkZzZHhsLWNpbmVtYXRpYy0xJTIyJTJDJTIwd2VpZ2h0X25hbWUlM0QlMjJweXRvcmNoX2xvcmFfd2VpZ2h0cy5zYWZldGVuc29ycyUyMiUyQyUyMGFkYXB0ZXJfbmFtZSUzRCUyMmNpbmVtYXRpYyUyMiUwQSklMEFwaXBlbGluZS51bmV0LmRpc2FibGVfbG9yYSgp",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.load_lora_weights( | |
| <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> | |
| ) | |
| pipeline.unet.disable_lora()`,lang:"py",wrap:!1}),l(s,r)},$$slots:{default:!0}}),o(b);var w=e(b,2),L=t(w);a(L,{name:"enable_adapters",anchor:"diffusers.loaders.PeftAdapterMixin.enable_adapters",source:"https://github.com/huggingface/diffusers/blob/vr_13966/src/diffusers/loaders/peft.py#L617",parameters:[]}),d(4),o(w);var v=e(w,2),A=t(v);a(A,{name:"enable_lora",anchor:"diffusers.loaders.PeftAdapterMixin.enable_lora",source:"https://github.com/huggingface/diffusers/blob/vr_13966/src/diffusers/loaders/peft.py#L740",parameters:[]});var E=e(A,4);f(E,{anchor:"diffusers.loaders.PeftAdapterMixin.enable_lora.example",children:(s,i)=>{var r=h(),n=e(p(r),2);c(n,{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMEF1dG9QaXBlbGluZUZvclRleHQySW1hZ2UlMEFpbXBvcnQlMjB0b3JjaCUwQSUwQXBpcGVsaW5lJTIwJTNEJTIwQXV0b1BpcGVsaW5lRm9yVGV4dDJJbWFnZS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIyc3RhYmlsaXR5YWklMkZzdGFibGUtZGlmZnVzaW9uLXhsLWJhc2UtMS4wJTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTBBKS50byglMjJjdWRhJTIyKSUwQXBpcGVsaW5lLmxvYWRfbG9yYV93ZWlnaHRzKCUwQSUyMCUyMCUyMCUyMCUyMmpiaWxja2UtaGYlMkZzZHhsLWNpbmVtYXRpYy0xJTIyJTJDJTIwd2VpZ2h0X25hbWUlM0QlMjJweXRvcmNoX2xvcmFfd2VpZ2h0cy5zYWZldGVuc29ycyUyMiUyQyUyMGFkYXB0ZXJfbmFtZSUzRCUyMmNpbmVtYXRpYyUyMiUwQSklMEFwaXBlbGluZS51bmV0LmVuYWJsZV9sb3JhKCk=",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.load_lora_weights( | |
| <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> | |
| ) | |
| pipeline.unet.enable_lora()`,lang:"py",wrap:!1}),l(s,r)},$$slots:{default:!0}}),o(v);var x=e(v,2),D=t(x);a(D,{name:"enable_lora_hotswap",anchor:"diffusers.loaders.PeftAdapterMixin.enable_lora_hotswap",source:"https://github.com/huggingface/diffusers/blob/vr_13966/src/diffusers/loaders/peft.py#L801",parameters:[{name:"target_rank",val:": int = 128"},{name:"check_compiled",val:": typing.Literal['error', 'warn', 'ignore'] = 'error'"}],parametersDescription:[{anchor:"diffusers.loaders.PeftAdapterMixin.enable_lora_hotswap.target_rank",description:`<strong>target_rank</strong> (<code>int</code>, <em>optional</em>, defaults to <code>128</code>) — | |
| The highest rank among all the adapters that will be loaded.`,name:"target_rank"},{anchor:"diffusers.loaders.PeftAdapterMixin.enable_lora_hotswap.check_compiled",description:`<strong>check_compiled</strong> (<code>str</code>, <em>optional</em>, defaults to <code>"error"</code>) — | |
| How to handle the case when the model is already compiled, which should generally be avoided. The | |
| options are:</p> | |
| <ul> | |
| <li>“error” (default): raise an error</li> | |
| <li>“warn”: issue a warning</li> | |
| <li>“ignore”: do nothing</li> | |
| </ul>`,name:"check_compiled"}]}),d(4),o(x);var M=e(x,2),z=t(M);a(z,{name:"load_lora_adapter",anchor:"diffusers.loaders.PeftAdapterMixin.load_lora_adapter",source:"https://github.com/huggingface/diffusers/blob/vr_13966/src/diffusers/loaders/peft.py#L80",parameters:[{name:"pretrained_model_name_or_path_or_dict",val:""},{name:"prefix",val:" = 'transformer'"},{name:"hotswap",val:": bool = False"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"diffusers.loaders.PeftAdapterMixin.load_lora_adapter.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 <em>model id</em> (for example <code>google/ddpm-celebahq-256</code>) of a pretrained model hosted on | |
| the Hub.</li> | |
| <li>A path to a <em>directory</em> (for example <code>./my_model_directory</code>) containing the model weights saved | |
| with <a href="/docs/diffusers/pr_13966/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.PeftAdapterMixin.load_lora_adapter.prefix",description:"<strong>prefix</strong> (<code>str</code>, <em>optional</em>) — Prefix to filter the state dict.",name:"prefix"},{anchor:"diffusers.loaders.PeftAdapterMixin.load_lora_adapter.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.PeftAdapterMixin.load_lora_adapter.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.PeftAdapterMixin.load_lora_adapter.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.PeftAdapterMixin.load_lora_adapter.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.PeftAdapterMixin.load_lora_adapter.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.PeftAdapterMixin.load_lora_adapter.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.PeftAdapterMixin.load_lora_adapter.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.PeftAdapterMixin.load_lora_adapter.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.PeftAdapterMixin.load_lora_adapter.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"},{anchor:"diffusers.loaders.PeftAdapterMixin.load_lora_adapter.hotswap",description:`<strong>hotswap</strong> — (<code>bool</code>, <em>optional</em>) | |
| Defaults to <code>False</code>. Whether to substitute an existing (LoRA) adapter with the newly loaded adapter | |
| in-place. This means that, instead of loading an additional adapter, this will take the existing | |
| adapter weights and replace them with the weights of the new adapter. This can be faster and more | |
| memory efficient. However, the main advantage of hotswapping is that when the model is compiled with | |
| torch.compile, loading the new adapter does not require recompilation of the model. When using | |
| hotswapping, the passed <code>adapter_name</code> should be the name of an already loaded adapter.</p> | |
| <p>If the new adapter and the old adapter have different ranks and/or LoRA alphas (i.e. scaling), you need | |
| to call an additional method before loading the adapter:`,name:"hotswap"}]}),d(2),o(M);var T=e(M,2),N=t(T);a(N,{name:"save_lora_adapter",anchor:"diffusers.loaders.PeftAdapterMixin.save_lora_adapter",source:"https://github.com/huggingface/diffusers/blob/vr_13966/src/diffusers/loaders/peft.py#L384",parameters:[{name:"save_directory",val:""},{name:"adapter_name",val:": str = 'default'"},{name:"upcast_before_saving",val:": bool = False"},{name:"safe_serialization",val:": bool = True"},{name:"weight_name",val:": str | None = None"}],parametersDescription:[{anchor:"diffusers.loaders.PeftAdapterMixin.save_lora_adapter.save_directory",description:`<strong>save_directory</strong> (<code>str</code> or <code>os.PathLike</code>) — | |
| Directory to save LoRA parameters to. Will be created if it doesn’t exist.`,name:"save_directory"},{anchor:"diffusers.loaders.PeftAdapterMixin.save_lora_adapter.adapter_name",description:`<strong>adapter_name</strong> — (<code>str</code>, defaults to “default”): The name of the adapter to serialize. Useful when the | |
| underlying model has multiple adapters loaded.`,name:"adapter_name"},{anchor:"diffusers.loaders.PeftAdapterMixin.save_lora_adapter.upcast_before_saving",description:`<strong>upcast_before_saving</strong> (<code>bool</code>, defaults to <code>False</code>) — | |
| Whether to cast the underlying model to <code>torch.float32</code> before serialization.`,name:"upcast_before_saving"},{anchor:"diffusers.loaders.PeftAdapterMixin.save_lora_adapter.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 the traditional PyTorch way with <code>pickle</code>.`,name:"safe_serialization"},{anchor:"diffusers.loaders.PeftAdapterMixin.save_lora_adapter.weight_name",description:"<strong>weight_name</strong> — (<code>str</code>, <em>optional</em>, defaults to <code>None</code>): Name of the file to serialize the state dict with.",name:"weight_name"}]}),d(2),o(T);var J=e(T,2),H=t(J);a(H,{name:"set_adapter",anchor:"diffusers.loaders.PeftAdapterMixin.set_adapter",source:"https://github.com/huggingface/diffusers/blob/vr_13966/src/diffusers/loaders/peft.py#L546",parameters:[{name:"adapter_name",val:": str | list[str]"}],parametersDescription:[{anchor:"diffusers.loaders.PeftAdapterMixin.set_adapter.adapter_name",description:`<strong>adapter_name</strong> (str | list[str])) — | |
| The list of adapters to set or the adapter name in the case of a single adapter.`,name:"adapter_name"}]}),d(4),o(J);var X=e(J,2),I=t(X);a(I,{name:"set_adapters",anchor:"diffusers.loaders.PeftAdapterMixin.set_adapters",source:"https://github.com/huggingface/diffusers/blob/vr_13966/src/diffusers/loaders/peft.py#L452",parameters:[{name:"adapter_names",val:": list[str] | str"},{name:"weights",val:": float | dict | list[float] | list[dict] | list[None] | None = None"}],parametersDescription:[{anchor:"diffusers.loaders.PeftAdapterMixin.set_adapters.adapter_names",description:`<strong>adapter_names</strong> (<code>list[str]</code> or <code>str</code>) — | |
| The names of the adapters to use.`,name:"adapter_names"},{anchor:"diffusers.loaders.PeftAdapterMixin.set_adapters.weights",description:`<strong>weights</strong> (<code>Union[List[float], float]</code>, <em>optional</em>) — | |
| The adapter(s) weights to use with the UNet. If <code>None</code>, the weights are set to <code>1.0</code> for all the | |
| adapters.`,name:"weights"}]});var K=e(I,4);f(K,{anchor:"diffusers.loaders.PeftAdapterMixin.set_adapters.example",children:(s,i)=>{var r=h(),n=e(p(r),2);c(n,{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMEF1dG9QaXBlbGluZUZvclRleHQySW1hZ2UlMEFpbXBvcnQlMjB0b3JjaCUwQSUwQXBpcGVsaW5lJTIwJTNEJTIwQXV0b1BpcGVsaW5lRm9yVGV4dDJJbWFnZS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIyc3RhYmlsaXR5YWklMkZzdGFibGUtZGlmZnVzaW9uLXhsLWJhc2UtMS4wJTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTBBKS50byglMjJjdWRhJTIyKSUwQXBpcGVsaW5lLmxvYWRfbG9yYV93ZWlnaHRzKCUwQSUyMCUyMCUyMCUyMCUyMmpiaWxja2UtaGYlMkZzZHhsLWNpbmVtYXRpYy0xJTIyJTJDJTIwd2VpZ2h0X25hbWUlM0QlMjJweXRvcmNoX2xvcmFfd2VpZ2h0cy5zYWZldGVuc29ycyUyMiUyQyUyMGFkYXB0ZXJfbmFtZSUzRCUyMmNpbmVtYXRpYyUyMiUwQSklMEFwaXBlbGluZS5sb2FkX2xvcmFfd2VpZ2h0cyglMjJuZXJpanMlMkZwaXhlbC1hcnQteGwlMjIlMkMlMjB3ZWlnaHRfbmFtZSUzRCUyMnBpeGVsLWFydC14bC5zYWZldGVuc29ycyUyMiUyQyUyMGFkYXB0ZXJfbmFtZSUzRCUyMnBpeGVsJTIyKSUwQXBpcGVsaW5lLnVuZXQuc2V0X2FkYXB0ZXJzKCU1QiUyMmNpbmVtYXRpYyUyMiUyQyUyMCUyMnBpeGVsJTIyJTVEJTJDJTIwd2VpZ2h0cyUzRCU1QjAuNSUyQyUyMDAuNSU1RCk=",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.load_lora_weights( | |
| <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> | |
| ) | |
| pipeline.load_lora_weights(<span class="hljs-string">"nerijs/pixel-art-xl"</span>, weight_name=<span class="hljs-string">"pixel-art-xl.safetensors"</span>, adapter_name=<span class="hljs-string">"pixel"</span>) | |
| pipeline.unet.set_adapters([<span class="hljs-string">"cinematic"</span>, <span class="hljs-string">"pixel"</span>], weights=[<span class="hljs-number">0.5</span>, <span class="hljs-number">0.5</span>])`,lang:"py",wrap:!1}),l(s,r)},$$slots:{default:!0}}),o(X),o(m);var $=e(m,2);te($,{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/loaders/peft.md"}),d(2),l(V,Z),de()}export{me as component}; | |
Xet Storage Details
- Size:
- 26.3 kB
- Xet hash:
- 21f32bb8f1111d40c82c42a6d009f926e9a7dd11403b87b814f9be21a4f6f5b9
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.