You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Triton/Gluon] [FlyDSL] Read (B, next_n) context lengths in the paged MQA logits kernels - #6153
Currently, vLLM passes context_lens to the paged MQA logits kernels as a 2D (B, next_n) table, the same layout DeepGEMM uses. The AITER kernels for paged_mqa_logits only read a 1D [B] vector. With MTP on, the 2D table gives them the wrong lengths: silently for Gluon and Triton, and as a reshape error for FlyDSL.
This PR lets the paged_mqa_logits kernels accept the 2D context_lens that vLLM sends with MTP, while staying backward compatible with the 1D context_lens that SGLang and ATOM send with MTP, and with the 1D format used without MTP.
Example: 4 requests, next_n=3, context lengths 8192 / 1500 / 3000 / 700, vLLM sends the following 2D array:
b
j=0
j=1
j=2
0
8190
8191
8192
1
1498
1499
1500
2
2998
2999
3000
3
698
699
700
The paged_mqa_logits kernels read the above 2D array as 1D and read the context_lens as [8190, 8191, 8192, 1498]. The fix uses the row length (next_n) as the stride and reads the last entry of each row, which gives [8192, 1500, 3000, 700].
What changes
Each kernel reads sequence b's length at b * stride + stride - 1.
1D [B]: stride is 1, so this is context_lens[b], the same load as today.
2D (B, n): stride is n, so this is the last entry of row b, which is the full sequence length.
The per-row causal mask is still built from that one length, as before.
Gluon and Triton: new ContextLenStride constexpr, default 1. The 1D path compiles to the same code as before.
FlyDSL: new runtime ctx_stride argument.
The wrappers pick the stride from the tensor's rank.
A strided [B] (for example table[:, -1]) is made contiguous. Before, every backend read it as if it were dense and got the wrong lengths.
A 2D table must be contiguous with at least B rows (FlyDSL: exactly B). Anything else raises ValueError.
AOT Gluon (Triton < 3.4): a stride other than 1 gets a different kernel name, so a missing prebuilt binary fails loudly instead of running the 1D kernel.
The ragged-K variants use prefix_sum_context_lens and are not touched.
Backward compatibility
Callers that pass 1D context_lens today, including ATOM and SGLang with MTP, are not affected.
[num_tokens] with Q [num_tokens, 1, ...]: unchanged. ATOM's DeepSeek-V4 indexer and SGLang's AITER wrapper use this.
(B, 1) behaves exactly like [B].
A contiguous (B, next_n) table is the only new input.
Tests
New test_paged_mqa_logits_2d_context_lens in op_tests/test_pa_mqa_logits_offset.py. For Gluon plain, Gluon preshuffle and FlyDSL (gfx950), a (B, next_n) table must give exactly the same logits as the 1D lengths. Mixed lengths (3000, 257, 64, 3), next_n=3.
The same test also checks that (B, 1) and a strided [B] give the same logits, and that a non-contiguous table or one with too few rows raises ValueError.
The existing tests in that file already cover 1D lengths with next_n > 1.
op_tests/test_flydsl_fp8_paged_mqa_logits.py (FlyDSL and Gluon, next_n 1 to 8, 1D lengths).
Results
MI355X, Triton 3.8, FlyDSL 0.3.4.1, AITER with the touched files at the PR base 7bfe279de plus this change:
test_pa_mqa_logits_offset.py: 108/108 passed, 10 runs in a row. The new test fails without this change.
test_flydsl_fp8_paged_mqa_logits.py: all tables pass, max error 5e-4.
2D and 1D give bit-identical logits for Gluon and FlyDSL. Stage1 and the varctx schedule are identical over 100 calls.
A strided [B] now matches a contiguous one on every backend.
Kernel time, 1D vs 2D, at the GLM-5 indexer shape with 8k context. The difference stays within ±1.5%. Measured before the last commit, which only adds Python-side checks:
path
B
next_n
1D µs
2D µs
Gluon preshuffle
16
3
10.02
10.01
Gluon preshuffle
128
5
70.50
70.00
FlyDSL
16
5
19.22
19.50
FlyDSL
128
5
60.06
60.52
Not tested: AOT Gluon (needs Triton < 3.4).
Found while testing (not fixed here)
These two paths give different results from run to run even with 1D lengths, so the new test skips them:
deepgemm_fp8_paged_mqa_logits_stage1: the -inf mask changes between identical calls.
Gluon preshuffle with VarCtxSchedule: up to 5 of 200 repeated calls differ.
Neither is on the vLLM decode path. Worth a separate issue.
Gluon, Triton stage1/schedule and FlyDSL wrappers take the last column of a 2D table, the layout DeepGEMM takes and vLLM passes.
Signed-off-by: Sriram Kumar <[email protected]>
…copy
Replaces the wrapper-side slice with a ContextLenStride the Gluon, Triton and FlyDSL kernels index with.
Signed-off-by: Sriram Kumar <[email protected]>
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 6153 --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.
amd-sriram
changed the title
[Triton/Gluon] [FlyDSL] Read (B, next_n) context lengths in the paged MQA logits kernels
[Triton/Gluon] Read (B, next_n) context lengths in the paged MQA logits kernels
Oct 12, 2026
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 6153 --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.
amd-sriram
changed the title
[Triton/Gluon] Read (B, next_n) context lengths in the paged MQA logits kernels
[Triton/Gluon] [FlyDSL] Read (B, next_n) context lengths in the paged MQA logits kernels
Oct 12, 2026
The new test pins ChunkK and WavePerEU even though these are the wrapper's current defaults. Triton/Gluon unit tests must exercise the wrapper-selected configuration rather than hard-code tuning values; otherwise a future default/config change can leave this regression test exercising a stale specialization. Remove these overrides.
Move attention test to Triton test directory
op_tests/test_pa_mqa_logits_offset.py:404
This new attention-op test is being added to the legacy op_tests/ root. The Triton test layout mirrors the wrapper path, so a test of aiter/ops/triton/attention/pa_mqa_logits.py belongs under op_tests/triton_tests/attention/ (which already exists). Move this case there so it follows the repository's test discovery and ownership convention.
…DSL table (#6140)
* [Triton][FlyDSL] Add aiter.paged_mqa_logits with a tuned Gluon/FlyDSL table
Picks the paged MQA logits backend and its launch knobs per shape from paged_mqa_logits_tuned.csv. Adds the tuner and op test, and gfx950 rows for the GLM-5 indexer.
Signed-off-by: Sriram Kumar <[email protected]>
* [Triton][FlyDSL] Move paged_mqa_logits next to fused_moe, GLM-5 rows to model_configs
Signed-off-by: Sriram Kumar <[email protected]>
* [Triton][FlyDSL] Look up paged_mqa_logits on the live GPU
get_gfx() follows GPU_ARCHS and skipped the tuned row.
* [Triton][FlyDSL] Drop context_len from the paged_mqa_logits merge key
The generic untuned header is the dedup key. Two rows that differ only
in context length now collide.
* fix: keep paged_mqa_logits run_config off the merge-key header
The generic untuned file no longer has context_len. pre_process still
runs on --run_config and needs that column.
* [FlyDSL] Check the live GPU in the gfx950 paged MQA logits kernel
get_gfx() follows GPU_ARCHS, so the kernel raised on gfx950 with
GPU_ARCHS=gfx942 once the dispatcher picked FlyDSL.
* test: run the shipped-row check with GPU_ARCHS set at process start
Setting GPU_ARCHS mid-process did not reach get_gfx(); the child process
also launches the real kernel.
* [FlyDSL] Fall back to the tuned Gluon knobs when FlyDSL cannot run
FlyDSL rows now store the winning Gluon ChunkK and WavePerEU.
GLM-5 gfx950 table retuned.
* test: check the dispatched paged_mqa_logits config without compiling
The shipped-row check records the config and no longer launches a kernel.
* ci: add paged_mqa_logits to the manual tuning recipes
* [Triton][FlyDSL] Pass context_lens through to the paged MQA logits kernels
Drop the 2D context_lens shim; #6153 adds 2D support in the kernels.
* [Triton][FlyDSL] Tune the GLM-5 paged_mqa_logits rows at 8k and 60k context
Matches the benchmark input lengths (8192 and 60000).
* Document the paged_mqa_logits contract and the context_len column
State the tensors the front-end takes instead of pointing at the Gluon
wrapper, and say that context_len is tuning metadata dispatch does not
read.
* Default the paged_mqa_logits tuner context lengths to 8192;60000
A row with no context_len (a generic-schema untuned CSV, or an empty cell) got an empty context list, so the tuner timed nothing and reported the shape as failed. Such rows now use --context_len, which defaults to the lengths the shipped table was tuned over; context_len stays out of the collision-key header.
* Exit nonzero when paged_mqa_logits tuning errors or is interrupted
TunerCommon.run() catches the exception and calls tune_summary with status Error or Interrupted. With no failed row recorded, the script exited 0 and op_tune.sh reported a pass.
* Reject a strided context_lens in paged_mqa_logits for both backends
Gluon already rejects a non-contiguous context_lens, but the FlyDSL wrapper reshapes it without removing the stride and the kernel reads it as dense, so a table[:, -1] view gave wrong causal bounds on the shipped B=64, next_n=8 FlyDSL row. run_paged_mqa_logits, which the op and the tuner share, now raises ValueError for it; the test covers that view.
* Document context_len as provenance and accept (B, next_n) context_lens
Dispatch deliberately does not key on context length; say so up front and at the loader, where the context_len column is free text that is never parsed (only the tuner reads it). Both kernels read the (B, next_n) table vLLM builds since #6451 and #6450, so the contract now lists it.
* Test (B, next_n) context_lens through paged_mqa_logits and each backend
Uses the shipped B=64, next_n=8 row, which dispatches to FlyDSL, and checks the op, Gluon and FlyDSL against the reference.
* Log each context's gap to its own best in the paged_mqa_logits tuner
The pick minimises the geomean over the row's contexts, which can hide a context where it is well off that context's best. Print the pick's time, the per-context best and the loss for every context.
* ci: upload model_configs tuned CSVs in the tuning artifact
The paged_mqa_logits job writes aiter/configs/model_configs/paged_mqa_logits_tuned_glm5.csv, which aiter/configs/*.csv does not match.
* Test CUDA graph replay and elementwise accuracy in paged_mqa_logits
Capture the op, Gluon and FlyDSL in a CUDA graph at 1024 tokens, change context_lens to 512 in place and replay: the output must match the reference at 512 and leave columns past it untouched, which fails if a launch reads the lengths on the host. The 2D context_lens check now also runs checkAllclose with the main test's tolerances.
---------
Signed-off-by: Sriram Kumar <[email protected]>
…DSL table (ROCm#6140)
* [Triton][FlyDSL] Add aiter.paged_mqa_logits with a tuned Gluon/FlyDSL table
Picks the paged MQA logits backend and its launch knobs per shape from paged_mqa_logits_tuned.csv. Adds the tuner and op test, and gfx950 rows for the GLM-5 indexer.
Signed-off-by: Sriram Kumar <[email protected]>
* [Triton][FlyDSL] Move paged_mqa_logits next to fused_moe, GLM-5 rows to model_configs
Signed-off-by: Sriram Kumar <[email protected]>
* [Triton][FlyDSL] Look up paged_mqa_logits on the live GPU
get_gfx() follows GPU_ARCHS and skipped the tuned row.
* [Triton][FlyDSL] Drop context_len from the paged_mqa_logits merge key
The generic untuned header is the dedup key. Two rows that differ only
in context length now collide.
* fix: keep paged_mqa_logits run_config off the merge-key header
The generic untuned file no longer has context_len. pre_process still
runs on --run_config and needs that column.
* [FlyDSL] Check the live GPU in the gfx950 paged MQA logits kernel
get_gfx() follows GPU_ARCHS, so the kernel raised on gfx950 with
GPU_ARCHS=gfx942 once the dispatcher picked FlyDSL.
* test: run the shipped-row check with GPU_ARCHS set at process start
Setting GPU_ARCHS mid-process did not reach get_gfx(); the child process
also launches the real kernel.
* [FlyDSL] Fall back to the tuned Gluon knobs when FlyDSL cannot run
FlyDSL rows now store the winning Gluon ChunkK and WavePerEU.
GLM-5 gfx950 table retuned.
* test: check the dispatched paged_mqa_logits config without compiling
The shipped-row check records the config and no longer launches a kernel.
* ci: add paged_mqa_logits to the manual tuning recipes
* [Triton][FlyDSL] Pass context_lens through to the paged MQA logits kernels
Drop the 2D context_lens shim; ROCm#6153 adds 2D support in the kernels.
* [Triton][FlyDSL] Tune the GLM-5 paged_mqa_logits rows at 8k and 60k context
Matches the benchmark input lengths (8192 and 60000).
* Document the paged_mqa_logits contract and the context_len column
State the tensors the front-end takes instead of pointing at the Gluon
wrapper, and say that context_len is tuning metadata dispatch does not
read.
* Default the paged_mqa_logits tuner context lengths to 8192;60000
A row with no context_len (a generic-schema untuned CSV, or an empty cell) got an empty context list, so the tuner timed nothing and reported the shape as failed. Such rows now use --context_len, which defaults to the lengths the shipped table was tuned over; context_len stays out of the collision-key header.
* Exit nonzero when paged_mqa_logits tuning errors or is interrupted
TunerCommon.run() catches the exception and calls tune_summary with status Error or Interrupted. With no failed row recorded, the script exited 0 and op_tune.sh reported a pass.
* Reject a strided context_lens in paged_mqa_logits for both backends
Gluon already rejects a non-contiguous context_lens, but the FlyDSL wrapper reshapes it without removing the stride and the kernel reads it as dense, so a table[:, -1] view gave wrong causal bounds on the shipped B=64, next_n=8 FlyDSL row. run_paged_mqa_logits, which the op and the tuner share, now raises ValueError for it; the test covers that view.
* Document context_len as provenance and accept (B, next_n) context_lens
Dispatch deliberately does not key on context length; say so up front and at the loader, where the context_len column is free text that is never parsed (only the tuner reads it). Both kernels read the (B, next_n) table vLLM builds since ROCm#6451 and ROCm#6450, so the contract now lists it.
* Test (B, next_n) context_lens through paged_mqa_logits and each backend
Uses the shipped B=64, next_n=8 row, which dispatches to FlyDSL, and checks the op, Gluon and FlyDSL against the reference.
* Log each context's gap to its own best in the paged_mqa_logits tuner
The pick minimises the geomean over the row's contexts, which can hide a context where it is well off that context's best. Print the pick's time, the per-context best and the loss for every context.
* ci: upload model_configs tuned CSVs in the tuning artifact
The paged_mqa_logits job writes aiter/configs/model_configs/paged_mqa_logits_tuned_glm5.csv, which aiter/configs/*.csv does not match.
* Test CUDA graph replay and elementwise accuracy in paged_mqa_logits
Capture the op, Gluon and FlyDSL in a CUDA graph at 1024 tokens, change context_lens to 512 in place and replay: the output must match the reference at 512 and leave columns past it untouched, which fails if a launch reads the lengths on the host. The 2D context_lens check now also runs checkAllclose with the main test's tolerances.
---------
Signed-off-by: Sriram Kumar <[email protected]>
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
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.
Motivation
Currently, vLLM passes
context_lensto the paged MQA logits kernels as a 2D(B, next_n)table, the same layout DeepGEMM uses. The AITER kernels for paged_mqa_logits only read a 1D[B]vector. With MTP on, the 2D table gives them the wrong lengths: silently for Gluon and Triton, and as areshapeerror for FlyDSL.This PR lets the paged_mqa_logits kernels accept the 2D
context_lensthat vLLM sends with MTP, while staying backward compatible with the 1Dcontext_lensthat SGLang and ATOM send with MTP, and with the 1D format used without MTP.Example: 4 requests,
next_n=3, context lengths 8192 / 1500 / 3000 / 700, vLLM sends the following 2D array:bj=0j=1j=2The paged_mqa_logits kernels read the above 2D array as 1D and read the context_lens as [8190, 8191, 8192, 1498]. The fix uses the row length (
next_n) as the stride and reads the last entry of each row, which gives [8192, 1500, 3000, 700].What changes
b's length atb * stride + stride - 1.[B]: stride is 1, so this iscontext_lens[b], the same load as today.(B, n): stride isn, so this is the last entry of rowb, which is the full sequence length.ContextLenStrideconstexpr, default 1. The 1D path compiles to the same code as before.ctx_strideargument.[B](for exampletable[:, -1]) is made contiguous. Before, every backend read it as if it were dense and got the wrong lengths.Brows (FlyDSL: exactlyB). Anything else raisesValueError.prefix_sum_context_lensand are not touched.Backward compatibility
Callers that pass 1D
context_lenstoday, including ATOM and SGLang with MTP, are not affected.[B]with Q[B, next_n, ...]: unchanged. ATOM's sparse indexer uses this.[num_tokens]with Q[num_tokens, 1, ...]: unchanged. ATOM's DeepSeek-V4 indexer and SGLang's AITER wrapper use this.(B, 1)behaves exactly like[B].(B, next_n)table is the only new input.Tests
test_paged_mqa_logits_2d_context_lensinop_tests/test_pa_mqa_logits_offset.py. For Gluon plain, Gluon preshuffle and FlyDSL (gfx950), a(B, next_n)table must give exactly the same logits as the 1D lengths. Mixed lengths(3000, 257, 64, 3),next_n=3.(B, 1)and a strided[B]give the same logits, and that a non-contiguous table or one with too few rows raisesValueError.next_n > 1.op_tests/test_flydsl_fp8_paged_mqa_logits.py(FlyDSL and Gluon,next_n1 to 8, 1D lengths).Results
MI355X, Triton 3.8, FlyDSL 0.3.4.1, AITER with the touched files at the PR base
7bfe279deplus this change:test_pa_mqa_logits_offset.py: 108/108 passed, 10 runs in a row. The new test fails without this change.test_flydsl_fp8_paged_mqa_logits.py: all tables pass, max error 5e-4.[B]now matches a contiguous one on every backend.Found while testing (not fixed here)
These two paths give different results from run to run even with 1D lengths, so the new test skips them:
deepgemm_fp8_paged_mqa_logits_stage1: the-infmask changes between identical calls.VarCtxSchedule: up to 5 of 200 repeated calls differ.Neither is on the vLLM decode path. Worth a separate issue.