Skip to content

Fix skipped test_model_xattn_padding test by updating mask padding logic #14699

Description

@PrakshaaleJain

Title:

Fix skipped test_model_xattn_padding test by updating mask padding logic

Description:

Currently, there is a skipped test in tests/models/unets/test_models_unet_2d_condition.py regarding cross-attention mask padding (test_model_xattn_padding).

The test is currently skipped with the following reason:

"we currently pad mask by target_length tokens (what unclip needs), whereas stable-diffusion's cross-attn needs to instead pad by remaining_length."

This is reflected by a dangling TODO in src/diffusers/models/attention_processor.py inside prepare_attention_mask (around line 740):

# TODO: for pipelines such as stable-diffusion, padding cross-attn mask:
#       we want to instead pad by (0, remaining_length), where remaining_length is:
#       remaining_length: int = target_length - current_length
# TODO: re-enable tests/models/test_models_unet_2d_condition.py#test_model_xattn_padding
attention_mask = F.pad(attention_mask, (0, target_length), value=0.0)

Expected Behavior / Proposed Solution:

  1. Update prepare_attention_mask in attention_processor.py (and any other relevant attention.py files) to pad the mask by remaining_length = target_length - current_length.
  2. Ensure the MPS torch.zeros() hack is also updated to pad by remaining_length rather than target_length.
  3. Verify that these changes do not break existing unclip tests/pipelines.
  4. Remove @pytest.mark.skip from test_model_xattn_padding in tests/models/unets/test_models_unet_2d_condition.py to re-enable it.

Relevant Files:

  • src/diffusers/models/attention_processor.py
  • tests/models/unets/test_models_unet_2d_condition.py

@sayakpaul If this is indeed technical debt that needs fixing, I would be happy to put together a PR to update the logic and re-enable the test myself!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions