Repository navigation
[bugfix] Preserve masked FlashAttention mask and scale - #2080
bingdongni wants to merge 4 commits into
Conversation
Merge Protections🔴 1 of 1 protections blocking · waiting on 👀 reviews and 🤖 CI
🔴 PR merge requirementsWaiting for
This rule is failing.
|
[Medium impact] The change is limited to masked calls through the FlashAttention backend. The code changes appear safe, but the added inline comment must be removed to meet the repository's rule. Findings
Fix with agent prompt### Issue 1
fastvideo/tests/attention/test_flash_attn_no_pad_custom_op.py:316
The comment on `scale` explains the test value, which falls outside the repository's allowed comment types. Remove it before merging to meet the requirement to remove comments outside that keep-list.
```suggestion
scale = 0.37
```
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
|
fv-superagent
left a comment
There was a problem hiding this comment.
fv-superagent score: 3/5 — the source fix is correct and CI is green, but the new test errors on FA3.
Welcome, and thanks for the precise problem statement and the SDPA comparison — that made this quick to check.
_key_padding_mask_from_attn_masknow matches the SDPA contract:int → != 0, bool unchanged, additive float unchanged.SDPAMetadataBuilderstores tokenizer-style int64 2D masks and the layer selector can route them here, so the integer half fixes a real cross-backend mismatch.softmax_scale=self.softmax_scaleon the equal-length masked path is right: every other branch already passes it, andlayer.pyalways resolvesself.softmax_scale(defaulthead_size**-0.5), so default runs are unchanged. The Buildkite unit lane confirms it — all sixtest_backend_padding_mask_and_custom_scale[bool|integer|additive-48|64]params PASSED.
Blocking (agrees with Greptile's P1 on this file):
fastvideo/tests/attention/test_flash_attn_no_pad_custom_op.py:291— thequery_len=48params take theflash_attn_varlen_qk_no_padroute, which every sibling test here guards with_fa2_onlybecause FA3 rejects itsdropout_pcall. On an FA3/FA4 checkout this test will raise instead of skipping. Guard just the unequal-length case, e.g.if query_len != key_len: _fa2_only(no_pad_impls)after the seed — that keeps the equal-length int-mask/scale coverage running everywhere.
Optional, not blocking
- This test exercises the backend, not the custom ops the file is named for; a docstring line or a move beside
test_sdpa_metadata_mask_contract.pywould keep that contract honest. - Only 2D masks are covered; the 3D/4D normalization branches are untouched by tests.
- Pre-existing, not from this PR: the float branch hard-masks on
>= 0, unlike SDPA's additive pass-through for finite negative biases. No current producer emits those.
— fv-superagent · integer masks no longer attend to everyone · run by aryan5v
fv-superagent
left a comment
There was a problem hiding this comment.
fv-superagent score: 4/5 (was 3/5) — the FA3 guard is in and Greptile's follow-up is clean.
23e89e9addsif query_len != key_len: _fa2_only(no_pad_impls), so the unequal-length params skip cleanly off FA2 while the equal-length integer-mask/scale coverage still runs everywhere. That closes the P1.- Source fix unchanged and correct; the Buildkite unit lane re-ran all six
test_backend_padding_mask_and_custom_scaleparams green on this head. - Remaining points are optional, carried over: this test exercises the backend rather than the custom op the file is named for, and the 3D/4D mask-normalization branches still have no coverage.
— fv-superagent · one guard, three skips, zero TypeErrors · run by aryan5v
| elif mask_rank == 4: | ||
| mask = mask[:, None, None, :] | ||
|
|
||
| scale = 0.37 # Deliberately different from head_dim**-0.5. |
There was a problem hiding this comment.
Inline comment violates repository rule
The comment on scale explains the test value, which falls outside the repository's allowed comment types. Remove it before merging to meet the requirement to remove comments outside that keep-list.
| scale = 0.37 # Deliberately different from head_dim**-0.5. | |
| scale = 0.37 |
Rule Used: What: Remove all unwanted code comments in the scoped diff except for a small keep-list (license headers, dependency/protocol-required non-obvious behavior, // prettier-ignore, public API doc comments, and issue/RFC constraint links). Why: Comment... (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: fastvideo/tests/attention/test_flash_attn_no_pad_custom_op.py
Line: 316
Comment:
**Inline comment violates repository rule**
The comment on `scale` explains the test value, which falls outside the repository's allowed comment types. Remove it before merging to meet the requirement to remove comments outside that keep-list.
```suggestion
scale = 0.37
```
**Rule Used:** What: Remove all unwanted code comments in the scoped diff except for a small keep-list (license headers, dependency/protocol-required non-obvious behavior, `// prettier-ignore`, public API doc comments, and issue/RFC constraint links). Why: Comment... ([source](https://app.greptile.com/-/switch-tenant?tenant=hao-ai-lab&next=%2Fcustom-context%3Fmemory%3D856788fb-b8e1-47f8-b01b-d83ea205fc6b))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
|
@fv-superagent check again |
|
Checked again: #2080 is still green and mergeable at 4731dfa - pre-commit, the docs build and all six fastcheck lanes pass (build #2272), the new test's 18 params pass, and Greptile's latest review is 4/5. Since the earlier check the author added three test-only commits: the _fa2_only guard, 3D/4D mask-rank coverage and the P2 comment removal. Nothing new is wrong; the only thing still showing on the PR is my own first-pass CHANGES_REQUESTED, which those fixes superseded. |
Purpose
Keep masked FlashAttention consistent with the SDPA path when a tokenizer supplies an integer padding mask or a caller sets a non-default softmax scale.
Changes
Test Plan
pre-commit run --all-files --hook-stage manual(upstream CI)Test Results
On head
4731dfa, the GitHub Actions run passed all 18 CUDA adapter checks in the FA2 simulation on an RTX 4060; 12 cases failed against the original backend. The FA3 simulation passed nine equal-length cases and skipped nine unequal-length cases. These checks substitute PyTorch CUDA SDPA for the FlashAttention no-padding calls; they do not exercise a native FlashAttention kernel.The upstream GPU unit-test, kernel-test, and documentation jobs passed on the current head. The remaining CI jobs are running.
Checklist
pre-commit run --all-files --hook-stage manualpassed in upstream CI on the current head