Skip to content

[FlyDSL] gfx950 paged FP8 MQA logits: write -inf past each MTP row's bound - #8327

Draft
amd-sriram wants to merge 2 commits into
ROCm:mainfrom
amd-sriram:flydsl-pmqa-per-row-ctx
Draft

amd-sriram wants to merge 2 commits into
ROCm:mainfrom
amd-sriram:flydsl-pmqa-per-row-ctx

Conversation

@amd-sriram

@amd-sriram amd-sriram commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The gfx950 FlyDSL fp8_paged_mqa_logits now writes -inf past each MTP row's causal bound, as the Gluon kernel and the gfx1250 FlyDSL kernel do. Before, those columns were left unwritten.

Motivation

Row j of request b is bounded at L_b - n_b + 1 + j, where L_b is the last column of the (B, next_n) context_lens table. Columns from that bound up to L_b were never written on gfx950:

vLLM's top-k reads row j up to its own context_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:

DCP 2, rank 0 Row 0 Row 1 Row 2
Global length 100 101 102
Local length (what top-k reads) 50 51 51
Columns the kernel writes (bound from the last column, 51) 49 50 51

Top-k then reads one column past the bound in rows 0 and 1 (columns 49 and 50): -inf with 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_logit writes -inf for columns below L_b that are past the row's bound, instead of skipping them. Columns at or past L_b are still not written. Docstring updated.
  • op_tests/test_flydsl_fp8_paged_mqa_logits.py: every kernel output is pre-filled with NaN; _grade fails 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 third context_lens mode (-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, 2D context_lens:

Hardware Workload/configuration Before After Change
MI355X B 16, next_n 1, KV 8192 11.28 11.37 +0.8%
MI355X B 64, next_n 3, KV 8192 29.86 29.98 +0.4%
MI355X B 256, next_n 3, KV 32768 324.79 325.88 +0.3%
MI355X B 256, next_n 5, KV 32768 435.66 438.99 +0.8%
MI355X Geomean, 48 shapes 1.000 1.0002 +0.0%

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

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

The kernel is gfx950 only; tested on MI355X.

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

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_b and 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 dcp on the kernel from main: fails at next_n 4 (unwritten cell); next_n 1 passes, as it has no causal band.
  • Full op test with this change (all three context_lens modes): 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: the dcp mode of _context_lens_arg builds 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 only dcp reads 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 -inf pre-fill passed whether or not the kernel wrote them.

@amd-sriram
amd-sriram requested a review from fhuizing November 19, 2026 23:37
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter standard tests on MI35X
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the Radeon R9700 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 8327 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@fhuizing fhuizing left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. Pre-fill with NaN in _kernel_inputs and at the out.fill_(-inf) sites.

  2. Make the grading aware of what the kernel is expected to write: column < L_b and row < n_b. Assert there is no NaN inside that region, set everything outside it to -inf, then run the existing _grade checks. 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")))
  3. 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.

  4. 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.

@amd-sriram

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @fhuizing!

Pre-fill with NaN in _kernel_inputs … Add the DCP table as a third mode in _context_lens_arg … The dedicated test can then go

Done in 863cc63:

  • Every kernel output is pre-filled with NaN.
  • _grade fails on a NaN anywhere with column < L_b and row < n_b, and sets everything else to -inf.
  • dcp is the third _context_lens_arg mode, so it runs over the whole grid. The dedicated test is gone.
  • The ragged test now checks that padded rows stay NaN.

With the kernel from main, -c dcp fails at next_n 4; with this PR the full grid passes on MI355X. The diff isn't shorter (+89/−86), because _grade now needs context_lens from every caller.

amd-sriram and others added 2 commits November 27, 2026 16:33
…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]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants