Skip to content

Commit ade1e11

Browse files
authored
Merge branch 'main' into fix-modular-required-default-14388
2 parents 56a0de1 + 360bef8 commit ade1e11

111 files changed

Lines changed: 9547 additions & 5332 deletions

File tree

Some content is hidden

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

.ai/models.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,27 @@ What you pass as `attn_mask=` to `dispatch_attention_fn` determines which backen
7575
- **Other mask types (structural, BlockMask, etc.)** — if the model requires a different mask pattern, figure out how to support as many backends as possible (e.g. use `window_size` kwarg for sliding window on flash, `BlockMask` for Flex) and document which backends are supported for that model.
7676
- **Don't declare `attention_mask` (or `encoder_hidden_states_mask`) in the forward signature if you ignore it.** "For API stability with other transformers" is not a reason; readers assume a declared param is honored, and downstream pipelines will pass padding masks that silently get dropped. Some existing models in the repo carry unused mask params for historical reasons — e.g. `QwenDoubleStreamAttnProcessor2_0.__call__` declares `encoder_hidden_states_mask` but never reads it (the joint mask is routed through `attention_mask` instead), and the block-level forward in `transformer_qwenimage.py` declares it but always receives `None`. This is a legacy behavior and should not be replicated in new models.
7777

78+
### Grouped-query attention
79+
80+
Fewer key/value heads than query heads can be spelled two ways. Either pass `enable_gqa=True` to `dispatch_attention_fn` and let the backend broadcast (`transformer_cosmos3.py`), or repeat the key/value heads in the processor after RoPE and pass no flag (`transformer_krea2.py`):
81+
82+
```python
83+
num_key_value_groups = attn.num_heads // attn.num_kv_heads
84+
if num_key_value_groups > 1:
85+
key = key.repeat_interleave(num_key_value_groups, dim=2)
86+
value = value.repeat_interleave(num_key_value_groups, dim=2)
87+
```
88+
89+
`dim=2` because tensors are `(batch_size, seq_len, num_heads, head_dim)` here. Must be `repeat_interleave`, not `repeat` — the groups are contiguous, and `repeat` gives a silently wrong pairing no shape check catches.
90+
91+
Both compute the same thing, so weigh the two on compatibility and performance and recommend whichever fits the model better.
92+
93+
- **Compatibility.** Most backends do not implement `enable_gqa` yet — flash, FA3, sage, cuDNN and the hub kernels raise on it, as does the context-parallel path. Grep `enable_gqa` in `attention_dispatch.py` for the current list rather than trusting this one; it changes as support lands. The flag limits the model to whichever backends still accept it, while repeating works on all of them.
94+
95+
- **Performance.** Depends on whether the model passes a mask. With a mask, no fused kernel takes a mask *and* mismatched head counts, so SDPA falls back to math and materializes the full `[batch_size, num_heads, seq_len_q, seq_len_kv]` score matrix — no error, no warning, only memory. Without a mask, flash broadcasts inside the kernel and the flag saves the key/value copy. Both effects scale with sequence length and head count, so measure at the model's real shape; `torch.backends.cuda.can_use_flash_attention(params, debug=True)` and `can_use_efficient_attention` print why a kernel was rejected, which is the fastest way to see which one you actually got.
96+
97+
- **Recommendation.** Repeat by default — it is portable and never pathological. Reach for `enable_gqa=True` only when the model never passes a mask *and* the measured saving justifies the narrower backend support. For scale: on Krea 2 at 1024×1024, masked, the flag cost 9.02 GiB and 26.7 ms per call against 0.16 GiB and 4.1 ms repeated; unmasked at the same shape it saved 0.11 GiB and 0.1 ms. `transformer_cosmos3.py` is the in-repo case where it is defensible — causal, never masked.
98+
7899
## Model class attributes
79100

80101
Each `ModelMixin` subclass can declare class-level attributes that configure optimization features. Each attribute corresponds to a user-facing API — the attribute controls how that feature behaves for the model. When adding a new transformer, set all that apply — skim `transformer_flux.py`, `transformer_wan.py`, `transformer_qwenimage.py` for examples.

.github/workflows/nightly_tests.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -342,19 +342,19 @@ jobs:
342342
matrix:
343343
config:
344344
- backend: "bitsandbytes"
345-
test_location: "bnb"
345+
marker: "bitsandbytes"
346346
additional_deps: ["peft"]
347347
- backend: "gguf"
348-
test_location: "gguf"
348+
marker: "gguf"
349349
additional_deps: ["peft", "kernels"]
350350
- backend: "torchao"
351-
test_location: "torchao"
352-
additional_deps: []
351+
marker: "torchao"
352+
additional_deps: ["mslk"]
353353
- backend: "optimum_quanto"
354-
test_location: "quanto"
354+
marker: "quanto"
355355
additional_deps: []
356356
- backend: "nvidia_modelopt"
357-
test_location: "modelopt"
357+
marker: "modelopt"
358358
additional_deps: []
359359
runs-on:
360360
group: aws-g6e-xlarge-plus
@@ -389,9 +389,12 @@ jobs:
389389
BIG_GPU_MEMORY: 40
390390
run: |
391391
pytest -n 1 --max-worker-restart=0 --dist=loadfile \
392+
-m "${{ matrix.config.marker }}" \
392393
--make-reports=tests_${{ matrix.config.backend }}_torch_cuda \
393394
--report-log=tests_${{ matrix.config.backend }}_torch_cuda.log \
394-
tests/quantization/${{ matrix.config.test_location }}
395+
tests/models \
396+
tests/quantization \
397+
tests/pipelines/testing_utils/quantization.py
395398
- name: Failure short reports
396399
if: ${{ failure() }}
397400
run: |
@@ -439,9 +442,10 @@ jobs:
439442
BIG_GPU_MEMORY: 40
440443
run: |
441444
pytest -n 1 --max-worker-restart=0 --dist=loadfile \
445+
-k "TestPipelineQuantization" \
442446
--make-reports=tests_pipeline_level_quant_torch_cuda \
443447
--report-log=tests_pipeline_level_quant_torch_cuda.log \
444-
tests/quantization/test_pipeline_level_quantization.py
448+
tests/pipelines/testing_utils/quantization.py
445449
- name: Failure short reports
446450
if: ${{ failure() }}
447451
run: |

.github/workflows/pr_tests.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ jobs:
114114
run:
115115
shell: bash
116116

117+
env:
118+
HF_TOKEN: ${{ secrets.DIFFUSERS_HF_HUB_READ_TOKEN }}
119+
117120
steps:
118121
- name: Checkout diffusers
119122
uses: actions/checkout@v6
@@ -242,6 +245,9 @@ jobs:
242245
run:
243246
shell: bash
244247

248+
env:
249+
HF_TOKEN: ${{ secrets.DIFFUSERS_HF_HUB_READ_TOKEN }}
250+
245251
steps:
246252
- name: Checkout diffusers
247253
uses: actions/checkout@v6

docs/source/en/_toctree.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@
401401
title: SD3Transformer2DModel
402402
- local: api/models/skyreels_v2_transformer_3d
403403
title: SkyReelsV2Transformer3DModel
404+
- local: api/models/stable_audio_3_transformer
405+
title: StableAudio3DiTModel
404406
- local: api/models/stable_audio_transformer
405407
title: StableAudioDiTModel
406408
- local: api/models/transformer2d
@@ -477,6 +479,8 @@
477479
title: AutoencoderKLWan
478480
- local: api/models/autoencoder_rae
479481
title: AutoencoderRAE
482+
- local: api/models/autoencoder_same
483+
title: AutoencoderSAME
480484
- local: api/models/consistency_decoder_vae
481485
title: ConsistencyDecoderVAE
482486
- local: api/models/ltx2_diffusion_decoder
@@ -503,6 +507,8 @@
503507
title: LongCat-AudioDiT
504508
- local: api/pipelines/stable_audio
505509
title: Stable Audio
510+
- local: api/pipelines/stable_audio_3
511+
title: Stable Audio 3
506512
title: Audio
507513
- sections:
508514
- local: api/pipelines/anima
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!--Copyright 2025 Stability AI and The HuggingFace Team. All rights reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4+
the License. You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
specific language governing permissions and limitations under the License.
11+
-->
12+
13+
# AutoencoderSAME
14+
15+
The **SAME** (Semantically-Aligned Music Encoder) autoencoder is used by [Stable Audio 3](https://stability.ai/news/stable-audio-3)
16+
to compress stereo audio waveforms into a compact latent sequence and reconstruct them.
17+
18+
The encoder stacks [`SAMETransformerResamplingBlock`] modules, each of which groups a fixed number of audio
19+
patch frames and produces one learnable output token via a differential transformer. The decoder inverts this
20+
process, expanding each latent token back to a patch of audio frames.
21+
22+
A soft-norm bottleneck (`SoftNormBottleneck`) normalises latents before and after the diffusion model,
23+
providing stable training dynamics.
24+
25+
## AutoencoderSAME
26+
27+
[[autodoc]] AutoencoderSAME
28+
- all
29+
- encode
30+
- decode
31+
32+
## SAMETransformerResamplingBlock
33+
34+
[[autodoc]] models.autoencoders.autoencoder_same.SAMETransformerResamplingBlock
35+
36+
## AutoencoderSAMEOutput
37+
38+
[[autodoc]] models.autoencoders.autoencoder_same.AutoencoderSAMEOutput
39+
40+
## AutoencoderSAMEDecoderOutput
41+
42+
[[autodoc]] models.autoencoders.autoencoder_same.AutoencoderSAMEDecoderOutput
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!--Copyright 2025 Stability AI and The HuggingFace Team. All rights reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4+
the License. You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
specific language governing permissions and limitations under the License.
11+
-->
12+
13+
# StableAudio3DiTModel
14+
15+
A rectified-flow velocity-prediction Diffusion Transformer (DiT) for audio generation, used in
16+
[Stable Audio 3](https://stability.ai/news/stable-audio-3).
17+
18+
Each [`StableAudio3DiTBlock`] performs:
19+
20+
1. **Self-attention** — differential multi-head attention with rotary position embeddings (RoPE).
21+
2. **Cross-attention** — attends to the token sequence from the T5Gemma text encoder.
22+
3. **Feed-forward** — SwiGLU projection.
23+
24+
The model is conditioned on a **timestep** (exponential Fourier features → linear projection) and a **global
25+
conditioning vector** (duration embedding from [`StableAudio3DurationEmbedder`]).
26+
27+
## StableAudio3DiTModel
28+
29+
[[autodoc]] StableAudio3DiTModel
30+
- all
31+
- forward
32+
33+
## StableAudio3DiTBlock
34+
35+
[[autodoc]] models.transformers.transformer_stable_audio3.StableAudio3DiTBlock
36+
37+
## StableAudio3DiTModelOutput
38+
39+
[[autodoc]] models.transformers.transformer_stable_audio3.StableAudio3DiTModelOutput

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ is not overwritten); this is the setup shown in [Usage](#usage). Drop both the `
145145

146146
## Adaptive stopping
147147

148-
A block usually converges before all `num_inference_steps` are spent, so by default the pipeline leaves a block's
149-
denoising loop early once every example's argmax prediction is stable for `stability_threshold` steps and the mean
150-
per-token entropy falls below `confidence_threshold` (`0.005`, the value used by the released checkpoint). This roughly
151-
halves the number of decoder forwards at matched quality and is the largest single throughput lever. Pass
152-
`confidence_threshold=None` to always run the full `num_inference_steps`:
148+
A block usually converges before all `num_inference_steps` are spent, so by default the pipeline freezes each batch
149+
example once its argmax prediction is stable for `stability_threshold` steps and its mean per-token entropy falls below
150+
`confidence_threshold` (`0.005`, the value used by the released checkpoint). The denoising loop ends once every example
151+
is frozen. This roughly halves the number of decoder forwards at matched quality and is the largest single throughput
152+
lever. Pass `confidence_threshold=None` to always run the full `num_inference_steps`:
153153

154154
```py
155155
output = pipe(prompt="Why is the sky blue?", gen_length=256, confidence_threshold=None) # disable adaptive stopping

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ specific language governing permissions and limitations under the License.
1313

1414
Kandinsky 5.0 Lite line-up of lightweight video generation models (2B parameters) that ranks #1 among open-source models in its class. It outperforms larger models and offers the best understanding of Russian concepts in the open-source ecosystem.
1515

16-
Kandinsky 5.0 Pro line-up of large high quality video generation models (19B parameters). It offers high qualty generation in HD and more generation formats like I2V.
16+
Kandinsky 5.0 Pro line-up of large high quality video generation models (19B parameters). It offers high quality generation in HD and more generation formats like I2V.
1717

1818
The model introduces several key innovations:
1919
- **Latent diffusion pipeline** with **Flow Matching** for improved training stability
@@ -54,7 +54,7 @@ Kandinsky 5.0 T2V Lite:
5454
### Basic Text-to-Video Generation
5555

5656
#### Pro
57-
**⚠️ Warning!** all Pro models should be infered with pipeline.enable_model_cpu_offload()
57+
**⚠️ Warning!** all Pro models should be inferred with pipeline.enable_model_cpu_offload()
5858
```python
5959
import torch
6060
from diffusers import Kandinsky5T2VPipeline
@@ -65,7 +65,7 @@ model_id = "kandinskylab/Kandinsky-5.0-T2V-Pro-sft-5s-Diffusers"
6565
pipe = Kandinsky5T2VPipeline.from_pretrained(model_id, dtype=torch.bfloat16)
6666

6767
pipe = pipe.to("cuda")
68-
pipeline.transformer.set_attention_backend("flex") # <--- Set attention bakend to Flex
68+
pipeline.transformer.set_attention_backend("flex") # <--- Set attention backend to Flex
6969
pipeline.enable_model_cpu_offload() # <--- Enable cpu offloading for single GPU inference
7070
pipeline.transformer.compile(mode="max-autotune-no-cudagraphs", dynamic=True) # <--- Compile with max-autotune-no-cudagraphs
7171

@@ -126,7 +126,7 @@ pipe = pipe.to("cuda")
126126

127127
pipe.transformer.set_attention_backend(
128128
"flex"
129-
) # <--- Set attention bakend to Flex
129+
) # <--- Set attention backend to Flex
130130
pipe.transformer.compile(
131131
mode="max-autotune-no-cudagraphs",
132132
dynamic=True
@@ -149,7 +149,7 @@ export_to_video(output, "output.mp4", fps=24, quality=9)
149149
```
150150

151151
### Diffusion Distilled model
152-
**⚠️ Warning!** all nocfg and diffusion distilled models should be infered wothout CFG (```guidance_scale=1.0```):
152+
**⚠️ Warning!** all nocfg and diffusion distilled models should be inferred without CFG (```guidance_scale=1.0```):
153153

154154
```python
155155
model_id = "kandinskylab/Kandinsky-5.0-T2V-Lite-distilled16steps-5s-Diffusers"
@@ -167,7 +167,7 @@ export_to_video(output, "output.mp4", fps=24, quality=9)
167167

168168

169169
### Basic Image-to-Video Generation
170-
**⚠️ Warning!** all Pro models should be infered with pipeline.enable_model_cpu_offload()
170+
**⚠️ Warning!** all Pro models should be inferred with pipeline.enable_model_cpu_offload()
171171
```python
172172
import torch
173173
from diffusers import Kandinsky5T2VPipeline
@@ -178,7 +178,7 @@ model_id = "kandinskylab/Kandinsky-5.0-I2V-Pro-sft-5s-Diffusers"
178178
pipe = Kandinsky5T2VPipeline.from_pretrained(model_id, dtype=torch.bfloat16)
179179

180180
pipe = pipe.to("cuda")
181-
pipeline.transformer.set_attention_backend("flex") # <--- Set attention bakend to Flex
181+
pipeline.transformer.set_attention_backend("flex") # <--- Set attention backend to Flex
182182
pipeline.enable_model_cpu_offload() # <--- Enable cpu offloading for single GPU inference
183183
pipeline.transformer.compile(mode="max-autotune-no-cudagraphs", dynamic=True) # <--- Compile with max-autotune-no-cudagraphs
184184

0 commit comments

Comments
 (0)