Skip to content

Commit 1c3137e

Browse files
committed
config
1 parent f8f0da0 commit 1c3137e

File tree

2 files changed

+110
-1
lines changed

2 files changed

+110
-1
lines changed

docs/source/en/using-diffusers/loading.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ pipeline = QwenImagePipeline.from_pretrained(
5252
)
5353
```
5454

55+
> [!TIP]
56+
> Refer to the [Single file format](./other-formats#single-file-format) docs to learn how to load single file models.
57+
5558
### Local pipelines
5659

5760
Pipelines can also be run locally. Use [`~huggingface_hub.snapshot_download`] to download a model repository.

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

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,112 @@ pipeline = DiffusionPipeline.from_single_file(
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`.
71+
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.
73+
74+
```py
75+
from diffusers import QwenImagePipeline
76+
77+
ckpt_path = "https://huggingface.co/lightx2v/Qwen-Image-Lightning/blob/main/Qwen-Image-Lightning-8steps-V1.1-bf16.safetensors"
78+
79+
pipeline = QwenImagePipeline.from_single_file(
80+
ckpt_path,
81+
config="lightx2v/Qwen-Image-Lightning"
82+
)
83+
```
84+
85+
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.
86+
87+
```py
88+
from diffusers import WanPipeline
89+
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"
92+
93+
pipeline = WanPipeline.from_single_file(
94+
ckpt_path,
95+
original_config=original_config
96+
)
97+
```
98+
99+
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.
100+
101+
Override default configs by passing the arguments directly to [`~loaders.FromSingleFileMixin.from_single_file`]. The examples below demonstrate how to override the configs in a pipeline or model.
102+
103+
```py
104+
from diffusers import StableDiffusionXLInstructPix2PixPipeline
105+
106+
ckpt_path = "https://huggingface.co/stabilityai/cosxl/blob/main/cosxl_edit.safetensors"
107+
pipeline = StableDiffusionXLInstructPix2PixPipeline.from_single_file(
108+
ckpt_path, config="diffusers/sdxl-instructpix2pix-768", is_cosxl_edit=True
109+
)
110+
```
111+
112+
```py
113+
from diffusers import UNet2DConditionModel
114+
115+
ckpt_path = "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/sd_xl_base_1.0_0.9vae.safetensors"
116+
model = UNet2DConditionModel.from_single_file(ckpt_path, upcast_attention=True)
117+
```
118+
119+
### Local files
120+
121+
The [`~loaders.FromSingleFileMixin.from_single_file`] method attempts to configure a pipeline or model by inferring the model type from the keys in the checkpoint file. For example, any single file checkpoint based on the Stable Diffusion XL base model is configured from [stabilityai/stable-diffusion-xl-base-1.0](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0).
122+
123+
If you're working with local files, download the config files with the [`~huggingface_hub.snapshot_download`] method and the model checkpoint with [`~huggingface_hub.hf_hub_download`]. These files are downloaded to your [cache directory](https://huggingface.co/docs/huggingface_hub/en/guides/manage-cache), but you can download them to a specific directory with the `local_dir` argument.
124+
125+
```py
126+
from huggingface_hub import hf_hub_download, snapshot_download
127+
from diffusers import QwenImagePipeline
128+
129+
my_local_checkpoint_path = hf_hub_download(
130+
repo_id="lightx2v/Qwen-Image-Lightning",
131+
filename="Qwen-Image-Lightning-8steps-V1.1-bf16.safetensors"
132+
)
133+
134+
my_local_config_path = snapshot_download(
135+
repo_id="lightx2v/Qwen-Image-Lightning",
136+
allow_patterns=["*.json", "**/*.json", "*.txt", "**/*.txt"]
137+
)
138+
139+
pipeline = QwenImagePipeline.from_single_file(
140+
my_local_checkpoint_path, config=my_local_config_path, local_files_only=True
141+
)
142+
```
143+
144+
### Symlink
145+
146+
If you're working with a file system that does not support symlinking, download the checkpoint file to a local directory first. Disable symlinking with `local_dir_use_symlink=False` in [`~huggingface_hub.snapshot_download`] and [`~huggingface_hub.hf_hub_download`].
147+
148+
```py
149+
from huggingface_hub import hf_hub_download, snapshot_download
150+
151+
my_local_checkpoint_path = hf_hub_download(
152+
repo_id="lightx2v/Qwen-Image-Lightning",
153+
filename="Qwen-Image-Lightning-8steps-V1.1-bf16.safetensors",
154+
local_dir="my_local_checkpoints",
155+
local_dir_use_symlinks=False,
156+
)
157+
print("My local checkpoint: ", my_local_checkpoint_path)
158+
159+
my_local_config_path = snapshot_download(
160+
repo_id="lightx2v/Qwen-Image-Lightning",
161+
allow_patterns=["*.json", "**/*.json", "*.txt", "**/*.txt"],
162+
local_dir_use_symlinks=False,
163+
)
164+
print("My local config: ", my_local_config_path)
165+
```
166+
167+
Pass these paths to [`~loaders.FromSingleFileMixin.from_single_file`].
168+
169+
```py
170+
from diffusers import QwenImagePipeline
171+
172+
pipeline = QwenImagePipeline.from_single_file(
173+
my_local_checkpoint_path, config=my_local_config_path, local_files_only=True
174+
)
175+
```
70176

71177
## File types
72178

@@ -115,7 +221,7 @@ pipeline = DiffusionPipeline.from_single_file(
115221

116222
### dduf
117223

118-
> [~TIP]
224+
> [!TIP]
119225
> DDUF is an experimental file type and the API may change. Refer to the DDUF [docs](https://huggingface.co/docs/hub/dduf) to learn more.
120226
121227
DDUF is a file type designed to unify different diffusion model distribution methods and weight-saving formats. It is a standardized and flexible method to package all components of a diffusion model into a single file, providing a balance between the Diffusers and single-file formats.

0 commit comments

Comments
 (0)