Skip to content

Commit c07fa50

Browse files
committed
feedback
1 parent 06011e6 commit c07fa50

File tree

2 files changed

+51
-45
lines changed

2 files changed

+51
-45
lines changed

docs/source/en/using-diffusers/other-formats.md

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ specific language governing permissions and limitations under the License.
1717
Diffusion models are typically stored in the Diffusers format or single-file format. Model files can be stored in various file types such as safetensors, dduf, or ckpt.
1818

1919
> [!TIP]
20-
> Format refers to the directory structure and file refers to the file type.
20+
> Format refers to whether the weights are stored in a directory structure and file refers to the file type.
2121
2222
This guide will show you how to load pipelines and models from these formats and files.
2323

@@ -41,59 +41,53 @@ Use [`~loaders.FromSingleFileMixin.from_single_file`] to load a single file.
4141

4242
```py
4343
import torch
44-
from diffusers import DiffusionPipeline
44+
from diffusers import StableDiffusionXLPipeline
4545

46-
pipeline = DiffusionPipeline.from_single_file(
46+
pipeline = StableDiffusionXLPipeline.from_single_file(
4747
"https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/sd_xl_base_1.0.safetensors",
4848
torch_dtype=torch.float16,
49-
device_map="cuda"
5049
)
5150
```
5251

5352
The [`~loaders.FromSingleFileMixin.from_single_file`] method also supports passing new models or schedulers.
5453

5554
```py
5655
import torch
57-
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
56+
from diffusers import FluxPipeline, FluxTransformer2DModel
5857

59-
scheduler = DPMSolverMultistepScheduler()
60-
pipeline = DiffusionPipeline.from_single_file(
61-
"https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/sd_xl_base_1.0.safetensors",
62-
scheduler=scheduler,
63-
torch_dtype=torch.float16,
64-
device_map="cuda"
58+
transformer = FluxTransformer2DModel.from_single_file(
59+
"https://huggingface.co/Kijai/flux-fp8/blob/main/flux1-dev-fp8.safetensors", torch_dtype=torch.bfloat16
60+
)
61+
pipeline = FluxPipeline.from_single_file(
62+
"black-forest-labs/FLUX.1-dev",
63+
transformer=transformer,
64+
torch_dtype=torch.bfloat16,
6565
)
6666
```
6767

6868
### Configuration options
6969

70-
Models have a `config.json` file in their repositories with important attributes such as the number of layers and attention heads. The [`~loaders.FromSingleFileMixin.from_single_file`] method automatically determines the appropriate config to use from `config.json`.
70+
Diffusers format models have a `config.json` file in their repositories with important attributes such as the number of layers and attention heads. The [`~loaders.FromSingleFileMixin.from_single_file`] method automatically determines the appropriate config to use from `config.json`. This may fail in a few rare instances though, in which case, you should use the `config` argument.
7171

72-
But if the models in a pipeline are different from the original implementation or if it doesn't have to necessary metadata to determine the correct config, then you need to use the `config` argument.
72+
You should also use the `config` argument if the models in a pipeline are different from the original implementation or if it doesn't have the necessary metadata to determine the correct config.
7373

7474
```py
75-
from diffusers import QwenImagePipeline
75+
from diffusers import StableDiffusionXLPipeline
7676

77-
ckpt_path = "https://huggingface.co/lightx2v/Qwen-Image-Lightning/blob/main/Qwen-Image-Lightning-8steps-V1.1-bf16.safetensors"
77+
ckpt_path = "https://huggingface.co/segmind/SSD-1B/blob/main/SSD-1B.safetensors"
7878

79-
pipeline = QwenImagePipeline.from_single_file(
80-
ckpt_path,
81-
config="lightx2v/Qwen-Image-Lightning"
82-
)
79+
pipeline = StableDiffusionXLPipeline.from_single_file(ckpt_path, config="segmind/SSD-1B")
8380
```
8481

8582
You could also load a config file not stored on the Hub by passing a local path or URL of the config file to the `original_config` argument.
8683

8784
```py
88-
from diffusers import WanPipeline
85+
from diffusers import StableDiffusionXLPipeline
8986

90-
ckpt_path = "https://huggingface.co/lightx2v/Qwen-Image-Lightning/blob/main/Qwen-Image-Lightning-8steps-V1.1-bf16.safetensors"
91-
original_config = "https://raw.githubusercontent.com/Wan-Video/Wan2.2/refs/heads/main/wan/configs/wan_ti2v_5B.py"
87+
ckpt_path = "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/sd_xl_base_1.0_0.9vae.safetensors"
88+
original_config = "https://raw.githubusercontent.com/Stability-AI/generative-models/main/configs/inference/sd_xl_base.yaml"
9289

93-
pipeline = WanPipeline.from_single_file(
94-
ckpt_path,
95-
original_config=original_config
96-
)
90+
pipeline = StableDiffusionXLPipeline.from_single_file(ckpt_path, original_config=original_config)
9791
```
9892

9993
Diffusers attempts to infer the pipeline components based on the signature types of the pipeline class when using `original_config` with `local_files_only=True`. It won't download the config files from a Hub repository to avoid backward breaking changes when you can't connect to the internet. This method isn't as reliable as providing a path to a local model with the `config` argument and may lead to errors. You should run the pipeline with `local_files_only=False` to download the config files to the local cache to avoid errors.
@@ -124,19 +118,19 @@ If you're working with local files, download the config files with the [`~huggin
124118

125119
```py
126120
from huggingface_hub import hf_hub_download, snapshot_download
127-
from diffusers import QwenImagePipeline
121+
from diffusers import StableDiffusionXLPipeline
128122

129123
my_local_checkpoint_path = hf_hub_download(
130-
repo_id="lightx2v/Qwen-Image-Lightning",
131-
filename="Qwen-Image-Lightning-8steps-V1.1-bf16.safetensors"
124+
repo_id="segmind/SSD-1B",
125+
filename="SSD-1B.safetensors"
132126
)
133127

134128
my_local_config_path = snapshot_download(
135-
repo_id="lightx2v/Qwen-Image-Lightning",
129+
repo_id="segmind/SSD-1B",
136130
allow_patterns=["*.json", "**/*.json", "*.txt", "**/*.txt"]
137131
)
138132

139-
pipeline = QwenImagePipeline.from_single_file(
133+
pipeline = StableDiffusionXLPipeline.from_single_file(
140134
my_local_checkpoint_path, config=my_local_config_path, local_files_only=True
141135
)
142136
```
@@ -147,18 +141,19 @@ If you're working with a file system that does not support symlinking, download
147141

