Skip to content

Commit b28f3eb

Browse files
committed
feedback
1 parent 67b53e3 commit b28f3eb

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

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

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,26 @@ pipeline = QwenImagePipeline.from_pretrained(
5454

5555
### Local pipelines
5656

57-
Pipelines can also be run locally. Download a checkpoint to your setup with [git-lfs](https://git-lfs.github.com/).
57+
Pipelines can also be run locally. Use [`~huggingface_hub.snapshot_download`] to download a model repository.
5858

59-
```bash
60-
git-lfs install
61-
git clone https://huggingface.co/Qwen/Qwen-Image
59+
```py
60+
from huggingface_hub import snapshot_download
61+
62+
snapshot_download(repo_id="Qwen/Qwen-Image")
6263
```
6364

64-
The model is downloaded to a local folder. Pass the folder path to [`~QwenImagePipeline.from_pretrained`] to load it.
65+
The model is downloaded to your [cache](../installation#cache). Pass the folder path to [`~QwenImagePipeline.from_pretrained`] to load it.
6566

6667
```py
6768
import torch
6869
from diffusers import QwenImagePipeline
6970

7071
pipeline = QwenImagePipeline.from_pretrained(
71-
"path/to/local/Qwen/Qwen-Image", torch_dtype=torch.bfloat16, device_map="cuda"
72+
"path/to/your/cache", torch_dtype=torch.bfloat16, device_map="cuda"
7273
)
7374
```
7475

75-
The [`~QwenImagePipeline.from_pretrained`] method won't download files from the Hub when it detects a local path. But this also means it won't download and cache any updates that have been made to the model.
76+
The [`~QwenImagePipeline.from_pretrained`] method won't download files from the Hub when it detects a local path. But this also means it won't download and cache any updates that have been made to the model either.
7677

7778
## Pipeline data types
7879

@@ -82,10 +83,10 @@ Pass the data type for each model as a dictionary to `torch_dtype`. Use the `def
8283

8384
```py
8485
import torch
85-
from diffusers import HunyuanVideoPipeline
86+
from diffusers import QwenImagePipeline
8687

87-
pipeline = HunyuanVideoPipeline.from_pretrained(
88-
"hunyuanvideo-community/HunyuanVideo",
88+
pipeline = QwenImagePipeline.from_pretrained(
89+
"Qwen/Qwen-Image",
8990
torch_dtype={"transformer": torch.bfloat16, "default": torch.float16},
9091
)
9192
print(pipeline.transformer.dtype, pipeline.vae.dtype)
@@ -95,10 +96,10 @@ You don't need to use a dictionary if you're loading all the models in the same
9596

9697
```py
9798
import torch
98-
from diffusers import HunyuanVideoPipeline
99+
from diffusers import QwenImagePipeline
99100

100-
pipeline = HunyuanVideoPipeline.from_pretrained(
101-
"hunyuanvideo-community/HunyuanVideo", torch_dtype=torch.bfloat16
101+
pipeline = QwenImagePipeline.from_pretrained(
102+
"Qwen/Qwen-Image", torch_dtype=torch.bfloat16
102103
)
103104
print(pipeline.transformer.dtype, pipeline.vae.dtype)
104105
```
@@ -111,9 +112,9 @@ Diffusers currently provides three options to `device_map`, `"cuda"`, `"balanced
111112

112113
| parameter | description |
113114
|---|---|
114-
| `"cuda"` | places model on CUDA device |
115+
| `"cuda"` | places model or pipeline on CUDA device |
115116
| `"balanced"` | evenly distributes model or pipeline on all GPUs |
116-
| `"auto"` | distribute model or pipeline from fastest device first to slowest |
117+
| `"auto"` | distribute model from fastest device first to slowest |
117118

118119
Use the `max_memory` argument in [`~DiffusionPipeline.from_pretrained`] to allocate a maximum amount of memory to use on each device. By default, Diffusers uses the maximum amount available.
119120

@@ -125,7 +126,7 @@ import torch
125126
from diffusers import DiffusionPipeline
126127

127128
pipeline = DiffusionPipeline.from_pretrained(
128-
"black-forest-labs/FLUX.1-dev",
129+
"Qwen/Qwen-Image",
129130
torch_dtype=torch.bfloat16,
130131
device_map="cuda",
131132
)
@@ -136,11 +137,11 @@ pipeline = DiffusionPipeline.from_pretrained(
136137

137138
```py
138139
import torch
139-
from diffusers import DiffusionPipeline, AutoModel
140+
from diffusers import AutoModel
140141

141142
max_memory = {0: "16GB", 1: "16GB"}
142143
transformer = AutoModel.from_pretrained(
143-
"black-forest-labs/FLUX.1-dev",
144+
"Qwen/Qwen-Image",
144145
subfolder="transformer",
145146
torch_dtype=torch.bfloat16
146147
device_map="cuda",
@@ -168,10 +169,7 @@ pipeline.reset_device_map()
168169

169170
Large models are often [sharded](../training/distributed_inference#model-sharding) into smaller files so that they are easier to load. Diffusers supports loading shards in parallel to speed up the loading process.
170171

171-
Set the environment variables below to enable parallel loading.
172-
173-
- Set `HF_ENABLE_PARALLEL_LOADING` to `"YES"` to enable parallel loading of shards.
174-
- Set `HF_PARALLEL_LOADING_WORKERS` to configure the number of parallel threads to use when loading shards. More workers loads a model faster but uses more memory.
172+
Set `HF_ENABLE_PARALLEL_LOADING` to `"YES"` to enable parallel loading of shards.
175173

176174
The `device_map` argument should be set to `"cuda"` to pre-allocate a large chunk of memory based on the model size. This substantially reduces model load time because warming up the memory allocator now avoids many smaller calls to the allocator later.
177175

@@ -222,7 +220,7 @@ Memory usage is determined by the pipeline with the highest memory requirement r
222220
The example below loads a pipeline and then loads a second pipeline with [`~DiffusionPipeline.from_pipe`] to use [perturbed-attention guidance (PAG)](../api/pipelines/pag) to improve generation quality.
223221

224222
> [!WARNING]
225-
> Use [`AutoPipelineForText2Image`] instead because [`DiffusionPipeline`] doesn't support PAG. Refer to the [AutoPipeline](../tutorials/autopipeline) docs to learn more.
223+
> Use [`AutoPipelineForText2Image`] because [`DiffusionPipeline`] doesn't support PAG. Refer to the [AutoPipeline](../tutorials/autopipeline) docs to learn more.
226224
227225
```py
228226
import torch
@@ -264,7 +262,7 @@ Some methods may not work correctly on pipelines created with [`~DiffusionPipeli
264262

265263
Diffusers provides a [safety checker](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/safety_checker.py) for older Stable Diffusion models to prevent generating harmful content. It screens the generated output against a set of hardcoded harmful concepts.
266264

267-
If you want to disable the safety checker, pass `safety_checker=None` in [`!DiffusionPipeline.from_pretrained`] as shown below.
265+
If you want to disable the safety checker, pass `safety_checker=None` in [`~DiffusionPipeline.from_pretrained`] as shown below.
268266

269267
```py
270268
from diffusers import DiffusionPipeline

0 commit comments

Comments
 (0)