Skip to content

Commit 231bd59

Browse files
authored
Merge branch 'main' into lora-tests-modular
2 parents 2291dc9 + 2ff5e58 commit 231bd59

37 files changed

Lines changed: 344 additions & 1225 deletions

.ai/references/testing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ Follow the style introduced in [#14113](https://github.com/huggingface/diffusers
3030
- `MemoryTesterMixin` — CPU offload, group offload, layerwise casting.
3131
- Cache mixins — `PyramidAttentionBroadcastTesterMixin`, `FasterCacheTesterMixin`, `FirstBlockCacheTesterMixin`, `TaylorSeerCacheTesterMixin`, `MagCacheTesterMixin`. Guidance-distilled models override the cache config (e.g. `FASTER_CACHE_CONFIG = {... "is_guidance_distilled": True}`). Don't introduce caching related tests in the first iteration. These tests are added on a case-by-case basis.
3232
- In the first pass, just add tests related to `PipelineTesterMixin` and `MemoryTesterMixin`.
33-
- **Declare a component that can't be offloaded — don't hand-write a skip.** Leaf-level offloading hooks only the supported leaf types (`nn.Linear`, `nn.Conv*`, `nn.Embedding` — see `_GO_LC_SUPPORTED_PYTORCH_LAYERS` in `src/diffusers/hooks/_common.py`) and onloads each on its own `forward`, so any code that reads a leaf's `.weight` instead of calling the leaf bypasses that leaf's hook and computes against offloaded weights. Which fix applies depends on who owns the component. For a diffusers model, set `_supports_group_offloading = False` on the `ModelMixin` subclass (as `HunyuanDiT2DModel` does) — both offload mixins honor the flag and skip themselves, so the gap is declared on the model instead of buried in a test file. For a third-party component you can't annotate, such as a `transformers` encoder, list it in `group_offloading_leaf_level_exclude_modules` on the config class; `enable_group_offload` keeps excluded components on the accelerator, so every other component stays covered — including the VAE, which the component-scoped `test_group_offloading_inference` leaves out. Block-level offloading is usually unaffected, hence the level in the name — a component that fails at both levels does need a skip.
34-
- `torch.nn.MultiheadAttention` is the common instance: it passes `self.out_proj.weight` straight to `torch.nn.functional.multi_head_attention_forward` instead of calling `self.out_proj`, so the hook on `out_proj` never fires. `SiglipVisionModel`'s attention pooling head wraps one — see `tests/pipelines/hunyuan_video/test_hunyuan_video_framepack.py`, whose `image_encoder` is excluded for this reason.
33+
- **Declare a component that can't be offloaded — don't hand-write a skip.** For a diffusers model, set `_supports_group_offloading = False` on the `ModelMixin` subclass (as `HunyuanDiT2DModel` does); for a third-party component you can't annotate, such as a `transformers` encoder, name it in `group_offloading_leaf_level_exclude_modules` or `group_offloading_block_level_exclude_modules` on the config class. **Every `nn.Module` component is group offloaded unless the list for that level names it**, and the two levels fail on opposite hazards: leaf-level when compute reads a leaf's `.weight` instead of calling the leaf, block-level when a component re-enters submodules without going through the group leader's `forward` (VAE decode paths, hence the `vae` / `image_encoder` defaults). A component that fails at both goes in both, and a name matching no component fails the test as a typo. **Each level's test runs twice, with and without `use_stream`** — a subclass overriding one must re-declare `@MemoryTesterMixin._USE_STREAM`, or the override collapses to a single un-parametrized test that errors on the missing argument and reports as a green `xfail`.
34+
- `torch.nn.MultiheadAttention` is the common leaf-level instance: it passes `self.out_proj.weight` straight to `torch.nn.functional.multi_head_attention_forward` instead of calling `self.out_proj`, so the hook on `out_proj` never fires. `SiglipVisionModel`'s attention pooling head wraps one — see `tests/pipelines/hunyuan_video/test_hunyuan_video_framepack.py`, whose `image_encoder` is excluded for this reason.
3535
- `HunyuanDiTAttentionPool` (`src/diffusers/models/embeddings.py`) shows the same failure without an MHA module: a plain `nn.Module` that hands its `q_proj` / `k_proj` / `v_proj` / `c_proj` weights to `torch.nn.functional.multi_head_attention_forward`, so all four projections stay offloaded rather than just one. `HunyuanDiT2DModel` opts out of group offloading entirely with `_supports_group_offloading = False`.
3636
- Before adding a skip or an exclusion, confirm the failure still reproduces — several existing skips are stale, having outlived the upstream cause.
3737
- **A migration that surfaces a `src/` gap marks the test `xfail`, it does not patch the pipeline.** Give the marker a module-level name and a `reason` naming the exact gap (`PNDM_*` in `tests/pipelines/pndm/test_pndm.py` is the worked example), and prefer `strict=True` so the marker reports XPASS — and gets deleted — the day the pipeline is fixed. Use `strict=False` only when one mark covers a group whose members do not all fail. Marking a whole test class keeps the mixin's own marks (`@is_memory`, `@require_accelerator`) intact; overriding individual inherited tests drops the decorators they were declared with, so re-declare those too.

.github/workflows/nightly_tests.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,6 @@ jobs:
461461
run_big_gpu_torch_tests,
462462
run_nightly_quantization_tests,
463463
run_nightly_pipeline_level_quantization_tests,
464-
# run_nightly_onnx_tests,
465464
torch_minimum_version_cuda_tests,
466465
]
467466
if: always()