148142
```py
149143
from huggingface_hub import hf_hub_download, snapshot_download
144+
from diffusers import StableDiffusionXLPipeline
150145

151146
my_local_checkpoint_path = hf_hub_download(
152-
repo_id="lightx2v/Qwen-Image-Lightning",
153-
filename="Qwen-Image-Lightning-8steps-V1.1-bf16.safetensors",
147+
repo_id="segmind/SSD-1B",
148+
filename="SSD-1B.safetensors"
154149
local_dir="my_local_checkpoints",
155-
local_dir_use_symlinks=False,
150+
local_dir_use_symlinks=False
156151
)
157152
print("My local checkpoint: ", my_local_checkpoint_path)
158153

159154
my_local_config_path = snapshot_download(
160-
repo_id="lightx2v/Qwen-Image-Lightning",
161-
allow_patterns=["*.json", "**/*.json", "*.txt", "**/*.txt"],
155+
repo_id="segmind/SSD-1B",
156+
allow_patterns=["*.json", "**/*.json", "*.txt", "**/*.txt"]
162157
local_dir_use_symlinks=False,
163158
)
164159
print("My local config: ", my_local_config_path)
@@ -167,9 +162,7 @@ print("My local config: ", my_local_config_path)
167162
Pass these paths to [`~loaders.FromSingleFileMixin.from_single_file`].
168163

169164
```py
170-
from diffusers import QwenImagePipeline
171-
172-
pipeline = QwenImagePipeline.from_single_file(
165+
pipeline = StableDiffusionXLPipeline.from_single_file(
173166
my_local_checkpoint_path, config=my_local_config_path, local_files_only=True
174167
)
175168
```
@@ -182,7 +175,7 @@ Models can be stored in several file types. Safetensors is the most common file
182175

183176
[Safetensors](https://hf.co/docs/safetensors) is a safe and fast file type for securely storing and loading tensors. It restricts the header size to limit certain types of attacks, supports lazy loading (useful for distributed setups), and generally loads faster.
184177

185-
Diffusers loads safetensors file by default if they are available and the Safetensors library is installed.
178+
Diffusers loads safetensors file by default (a required dependency) if they are available and the Safetensors library is installed.
186179

187180
Use [`~DiffusionPipeline.from_pretrained`] or [`~loaders.FromSingleFileMixin.from_single_file`] to load safetensor files.
188181

@@ -199,13 +192,12 @@ pipeline = DiffusionPipeline.from_pretrained(
199192
pipeline = DiffusionPipeline.from_single_file(
200193
"https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/sd_xl_base_1.0.safetensors",
201194
torch_dtype=torch.float16,
202-
device_map="cuda"
203195
)
204196
```
205197

206-
If you're using a checkpoint trained with a Diffusers training script, metadata such as the LoRA configuration, is automatically saved. When the file is loaded, the metadata is parsed to correctly configure the LoRA and avoid missing or incorrect LoRA configs. Inspect the metadata of a safetensors file by clicking on the <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/safetensors/logo.png" alt="safetensors logo" height="15em" style="vertical-align: middle;"> logo next to the file on the Hub.
198+
If you're using a checkpoint trained with a Diffusers training script, metadata such as the LoRA configuration, is automatically saved. When the file is loaded, the metadata is parsed to correctly configure the LoRA and avoid missing or incorrect LoRA configs. Inspect the metadata of a safetensors file by clicking on the <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/safetensors/logo.png" alt="safetensors logo" style="vertical-align: middle; display: inline-block; max-height: 0.8em; max-width: 0.8em; margin: 0; padding: 0; line-height: 1;"> logo next to the file on the Hub.
207199

208-
Save the metadata for LoRAs that aren't trained with Diffusers with the `transformer_lora_adapter_metadata` and `text_encoder_lora_adapter_metadata` arguments in [`~loaders.FluxLoraLoaderMixin.save_lora_weights`]. This is only supported for safetensors files.
200+
Save the metadata for LoRAs that aren't trained with Diffusers with either `transformer_lora_adapter_metadata` or `unet_lora_adapter_metadata` depending on your model. For the text encoder, use the `text_encoder_lora_adapter_metadata` and `text_encoder_2_lora_adapter_metadata` arguments in [`~loaders.FluxLoraLoaderMixin.save_lora_weights`]. This is only supported for safetensors files.
209201

210202
```py
211203
import torch
@@ -216,8 +208,8 @@ pipeline = FluxPipeline.from_pretrained(
216208
).to("cuda")
217209
pipeline.load_lora_weights("linoyts/yarn_art_Flux_LoRA")
218210
pipeline.save_lora_weights(
219-
transformer_lora_adapter_metadata={"r": 16, "lora_alpha": 16},
220-
text_encoder_lora_adapter_metadata={"r": 8, "lora_alpha": 8}
211+
text_encoder_lora_adapter_metadata={"r": 8, "lora_alpha": 8},
212+
text_encoder_2_lora_adapter_metadata={"r": 8, "lora_alpha": 8}
221213
)
222214
```
223215

src/diffusers/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,13 @@
330330
]
331331
)
332332
_import_structure["training_utils"] = ["EMAModel"]
333+
_import_structure["image_processor"] = [
334+
"VaeImageProcessor",
335+
"VaeImageProcessorLDM3D",
336+
"PixArtImageProcessor",
337+
"IPAdapterMaskProcessor",
338+
]
339+
_import_structure["video_processor"] = ["VideoProcessor"]
333340

334341
try:
335342
if not (is_torch_available() and is_scipy_available()):
@@ -990,6 +997,13 @@
990997
VQDiffusionScheduler,
991998
)
992999
from .training_utils import EMAModel
1000+
from .image_processor import (
1001+
VaeImageProcessor,
1002+
VaeImageProcessorLDM3D,
1003+
PixArtImageProcessor,
1004+
IPAdapterMaskProcessor,
1005+
)
1006+
from .video_processor import VideoProcessor
9931007

9941008
try:
9951009
if not (is_torch_available() and is_scipy_available()):

0 commit comments

Comments
 (0)