Skip to content

Commit 4fd6b1f

Browse files
committed
updates
2 parents 0ccb5b5 + 02c777c commit 4fd6b1f

Some content is hidden

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

45 files changed

+2020
-234
lines changed

.github/workflows/push_tests_mps.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
shell: arch -arch arm64 bash {0}
4747
run: |
4848
${CONDA_RUN} python -m pip install --upgrade pip uv
49-
${CONDA_RUN} python -m uv pip install -e [quality,test]
49+
${CONDA_RUN} python -m uv pip install -e ".[quality,test]"
5050
${CONDA_RUN} python -m uv pip install torch torchvision torchaudio
5151
${CONDA_RUN} python -m uv pip install accelerate@git+https://github.com/huggingface/accelerate.git
5252
${CONDA_RUN} python -m uv pip install transformers --upgrade

docs/source/en/api/models/autoencoder_kl_hunyuan_video.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The model can be loaded with the following code snippet.
1818
```python
1919
from diffusers import AutoencoderKLHunyuanVideo
2020

21-
vae = AutoencoderKLHunyuanVideo.from_pretrained("tencent/HunyuanVideo", torch_dtype=torch.float16)
21+
vae = AutoencoderKLHunyuanVideo.from_pretrained("hunyuanvideo-community/HunyuanVideo", subfolder="vae", torch_dtype=torch.float16)
2222
```
2323

2424
## AutoencoderKLHunyuanVideo

docs/source/en/api/models/hunyuan_video_transformer_3d.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The model can be loaded with the following code snippet.
1818
```python
1919
from diffusers import HunyuanVideoTransformer3DModel
2020

21-
transformer = HunyuanVideoTransformer3DModel.from_pretrained("tencent/HunyuanVideo", torch_dtype=torch.bfloat16)
21+
transformer = HunyuanVideoTransformer3DModel.from_pretrained("hunyuanvideo-community/HunyuanVideo", subfolder="transformer", torch_dtype=torch.bfloat16)
2222
```
2323

2424
## HunyuanVideoTransformer3DModel

docs/source/en/api/models/sana_transformer2d.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The model can be loaded with the following code snippet.
2222
```python
2323
from diffusers import SanaTransformer2DModel
2424

25-
transformer = SanaTransformer2DModel.from_pretrained("Efficient-Large-Model/Sana_1600M_1024px_diffusers", subfolder="transformer", torch_dtype=torch.float16)
25+
transformer = SanaTransformer2DModel.from_pretrained("Efficient-Large-Model/Sana_1600M_1024px_BF16_diffusers", subfolder="transformer", torch_dtype=torch.bfloat16)
2626
```
2727

