Repository navigation
[FlyDSL] gfx950 paged FP8 MQA logits: write -inf past each MTP row's bound - #8327
amd-sriram wants to merge 2 commits into
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
fhuizing
left a comment
There was a problem hiding this comment.
Hey Sriram,
The kernel change looks right to me, the suggestion below is a review combined with an agent, I did not run tests myself, just reasoning from code.
Suggestion: move the NaN pre-fill into the shared harness
-
Pre-fill with NaN in
_kernel_inputsand at theout.fill_(-inf)sites. -
Make the grading aware of what the kernel is expected to write: column
< L_band row< n_b. Assert there is no NaN inside that region, set everything outside it to-inf, then run the existing_gradechecks. Roughly:col = torch.arange(out.shape[-1], device=out.device) must_write = (col[None, :] < ctx_last[:, None]) & (row_idx[:, None] < n_rows[:, None]) assert not out[must_write].isnan().any(), "unwritten column" out = torch.where(must_write, out, torch.full_like(out, float("-inf")))
-
Add the DCP table as a third mode in
_context_lens_arg, next to 1D and consecutive 2D, so it runs over the whole grid. -
The dedicated test can then go, since its NaN fill, its "unwritten column" assert and the overwrite of
out[rows, L_b:]would all live in the shared path.
This should come out around 35 to 40 lines shorter than the current test, and every case in the grid gains the check instead of one shape (B=5, next_n=3). It would also make the ragged test's out[unused] == -inf assert meaningful; with the -inf pre-fill it passes whether or not the kernel touches those rows.
e13676e to
47cec04
Compare
|
Thanks for the review, @fhuizing!
Done in 863cc63:
With the kernel from main, |
…bound Row j of a request is bounded at L_b - n_b + 1 + j, where L_b is the last column of the (B, next_n) context_lens table. The kernel wrote nothing between that bound and L_b, while the Gluon kernel (and the gfx1250 FlyDSL kernel) write -inf there. vLLM's top-k reads row j up to its own context_lens[b, j]. With decode context parallel the per-row lengths are localized per rank, so two rows can share a length (e.g. [50, 51, 51]) and top-k reads columns past the bound: stale workspace data with this kernel, -inf with Gluon. Write -inf for every column below L_b past the row's bound, as gfx1250 does. Add a test with the DCP 2 table that fills the output with NaN and fails on any unwritten column below L_b. Signed-off-by: Sriram Kumar <[email protected]>
…rnel must write, DCP as a context-lens mode
863cc63 to
c43c954
Compare
Summary
The gfx950 FlyDSL
fp8_paged_mqa_logitsnow writes-infpast each MTP row's causal bound, as the Gluon kernel and the gfx1250 FlyDSL kernel do. Before, those columns were left unwritten.Motivation
Row
jof requestbis bounded atL_b - n_b + 1 + j, whereL_bis the last column of the(B, next_n)context_lenstable. Columns from that bound up toL_bwere never written on gfx950:-infwritten there.vLLM's top-k reads row
jup to its owncontext_lens[b, j]. With decode context parallel (DCP), vLLM gives each rank its local share of every row's length, so two rows can end up with the same length:Top-k then reads one column past the bound in rows 0 and 1 (columns 49 and 50):
-infwith Gluon, stale workspace data with this kernel. This is why vllm#60042 keeps the Gluon call for MTP with DCP.Changes
fp8_paged_mqa_logits_gfx950.py:_store_logitwrites-inffor columns belowL_bthat are past the row's bound, instead of skipping them. Columns at or pastL_bare still not written. Docstring updated.op_tests/test_flydsl_fp8_paged_mqa_logits.py: every kernel output is pre-filled with NaN;_gradefails on any NaN in the cells the kernel must write (column< L_b, row< n_b) and ignores the rest. The DCP row lengths are a thirdcontext_lensmode (-c dcp) in the main grid.Performance (if applicable)
Kernel time (µs, best of 2 runs),
HEADS=32,HEAD_DIM=128, KV block 64, FP8 E4M3, 2Dcontext_lens:The 48 shapes are B 16/64/256 × next_n 1/2/3/5 × KV 8192/32768 × 1D/2D
context_lens. Per-shape change ranges from -2.5% to +1.9%; the same kernel varied by up to 10% between two runs, so this is noise.Testing
The kernel is gfx950 only; tested on MI355X.
Documentation
Dependencies
Breaking Changes
None. Columns that were unwritten are now
-inf; every written logit is unchanged.PR Self-Review
Reviewed revision
c43c954
Behavior and intent
Only columns below
L_band past the row's bound change: from unwritten to-inf. Callers whose row lengths are consecutive (vLLM without DCP) read only written columns and see the same values.Validation and unverified scope
MI355X, one GPU,
python op_tests/test_flydsl_fp8_paged_mqa_logits.py:-c dcpon the kernel from main: fails atnext_n4 (unwritten cell);next_n1 passes, as it has no causal band.context_lensmodes): passes.Not verified: end-to-end vLLM with MTP + DCP using this kernel (vllm#60042 still gates that path to Gluon; the gate goes once this lands).
PR-specific question
Changed op tests
test_flydsl_fp8_paged_mqa_logits.py: thedcpmode of_context_lens_argbuilds the(B, next_n)table vLLM uses with DCP 2 on rank 0 (rows repeat, e.g.[50, 51, 51]). With consecutive row lengths (1d,2d) the bound and each row's length agree, so onlydcpreads the columns that used to be unwritten. The NaN pre-fill also makes the ragged test's padded-row check real: it now asserts those rows stay NaN, where the old-infpre-fill passed whether or not the kernel wrote them.