src/diffusers/models/transformers/transformer_prx.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ def __call__(
161161
ones_img = torch.ones((bs, l_img), dtype=torch.bool, device=device)
162162
attention_mask = attention_mask.to(device=device, dtype=torch.bool)
163163
joint_mask = torch.cat([attention_mask, ones_img], dim=-1)
164-
attn_mask_tensor = joint_mask[:, None, None, :].expand(-1, attn.heads, l_img, -1)
164+
# Every attention backend broadcasts the mask itself, so materialising
165+
# [B, heads, L_img, L_all] only costs bandwidth: at batch 32, 1024 image tokens
166+
# and 28 heads that is a 1.1 GiB mask read per block. Keep it broadcastable.
167+
attn_mask_tensor = joint_mask[:, None, None, :]
165168

166169
# Apply attention using dispatch_attention_fn for backend support
167170
# Reshape to match dispatch_attention_fn expectations: [B, L, H, D]

src/diffusers/pipelines/chroma/pipeline_chroma.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,14 +628,14 @@ def __call__(
628628
The height in pixels of the generated image. This is set to 1024 by default for the best results.
629629
width (`int`, *optional*, defaults to self.unet.config.sample_size * self.vae_scale_factor):
630630
The width in pixels of the generated image. This is set to 1024 by default for the best results.
631-
num_inference_steps (`int`, *optional*, defaults to 50):
631+
num_inference_steps (`int`, *optional*, defaults to 35):
632632
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
633633
expense of slower inference.
634634
sigmas (`list[float]`, *optional*):
635635
Custom sigmas to use for the denoising process with schedulers which support a `sigmas` argument in
636636
their `set_timesteps` method. If not defined, the default behavior when `num_inference_steps` is passed
637637
will be used.
638-
guidance_scale (`float`, *optional*, defaults to 3.5):
638+
guidance_scale (`float`, *optional*, defaults to 5.0):
639639
Guidance scale as defined in [Classifier-Free Diffusion
640640
Guidance](https://huggingface.co/papers/2207.12598). `guidance_scale` is defined as `w` of equation 2.
641641
of [Imagen Paper](https://huggingface.co/papers/2205.11487). Guidance scale is enabled by setting

src/diffusers/pipelines/chroma/pipeline_chroma_img2img.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ def __call__(
698698
Custom sigmas to use for the denoising process with schedulers which support a `sigmas` argument in
699699
their `set_timesteps` method. If not defined, the default behavior when `num_inference_steps` is passed
700700
will be used.
701-
guidance_scale (`float`, *optional*, defaults to 3.5):
701+
guidance_scale (`float`, *optional*, defaults to 5.0):
702702
Guidance scale as defined in [Classifier-Free Diffusion
703703
Guidance](https://huggingface.co/papers/2207.12598). `guidance_scale` is defined as `w` of equation 2.
704704
of [Imagen Paper](https://huggingface.co/papers/2205.11487). Guidance scale is enabled by setting

src/diffusers/pipelines/chroma/pipeline_chroma_inpainting.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -828,20 +828,20 @@ def __call__(
828828
with the same aspect ratio of the image and contains all masked area, and then expand that area based
829829
on `padding_mask_crop`. The image and mask_image will then be cropped based on the expanded area before
830830
resizing to the original image size for inpainting.
831-
num_inference_steps (`int`, *optional*, defaults to 35):
831+
num_inference_steps (`int`, *optional*, defaults to 28):
832832
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
833833
expense of slower inference.
834834
sigmas (`List[float]`, *optional*):
835835
Custom sigmas to use for the denoising process with schedulers which support a `sigmas` argument in
836836
their `set_timesteps` method. If not defined, the default behavior when `num_inference_steps` is passed
837837
will be used.
838-
guidance_scale (`float`, *optional*, defaults to 3.5):
838+
guidance_scale (`float`, *optional*, defaults to 7.0):
839839
Guidance scale as defined in [Classifier-Free Diffusion
840840
Guidance](https://huggingface.co/papers/2207.12598). `guidance_scale` is defined as `w` of equation 2.
841841
of [Imagen Paper](https://huggingface.co/papers/2205.11487). Guidance scale is enabled by setting
842842
`guidance_scale > 1`. Higher guidance scale encourages to generate images that are closely linked to
843843
the text `prompt`, usually at the expense of lower image quality.
844-
strength (`float, *optional*, defaults to 0.9):
844+
strength (`float, *optional*, defaults to 0.6):
845845
Conceptually, indicates how much to transform the reference image. Must be between 0 and 1. image will
846846
be used as a starting point, adding more noise to it the larger the strength. The number of denoising
847847
steps depends on the amount of noise initially added. When strength is 1, added noise will be maximum
@@ -900,7 +900,7 @@ def __call__(
900900
The list of tensor inputs for the `callback_on_step_end` function. The tensors specified in the list
901901
will be passed as `callback_kwargs` argument. You will only be able to include variables listed in the
902902
`._callback_tensor_inputs` attribute of your pipeline class.
903-
max_sequence_length (`int` defaults to 512): Maximum sequence length to use with the `prompt`.
903+
max_sequence_length (`int` defaults to 256): Maximum sequence length to use with the `prompt`.
904904
905905
Examples:
906906

src/diffusers/pipelines/deprecated/stable_diffusion_variants/pipeline_onnx_stable_diffusion_inpaint_legacy.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from ....schedulers import DDIMScheduler, LMSDiscreteScheduler, PNDMScheduler
1111
from ....utils import deprecate, logging
1212
from ...onnx_utils import ORT_TO_NP_TYPE, OnnxRuntimeModel
13-
from ...pipeline_utils import DiffusionPipeline
13+
from ...pipeline_utils import DeprecatedPipelineMixin, DiffusionPipeline
1414
from ...stable_diffusion.pipeline_output import StableDiffusionPipelineOutput
1515

1616

@@ -38,7 +38,9 @@ def preprocess_mask(mask, scale_factor=8):
3838
return mask
3939

4040

41-
class OnnxStableDiffusionInpaintPipelineLegacy(DiffusionPipeline):
41+
class OnnxStableDiffusionInpaintPipelineLegacy(DeprecatedPipelineMixin, DiffusionPipeline):
42+
_last_supported_version = "0.43.0"
43+
4244
r"""
4345
Pipeline for text-guided image inpainting using Stable Diffusion. This is a *legacy feature* for Onnx pipelines to
4446
provide compatibility with StableDiffusionInpaintPipelineLegacy and may be removed in the future.

src/diffusers/pipelines/onnx_utils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from huggingface_hub import hf_hub_download
2525
from huggingface_hub.utils import validate_hf_hub_args
2626

27-
from ..utils import ONNX_EXTERNAL_WEIGHTS_NAME, ONNX_WEIGHTS_NAME, is_onnx_available, logging
27+
from ..utils import ONNX_EXTERNAL_WEIGHTS_NAME, ONNX_WEIGHTS_NAME, deprecate, is_onnx_available, logging
2828

2929

3030
if is_onnx_available():
@@ -50,8 +50,14 @@
5050

5151

5252
class OnnxRuntimeModel:
53+
_last_supported_version = "0.43.0"
54+
5355
def __init__(self, model=None, **kwargs):
54-
logger.info("`diffusers.OnnxRuntimeModel` is experimental and might change in the future.")
56+
deprecate(
57+
"OnnxRuntimeModel",
58+
"0.43.0",
59+
"Please use Optimum for ONNX Runtime support.",
60+
)
5561
self.model = model
5662
self.model_save_dir = kwargs.get("model_save_dir", None)
5763
self.latest_model_name = kwargs.get("latest_model_name", ONNX_WEIGHTS_NAME)

src/diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@
2323
from ...schedulers import DDIMScheduler, LMSDiscreteScheduler, PNDMScheduler
2424
from ...utils import deprecate, logging
2525
from ..onnx_utils import ORT_TO_NP_TYPE, OnnxRuntimeModel
26-
from ..pipeline_utils import DiffusionPipeline
26+
from ..pipeline_utils import DeprecatedPipelineMixin, DiffusionPipeline
2727
from . import StableDiffusionPipelineOutput
2828

2929

3030
logger = logging.get_logger(__name__)
3131

3232

33-
class OnnxStableDiffusionPipeline(DiffusionPipeline):
33+
class OnnxStableDiffusionPipeline(DeprecatedPipelineMixin, DiffusionPipeline):
34+
_last_supported_version = "0.43.0"
35+
3436
vae_encoder: OnnxRuntimeModel
3537
vae_decoder: OnnxRuntimeModel
3638
text_encoder: OnnxRuntimeModel

src/diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_img2img.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from ...schedulers import DDIMScheduler, LMSDiscreteScheduler, PNDMScheduler
2525
from ...utils import PIL_INTERPOLATION, deprecate, logging
2626
from ..onnx_utils import ORT_TO_NP_TYPE, OnnxRuntimeModel
27-
from ..pipeline_utils import DiffusionPipeline
27+
from ..pipeline_utils import DeprecatedPipelineMixin, DiffusionPipeline
2828
from . import StableDiffusionPipelineOutput
2929

3030

@@ -55,7 +55,9 @@ def preprocess(image):
5555
return image
5656

5757

58-
class OnnxStableDiffusionImg2ImgPipeline(DiffusionPipeline):
58+
class OnnxStableDiffusionImg2ImgPipeline(DeprecatedPipelineMixin, DiffusionPipeline):
59+
_last_supported_version = "0.43.0"
60+
5961
r"""
6062
Pipeline for text-guided image to image generation using Stable Diffusion.
6163

0 commit comments

Comments
 (0)