Repository navigation
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
WAITING ON AUTHORPR Self-ReviewRevision Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision. Questions to answer in the PR description
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
e227af3 to
ecde484
Compare
The gate ran as ~10 torch ops per quantized mha_v4 call: below 2048 keys a full fp32 copy of K, then mean/sum reductions over the strided key axis on 4-8 workgroups. It now runs as two deterministic HIP kernels behind one host call (aiter::mha_v4_k_smooth_mean): per-(batch*head, chunk) moments over the same strided sample, then a per-head fold and gate. Same definition, same threshold; the output matches the torch formula within fp32 rounding. gfx950, eager mha_v4 wall time per call (us), main / this / gate as no-op: MXFP4 hd256 h16 s4096 210.6 / 135.2 / 119.5 MXFP6 hd256 h16 s4096 217.4 / 139.8 / 128.1 MXFP4 hd256 h32 s2048 222.0 / 133.4 / 110.8 MXFP6 hd256 h32 s2048 229.4 / 125.7 / 101.8 MXFP8 hd128 h16 s4096 186.4 / 140.8 / 115.3 FP8 hd128 h16 s4096 270.5 / 219.2 / 189.2 MXFP4 hd128 h5 s65536 2556.6 / 2479.0 / 2476.0 FP8 hd128 h5 s65536 3882.2 / 3857.2 / 3848.8 The gate alone: 5.5-11 us GPU (graph replay) and ~20 us host, against 57-131 us GPU before. test_mha_v4 checks the op against the torch formula (both gate outcomes, head-sliced and misaligned K views, hd128/hd256, partial and strided samples). test_mha_v4 332/332 and test_mha_v4_sparse 290 (5 skipped) pass on gfx950. Signed-off-by: jcaraban <jcaraban@amd.com>
ecde484 to
dce26cb
Compare
Summary
mha_v4evaluates its K-smoothing gate (#5798) on every quantized call as ~10 torch ops; at small shapes that costs more than the attention kernel. This runs the same gate as two deterministic HIP kernels behind one call (aiter::mha_v4_k_smooth_mean).Performance
MI355X, eager
mha_v4per call (us): main / this PR / gate disabled.PR Self-Review
Reviewed revision
e227af3Behavior and intent
Same sample, threshold and output (up to fp32 summation order); only the cost changes. The gate drops from ~10 launches to one host call, removing most of the overhead reported against #5798 while keeping its accuracy protection.
Validation and unverified scope
MI355X:
python3 op_tests/test_mha_v4.py332 passed,python3 op_tests/test_mha_v4_sparse.py290 passed (5 skipped). The new test fails when the op's sample size differs from the reference. Unverified: gfx942 (MI300X) not run, although the FP8 recipe reaches this op there.PR-specific question
Every quantized
mha_v4recipe on gfx942/gfx950 calls it through_k_mean; BF16 recipes and non-CUDA K skip it. The host checks BSHD fp16/bf16 K with a contiguous last dim and head dim 64/128/256; misaligned views take a scalar-load path.Changed op tests
op_tests/test_mha_v4.py: addstest_mha_v4_k_smooth_mean_matches_reference, comparing the op with the previous torch formula on both gate outcomes, head-sliced and misaligned K, hd128/hd256. Existing tests only check the gate's end effect on accuracy, not its value.