Skip to content

Align repeated prompt attention masks with their embeddings - #15492

Open
mertkayacs wants to merge 1 commit into
huggingface:mainfrom
mertkayacs:fix/repeat-attention-mask-per-prompt
Open

mertkayacs wants to merge 1 commit into
huggingface:mainfrom
mertkayacs:fix/repeat-attention-mask-per-prompt

Conversation

@mertkayacs

Copy link
Copy Markdown
Contributor

What does this PR do?

With several prompts and num_images_per_prompt > 1, embeddings are expanded as [p0, p0, p1, p1] but the prompt attention masks are tiled as [m0, m1, m0, m1], so the middle samples get the wrong mask. I changed the mask expansion to repeat each row next to its embedding in Sana, Sana ControlNet, Sana Sprint, Sana Sprint Img2Img, Sana PAG, AuraFlow, Kandinsky 3, Kandinsky 3 Img2Img, Lumina2, PRX and PRX Pixel, and added tests/pipelines/test_prompt_attention_mask.py.

Fixes #15462

Verification:

  • New test file: 22 passed with the fix, 11 failed with the source changes reverted (all num_images_per_prompt=2 cases).
  • ruff check, ruff format --check, utils/check_copies.py, utils/check_dummies.py and utils/check_ai.py pass on the changed files.
  • Fast tests of all touched pipelines on a hosted CPU job: 217 passed with the patch, the only failures on main were the 11 new cases. The touched files are unchanged on current main.

Self-review notes (I used Codex to help trace, implement and test this): verdict READY. I traced the positive and negative expansion paths and synced the copied methods. Kandinsky 3 keeps the 2D shape for direct single-prompt calls with 1D masks. AuraFlow's precomputed padding is tracked in #13624. Lumina2's precomputed negative embeddings skip expansion, so the test covers its positive mask only.

Before submitting

Who can review?

Anyone in the community is free to review the PR once the tests have passed.

@mertkayacs

Copy link
Copy Markdown
Contributor Author

@yiyixuxu @sayakpaul could one of you review this when you have time?

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prompt attention masks are misordered when generating multiple images per prompt

1 participant