Load different Stable Diffusion formats
Last updated
Last updated
Stable Diffusion models are available in different formats depending on the framework theyโre trained and saved with, and where you download them from. Converting these formats for use in ๐ Diffusers allows you to use all the features supported by the library, such as for inference, , and a variety of techniques and methods for .
We highly recommend using the .safetensors
format because it is more secure than traditional pickled files which are vulnerable and can be exploited to execute any code on your machine (learn more in the guide).
This guide will show you how to convert other Stable Diffusion formats to be compatible with ๐ Diffusers.
The checkpoint - or .ckpt
- format is commonly used to store and save models. The .ckpt
file contains the entire model and is typically several GBs in size. While you can load and use a .ckpt
file directly with the method, it is generally better to convert the .ckpt
file to ๐ Diffusers so both formats are available.
There are two options for converting a .ckpt
file; use a Space to convert the checkpoint or convert the .ckpt
file with a script.
The easiest and most convenient way to convert a .ckpt
file is to use the Space. You can follow the instructions on the Space to convert the .ckpt
file.
This approach works well for basic models, but it may struggle with more customized models. Youโll know the Space failed if it returns an empty pull request or error. In this case, you can try converting the .ckpt
file with a script.
๐ Diffusers provides a for converting .ckpt
files. This approach is more reliable than the Space above.
Before you start, make sure you have a local clone of ๐ Diffusers to run the script and log in to your BOINC AI account so you can open pull requests and push your converted model to the Hub.
Copied
To use the script:
Copied
Open a pull request on the repository where youโre converting the checkpoint from:
Copied
There are several input arguments to configure in the conversion script, but the most important ones are:
checkpoint_path
: the path to the .ckpt
file to convert.
original_config_file
: a YAML file defining the configuration of the original architecture. If you canโt find this file, try searching for the YAML file in the GitHub repository where you found the .ckpt
file.
dump_path
: the path to the converted model.
Now you can run the script to convert the .ckpt
file:
Copied
Copied
๐งช This is an experimental feature. Only Stable Diffusion v1 checkpoints are supported by the Convert KerasCV Space at the moment.
The Convert KerasCV Space allows you to input the following:
Your BOINC AI token.
Paths to download the UNet and text encoder weights from. Depending on how the model was trained, you donโt necessarily need to provide the paths to both the UNet and text encoder. For example, Textual Inversion only requires the embeddings from the text encoder and a text-to-image model only requires the UNet weights.
Placeholder token is only applicable for textual inversion models.
The output_repo_prefix
is the name of the repository where the converted model is stored.
Click the Submit button to automatically convert the KerasCV checkpoint! Once the checkpoint is successfully converted, youโll see a link to the new repository containing the converted checkpoint. Follow the link to the new repository, and youโll see the Convert KerasCV Space generated a model card with an inference widget to try out the converted model.
If you prefer to run inference with code, click on the Use in Diffusers button in the upper right corner of the model card to copy and paste the code snippet:
Copied
Then you can generate an image like:
Copied
Copied
Copied
Copied
Now you can use the pipeline to generate images:
Copied
Display the images:
Copied
Git clone the repository containing the .ckpt
file you want to convert. For this example, letโs convert this .ckpt
file:
For example, you can take the cldm_v15.yaml
file from the repository because the TemporalNet model is a Stable Diffusion v1.5 and ControlNet model.
Once the conversion is done, upload your converted model and test out the resulting !
supports training for v1 and v2. However, it offers limited support for experimenting with Stable Diffusion models for inference and deployment whereas ๐ Diffusers has a more complete set of features for this purpose, such as different , , and .
The Space converts .pb
or .h5
files to PyTorch, and then wraps them in a so it is ready for inference. The converted checkpoint is stored in a repository on the BOINC AI Hub.
For this example, letโs convert the checkpoint which was trained with Textual Inversion. It uses the special token <my-funny-cat>
to personalize images with cats.
(A1111) is a popular web UI for Stable Diffusion that supports model sharing platforms like . Models trained with the Low-Rank Adaptation (LoRA) technique are especially popular because theyโre fast to train and have a much smaller file size than a fully finetuned model. ๐ Diffusers supports loading A1111 LoRA checkpoints with :
Download a LoRA checkpoint from Civitai; this example uses the checkpoint, but feel free to try out any LoRA checkpoint!
Load the LoRA checkpoint into the pipeline with the method: