Single files
The from_single_file() method allows you to load:
- a model stored in a single file, which is useful if you’re working with models from the diffusion ecosystem, like Automatic1111, and commonly rely on a single-file layout to store and share models
- a model stored in their originally distributed layout, which is useful if you’re working with models finetuned with other services, and want to load it directly into Diffusers model objects and pipelines
Read the Model files and layouts guide to learn more about the Diffusers-multifolder layout versus the single-file layout, and how to load models stored in these different layouts.
Supported pipelines
- CogVideoXPipeline
- StableDiffusionPipeline
- StableDiffusionImg2ImgPipeline
- StableDiffusionInpaintPipeline
- StableDiffusionControlNetPipeline
- StableDiffusionControlNetImg2ImgPipeline
- StableDiffusionControlNetInpaintPipeline
- StableDiffusionUpscalePipeline
- StableDiffusionXLPipeline
- StableDiffusionXLImg2ImgPipeline
- StableDiffusionXLInpaintPipeline
- StableDiffusionXLInstructPix2PixPipeline
- StableDiffusionXLControlNetPipeline
- StableDiffusionXLKDiffusionPipeline
- StableDiffusion3Pipeline
- LatentConsistencyModelPipeline
- LatentConsistencyModelImg2ImgPipeline
- StableDiffusionControlNetXSPipeline
- StableDiffusionXLControlNetXSPipeline
- LEditsPPPipelineStableDiffusion
- LEditsPPPipelineStableDiffusionXL
- PIAPipeline
Supported models
- UNet2DConditionModel
StableCascadeUNet
- AutoencoderKL
- AutoencoderKLCogVideoX
- ControlNetModel
- SD3Transformer2DModel
- FluxTransformer2DModel
FromSingleFileMixin
Load model weights saved in the .ckpt
format into a DiffusionPipeline.
from_single_file
< source >( pretrained_model_link_or_path **kwargs )
Parameters
- pretrained_model_link_or_path (
str
oros.PathLike
, optional) — Can be either:- A link to the
.ckpt
file (for example"https://huggingface.co/<repo_id>/blob/main/<path_to_file>.ckpt"
) on the Hub. - A path to a file containing all pipeline weights.
- A link to the
- torch_dtype (
str
ortorch.dtype
, optional) — Override the defaulttorch.dtype
and load the model with another dtype. - 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. - 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. - 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 (
str
or 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. - original_config_file (
str
, optional) — The path to the original config file that was used to train the model. If not provided, the config file will be inferred from the checkpoint file. - config (
str
, optional) — Can be either:- A string, the repo id (for example
CompVis/ldm-text2im-large-256
) of a pretrained pipeline hosted on the Hub. - A path to a directory (for example
./my_pipeline_directory/
) containing the pipeline component configs in Diffusers format.
- A string, the repo id (for example
- kwargs (remaining dictionary of keyword arguments, optional) —
Can be used to overwrite load and saveable variables (the pipeline components of the specific pipeline
class). The overwritten components are passed directly to the pipelines
__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.ckpt")
>>> # 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")
FromOriginalModelMixin
Load pretrained weights saved in the .ckpt
or .safetensors
format into a model.
from_single_file
< source >( pretrained_model_link_or_path_or_dict: Optional = None **kwargs )
Parameters
- pretrained_model_link_or_path_or_dict (
str
, optional) — Can be either:- A link to the
.safetensors
or.ckpt
file (for example"https://huggingface.co/<repo_id>/blob/main/<path_to_file>.safetensors"
) on the Hub. - A path to a local file containing the weights of the component model.
- A state dict containing the component model weights.
- A link to the
- config (
str
, optional) —- A string, the repo id (for example
CompVis/ldm-text2im-large-256
) of a pretrained pipeline hosted on the Hub. - A path to a directory (for example
./my_pipeline_directory/
) containing the pipeline component configs in Diffusers format.
- A string, the repo id (for example
- subfolder (
str
, optional, defaults to""
) — The subfolder location of a model file within a larger model repository on the Hub or locally. - original_config (
str
, optional) — Dict or path to a yaml file containing the configuration for the model in its original format. If a dict is provided, it will be used to initialize the model configuration. - torch_dtype (
str
ortorch.dtype
, optional) — Override the defaulttorch.dtype
and load the model with another dtype. If"auto"
is passed, the dtype is automatically derived from the model’s weights. - 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. - 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. - 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 to True, the model won’t be downloaded from the Hub. - token (
str
or 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. - kwargs (remaining dictionary of keyword arguments, optional) —
Can be used to overwrite load and saveable variables (for example the pipeline components of the
specific pipeline class). The overwritten components are directly passed to the pipelines
__init__
method. See example below for more information.
Instantiate a model from pretrained weights saved in the original .ckpt
or .safetensors
format. The model
is set in evaluation mode (model.eval()
) by default.