Diffusers supports loading pretrained pipeline (or model) weights stored in a single file, such as a ckpt
or safetensors
file. These single file types are typically produced from community trained models. There are three classes for loading single file weights:
FromSingleFileMixin
supports loading pretrained pipeline weights stored in a single file, which can either be a ckpt
or safetensors
file.FromOriginalVAEMixin
supports loading a pretrained AutoencoderKL from pretrained ControlNet weights stored in a single file, which can either be a ckpt
or safetensors
file.FromOriginalControlnetMixin
supports loading pretrained ControlNet weights stored in a single file, which can either be a ckpt
or safetensors
file.To learn more about how to load single file weights, see the Load different Stable Diffusion formats loading guide.
Load model weights saved in the .ckpt
format into a DiffusionPipeline.
( pretrained_model_link_or_path **kwargs )
Parameters
str
or os.PathLike
, optional) —
Can be either:.ckpt
file (for example
"https://huggingface.co/<repo_id>/blob/main/<path_to_file>.ckpt"
) on the Hub.str
or torch.dtype
, optional) —
Override the default torch.dtype
and load the model with another dtype. If "auto"
is passed, the
dtype is automatically derived from the model’s weights. bool
, optional, defaults to False
) —
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
cached versions if they exist. Union[str, os.PathLike]
, optional) —
Path to a directory where a downloaded pretrained model configuration is cached if the standard cache
is not used. bool
, optional, defaults to False
) —
Whether or not to resume downloading the model weights and configuration files. If set to False
, any
incompletely downloaded files are deleted. 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. bool
, optional, defaults to False
) —
Whether to only load local model weights and configuration files or not. If set to True
, the model
won’t be downloaded from the Hub. str
or bool, optional) —
The token to use as HTTP bearer authorization for remote files. If True
, the token generated from
diffusers-cli login
(stored in ~/.huggingface
) is used. 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. bool
, optional, defaults to None
) —
If set to None
, the safetensors weights are downloaded if they’re available and if the
safetensors library is installed. If set to True
, the model is forcibly loaded from safetensors
weights. If set to False
, safetensors weights are not loaded. bool
, optional, defaults to False
) —
Whether to extract the EMA weights or not. Pass True
to extract the EMA weights which usually yield
higher quality images for inference. Non-EMA weights are usually better for continuing finetuning. bool
, optional, defaults to None
) —
Whether the attention computation should always be upcasted. int
, optional, defaults to 512) —
The image size the model was trained on. Use 512 for all Stable Diffusion v1 models and the Stable
Diffusion v2 base model. Use 768 for Stable Diffusion v2. str
, optional) —
The prediction type the model was trained on. Use 'epsilon'
for all Stable Diffusion v1 models and
the Stable Diffusion v2 base model. Use 'v_prediction'
for Stable Diffusion v2. int
, optional, defaults to None
) —
The number of input channels. If None
, it is automatically inferred. str
, optional, defaults to "pndm"
) —
Type of scheduler to use. Should be one of ["pndm", "lms", "heun", "euler", "euler-ancestral", "dpm", "ddim"]
. bool
, optional, defaults to True
) —
Whether to load the safety checker or not. None
) —
An instance of CLIPTextModel
to use, specifically the
clip-vit-large-patch14 variant. If this
parameter is None
, the function loads a new instance of CLIPTextModel
by itself if needed. AutoencoderKL
, optional, defaults to None
) —
Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations. If
this parameter is None
, the function will load a new instance of [CLIP] by itself, if needed. None
) —
An instance of CLIPTokenizer
to use. If this parameter is None
, the function loads a new instance
of CLIPTokenizer
by itself if needed. str
) —
Path to .yaml
config file corresponding to the original architecture. If None
, will be
automatically inferred by looking for a key that only exists in SD2.0 models. __init__
method. See example below for more information. Instantiate a DiffusionPipeline from pretrained pipeline weights saved in the .ckpt
or .safetensors
format. The pipeline is set in evaluation mode (model.eval()
) by default.
Examples:
>>> from diffusers import StableDiffusionPipeline
>>> # Download pipeline from huggingface.co and cache.
>>> pipeline = StableDiffusionPipeline.from_single_file(
... "https://huggingface.co/WarriorMama777/OrangeMixs/blob/main/Models/AbyssOrangeMix/AbyssOrangeMix.safetensors"
... )
>>> # Download pipeline from local file
>>> # file is downloaded under ./v1-5-pruned-emaonly.ckpt
>>> pipeline = StableDiffusionPipeline.from_single_file("./v1-5-pruned-emaonly")
>>> # Enable float16 and move to GPU
>>> pipeline = StableDiffusionPipeline.from_single_file(
... "https://huggingface.co/runwayml/stable-diffusion-v1-5/blob/main/v1-5-pruned-emaonly.ckpt",
... torch_dtype=torch.float16,
... )
>>> pipeline.to("cuda")
Load pretrained ControlNet weights saved in the .ckpt
or .safetensors
format into an AutoencoderKL.
( pretrained_model_link_or_path **kwargs )
Parameters
str
or os.PathLike
, optional) —
Can be either:.ckpt
file (for example
"https://huggingface.co/<repo_id>/blob/main/<path_to_file>.ckpt"
) on the Hub.str
or torch.dtype
, optional) —
Override the default torch.dtype
and load the model with another dtype. If "auto"
is passed, the
dtype is automatically derived from the model’s weights. bool
, optional, defaults to False
) —
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
cached versions if they exist. Union[str, os.PathLike]
, optional) —
Path to a directory where a downloaded pretrained model configuration is cached if the standard cache
is not used. bool
, optional, defaults to False
) —
Whether or not to resume downloading the model weights and configuration files. If set to False
, any
incompletely downloaded files are deleted. 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. bool
, optional, defaults to False
) —
Whether to only load local model weights and configuration files or not. If set to True, the model
won’t be downloaded from the Hub. str
or bool, optional) —
The token to use as HTTP bearer authorization for remote files. If True
, the token generated from
diffusers-cli login
(stored in ~/.huggingface
) is used. 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. int
, optional, defaults to 512) —
The image size the model was trained on. Use 512 for all Stable Diffusion v1 models and the Stable
Diffusion v2 base model. Use 768 for Stable Diffusion v2. bool
, optional, defaults to None
) —
If set to None
, the safetensors weights are downloaded if they’re available and if the
safetensors library is installed. If set to True
, the model is forcibly loaded from safetensors
weights. If set to False
, safetensors weights are not loaded. bool
, optional, defaults to None
) —
Whether the attention computation should always be upcasted. float
, optional, defaults to 0.18215) —
The component-wise standard deviation of the trained latent space computed using the first batch of the
training set. This is used to scale the latent space to have unit variance when training the diffusion
model. The latents are scaled with the formula z = z * scaling_factor
before being passed to the
diffusion model. When decoding, the latents are scaled back to the original scale with the formula: z = 1 / scaling_factor * z
. For more details, refer to sections 4.3.2 and D.1 of the High-Resolution
Image Synthesis with Latent Diffusion Models paper. __init__
method. See example below for more information. Instantiate a AutoencoderKL from pretrained ControlNet weights saved in the original .ckpt
or
.safetensors
format. The pipeline is set in evaluation mode (model.eval()
) by default.
Make sure to pass both image_size
and scaling_factor
to from_single_file()
if you’re loading
a VAE from SDXL or a Stable Diffusion v2 model or higher.
Load pretrained ControlNet weights saved in the .ckpt
or .safetensors
format into a ControlNetModel.
( pretrained_model_link_or_path **kwargs )
Parameters
str
or os.PathLike
, optional) —
Can be either:.ckpt
file (for example
"https://huggingface.co/<repo_id>/blob/main/<path_to_file>.ckpt"
) on the Hub.str
or torch.dtype
, optional) —
Override the default torch.dtype
and load the model with another dtype. If "auto"
is passed, the
dtype is automatically derived from the model’s weights. bool
, optional, defaults to False
) —
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
cached versions if they exist. Union[str, os.PathLike]
, optional) —
Path to a directory where a downloaded pretrained model configuration is cached if the standard cache
is not used. bool
, optional, defaults to False
) —
Whether or not to resume downloading the model weights and configuration files. If set to False
, any
incompletely downloaded files are deleted. 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. bool
, optional, defaults to False
) —
Whether to only load local model weights and configuration files or not. If set to True, the model
won’t be downloaded from the Hub. str
or bool, optional) —
The token to use as HTTP bearer authorization for remote files. If True
, the token generated from
diffusers-cli login
(stored in ~/.huggingface
) is used. 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. bool
, optional, defaults to None
) —
If set to None
, the safetensors weights are downloaded if they’re available and if the
safetensors library is installed. If set to True
, the model is forcibly loaded from safetensors
weights. If set to False
, safetensors weights are not loaded. int
, optional, defaults to 512) —
The image size the model was trained on. Use 512 for all Stable Diffusion v1 models and the Stable
Diffusion v2 base model. Use 768 for Stable Diffusion v2. bool
, optional, defaults to None
) —
Whether the attention computation should always be upcasted. __init__
method. See example below for more information. Instantiate a ControlNetModel from pretrained ControlNet weights saved in the original .ckpt
or
.safetensors
format. The pipeline is set in evaluation mode (model.eval()
) by default.
Examples:
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel
url = "https://huggingface.co/lllyasviel/ControlNet-v1-1/blob/main/control_v11p_sd15_canny.pth" # can also be a local path
model = ControlNetModel.from_single_file(url)
url = "https://huggingface.co/runwayml/stable-diffusion-v1-5/blob/main/v1-5-pruned.safetensors" # can also be a local path
pipe = StableDiffusionControlNetPipeline.from_single_file(url, controlnet=controlnet)