|
22 | 22 |
|
23 | 23 | class FromOriginalVAEMixin: |
24 | 24 | """ |
25 | | - Load pretrained ControlNet weights saved in the `.ckpt` or `.safetensors` format into a [`ControlNetModel`]. |
| 25 | + Load pretrained AutoencoderKL weights saved in the `.ckpt` or `.safetensors` format into a [`ControlNetModel`]. |
26 | 26 | """ |
27 | 27 |
|
28 | 28 | @classmethod |
29 | 29 | @validate_hf_hub_args |
30 | 30 | def from_single_file(cls, pretrained_model_link_or_path, **kwargs): |
31 | 31 | r""" |
32 | | - Instantiate a [`ControlNetModel`] from pretrained ControlNet weights saved in the original `.ckpt` or |
| 32 | + Instantiate a [`AutoencoderKL`] from pretrained ControlNet weights saved in the original `.ckpt` or |
33 | 33 | `.safetensors` format. The pipeline is set in evaluation mode (`model.eval()`) by default. |
34 | 34 |
|
35 | 35 | Parameters: |
@@ -62,32 +62,35 @@ def from_single_file(cls, pretrained_model_link_or_path, **kwargs): |
62 | 62 | revision (`str`, *optional*, defaults to `"main"`): |
63 | 63 | The specific model version to use. It can be a branch name, a tag name, a commit id, or any identifier |
64 | 64 | allowed by Git. |
| 65 | + image_size (`int`, *optional*, defaults to 512): |
| 66 | + The image size the model was trained on. Use 512 for all Stable Diffusion v1 models and the Stable |
| 67 | + Diffusion v2 base model. Use 768 for Stable Diffusion v2. |
65 | 68 | use_safetensors (`bool`, *optional*, defaults to `None`): |
66 | 69 | If set to `None`, the safetensors weights are downloaded if they're available **and** if the |
67 | 70 | safetensors library is installed. If set to `True`, the model is forcibly loaded from safetensors |
68 | 71 | weights. If set to `False`, safetensors weights are not loaded. |
69 | | - image_size (`int`, *optional*, defaults to 512): |
70 | | - The image size the model was trained on. Use 512 for all Stable Diffusion v1 models and the Stable |
71 | | - Diffusion v2 base model. Use 768 for Stable Diffusion v2. |
72 | | - upcast_attention (`bool`, *optional*, defaults to `None`): |
73 | | - Whether the attention computation should always be upcasted. |
74 | 72 | kwargs (remaining dictionary of keyword arguments, *optional*): |
75 | 73 | Can be used to overwrite load and saveable variables (for example the pipeline components of the |
76 | 74 | specific pipeline class). The overwritten components are directly passed to the pipelines `__init__` |
77 | 75 | method. See example below for more information. |
78 | 76 |
|
| 77 | + <Tip warning={true}> |
| 78 | +
|
| 79 | + Make sure to pass both `image_size` and `scaling_factor` to `from_single_file()` if you're loading |
| 80 | + a VAE from SDXL or a Stable Diffusion v2 model or higher. |
| 81 | +
|
| 82 | + </Tip> |
| 83 | +
|
79 | 84 | Examples: |
80 | 85 |
|
81 | 86 | ```py |
82 | | - from diffusers import StableDiffusionControlNetPipeline, ControlNetModel |
| 87 | + from diffusers import AutoencoderKL |
83 | 88 |
|
84 | | - url = "https://huggingface.co/lllyasviel/ControlNet-v1-1/blob/main/control_v11p_sd15_canny.pth" # can also be a local path |
85 | | - model = ControlNetModel.from_single_file(url) |
86 | | -
|
87 | | - url = "https://huggingface.co/runwayml/stable-diffusion-v1-5/blob/main/v1-5-pruned.safetensors" # can also be a local path |
88 | | - pipe = StableDiffusionControlNetPipeline.from_single_file(url, controlnet=controlnet) |
| 89 | + url = "https://huggingface.co/stabilityai/sd-vae-ft-mse-original/blob/main/vae-ft-mse-840000-ema-pruned.safetensors" # can also be local file |
| 90 | + model = AutoencoderKL.from_single_file(url) |
89 | 91 | ``` |
90 | 92 | """ |
| 93 | + |
91 | 94 | original_config_file = kwargs.pop("original_config_file", None) |
92 | 95 | resume_download = kwargs.pop("resume_download", False) |
93 | 96 | force_download = kwargs.pop("force_download", False) |
|
0 commit comments