Buckets:
LoRA
LoRA is a fast and lightweight training method that inserts and trains a significantly smaller number of parameters instead of all the model parameters. This produces a smaller file (~100 MBs) and makes it easier to quickly train a model to learn a new concept. LoRA weights are typically loaded into the denoiser, text encoder or both. The denoiser usually corresponds to a UNet (UNet2DConditionModel, for example) or a Transformer (SD3Transformer2DModel, for example). There are several classes for loading LoRA weights:
StableDiffusionLoraLoaderMixinprovides functions for loading and unloading, fusing and unfusing, enabling and disabling, and more functions for managing LoRA weights. This class can be used with any model.StableDiffusionXLLoraLoaderMixinis a Stable Diffusion (SDXL) version of theStableDiffusionLoraLoaderMixinclass for loading and saving LoRA weights. It can only be used with the SDXL model.SD3LoraLoaderMixinprovides similar functions for Stable Diffusion 3.FluxLoraLoaderMixinprovides similar functions for Flux.CogVideoXLoraLoaderMixinprovides similar functions for CogVideoX.Mochi1LoraLoaderMixinprovides similar functions for Mochi.AuraFlowLoraLoaderMixinprovides similar functions for AuraFlow.LTXVideoLoraLoaderMixinprovides similar functions for LTX-Video.SanaLoraLoaderMixinprovides similar functions for Sana.HunyuanVideoLoraLoaderMixinprovides similar functions for HunyuanVideo.Lumina2LoraLoaderMixinprovides similar functions for Lumina2.WanLoraLoaderMixinprovides similar functions for Wan.SkyReelsV2LoraLoaderMixinprovides similar functions for SkyReels-V2.CogView4LoraLoaderMixinprovides similar functions for CogView4.AmusedLoraLoaderMixinis for the AmusedPipeline.HiDreamImageLoraLoaderMixinprovides similar functions for HiDream ImageQwenImageLoraLoaderMixinprovides similar functions for Qwen ImageLoraBaseMixinprovides a base class with several utility methods to fuse, unfuse, unload, LoRAs and more.
To learn more about how to load LoRA weights, see the LoRA loading guide.
LoraBaseMixin[[diffusers.loaders.lora_base.LoraBaseMixin]]
class diffusers.loaders.lora_base.LoraBaseMixindiffusers.loaders.lora_base.LoraBaseMixin
delete_adaptersdiffusers.loaders.lora_base.LoraBaseMixin.delete_adaptersUnion[List[str], str]) --
The names of the adapters to delete.0
Delete an adapter's LoRA layers from the pipeline.
Example:
from diffusers import AutoPipelineForText2Image
import torch
pipeline = AutoPipelineForText2Image.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16
).to("cuda")
pipeline.load_lora_weights(
"jbilcke-hf/sdxl-cinematic-1", weight_name="pytorch_lora_weights.safetensors", adapter_names="cinematic"
)
pipeline.delete_adapters("cinematic")
disable_loradiffusers.loaders.lora_base.LoraBaseMixin.disable_lora
Disables the active LoRA layers of the pipeline.
Example:
from diffusers import AutoPipelineForText2Image
import torch
pipeline = AutoPipelineForText2Image.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16
).to("cuda")
pipeline.load_lora_weights(
"jbilcke-hf/sdxl-cinematic-1", weight_name="pytorch_lora_weights.safetensors", adapter_name="cinematic"
)
pipeline.disable_lora()
enable_loradiffusers.loaders.lora_base.LoraBaseMixin.enable_lora
Enables the active LoRA layers of the pipeline.
Example:
from diffusers import AutoPipelineForText2Image
import torch
pipeline = AutoPipelineForText2Image.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16
).to("cuda")
pipeline.load_lora_weights(
"jbilcke-hf/sdxl-cinematic-1", weight_name="pytorch_lora_weights.safetensors", adapter_name="cinematic"
)
pipeline.enable_lora()
enable_lora_hotswapdiffusers.loaders.lora_base.LoraBaseMixin.enable_lora_hotswapint) --
The highest rank among all the adapters that will be loaded.
- check_compiled (
str, optional, defaults to"error") -- How to handle a model that is already compiled. The check can return the following messages:- "error" (default): raise an error
- "warn": issue a warning
- "ignore": do nothing0
Hotswap adapters without triggering recompilation of a model or if the ranks of the loaded adapters are different.
fuse_loradiffusers.loaders.lora_base.LoraBaseMixin.fuse_loraList[str]): List of LoRA-injectable components to fuse the LoRAs into.
- lora_scale (
float, defaults to 1.0) -- Controls how much to influence the outputs with the LoRA parameters. - safe_fusing (
bool, defaults toFalse) -- Whether to check fused weights for NaN values before fusing and if values are NaN not fusing them. - adapter_names (
List[str], optional) -- Adapter names to be used for fusing. If nothing is passed, all active adapters will be fused.0
Fuses the LoRA parameters into the original parameters of the corresponding blocks.
> This is an experimental API.
Example:
from diffusers import DiffusionPipeline
import torch
pipeline = DiffusionPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16
).to("cuda")
pipeline.load_lora_weights("nerijs/pixel-art-xl", weight_name="pixel-art-xl.safetensors", adapter_name="pixel")
pipeline.fuse_lora(lora_scale=0.7)
get_active_adaptersdiffusers.loaders.lora_base.LoraBaseMixin.get_active_adapters
Gets the list of the current active adapters.
Example:
from diffusers import DiffusionPipeline
pipeline = DiffusionPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0",
).to("cuda")
pipeline.load_lora_weights("CiroN2022/toy-face", weight_name="toy_face_sdxl.safetensors", adapter_name="toy")
pipeline.get_active_adapters()
get_list_adaptersdiffusers.loaders.lora_base.LoraBaseMixin.get_list_adapters
Gets the current list of all available adapters in the pipeline.
set_adaptersdiffusers.loaders.lora_base.LoraBaseMixin.set_adaptersList[str] or str) --
The names of the adapters to use.
- adapter_weights (
Union[List[float], float], optional) -- The adapter(s) weights to use with the UNet. IfNone, the weights are set to1.0for all the adapters.0
Set the currently active adapters for use in the pipeline.
Example:
from diffusers import AutoPipelineForText2Image
import torch
pipeline = AutoPipelineForText2Image.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16
).to("cuda")
pipeline.load_lora_weights(
"jbilcke-hf/sdxl-cinematic-1", weight_name="pytorch_lora_weights.safetensors", adapter_name="cinematic"
)
pipeline.load_lora_weights("nerijs/pixel-art-xl", weight_name="pixel-art-xl.safetensors", adapter_name="pixel")
pipeline.set_adapters(["cinematic", "pixel"], adapter_weights=[0.5, 0.5])
set_lora_devicediffusers.loaders.lora_base.LoraBaseMixin.set_lora_deviceList[str]) --
List of adapters to send device to.
- device (
Union[torch.device, str, int]) -- Device to send the adapters to. Can be either a torch device, a str or an integer.0
Moves the LoRAs listed in adapter_names to a target device. Useful for offloading the LoRA to the CPU in case
you want to load multiple adapters and free some GPU memory.
After offloading the LoRA adapters to CPU, as long as the rest of the model is still on GPU, the LoRA adapters can no longer be used for inference, as that would cause a device mismatch. Remember to set the device back to GPU before using those LoRA adapters for inference.
>>> pipe.load_lora_weights(path_1, adapter_name="adapter-1")
>>> pipe.load_lora_weights(path_2, adapter_name="adapter-2")
>>> pipe.set_adapters("adapter-1")
>>> image_1 = pipe(**kwargs)
>>> # switch to adapter-2, offload adapter-1
>>> pipeline.set_lora_device(adapter_names=["adapter-1"], device="cpu")
>>> pipeline.set_lora_device(adapter_names=["adapter-2"], device="cuda:0")
>>> pipe.set_adapters("adapter-2")
>>> image_2 = pipe(**kwargs)
>>> # switch back to adapter-1, offload adapter-2
>>> pipeline.set_lora_device(adapter_names=["adapter-2"], device="cpu")
>>> pipeline.set_lora_device(adapter_names=["adapter-1"], device="cuda:0")
>>> pipe.set_adapters("adapter-1")
>>> ...
unfuse_loradiffusers.loaders.lora_base.LoraBaseMixin.unfuse_loraList[str]) -- List of LoRA-injectable components to unfuse LoRA from.
- unfuse_unet (
bool, defaults toTrue) -- Whether to unfuse the UNet LoRA parameters. - unfuse_text_encoder (
bool, defaults toTrue) -- Whether to unfuse the text encoder LoRA parameters. If the text encoder wasn't monkey-patched with the LoRA parameters then it won't have any effect.0
Reverses the effect of
pipe.fuse_lora().
> This is an experimental API.
unload_lora_weightsdiffusers.loaders.lora_base.LoraBaseMixin.unload_lora_weights
Unloads the LoRA parameters.
Examples:
>>> # Assuming `pipeline` is already loaded with the LoRA parameters.
>>> pipeline.unload_lora_weights()
>>> ...
write_lora_layersdiffusers.loaders.lora_base.LoraBaseMixin.write_lora_layers
StableDiffusionLoraLoaderMixin[[diffusers.loaders.StableDiffusionLoraLoaderMixin]]
class diffusers.loaders.StableDiffusionLoraLoaderMixindiffusers.loaders.StableDiffusionLoraLoaderMixin
Load LoRA layers into Stable Diffusion UNet2DConditionModel and
CLIPTextModel.
load_lora_into_text_encoderdiffusers.loaders.StableDiffusionLoraLoaderMixin.load_lora_into_text_encoderdict) --
A standard state dict containing the lora layer parameters. The key should be prefixed with an
additional text_encoder to distinguish between unet lora layers.
- network_alphas (
Dict[str, float]) -- The value of the network alpha used for stable learning and preventing underflow. This value has the same meaning as the--network_alphaoption in the kohya-ss trainer script. Refer to this link. - text_encoder (
CLIPTextModel) -- The text encoder model to load the LoRA layers into. - prefix (
str) -- Expected prefix of thetext_encoderin thestate_dict. - lora_scale (
float) -- How much to scale the output of the lora linear layer before it is added with the output of the regular lora layer. - adapter_name (
str, optional) -- Adapter name to be used for referencing the loaded adapter model. If not specified, it will usedefault_{i}where i is the total number of adapters being loaded. - low_cpu_mem_usage (
bool, optional) -- Speed up model loading by only loading the pretrained LoRA weights and not initializing the random weights. - hotswap (
bool, optional) -- See load_lora_weights(). - metadata (
dict) -- Optional LoRA adapter metadata. When supplied, theLoraConfigarguments ofpeftwon't be derived from the state dict.0
This will load the LoRA layers specified in state_dict into text_encoder
load_lora_into_unetdiffusers.loaders.StableDiffusionLoraLoaderMixin.load_lora_into_unetdict) --
A standard state dict containing the lora layer parameters. The keys can either be indexed directly
into the unet or prefixed with an additional unet which can be used to distinguish between text
encoder lora layers.
- network_alphas (
Dict[str, float]) -- The value of the network alpha used for stable learning and preventing underflow. This value has the same meaning as the--network_alphaoption in the kohya-ss trainer script. Refer to this link. - unet (
UNet2DConditionModel) -- The UNet model to load the LoRA layers into. - adapter_name (
str, optional) -- Adapter name to be used for referencing the loaded adapter model. If not specified, it will usedefault_{i}where i is the total number of adapters being loaded. - low_cpu_mem_usage (
bool, optional) -- Speed up model loading only loading the pretrained LoRA weights and not initializing the random weights. - hotswap (
bool, optional) -- See load_lora_weights(). - metadata (
dict) -- Optional LoRA adapter metadata. When supplied, theLoraConfigarguments ofpeftwon't be derived from the state dict.0
This will load the LoRA layers specified in state_dict into unet.
load_lora_weightsdiffusers.loaders.StableDiffusionLoraLoaderMixin.load_lora_weightsstr or os.PathLike or dict) --
See lora_state_dict().
adapter_name (
str, optional) -- Adapter name to be used for referencing the loaded adapter model. If not specified, it will usedefault_{i}where i is the total number of adapters being loaded.low_cpu_mem_usage (
bool, optional) -- Speed up model loading by only loading the pretrained LoRA weights and not initializing the random weights.hotswap (
bool, optional) -- Defaults toFalse. 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 passedadapter_nameshould be the name of an already loaded adapter.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:
pipeline = ... # load diffusers pipeline
max_rank = ... # the highest rank among all LoRAs that you want to load
# call *before* compiling and loading the LoRA adapter
pipeline.enable_lora_hotswap(target_rank=max_rank)
pipeline.load_lora_weights(file_name)
# optionally compile the model now
Note that hotswapping adapters of the text encoder is not yet supported. There are some further limitations to this technique, which are documented here: https://huggingface.co/docs/peft/main/en/package_reference/hotswap
- kwargs (
dict, optional) -- See lora_state_dict().0 Load LoRA weights specified inpretrained_model_name_or_path_or_dictintoself.unetandself.text_encoder.
All kwargs are forwarded to self.lora_state_dict.
See lora_state_dict() for more details on how the state dict is loaded.
See load_lora_into_unet() for more details on how the state dict is
loaded into self.unet.
See load_lora_into_text_encoder() for more details on how the state
dict is loaded into self.text_encoder.
lora_state_dictdiffusers.loaders.StableDiffusionLoraLoaderMixin.lora_state_dictstr or os.PathLike or dict) --
Can be either:
A string, the model id (for example
google/ddpm-celebahq-256) of a pretrained model hosted on the Hub.A path to a directory (for example
./my_model_directory) containing the model weights saved with ModelMixin.save_pretrained().cache_dir (
Union[str, os.PathLike], optional) -- Path to a directory where a downloaded pretrained model configuration is cached if the standard cache is not used.force_download (
bool, optional, defaults toFalse) -- Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.proxies (
Dict[str, str], optional) -- A dictionary of proxy servers to use by protocol or endpoint, for example,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.local_files_only (
bool, optional, defaults toFalse) -- Whether to only load local model weights and configuration files or not. If set toTrue, the model won't be downloaded from the Hub.token (
stror bool, optional) -- The token to use as HTTP bearer authorization for remote files. IfTrue, the token generated fromdiffusers-cli login(stored in~/.huggingface) is used.revision (
str, optional, defaults to"main") -- The specific model version to use. It can be a branch name, a tag name, a commit id, or any identifier allowed by Git.subfolder (
str, optional, defaults to"") -- The subfolder location of a model file within a larger model repository on the Hub or locally.weight_name (
str, optional, defaults to None) -- Name of the serialized state dict file.return_lora_metadata (
bool, optional, defaults to False) -- When enabled, additionally return the LoRA adapter metadata, typically found in the state dict.0
Return state dict for lora weights and the network alphas.
> We support loading A1111 formatted LoRA checkpoints in a limited capacity. > > This function is experimental and might change in the future.
save_lora_weightsdiffusers.loaders.StableDiffusionLoraLoaderMixin.save_lora_weightsstr or os.PathLike) --
Directory to save LoRA parameters to. Will be created if it doesn't exist.
- unet_lora_layers (
Dict[str, torch.nn.Module]orDict[str, torch.Tensor]) -- State dict of the LoRA layers corresponding to theunet. - text_encoder_lora_layers (
Dict[str, torch.nn.Module]orDict[str, torch.Tensor]) -- State dict of the LoRA layers corresponding to thetext_encoder. Must explicitly pass the text encoder LoRA state dict because it comes from 🤗 Transformers. - is_main_process (
bool, optional, defaults toTrue) -- 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, setis_main_process=Trueonly on the main process to avoid race conditions. - save_function (
Callable) -- The function to use to save the state dictionary. Useful during distributed training when you need to replacetorch.savewith another method. Can be configured with the environment variableDIFFUSERS_SAVE_MODE. - safe_serialization (
bool, optional, defaults toTrue) -- Whether to save the model usingsafetensorsor the traditional PyTorch way withpickle. - unet_lora_adapter_metadata -- LoRA adapter metadata associated with the unet to be serialized with the state dict.
- text_encoder_lora_adapter_metadata -- LoRA adapter metadata associated with the text encoder to be serialized with the state dict.0
Save the LoRA parameters corresponding to the UNet and text encoder.
StableDiffusionXLLoraLoaderMixin[[diffusers.loaders.StableDiffusionXLLoraLoaderMixin]]
class diffusers.loaders.StableDiffusionXLLoraLoaderMixindiffusers.loaders.StableDiffusionXLLoraLoaderMixin
Load LoRA layers into Stable Diffusion XL UNet2DConditionModel,
CLIPTextModel, and
CLIPTextModelWithProjection.
fuse_loradiffusers.loaders.StableDiffusionXLLoraLoaderMixin.fuse_lora
See fuse_lora() for more details.
load_lora_into_text_encoderdiffusers.loaders.StableDiffusionXLLoraLoaderMixin.load_lora_into_text_encoderdict) --
A standard state dict containing the lora layer parameters. The key should be prefixed with an
additional text_encoder to distinguish between unet lora layers.
- network_alphas (
Dict[str, float]) -- The value of the network alpha used for stable learning and preventing underflow. This value has the same meaning as the--network_alphaoption in the kohya-ss trainer script. Refer to this link. - text_encoder (
CLIPTextModel) -- The text encoder model to load the LoRA layers into. - prefix (
str) -- Expected prefix of thetext_encoderin thestate_dict. - lora_scale (
float) -- How much to scale the output of the lora linear layer before it is added with the output of the regular lora layer. - adapter_name (
str, optional) -- Adapter name to be used for referencing the loaded adapter model. If not specified, it will usedefault_{i}where i is the total number of adapters being loaded. - low_cpu_mem_usage (
bool, optional) -- Speed up model loading by only loading the pretrained LoRA weights and not initializing the random weights. - hotswap (
bool, optional) -- See load_lora_weights(). - metadata (
dict) -- Optional LoRA adapter metadata. When supplied, theLoraConfigarguments ofpeftwon't be derived from the state dict.0
This will load the LoRA layers specified in state_dict into text_encoder
load_lora_into_unetdiffusers.loaders.StableDiffusionXLLoraLoaderMixin.load_lora_into_unetdict) --
A standard state dict containing the lora layer parameters. The keys can either be indexed directly
into the unet or prefixed with an additional unet which can be used to distinguish between text
encoder lora layers.
- network_alphas (
Dict[str, float]) -- The value of the network alpha used for stable learning and preventing underflow. This value has the same meaning as the--network_alphaoption in the kohya-ss trainer script. Refer to this link. - unet (
UNet2DConditionModel) -- The UNet model to load the LoRA layers into. - adapter_name (
str, optional) -- Adapter name to be used for referencing the loaded adapter model. If not specified, it will usedefault_{i}where i is the total number of adapters being loaded. - low_cpu_mem_usage (
bool, optional) -- Speed up model loading only loading the pretrained LoRA weights and not initializing the random weights. - hotswap (
bool, optional) -- See load_lora_weights(). - metadata (
dict) -- Optional LoRA adapter metadata. When supplied, theLoraConfigarguments ofpeftwon't be derived from the state dict.0
This will load the LoRA layers specified in state_dict into unet.
load_lora_weightsdiffusers.loaders.StableDiffusionXLLoraLoaderMixin.load_lora_weights
See load_lora_weights() for more details.
lora_state_dictdiffusers.loaders.StableDiffusionXLLoraLoaderMixin.lora_state_dictstr or os.PathLike or dict) --
Can be either:
A string, the model id (for example
google/ddpm-celebahq-256) of a pretrained model hosted on the Hub.A path to a directory (for example
./my_model_directory) containing the model weights saved with ModelMixin.save_pretrained().cache_dir (
Union[str, os.PathLike], optional) -- Path to a directory where a downloaded pretrained model configuration is cached if the standard cache is not used.force_download (
bool, optional, defaults toFalse) -- Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.proxies (
Dict[str, str], optional) -- A dictionary of proxy servers to use by protocol or endpoint, for example,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.local_files_only (
bool, optional, defaults toFalse) -- Whether to only load local model weights and configuration files or not. If set toTrue, the model won't be downloaded from the Hub.token (
stror bool, optional) -- The token to use as HTTP bearer authorization for remote files. IfTrue, the token generated fromdiffusers-cli login(stored in~/.huggingface) is used.revision (
str, optional, defaults to"main") -- The specific model version to use. It can be a branch name, a tag name, a commit id, or any identifier allowed by Git.subfolder (
str, optional, defaults to"") -- The subfolder location of a model file within a larger model repository on the Hub or locally.weight_name (
str, optional, defaults to None) -- Name of the serialized state dict file.return_lora_metadata (
bool, optional, defaults to False) -- When enabled, additionally return the LoRA adapter metadata, typically found in the state dict.0
Return state dict for lora weights and the network alphas.
> We support loading A1111 formatted LoRA checkpoints in a limited capacity. > > This function is experimental and might change in the future.
save_lora_weightsdiffusers.loaders.StableDiffusionXLLoraLoaderMixin.save_lora_weights
See save_lora_weights() for more information.
unfuse_loradiffusers.loaders.StableDiffusionXLLoraLoaderMixin.unfuse_lora
See unfuse_lora() for more details.
SD3LoraLoaderMixin[[diffusers.loaders.SD3LoraLoaderMixin]]
class diffusers.loaders.SD3LoraLoaderMixindiffusers.loaders.SD3LoraLoaderMixin
Load LoRA layers into SD3Transformer2DModel,
CLIPTextModel, and
CLIPTextModelWithProjection.
Specific to StableDiffusion3Pipeline.
fuse_loradiffusers.loaders.SD3LoraLoaderMixin.fuse_lora
See fuse_lora() for more details.
load_lora_into_text_encoderdiffusers.loaders.SD3LoraLoaderMixin.load_lora_into_text_encoderdict) --
A standard state dict containing the lora layer parameters. The key should be prefixed with an
additional text_encoder to distinguish between unet lora layers.
- network_alphas (
Dict[str, float]) -- The value of the network alpha used for stable learning and preventing underflow. This value has the same meaning as the--network_alphaoption in the kohya-ss trainer script. Refer to this link. - text_encoder (
CLIPTextModel) -- The text encoder model to load the LoRA layers into. - prefix (
str) -- Expected prefix of thetext_encoderin thestate_dict. - lora_scale (
float) -- How much to scale the output of the lora linear layer before it is added with the output of the regular lora layer. - adapter_name (
str, optional) -- Adapter name to be used for referencing the loaded adapter model. If not specified, it will usedefault_{i}where i is the total number of adapters being loaded. - low_cpu_mem_usage (
bool, optional) -- Speed up model loading by only loading the pretrained LoRA weights and not initializing the random weights. - hotswap (
bool, optional) -- See load_lora_weights(). - metadata (
dict) -- Optional LoRA adapter metadata. When supplied, theLoraConfigarguments ofpeftwon't be derived from the state dict.0
This will load the LoRA layers specified in state_dict into text_encoder
load_lora_into_transformerdiffusers.loaders.SD3LoraLoaderMixin.load_lora_into_transformer
See load_lora_into_unet() for more details.
load_lora_weightsdiffusers.loaders.SD3LoraLoaderMixin.load_lora_weights
See load_lora_weights() for more details.
lora_state_dictdiffusers.loaders.SD3LoraLoaderMixin.lora_state_dict
See lora_state_dict() for more details.
save_lora_weightsdiffusers.loaders.SD3LoraLoaderMixin.save_lora_weights
See save_lora_weights() for more information.
unfuse_loradiffusers.loaders.SD3LoraLoaderMixin.unfuse_lora
See unfuse_lora() for more details.
FluxLoraLoaderMixin[[diffusers.loaders.FluxLoraLoaderMixin]]
class diffusers.loaders.FluxLoraLoaderMixindiffusers.loaders.FluxLoraLoaderMixin
Load LoRA layers into FluxTransformer2DModel,
CLIPTextModel.
Specific to StableDiffusion3Pipeline.
fuse_loradiffusers.loaders.FluxLoraLoaderMixin.fuse_lora
See lora_state_dict() for more details.
load_lora_into_text_encoderdiffusers.loaders.FluxLoraLoaderMixin.load_lora_into_text_encoderdict) --
A standard state dict containing the lora layer parameters. The key should be prefixed with an
additional text_encoder to distinguish between unet lora layers.
- network_alphas (
Dict[str, float]) -- The value of the network alpha used for stable learning and preventing underflow. This value has the same meaning as the--network_alphaoption in the kohya-ss trainer script. Refer to this link. - text_encoder (
CLIPTextModel) -- The text encoder model to load the LoRA layers into. - prefix (
str) -- Expected prefix of thetext_encoderin thestate_dict. - lora_scale (
float) -- How much to scale the output of the lora linear layer before it is added with the output of the regular lora layer. - adapter_name (
str, optional) -- Adapter name to be used for referencing the loaded adapter model. If not specified, it will usedefault_{i}where i is the total number of adapters being loaded. - low_cpu_mem_usage (
bool, optional) -- Speed up model loading by only loading the pretrained LoRA weights and not initializing the random weights. - hotswap (
bool, optional) -- See load_lora_weights(). - metadata (
dict) -- Optional LoRA adapter metadata. When supplied, theLoraConfigarguments ofpeftwon't be derived from the state dict.0
This will load the LoRA layers specified in state_dict into text_encoder
load_lora_into_transformerdiffusers.loaders.FluxLoraLoaderMixin.load_lora_into_transformer
See load_lora_into_unet() for more details.
load_lora_weightsdiffusers.loaders.FluxLoraLoaderMixin.load_lora_weightsstr or os.PathLike or dict) --
See lora_state_dict().
- adapter_name (
str, optional) -- Adapter name to be used for referencing the loaded adapter model. If not specified, it will usedefault_{i}where i is the total number of adapters being loaded. - low_cpu_mem_usage (
bool, optional) -- `Speed up model loading by only loading the pretrained LoRA weights and not initializing the random weights. - hotswap (
bool, optional) -- See load_lora_weights(). - kwargs (
dict, optional) -- See lora_state_dict().0
Load LoRA weights specified in pretrained_model_name_or_path_or_dict into self.transformer and
self.text_encoder.
All kwargs are forwarded to self.lora_state_dict.
See lora_state_dict() for more details on how the state dict is loaded.
See ~loaders.StableDiffusionLoraLoaderMixin.load_lora_into_transformer for more details on how the state
dict is loaded into self.transformer.
lora_state_dictdiffusers.loaders.FluxLoraLoaderMixin.lora_state_dict
See lora_state_dict() for more details.
save_lora_weightsdiffusers.loaders.FluxLoraLoaderMixin.save_lora_weightsstr or os.PathLike) --
Directory to save LoRA parameters to. Will be created if it doesn't exist.
- transformer_lora_layers (
Dict[str, torch.nn.Module]orDict[str, torch.Tensor]) -- State dict of the LoRA layers corresponding to thetransformer. - text_encoder_lora_layers (
Dict[str, torch.nn.Module]orDict[str, torch.Tensor]) -- State dict of the LoRA layers corresponding to thetext_encoder. Must explicitly pass the text encoder LoRA state dict because it comes from 🤗 Transformers. - is_main_process (
bool, optional, defaults toTrue) -- 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, setis_main_process=Trueonly on the main process to avoid race conditions. - save_function (
Callable) -- The function to use to save the state dictionary. Useful during distributed training when you need to replacetorch.savewith another method. Can be configured with the environment variableDIFFUSERS_SAVE_MODE. - safe_serialization (
bool, optional, defaults toTrue) -- Whether to save the model usingsafetensorsor the traditional PyTorch way withpickle. - transformer_lora_adapter_metadata -- LoRA adapter metadata associated with the transformer to be serialized with the state dict.
- text_encoder_lora_adapter_metadata -- LoRA adapter metadata associated with the text encoder to be serialized with the state dict.0
Save the LoRA parameters corresponding to the UNet and text encoder.
unfuse_loradiffusers.loaders.FluxLoraLoaderMixin.unfuse_loraList[str]) -- List of LoRA-injectable components to unfuse LoRA from.0
Reverses the effect of
pipe.fuse_lora().
> This is an experimental API.
unload_lora_weightsdiffusers.loaders.FluxLoraLoaderMixin.unload_lora_weightsbool, defaults to False) -- Whether to reset the LoRA-loaded modules
to their original params. Refer to the Flux
documentation to learn more.0
Unloads the LoRA parameters.
Examples:
>>> # Assuming `pipeline` is already loaded with the LoRA parameters.
>>> pipeline.unload_lora_weights()
>>> ...
CogVideoXLoraLoaderMixin[[diffusers.loaders.CogVideoXLoraLoaderMixin]]
class diffusers.loaders.CogVideoXLoraLoaderMixindiffusers.loaders.CogVideoXLoraLoaderMixin
Load LoRA layers into CogVideoXTransformer3DModel. Specific to CogVideoXPipeline.
fuse_loradiffusers.loaders.CogVideoXLoraLoaderMixin.fuse_lora
See fuse_lora() for more details.
load_lora_into_transformerdiffusers.loaders.CogVideoXLoraLoaderMixin.load_lora_into_transformer
See load_lora_into_unet() for more details.
load_lora_weightsdiffusers.loaders.CogVideoXLoraLoaderMixin.load_lora_weights
See load_lora_weights() for more details.
lora_state_dictdiffusers.loaders.CogVideoXLoraLoaderMixin.lora_state_dict
See lora_state_dict() for more details.
save_lora_weightsdiffusers.loaders.CogVideoXLoraLoaderMixin.save_lora_weights
See save_lora_weights() for more information.
unfuse_loradiffusers.loaders.CogVideoXLoraLoaderMixin.unfuse_lora
See unfuse_lora() for more details.
Mochi1LoraLoaderMixin[[diffusers.loaders.Mochi1LoraLoaderMixin]]
class diffusers.loaders.Mochi1LoraLoaderMixindiffusers.loaders.Mochi1LoraLoaderMixin
Load LoRA layers into MochiTransformer3DModel. Specific to MochiPipeline.
fuse_loradiffusers.loaders.Mochi1LoraLoaderMixin.fuse_lora
See fuse_lora() for more details.
load_lora_into_transformerdiffusers.loaders.Mochi1LoraLoaderMixin.load_lora_into_transformer
See load_lora_into_unet() for more details.
load_lora_weightsdiffusers.loaders.Mochi1LoraLoaderMixin.load_lora_weights
See load_lora_weights() for more details.
lora_state_dictdiffusers.loaders.Mochi1LoraLoaderMixin.lora_state_dict
See lora_state_dict() for more details.
save_lora_weightsdiffusers.loaders.Mochi1LoraLoaderMixin.save_lora_weights
See save_lora_weights() for more information.
unfuse_loradiffusers.loaders.Mochi1LoraLoaderMixin.unfuse_lora
See unfuse_lora() for more details.
AuraFlowLoraLoaderMixin[[diffusers.loaders.AuraFlowLoraLoaderMixin]]
class diffusers.loaders.AuraFlowLoraLoaderMixindiffusers.loaders.AuraFlowLoraLoaderMixin
Load LoRA layers into AuraFlowTransformer2DModel Specific to AuraFlowPipeline.
fuse_loradiffusers.loaders.AuraFlowLoraLoaderMixin.fuse_lora
See fuse_lora() for more details.
load_lora_into_transformerdiffusers.loaders.AuraFlowLoraLoaderMixin.load_lora_into_transformer
See load_lora_into_unet() for more details.
load_lora_weightsdiffusers.loaders.AuraFlowLoraLoaderMixin.load_lora_weights
See load_lora_weights() for more details.
lora_state_dictdiffusers.loaders.AuraFlowLoraLoaderMixin.lora_state_dict
See lora_state_dict() for more details.
save_lora_weightsdiffusers.loaders.AuraFlowLoraLoaderMixin.save_lora_weights
See save_lora_weights() for more information.
unfuse_loradiffusers.loaders.AuraFlowLoraLoaderMixin.unfuse_lora
See unfuse_lora() for more details.
LTXVideoLoraLoaderMixin[[diffusers.loaders.LTXVideoLoraLoaderMixin]]
class diffusers.loaders.LTXVideoLoraLoaderMixindiffusers.loaders.LTXVideoLoraLoaderMixin
Load LoRA layers into LTXVideoTransformer3DModel. Specific to LTXPipeline.
fuse_loradiffusers.loaders.LTXVideoLoraLoaderMixin.fuse_lora
See fuse_lora() for more details.
load_lora_into_transformerdiffusers.loaders.LTXVideoLoraLoaderMixin.load_lora_into_transformer
See load_lora_into_unet() for more details.
load_lora_weightsdiffusers.loaders.LTXVideoLoraLoaderMixin.load_lora_weights
See load_lora_weights() for more details.
lora_state_dictdiffusers.loaders.LTXVideoLoraLoaderMixin.lora_state_dict
See lora_state_dict() for more details.
save_lora_weightsdiffusers.loaders.LTXVideoLoraLoaderMixin.save_lora_weights
See save_lora_weights() for more information.
unfuse_loradiffusers.loaders.LTXVideoLoraLoaderMixin.unfuse_lora
See unfuse_lora() for more details.
SanaLoraLoaderMixin[[diffusers.loaders.SanaLoraLoaderMixin]]
class diffusers.loaders.SanaLoraLoaderMixindiffusers.loaders.SanaLoraLoaderMixin
Load LoRA layers into SanaTransformer2DModel. Specific to SanaPipeline.
fuse_loradiffusers.loaders.SanaLoraLoaderMixin.fuse_lora
See fuse_lora() for more details.
load_lora_into_transformerdiffusers.loaders.SanaLoraLoaderMixin.load_lora_into_transformer
See load_lora_into_unet() for more details.
load_lora_weightsdiffusers.loaders.SanaLoraLoaderMixin.load_lora_weights
See load_lora_weights() for more details.
lora_state_dictdiffusers.loaders.SanaLoraLoaderMixin.lora_state_dict
See lora_state_dict() for more details.
save_lora_weightsdiffusers.loaders.SanaLoraLoaderMixin.save_lora_weights
See save_lora_weights() for more information.
unfuse_loradiffusers.loaders.SanaLoraLoaderMixin.unfuse_lora
See unfuse_lora() for more details.
HunyuanVideoLoraLoaderMixin[[diffusers.loaders.HunyuanVideoLoraLoaderMixin]]
class diffusers.loaders.HunyuanVideoLoraLoaderMixindiffusers.loaders.HunyuanVideoLoraLoaderMixin
Load LoRA layers into HunyuanVideoTransformer3DModel. Specific to HunyuanVideoPipeline.
fuse_loradiffusers.loaders.HunyuanVideoLoraLoaderMixin.fuse_lora
See fuse_lora() for more details.
load_lora_into_transformerdiffusers.loaders.HunyuanVideoLoraLoaderMixin.load_lora_into_transformer
See load_lora_into_unet() for more details.
load_lora_weightsdiffusers.loaders.HunyuanVideoLoraLoaderMixin.load_lora_weights
See load_lora_weights() for more details.
lora_state_dictdiffusers.loaders.HunyuanVideoLoraLoaderMixin.lora_state_dict
See lora_state_dict() for more details.
save_lora_weightsdiffusers.loaders.HunyuanVideoLoraLoaderMixin.save_lora_weights
See save_lora_weights() for more information.
unfuse_loradiffusers.loaders.HunyuanVideoLoraLoaderMixin.unfuse_lora
See unfuse_lora() for more details.
Lumina2LoraLoaderMixin[[diffusers.loaders.Lumina2LoraLoaderMixin]]
class diffusers.loaders.Lumina2LoraLoaderMixindiffusers.loaders.Lumina2LoraLoaderMixin
Load LoRA layers into Lumina2Transformer2DModel. Specific to Lumina2Text2ImgPipeline.
fuse_loradiffusers.loaders.Lumina2LoraLoaderMixin.fuse_lora
See fuse_lora() for more details.
load_lora_into_transformerdiffusers.loaders.Lumina2LoraLoaderMixin.load_lora_into_transformer
See load_lora_into_unet() for more details.
load_lora_weightsdiffusers.loaders.Lumina2LoraLoaderMixin.load_lora_weights
See load_lora_weights() for more details.
lora_state_dictdiffusers.loaders.Lumina2LoraLoaderMixin.lora_state_dict
See lora_state_dict() for more details.
save_lora_weightsdiffusers.loaders.Lumina2LoraLoaderMixin.save_lora_weights
See save_lora_weights() for more information.
unfuse_loradiffusers.loaders.Lumina2LoraLoaderMixin.unfuse_lora
See unfuse_lora() for more details.
CogView4LoraLoaderMixin[[diffusers.loaders.CogView4LoraLoaderMixin]]
class diffusers.loaders.CogView4LoraLoaderMixindiffusers.loaders.CogView4LoraLoaderMixin
Load LoRA layers into WanTransformer3DModel. Specific to CogView4Pipeline.
fuse_loradiffusers.loaders.CogView4LoraLoaderMixin.fuse_lora
See fuse_lora() for more details.
load_lora_into_transformerdiffusers.loaders.CogView4LoraLoaderMixin.load_lora_into_transformer
See load_lora_into_unet() for more details.
load_lora_weightsdiffusers.loaders.CogView4LoraLoaderMixin.load_lora_weights
See load_lora_weights() for more details.
lora_state_dictdiffusers.loaders.CogView4LoraLoaderMixin.lora_state_dict
See lora_state_dict() for more details.
save_lora_weightsdiffusers.loaders.CogView4LoraLoaderMixin.save_lora_weights
See save_lora_weights() for more information.
unfuse_loradiffusers.loaders.CogView4LoraLoaderMixin.unfuse_lora
See unfuse_lora() for more details.
WanLoraLoaderMixin[[diffusers.loaders.WanLoraLoaderMixin]]
class diffusers.loaders.WanLoraLoaderMixindiffusers.loaders.WanLoraLoaderMixin
Load LoRA layers into WanTransformer3DModel. Specific to WanPipeline and [WanImageToVideoPipeline].
fuse_loradiffusers.loaders.WanLoraLoaderMixin.fuse_lora
See fuse_lora() for more details.
load_lora_into_transformerdiffusers.loaders.WanLoraLoaderMixin.load_lora_into_transformer
See load_lora_into_unet() for more details.
load_lora_weightsdiffusers.loaders.WanLoraLoaderMixin.load_lora_weights
See load_lora_weights() for more details.
lora_state_dictdiffusers.loaders.WanLoraLoaderMixin.lora_state_dict
See lora_state_dict() for more details.
save_lora_weightsdiffusers.loaders.WanLoraLoaderMixin.save_lora_weights
See save_lora_weights() for more information.
unfuse_loradiffusers.loaders.WanLoraLoaderMixin.unfuse_lora
See unfuse_lora() for more details.
SkyReelsV2LoraLoaderMixin[[diffusers.loaders.SkyReelsV2LoraLoaderMixin]]
class diffusers.loaders.SkyReelsV2LoraLoaderMixindiffusers.loaders.SkyReelsV2LoraLoaderMixin
Load LoRA layers into SkyReelsV2Transformer3DModel.
fuse_loradiffusers.loaders.SkyReelsV2LoraLoaderMixin.fuse_lora
See fuse_lora() for more details.
load_lora_into_transformerdiffusers.loaders.SkyReelsV2LoraLoaderMixin.load_lora_into_transformer
See load_lora_into_unet() for more details.
load_lora_weightsdiffusers.loaders.SkyReelsV2LoraLoaderMixin.load_lora_weights
See load_lora_weights() for more details.
lora_state_dictdiffusers.loaders.SkyReelsV2LoraLoaderMixin.lora_state_dict
See lora_state_dict() for more details.
save_lora_weightsdiffusers.loaders.SkyReelsV2LoraLoaderMixin.save_lora_weights
See save_lora_weights() for more information.
unfuse_loradiffusers.loaders.SkyReelsV2LoraLoaderMixin.unfuse_lora
See unfuse_lora() for more details.
AmusedLoraLoaderMixin[[diffusers.loaders.AmusedLoraLoaderMixin]]
class diffusers.loaders.AmusedLoraLoaderMixindiffusers.loaders.AmusedLoraLoaderMixin
load_lora_into_transformerdiffusers.loaders.AmusedLoraLoaderMixin.load_lora_into_transformer
See load_lora_into_unet() for more details.
save_lora_weightsdiffusers.loaders.AmusedLoraLoaderMixin.save_lora_weightsstr or os.PathLike) --
Directory to save LoRA parameters to. Will be created if it doesn't exist.
- unet_lora_layers (
Dict[str, torch.nn.Module]orDict[str, torch.Tensor]) -- State dict of the LoRA layers corresponding to theunet. - text_encoder_lora_layers (
Dict[str, torch.nn.Module]orDict[str, torch.Tensor]) -- State dict of the LoRA layers corresponding to thetext_encoder. Must explicitly pass the text encoder LoRA state dict because it comes from 🤗 Transformers. - is_main_process (
bool, optional, defaults toTrue) -- 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, setis_main_process=Trueonly on the main process to avoid race conditions. - save_function (
Callable) -- The function to use to save the state dictionary. Useful during distributed training when you need to replacetorch.savewith another method. Can be configured with the environment variableDIFFUSERS_SAVE_MODE. - safe_serialization (
bool, optional, defaults toTrue) -- Whether to save the model usingsafetensorsor the traditional PyTorch way withpickle.0
Save the LoRA parameters corresponding to the UNet and text encoder.
HiDreamImageLoraLoaderMixin[[diffusers.loaders.HiDreamImageLoraLoaderMixin]]
class diffusers.loaders.HiDreamImageLoraLoaderMixindiffusers.loaders.HiDreamImageLoraLoaderMixin
Load LoRA layers into HiDreamImageTransformer2DModel. Specific to HiDreamImagePipeline.
fuse_loradiffusers.loaders.HiDreamImageLoraLoaderMixin.fuse_lora
See fuse_lora() for more details.
load_lora_into_transformerdiffusers.loaders.HiDreamImageLoraLoaderMixin.load_lora_into_transformer
See load_lora_into_unet() for more details.
load_lora_weightsdiffusers.loaders.HiDreamImageLoraLoaderMixin.load_lora_weights
See load_lora_weights() for more details.
lora_state_dictdiffusers.loaders.HiDreamImageLoraLoaderMixin.lora_state_dict
See lora_state_dict() for more details.
save_lora_weightsdiffusers.loaders.HiDreamImageLoraLoaderMixin.save_lora_weights
See save_lora_weights() for more information.
unfuse_loradiffusers.loaders.HiDreamImageLoraLoaderMixin.unfuse_lora
See unfuse_lora() for more details.
QwenImageLoraLoaderMixin[[diffusers.loaders.QwenImageLoraLoaderMixin]]
class diffusers.loaders.QwenImageLoraLoaderMixindiffusers.loaders.QwenImageLoraLoaderMixin
Load LoRA layers into QwenImageTransformer2DModel. Specific to QwenImagePipeline.
fuse_loradiffusers.loaders.QwenImageLoraLoaderMixin.fuse_lora
See fuse_lora() for more details.
load_lora_into_transformerdiffusers.loaders.QwenImageLoraLoaderMixin.load_lora_into_transformer
See load_lora_into_unet() for more details.
load_lora_weightsdiffusers.loaders.QwenImageLoraLoaderMixin.load_lora_weights
See load_lora_weights() for more details.
lora_state_dictdiffusers.loaders.QwenImageLoraLoaderMixin.lora_state_dict
See lora_state_dict() for more details.
save_lora_weightsdiffusers.loaders.QwenImageLoraLoaderMixin.save_lora_weights
See save_lora_weights() for more information.
unfuse_loradiffusers.loaders.QwenImageLoraLoaderMixin.unfuse_lora
See unfuse_lora() for more details.
KandinskyLoraLoaderMixin[[diffusers.loaders.KandinskyLoraLoaderMixin]]
class diffusers.loaders.KandinskyLoraLoaderMixindiffusers.loaders.KandinskyLoraLoaderMixin
Load LoRA layers into Kandinsky5Transformer3DModel,
fuse_loradiffusers.loaders.KandinskyLoraLoaderMixin.fuse_loraList[str]): List of LoRA-injectable components to fuse the LoRAs into.
- lora_scale (
float, defaults to 1.0) -- Controls how much to influence the outputs with the LoRA parameters. - safe_fusing (
bool, defaults toFalse) -- Whether to check fused weights for NaN values before fusing. - adapter_names (
List[str], optional) -- Adapter names to be used for fusing.0
Fuses the LoRA parameters into the original parameters of the corresponding blocks.
Example:
from diffusers import Kandinsky5T2VPipeline
pipeline = Kandinsky5T2VPipeline.from_pretrained("ai-forever/Kandinsky-5.0-T2V")
pipeline.load_lora_weights("path/to/lora.safetensors")
pipeline.fuse_lora(lora_scale=0.7)
load_lora_into_transformerdiffusers.loaders.KandinskyLoraLoaderMixin.load_lora_into_transformerdict) --
A standard state dict containing the lora layer parameters.
- transformer (
Kandinsky5Transformer3DModel) -- The transformer model to load the LoRA layers into. - adapter_name (
str, optional) -- Adapter name to be used for referencing the loaded adapter model. - low_cpu_mem_usage (
bool, optional) -- Speed up model loading by only loading the pretrained LoRA weights. - hotswap (
bool, optional) -- See load_lora_weights(). - metadata (
dict) -- Optional LoRA adapter metadata.0
Load the LoRA layers specified in state_dict into transformer.
load_lora_weightsdiffusers.loaders.KandinskyLoraLoaderMixin.load_lora_weightsstr or os.PathLike or dict) --
See lora_state_dict().
- adapter_name (
str, optional) -- Adapter name to be used for referencing the loaded adapter model. - hotswap (
bool, optional) -- Whether to substitute an existing (LoRA) adapter with the newly loaded adapter in-place. - low_cpu_mem_usage (
bool, optional) -- Speed up model loading by only loading the pretrained LoRA weights and not initializing the random weights. - kwargs (
dict, optional) -- See lora_state_dict().0
Load LoRA weights specified in pretrained_model_name_or_path_or_dict into self.transformer
lora_state_dictdiffusers.loaders.KandinskyLoraLoaderMixin.lora_state_dictstr or os.PathLike or dict) --
Can be either:
A string, the model id of a pretrained model hosted on the Hub.
A path to a directory containing the model weights.
cache_dir (
Union[str, os.PathLike], optional) -- Path to a directory where a downloaded pretrained model configuration is cached.force_download (
bool, optional, defaults toFalse) -- Whether or not to force the (re-)download of the model weights.proxies (
Dict[str, str], optional) -- A dictionary of proxy servers to use by protocol or endpoint.local_files_only (
bool, optional, defaults toFalse) -- Whether to only load local model weights and configuration files.token (
stror bool, optional) -- The token to use as HTTP bearer authorization for remote files.revision (
str, optional, defaults to"main") -- The specific model version to use.subfolder (
str, optional, defaults to"") -- The subfolder location of a model file within a larger model repository.weight_name (
str, optional, defaults to None) -- Name of the serialized state dict file.use_safetensors (
bool, optional) -- Whether to use safetensors for loading.return_lora_metadata (
bool, optional, defaults to False) -- When enabled, additionally return the LoRA adapter metadata.0
Return state dict for lora weights and the network alphas.
save_lora_weightsdiffusers.loaders.KandinskyLoraLoaderMixin.save_lora_weightsstr or os.PathLike) --
Directory to save LoRA parameters to.
- transformer_lora_layers (
Dict[str, torch.nn.Module]orDict[str, torch.Tensor]) -- State dict of the LoRA layers corresponding to thetransformer. - is_main_process (
bool, optional, defaults toTrue) -- Whether the process calling this is the main process. - save_function (
Callable) -- The function to use to save the state dictionary. - safe_serialization (
bool, optional, defaults toTrue) -- Whether to save the model usingsafetensorsor the traditional PyTorch way. - transformer_lora_adapter_metadata -- LoRA adapter metadata associated with the transformer.0
Save the LoRA parameters corresponding to the transformer and text encoders.
unfuse_loradiffusers.loaders.KandinskyLoraLoaderMixin.unfuse_loraList[str]) -- List of LoRA-injectable components to unfuse LoRA from.0
Reverses the effect of pipe.fuse_lora().
LoraBaseMixin[[diffusers.loaders.lora_base.LoraBaseMixin]]
class diffusers.loaders.lora_base.LoraBaseMixindiffusers.loaders.lora_base.LoraBaseMixin
delete_adaptersdiffusers.loaders.lora_base.LoraBaseMixin.delete_adaptersUnion[List[str], str]) --
The names of the adapters to delete.0
Delete an adapter's LoRA layers from the pipeline.
Example:
from diffusers import AutoPipelineForText2Image
import torch
pipeline = AutoPipelineForText2Image.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16
).to("cuda")
pipeline.load_lora_weights(
"jbilcke-hf/sdxl-cinematic-1", weight_name="pytorch_lora_weights.safetensors", adapter_names="cinematic"
)
pipeline.delete_adapters("cinematic")
disable_loradiffusers.loaders.lora_base.LoraBaseMixin.disable_lora
Disables the active LoRA layers of the pipeline.
Example:
from diffusers import AutoPipelineForText2Image
import torch
pipeline = AutoPipelineForText2Image.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16
).to("cuda")
pipeline.load_lora_weights(
"jbilcke-hf/sdxl-cinematic-1", weight_name="pytorch_lora_weights.safetensors", adapter_name="cinematic"
)
pipeline.disable_lora()
enable_loradiffusers.loaders.lora_base.LoraBaseMixin.enable_lora
Enables the active LoRA layers of the pipeline.
Example:
from diffusers import AutoPipelineForText2Image
import torch
pipeline = AutoPipelineForText2Image.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16
).to("cuda")
pipeline.load_lora_weights(
"jbilcke-hf/sdxl-cinematic-1", weight_name="pytorch_lora_weights.safetensors", adapter_name="cinematic"
)
pipeline.enable_lora()
enable_lora_hotswapdiffusers.loaders.lora_base.LoraBaseMixin.enable_lora_hotswapint) --
The highest rank among all the adapters that will be loaded.
- check_compiled (
str, optional, defaults to"error") -- How to handle a model that is already compiled. The check can return the following messages:- "error" (default): raise an error
- "warn": issue a warning
- "ignore": do nothing0
Hotswap adapters without triggering recompilation of a model or if the ranks of the loaded adapters are different.
fuse_loradiffusers.loaders.lora_base.LoraBaseMixin.fuse_loraList[str]): List of LoRA-injectable components to fuse the LoRAs into.
- lora_scale (
float, defaults to 1.0) -- Controls how much to influence the outputs with the LoRA parameters. - safe_fusing (
bool, defaults toFalse) -- Whether to check fused weights for NaN values before fusing and if values are NaN not fusing them. - adapter_names (
List[str], optional) -- Adapter names to be used for fusing. If nothing is passed, all active adapters will be fused.0
Fuses the LoRA parameters into the original parameters of the corresponding blocks.
> This is an experimental API.
Example:
from diffusers import DiffusionPipeline
import torch
pipeline = DiffusionPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16
).to("cuda")
pipeline.load_lora_weights("nerijs/pixel-art-xl", weight_name="pixel-art-xl.safetensors", adapter_name="pixel")
pipeline.fuse_lora(lora_scale=0.7)
get_active_adaptersdiffusers.loaders.lora_base.LoraBaseMixin.get_active_adapters
Gets the list of the current active adapters.
Example:
from diffusers import DiffusionPipeline
pipeline = DiffusionPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0",
).to("cuda")
pipeline.load_lora_weights("CiroN2022/toy-face", weight_name="toy_face_sdxl.safetensors", adapter_name="toy")
pipeline.get_active_adapters()
get_list_adaptersdiffusers.loaders.lora_base.LoraBaseMixin.get_list_adapters
Gets the current list of all available adapters in the pipeline.
set_adaptersdiffusers.loaders.lora_base.LoraBaseMixin.set_adaptersList[str] or str) --
The names of the adapters to use.
- adapter_weights (
Union[List[float], float], optional) -- The adapter(s) weights to use with the UNet. IfNone, the weights are set to1.0for all the adapters.0
Set the currently active adapters for use in the pipeline.
Example:
from diffusers import AutoPipelineForText2Image
import torch
pipeline = AutoPipelineForText2Image.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16
).to("cuda")
pipeline.load_lora_weights(
"jbilcke-hf/sdxl-cinematic-1", weight_name="pytorch_lora_weights.safetensors", adapter_name="cinematic"
)
pipeline.load_lora_weights("nerijs/pixel-art-xl", weight_name="pixel-art-xl.safetensors", adapter_name="pixel")
pipeline.set_adapters(["cinematic", "pixel"], adapter_weights=[0.5, 0.5])
set_lora_devicediffusers.loaders.lora_base.LoraBaseMixin.set_lora_deviceList[str]) --
List of adapters to send device to.
- device (
Union[torch.device, str, int]) -- Device to send the adapters to. Can be either a torch device, a str or an integer.0
Moves the LoRAs listed in adapter_names to a target device. Useful for offloading the LoRA to the CPU in case
you want to load multiple adapters and free some GPU memory.
After offloading the LoRA adapters to CPU, as long as the rest of the model is still on GPU, the LoRA adapters can no longer be used for inference, as that would cause a device mismatch. Remember to set the device back to GPU before using those LoRA adapters for inference.
>>> pipe.load_lora_weights(path_1, adapter_name="adapter-1")
>>> pipe.load_lora_weights(path_2, adapter_name="adapter-2")
>>> pipe.set_adapters("adapter-1")
>>> image_1 = pipe(**kwargs)
>>> # switch to adapter-2, offload adapter-1
>>> pipeline.set_lora_device(adapter_names=["adapter-1"], device="cpu")
>>> pipeline.set_lora_device(adapter_names=["adapter-2"], device="cuda:0")
>>> pipe.set_adapters("adapter-2")
>>> image_2 = pipe(**kwargs)
>>> # switch back to adapter-1, offload adapter-2
>>> pipeline.set_lora_device(adapter_names=["adapter-2"], device="cpu")
>>> pipeline.set_lora_device(adapter_names=["adapter-1"], device="cuda:0")
>>> pipe.set_adapters("adapter-1")
>>> ...
unfuse_loradiffusers.loaders.lora_base.LoraBaseMixin.unfuse_loraList[str]) -- List of LoRA-injectable components to unfuse LoRA from.
- unfuse_unet (
bool, defaults toTrue) -- Whether to unfuse the UNet LoRA parameters. - unfuse_text_encoder (
bool, defaults toTrue) -- Whether to unfuse the text encoder LoRA parameters. If the text encoder wasn't monkey-patched with the LoRA parameters then it won't have any effect.0
Reverses the effect of
pipe.fuse_lora().
> This is an experimental API.
unload_lora_weightsdiffusers.loaders.lora_base.LoraBaseMixin.unload_lora_weights
Unloads the LoRA parameters.
Examples:
>>> # Assuming `pipeline` is already loaded with the LoRA parameters.
>>> pipeline.unload_lora_weights()
>>> ...
write_lora_layersdiffusers.loaders.lora_base.LoraBaseMixin.write_lora_layers
Xet Storage Details
- Size:
- 156 kB
- Xet hash:
- 4f14550637c35567f786f555a6b237a656a004ab7d0b7bd6ef66abd6e8a0e962
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.