2828
## SanaTransformer2DModel

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,43 @@ images = pipe(
268268
images[0].save("flux-redux.png")
269269
```
270270

271+
## Combining Flux Turbo LoRAs with Flux Control, Fill, and Redux
272+
273+
We can combine Flux Turbo LoRAs with Flux Control and other pipelines like Fill and Redux to enable few-steps' inference. The example below shows how to do that for Flux Control LoRA for depth and turbo LoRA from [`ByteDance/Hyper-SD`](https://hf.co/ByteDance/Hyper-SD).
274+
275+
```py
276+
from diffusers import FluxControlPipeline
277+
from image_gen_aux import DepthPreprocessor
278+
from diffusers.utils import load_image
279+
from huggingface_hub import hf_hub_download
280+
import torch
281+
282+
control_pipe = FluxControlPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16)
283+
control_pipe.load_lora_weights("black-forest-labs/FLUX.1-Depth-dev-lora", adapter_name="depth")
284+
control_pipe.load_lora_weights(
285+
hf_hub_download("ByteDance/Hyper-SD", "Hyper-FLUX.1-dev-8steps-lora.safetensors"), adapter_name="hyper-sd"
286+
)
287+
control_pipe.set_adapters(["depth", "hyper-sd"], adapter_weights=[0.85, 0.125])
288+
control_pipe.enable_model_cpu_offload()
289+
290+
prompt = "A robot made of exotic candies and chocolates of different kinds. The background is filled with confetti and celebratory gifts."
291+
control_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/robot.png")
292+
293+
processor = DepthPreprocessor.from_pretrained("LiheYoung/depth-anything-large-hf")
294+
control_image = processor(control_image)[0].convert("RGB")
295+
296+
image = control_pipe(
297+
prompt=prompt,
298+
control_image=control_image,
299+
height=1024,
300+
width=1024,
301+
num_inference_steps=8,
302+
guidance_scale=10.0,
303+
generator=torch.Generator().manual_seed(42),
304+
).images[0]
305+
image.save("output.png")
306+
```
307+
271308
## Running FP16 inference
272309

273310
Flux can generate high-quality images with FP16 (i.e. to accelerate inference on Turing/Volta GPUs) but produces different outputs compared to FP32/BF16. The issue is that some activations in the text encoders have to be clipped when running in FP16, which affects the overall image. Forcing text encoders to run with FP32 inference thus removes this output difference. See [here](https://github.com/huggingface/diffusers/pull/9097#issuecomment-2272292516) for details.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Recommendations for inference:
2929
- Transformer should be in `torch.bfloat16`.
3030
- VAE should be in `torch.float16`.
3131
- `num_frames` should be of the form `4 * k + 1`, for example `49` or `129`.
32-
- For smaller resolution images, try lower values of `shift` (between `2.0` to `5.0`) in the [Scheduler](https://huggingface.co/docs/diffusers/main/en/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler.shift). For larger resolution images, try higher values (between `7.0` and `12.0`). The default value is `7.0` for HunyuanVideo.
32+
- For smaller resolution videos, try lower values of `shift` (between `2.0` to `5.0`) in the [Scheduler](https://huggingface.co/docs/diffusers/main/en/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler.shift). For larger resolution images, try higher values (between `7.0` and `12.0`). The default value is `7.0` for HunyuanVideo.
3333
- For more information about supported resolutions and other details, please refer to the original repository [here](https://github.com/Tencent/HunyuanVideo/).
3434

3535
## HunyuanVideoPipeline

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ transformer = LTXVideoTransformer3DModel.from_single_file(
7979
pipe = LTXPipeline.from_pretrained(
8080
"Lightricks/LTX-Video",
8181
transformer=transformer,
82-
generator=torch.manual_seed(0),
8382
torch_dtype=torch.bfloat16,
8483
)
8584
pipe.enable_model_cpu_offload()

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

Lines changed: 196 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414
-->
1515

16-
# Mochi
16+
# Mochi 1 Preview
1717

1818
[Mochi 1 Preview](https://huggingface.co/genmo/mochi-1-preview) from Genmo.
1919

@@ -25,6 +25,201 @@ Make sure to check out the Schedulers [guide](../../using-diffusers/schedulers.m
2525

2626
</Tip>
2727

28+
## Generating videos with Mochi-1 Preview
29+
30+
The following example will download the full precision `mochi-1-preview` weights and produce the highest quality results but will require at least 42GB VRAM to run.
31+
32+
```python
33+
import torch
34+
from diffusers import MochiPipeline
35+
from diffusers.utils import export_to_video
36+
37+
pipe = MochiPipeline.from_pretrained("genmo/mochi-1-preview")
38+
39+
# Enable memory savings
40+
pipe.enable_model_cpu_offload()
41+
pipe.enable_vae_tiling()
42+
43+
prompt = "Close-up of a chameleon's eye, with its scaly skin changing color. Ultra high resolution 4k."
44+
45+
with torch.autocast("cuda", torch.bfloat16, cache_enabled=False):
46+
frames = pipe(prompt, num_frames=85).frames[0]
47+
48+
export_to_video(frames, "mochi.mp4", fps=30)
49+
```
50+
51+
## Using a lower precision variant to save memory
52+
53+
The following example will use the `bfloat16` variant of the model and requires 22GB VRAM to run. There is a slight drop in the quality of the generated video as a result.
54+
55+
```python
56+
import torch
57+
from diffusers import MochiPipeline
58+
from diffusers.utils import export_to_video
59+
60+
pipe = MochiPipeline.from_pretrained("genmo/mochi-1-preview", variant="bf16", torch_dtype=torch.bfloat16)
61+
62+
# Enable memory savings
63+
pipe.enable_model_cpu_offload()
64+
pipe.enable_vae_tiling()
65+
66+
prompt = "Close-up of a chameleon's eye, with its scaly skin changing color. Ultra high resolution 4k."
67+
frames = pipe(prompt, num_frames=85).frames[0]
68+
69+
export_to_video(frames, "mochi.mp4", fps=30)
70+
```
71+
72+
## Reproducing the results from the Genmo Mochi repo
73+
74+
The [Genmo Mochi implementation](https://github.com/genmoai/mochi/tree/main) uses different precision values for each stage in the inference process. The text encoder and VAE use `torch.float32`, while the DiT uses `torch.bfloat16` with the [attention kernel](https://pytorch.org/docs/stable/generated/torch.nn.attention.sdpa_kernel.html#torch.nn.attention.sdpa_kernel) set to `EFFICIENT_ATTENTION`. Diffusers pipelines currently do not support setting different `dtypes` for different stages of the pipeline. In order to run inference in the same way as the the original implementation, please refer to the following example.
75+
76+
<Tip>
77+
The original Mochi implementation zeros out empty prompts. However, enabling this option and placing the entire pipeline under autocast can lead to numerical overflows with the T5 text encoder.
78+
79+
When enabling `force_zeros_for_empty_prompt`, it is recommended to run the text encoding step outside the autocast context in full precision.
80+
</Tip>
81+
82+
<Tip>
83+
Decoding the latents in full precision is very memory intensive. You will need at least 70GB VRAM to generate the 163 frames in this example. To reduce memory, either reduce the number of frames or run the decoding step in `torch.bfloat16`.
84+
</Tip>
85+
86+
```python
87+
import torch
88+
from torch.nn.attention import SDPBackend, sdpa_kernel
89+
90+
from diffusers import MochiPipeline
91+
from diffusers.utils import export_to_video
92+
from diffusers.video_processor import VideoProcessor
93+
94+
pipe = MochiPipeline.from_pretrained("genmo/mochi-1-preview", force_zeros_for_empty_prompt=True)
95+
pipe.enable_vae_tiling()
96+
pipe.enable_model_cpu_offload()
97+
98+
prompt = "An aerial shot of a parade of elephants walking across the African savannah. The camera showcases the herd and the surrounding landscape."
99+
100+
with torch.no_grad():
101+
prompt_embeds, prompt_attention_mask, negative_prompt_embeds, negative_prompt_attention_mask = (
102+
pipe.encode_prompt(prompt=prompt)
103+
)
104+
105+
with torch.autocast("cuda", torch.bfloat16):
106+
with sdpa_kernel(SDPBackend.EFFICIENT_ATTENTION):
107+
frames = pipe(
108+
prompt_embeds=prompt_embeds,
109+
prompt_attention_mask=prompt_attention_mask,
110+
negative_prompt_embeds=negative_prompt_embeds,
111+
negative_prompt_attention_mask=negative_prompt_attention_mask,
112+
guidance_scale=4.5,
113+
num_inference_steps=64,
114+
height=480,
115+
width=848,
116+
num_frames=163,
117+
generator=torch.Generator("cuda").manual_seed(0),
118+
output_type="latent",
119+
return_dict=False,
120+
)[0]
121+
122+
video_processor = VideoProcessor(vae_scale_factor=8)
123+
has_latents_mean = hasattr(pipe.vae.config, "latents_mean") and pipe.vae.config.latents_mean is not None
124+
has_latents_std = hasattr(pipe.vae.config, "latents_std") and pipe.vae.config.latents_std is not None
125+
if has_latents_mean and has_latents_std:
126+
latents_mean = (
127+
torch.tensor(pipe.vae.config.latents_mean).view(1, 12, 1, 1, 1).to(frames.device, frames.dtype)
128+
)
129+
latents_std = (
130+
torch.tensor(pipe.vae.config.latents_std).view(1, 12, 1, 1, 1).to(frames.device, frames.dtype)
131+
)
132+
frames = frames * latents_std / pipe.vae.config.scaling_factor + latents_mean
133+
else:
134+
frames = frames / pipe.vae.config.scaling_factor
135+
136+
with torch.no_grad():
137+
video = pipe.vae.decode(frames.to(pipe.vae.dtype), return_dict=False)[0]
138+
139+
video = video_processor.postprocess_video(video)[0]
140+
export_to_video(video, "mochi.mp4", fps=30)
141+
```
142+
143+
## Running inference with multiple GPUs
144+
145+
It is possible to split the large Mochi transformer across multiple GPUs using the `device_map` and `max_memory` options in `from_pretrained`. In the following example we split the model across two GPUs, each with 24GB of VRAM.
146+
147+
```python
148+
import torch
149+
from diffusers import MochiPipeline, MochiTransformer3DModel
150+
from diffusers.utils import export_to_video
151+
152+
model_id = "genmo/mochi-1-preview"
153+
transformer = MochiTransformer3DModel.from_pretrained(
154+
model_id,
155+
subfolder="transformer",
156+
device_map="auto",
157+
max_memory={0: "24GB", 1: "24GB"}
158+
)
159+
160+
pipe = MochiPipeline.from_pretrained(model_id, transformer=transformer)
161+
pipe.enable_model_cpu_offload()
162+
pipe.enable_vae_tiling()
163+
164+
with torch.autocast(device_type="cuda", dtype=torch.bfloat16, cache_enabled=False):
165+
frames = pipe(
166+
prompt="Close-up of a chameleon's eye, with its scaly skin changing color. Ultra high resolution 4k.",
167+
negative_prompt="",
168+
height=480,
169+
width=848,
170+
num_frames=85,
171+
num_inference_steps=50,
172+
guidance_scale=4.5,
173+
num_videos_per_prompt=1,
174+
generator=torch.Generator(device="cuda").manual_seed(0),
175+
max_sequence_length=256,
176+
output_type="pil",
177+
).frames[0]
178+
179+
export_to_video(frames, "output.mp4", fps=30)
180+
```
181+
182+
## Using single file loading with the Mochi Transformer
183+
184+
You can use `from_single_file` to load the Mochi transformer in its original format.
185+
186+
<Tip>
187+
Diffusers currently doesn't support using the FP8 scaled versions of the Mochi single file checkpoints.
188+
</Tip>
189+
190+
```python
191+
import torch
192+
from diffusers import MochiPipeline, MochiTransformer3DModel
193+
from diffusers.utils import export_to_video
194+
195+
model_id = "genmo/mochi-1-preview"
196+
197+
ckpt_path = "https://huggingface.co/Comfy-Org/mochi_preview_repackaged/blob/main/split_files/diffusion_models/mochi_preview_bf16.safetensors"
198+
199+
transformer = MochiTransformer3DModel.from_pretrained(ckpt_path, torch_dtype=torch.bfloat16)
200+
201+
pipe = MochiPipeline.from_pretrained(model_id, transformer=transformer)
202+
pipe.enable_model_cpu_offload()
203+
pipe.enable_vae_tiling()
204+
205+
with torch.autocast(device_type="cuda", dtype=torch.bfloat16, cache_enabled=False):
206+
frames = pipe(
207+
prompt="Close-up of a chameleon's eye, with its scaly skin changing color. Ultra high resolution 4k.",
208+
negative_prompt="",
209+
height=480,
210+
width=848,
211+
num_frames=85,
212+
num_inference_steps=50,
213+
guidance_scale=4.5,
214+
num_videos_per_prompt=1,
215+
generator=torch.Generator(device="cuda").manual_seed(0),
216+
max_sequence_length=256,
217+
output_type="pil",
218+
).frames[0]
219+
220+
export_to_video(frames, "output.mp4", fps=30)
221+
```
222+
28223
## MochiPipeline
29224

30225
[[autodoc]] MochiPipeline

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ Available models:
3232

3333
| Model | Recommended dtype |
3434
|:-----:|:-----------------:|
35+
| [`Efficient-Large-Model/Sana_1600M_1024px_BF16_diffusers`](https://huggingface.co/Efficient-Large-Model/Sana_1600M_1024px_BF16_diffusers) | `torch.bfloat16` |
3536
| [`Efficient-Large-Model/Sana_1600M_1024px_diffusers`](https://huggingface.co/Efficient-Large-Model/Sana_1600M_1024px_diffusers) | `torch.float16` |
3637
| [`Efficient-Large-Model/Sana_1600M_1024px_MultiLing_diffusers`](https://huggingface.co/Efficient-Large-Model/Sana_1600M_1024px_MultiLing_diffusers) | `torch.float16` |
37-
| [`Efficient-Large-Model/Sana_1600M_1024px_BF16_diffusers`](https://huggingface.co/Efficient-Large-Model/Sana_1600M_1024px_BF16_diffusers) | `torch.bfloat16` |
3838
| [`Efficient-Large-Model/Sana_1600M_512px_diffusers`](https://huggingface.co/Efficient-Large-Model/Sana_1600M_512px_diffusers) | `torch.float16` |
3939
| [`Efficient-Large-Model/Sana_1600M_512px_MultiLing_diffusers`](https://huggingface.co/Efficient-Large-Model/Sana_1600M_512px_MultiLing_diffusers) | `torch.float16` |
4040
| [`Efficient-Large-Model/Sana_600M_1024px_diffusers`](https://huggingface.co/Efficient-Large-Model/Sana_600M_1024px_diffusers) | `torch.float16` |

docs/source/en/quantization/gguf.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,11 @@ transformer = FluxTransformer2DModel.from_single_file(
4545
pipe = FluxPipeline.from_pretrained(
4646
"black-forest-labs/FLUX.1-dev",
4747
transformer=transformer,
48-
generator=torch.manual_seed(0),
4948
torch_dtype=torch.bfloat16,
5049
)
5150
pipe.enable_model_cpu_offload()
5251
prompt = "A cat holding a sign that says hello world"
53-
image = pipe(prompt).images[0]
52+
image = pipe(prompt, generator=torch.manual_seed(0)).images[0]
5453
image.save("flux-gguf.png")
5554
```
5655

0 commit comments

Comments
 (0)