Repository navigation
[FlyDSL] [DSv4] Bound the FP4 MQA-logits store with a window-sized V# instead of a compare - #5285
Merged
Merged
Conversation
Contributor
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
PR title tags & labels: |
The per-token store was guarded in software -- `is_writer & (tok >=
local_start) & (tok < local_end)` -- which lowers to 2 v_cmp + 2 s_and_b64 +
s_or_b64 + s_and_saveexec_b64 + s_cbranch_execz per n-tile: 28 instructions
per chunk, 11.6% of the steady-state loop body and second only to the
reduction itself.
Size a buffer descriptor to the window instead and num_records IS the test,
in hardware. A token below the window underflows to a large unsigned offset
and is dropped by the same bound, so one check covers both ends.
Two things this gets wrong if done casually:
- Lanes 16..63 hold redundant copies of the butterfly result and must not
write. Parking them past num_records needs a CONSTANT offset, not a
multiple of the window length: `token_base - local_start` is negative for a
token below a non-zero window start, and adding the length to that lands
back INSIDE the window, racing the lane that owns the column.
- The window bounds must go through readfirstlane. They are wave-uniform but
arrive from cta_info in VGPRs, and a divergent descriptor makes the compiler
wrap the store in a waterfall loop -- 252 instructions, worse than the guard
it replaces.
Steady-state loop body 242 -> 203 instructions. MI355X, 2 interleaved reps,
min over 15-20 iters:
rows=8192 W~2064 124.4us -> 119.0us (-4.4%)
rows=1024 W~32768 241.0us -> 225.4us (-6.5%)
Same fold on the rectangular decode twin. Output is unchanged -- cells
outside the window still hold the caller's -inf pre-fill, which
test_flydsl_pa_mqa_logits_fp4{,_prefill}.py already assert on every case,
including the one window set with a non-zero local_start.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
valarLip
force-pushed
the
perf/mqa-logits-window-vsharp
branch
from
September 5, 2026 05:57
f1f8190 to
637f8cb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The FP4 MQA-logits scorer guarded its per-token store in software:
That lowers to
2 v_cmp + 2 s_and_b64 + s_or_b64 + s_and_saveexec_b64 + s_cbranch_execzper n-tile — 28 instructions per chunk, 11.6% of thesteady-state loop body, second only to the reduction itself.
This sizes a buffer descriptor to
[local_start, local_end)instead, sonum_recordsis the window test, in hardware.A token below the window underflows to a large unsigned offset and is
dropped by the same bound, so one comparison covers both ends.
Two traps, both hit while writing this:
write. Parking them past
num_recordsneeds a constant offset, not amultiple of the window length:
token_base - local_startis negative for atoken below a non-zero window start, and adding the length to that lands
back inside the window, racing the lane that owns the column. Caught by
test_flydsl_pa_mqa_logits_fp4_prefill.py's one non-zero-local_startcase— it went non-deterministic (cos 0.79/0.94/0.99 across runs) where the other
eight stayed at 1.000000.
readfirstlane. They are wave-uniform butarrive from
cta_infovia a buffer load, i.e. in VGPRs, and a divergentdescriptor makes the compiler wrap the store in a waterfall loop — 252
instructions, worse than the guard it replaces.
Both the descriptor and the lane offset are chunk-invariant, so both are built
once outside the loop.
Same fold applied to the rectangular decode twin (
pa_mqa_logits_fp4.py).Numbers
Steady-state loop body 242 → 203 instructions. MI355X (gfx950), 3
interleaved reps, min over 40 iterations:
Isolated: only the store path was reverted for the "before" column, so this
is the fold alone and not a mix of unrelated edits.
Correctness
Output is unchanged — cells outside the window still hold the caller's
-infpre-fill, which
test_flydsl_pa_mqa_logits_fp4.pyandtest_flydsl_pa_mqa_logits_fp4_prefill.pyalready assert on every case(
oob_neginf=True,cos_exact=1.000000/cos_sim=1.0000on all 13 —including the non-zero-
local_startwindow set that caught the lane-offsetbug above).
One edge the existing suite does not cover, verified locally but not added
here: a zero-length window (
num_records == 0), which only exists as aconcept once the bound is in hardware. Checked with an all-empty-window batch
and with a single live row among empty ones; nothing is written in either.
Test plan
op_tests/test_flydsl_pa_mqa_logits_fp4_prefill.py— 8 cases passop_tests/test_flydsl_pa_mqa_logits_fp4.py— 5 shapes,cos_sim=1.0000buffer_store_dword ... offen, zerov_cmp/s_and_saveexec/s_cbranch_execzleft in the loop body, no waterfallback-edge
the in-window cells so I would expect no movement
Note for reviewers
#5282 touches the same file. It rewrites the schedule side
(
compute_prefill_schedule,_RowPlan,_row_plan,_prefill_{row_plan,cta_info}_kernel); this touches only the scoringkernel's store path. Different regions, so they should merge, but the two
should probably land in a known order.
🤖 Generated with Claude Code