Repository navigation
MHA v4: fix torch 2.10 Dynamo graph break - #7647
Conversation
AttentionScaleMode(k_scale_mode) in mha_v4_packed graph-breaks under torch 2.10's Dynamo. Compare the IntEnum value directly instead; the result is unchanged. Signed-off-by: Niko Säkkinen <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
NOT READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
…#7647) AttentionScaleMode(k_scale_mode) in mha_v4_packed graph-breaks under torch 2.10's Dynamo. Compare the IntEnum value directly instead; the result is unchanged. Signed-off-by: Niko Säkkinen <[email protected]> Co-authored-by: Xin Huang <[email protected]>
Summary
Fix the Dynamo graph break in block-sparse
mha_v4under torch 2.10, which turnstest_mha_v4_sparse.pyred on MI300X CI.Motivation
test_mha_v4_sparse_block_mask_compiles_without_graph_breaksfails on the CI image (torch 2.10) withSourcelessBuilder.create does not know how to wrap <class 'method'>. The cause isAttentionScaleMode(k_scale_mode)inmha_v4_packed: torch 2.10's Dynamo can't trace building an enum from a value. Newer torch can, so this didn't show up locally.Changes
aiter/ops/mha_v4.py: comparek_scale_modetoAttentionScaleMode.E8M0_PER_1X32directly instead of wrapping it in the enum constructor.AttentionScaleModeis anIntEnumand the scale modes are already checked by_validate_scale_recipe, so behaviour doesn't change.Testing
Documentation
Dependencies
Breaking Changes
None
PR Self-Review
Reviewed revision
80b9b43
Behavior and intent
No functional change.
mha_v4_packeddecided whether to make the K scales head-major withAttentionScaleMode(k_scale_mode) == AttentionScaleMode.E8M0_PER_1X32. Under torch 2.10 (the CI image), Dynamo can't trace building an enum from a value. It graph-breaks withSourcelessBuilder.create does not know how to wrap <class 'method'>, which failstest_mha_v4_sparse_block_mask_compiles_without_graph_breaksand failstorch.compile(fullgraph=True)on the block-sparse path. The fix comparesk_scale_modeto the enum constant directly.AttentionScaleModeis anIntEnum, so the result is the same whether the value is an enum or a plain int._validate_scale_recipehas already checked the value at that point, so the constructor's own validation was redundant.Validation and unverified scope
MI300X (gfx942), CI image
rocm/pytorch:rocm7.2.4_ubuntu24.04_py3.12_pytorch_release_2.10.0:python op_tests/test_mha_v4_sparse.py: before the fix, 126 ran and 1 failed (the graph-break check, with the error above). After it: 127 ran, 168 skipped, 0 failed.python op_tests/test_mha_v4.py: 66 ran, 261 skipped, 0 failed.torch._dynamo.explainonmha_v4(..., block_mask=mask)with FP8 operands: 1 graph break before the fix, 0 after.aiter/ops/mha_v4.py.Unverified:
PR-specific question
The only path whose behaviour could change is the head-major K-scale branch (
kv_tile == 64with E8M0 K scales and FP8 or MXFP4 K). Getting this comparison wrong would silently skip the K-scale re-layout on gfx950 MXFP8/MXFP4 64x64 sparse calls and corrupt their output. Evidence that it doesn't:IntEnumsemantics:5 == AttentionScaleMode.E8M0_PER_1X32andAttentionScaleMode(5) == AttentionScaleMode.E8M0_PER_1X32are both true, and every other validated value compares false either way._validate_scale_recipebefore this point, so the constructor never rejected anything here.test_mha_v4_sparse.py(e.g.test_mha_v4_sparse_64x64_all_true_mask_matches_dense), which the gfx950 CI job runs.Changed op tests
None