Skip to content

Commit a032025

Browse files
committed
Merge branch 'dduf' of github.com:huggingface/diffusers into dduf
2 parents f3a4ddc + 15d4569 commit a032025

File tree

124 files changed

+1098
-281
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+1098
-281
lines changed

.github/workflows/nightly_tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ jobs:
359359
test_location: "bnb"
360360
- backend: "gguf"
361361
test_location: "gguf"
362+
- backend: "torchao"
363+
test_location: "torchao"
362364
runs-on:
363365
group: aws-g6e-xlarge-plus
364366
container:

.github/workflows/pypi_publish.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
- name: Test installing diffusers and importing
6969
run: |
7070
pip install diffusers && pip uninstall diffusers -y
71-
pip install -i https://testpypi.python.org/pypi diffusers
71+
pip install -i https://test.pypi.org/simple/ diffusers
7272
python -c "from diffusers import __version__; print(__version__)"
7373
python -c "from diffusers import DiffusionPipeline; pipe = DiffusionPipeline.from_pretrained('fusing/unet-ldm-dummy-update'); pipe()"
7474
python -c "from diffusers import DiffusionPipeline; pipe = DiffusionPipeline.from_pretrained('hf-internal-testing/tiny-stable-diffusion-pipe', safety_checker=None); pipe('ah suh du')"

docs/source/en/api/pipelines/hunyuan_video.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
<Tip>
2222

23-
Make sure to check out the Schedulers [guide](../../using-diffusers/schedulers.md) to learn how to explore the tradeoff between scheduler speed and quality, and see the [reuse components across pipelines](../../using-diffusers/loading.md#reuse-a-pipeline) section to learn how to efficiently load the same components into multiple pipelines.
23+
Make sure to check out the Schedulers [guide](https://huggingface.co/docs/diffusers/main/en/using-diffusers/schedulers) to learn how to explore the tradeoff between scheduler speed and quality, and see the [reuse components across pipelines](https://huggingface.co/docs/diffusers/main/en/using-diffusers/loading#reuse-a-pipeline) section to learn how to efficiently load the same components into multiple pipelines.
2424

2525
</Tip>
2626

docs/source/en/api/pipelines/hunyuandit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ HunyuanDiT has the following components:
3030

3131
<Tip>
3232

33-
Make sure to check out the Schedulers [guide](../../using-diffusers/schedulers.md) to learn how to explore the tradeoff between scheduler speed and quality, and see the [reuse components across pipelines](../../using-diffusers/loading.md#reuse-a-pipeline) section to learn how to efficiently load the same components into multiple pipelines.
33+
Make sure to check out the Schedulers [guide](https://huggingface.co/docs/diffusers/main/en/using-diffusers/schedulers) to learn how to explore the tradeoff between scheduler speed and quality, and see the [reuse components across pipelines](https://huggingface.co/docs/diffusers/main/en/using-diffusers/loading#reuse-a-pipeline) section to learn how to efficiently load the same components into multiple pipelines.
3434

3535
</Tip>
3636

docs/source/en/community_projects.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,8 @@ Happy exploring, and thank you for being part of the Diffusers community!
7979
<td><a href="https://github.com/Netwrck/stable-diffusion-server"> Stable Diffusion Server </a></td>
8080
<td>A server configured for Inpainting/Generation/img2img with one stable diffusion model</td>
8181
</tr>
82+
<tr style="border-top: 2px solid black">
83+
<td><a href="https://github.com/suzukimain/auto_diffusers"> Model Search </a></td>
84+
<td>Search models on Civitai and Hugging Face</td>
85+
</tr>
8286
</table>

docs/source/en/quantization/torchao.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Quantize a model by passing [`TorchAoConfig`] to [`~ModelMixin.from_pretrained`]
2525
The example below only quantizes the weights to int8.
2626

2727
```python
28+
import torch
2829
from diffusers import FluxPipeline, FluxTransformer2DModel, TorchAoConfig
2930

3031
model_id = "black-forest-labs/FLUX.1-dev"
@@ -44,6 +45,10 @@ pipe = FluxPipeline.from_pretrained(
4445
)
4546
pipe.to("cuda")
4647

48+
# Without quantization: ~31.447 GB
49+
# With quantization: ~20.40 GB
50+
print(f"Pipeline memory usage: {torch.cuda.max_memory_reserved() / 1024**3:.3f} GB")
51+
4752
prompt = "A cat holding a sign that says hello world"
4853
image = pipe(
4954
prompt, num_inference_steps=50, guidance_scale=4.5, max_sequence_length=512
@@ -88,6 +93,63 @@ Some quantization methods are aliases (for example, `int8wo` is the commonly use
8893

8994
Refer to the official torchao documentation for a better understanding of the available quantization methods and the exhaustive list of configuration options available.
9095

96+
## Serializing and Deserializing quantized models
97+
98+
To serialize a quantized model in a given dtype, first load the model with the desired quantization dtype and then save it using the [`~ModelMixin.save_pretrained`] method.
99+
100+
```python
101+
import torch
102+
from diffusers import FluxTransformer2DModel, TorchAoConfig
103+
104+
quantization_config = TorchAoConfig("int8wo")
105+
transformer = FluxTransformer2DModel.from_pretrained(
106+
"black-forest-labs/Flux.1-Dev",
107+
subfolder="transformer",
108+
quantization_config=quantization_config,
109+
torch_dtype=torch.bfloat16,
110+
)
111+
transformer.save_pretrained("/path/to/flux_int8wo", safe_serialization=False)
112+
```
113+
114+
To load a serialized quantized model, use the [`~ModelMixin.from_pretrained`] method.
115+
116+
```python
117+
import torch
118+
from diffusers import FluxPipeline, FluxTransformer2DModel
119+
120+
transformer = FluxTransformer2DModel.from_pretrained("/path/to/flux_int8wo", torch_dtype=torch.bfloat16, use_safetensors=False)
121+
pipe = FluxPipeline.from_pretrained("black-forest-labs/Flux.1-Dev", transformer=transformer, torch_dtype=torch.bfloat16)
122+
pipe.to("cuda")
123+
124+
prompt = "A cat holding a sign that says hello world"
125+
image = pipe(prompt, num_inference_steps=30, guidance_scale=7.0).images[0]
126+
image.save("output.png")
127+
```
128+
129+
Some quantization methods, such as `uint4wo`, cannot be loaded directly and may result in an `UnpicklingError` when trying to load the models, but work as expected when saving them. In order to work around this, one can load the state dict manually into the model. Note, however, that this requires using `weights_only=False` in `torch.load`, so it should be run only if the weights were obtained from a trustable source.
130+
131+
```python
132+
import torch
133+
from accelerate import init_empty_weights
134+
from diffusers import FluxPipeline, FluxTransformer2DModel, TorchAoConfig
135+
136+
# Serialize the model
137+
transformer = FluxTransformer2DModel.from_pretrained(
138+
"black-forest-labs/Flux.1-Dev",
139+
subfolder="transformer",
140+
quantization_config=TorchAoConfig("uint4wo"),
141+
torch_dtype=torch.bfloat16,
142+
)
143+
transformer.save_pretrained("/path/to/flux_uint4wo", safe_serialization=False, max_shard_size="50GB")
144+
# ...
145+
146+
# Load the model
147+
state_dict = torch.load("/path/to/flux_uint4wo/diffusion_pytorch_model.bin", weights_only=False, map_location="cpu")
148+
with init_empty_weights():
149+
transformer = FluxTransformer2DModel.from_config("/path/to/flux_uint4wo/config.json")
150+
transformer.load_state_dict(state_dict, strict=True, assign=True)
151+
```
152+
91153
## Resources
92154

93155
- [TorchAO Quantization API](https://github.com/pytorch/ao/blob/main/torchao/quantization/README.md)

examples/advanced_diffusion_training/train_dreambooth_lora_flux_advanced.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
import wandb
7575

7676
# Will error if the minimal version of diffusers is not installed. Remove at your own risks.
77-
check_min_version("0.32.0.dev0")
77+
check_min_version("0.33.0.dev0")
7878

7979
logger = get_logger(__name__)
8080

examples/advanced_diffusion_training/train_dreambooth_lora_sd15_advanced.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373

7474

7575
# Will error if the minimal version of diffusers is not installed. Remove at your own risks.
76-
check_min_version("0.32.0.dev0")
76+
check_min_version("0.33.0.dev0")
7777

7878
logger = get_logger(__name__)
7979

examples/advanced_diffusion_training/train_dreambooth_lora_sdxl_advanced.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
import wandb
8080

8181
# Will error if the minimal version of diffusers is not installed. Remove at your own risks.
82-
check_min_version("0.32.0.dev0")
82+
check_min_version("0.33.0.dev0")
8383

8484
logger = get_logger(__name__)
8585

examples/cogvideo/train_cogvideox_image_to_video_lora.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
import wandb
6262

6363
# Will error if the minimal version of diffusers is not installed. Remove at your own risks.
64-
check_min_version("0.32.0.dev0")
64+
check_min_version("0.33.0.dev0")
6565

6666
logger = get_logger(__name__)
6767

0 commit comments

Comments
 (0)