Skip to content

[Triton/Gluon] [Bugfix] [Perf] Support page size 8 in paged MQA logits on both layouts, and fix large KV offsets - #5749

Merged
valarLip merged 10 commits into
mainfrom
zhiding512/mqa-logits-page8-main-20260922
Sep 23, 2026
Merged

valarLip merged 10 commits into
mainfrom
zhiding512/mqa-logits-page8-main-20260922

Conversation

@zhiding512

@zhiding512 zhiding512 commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem

On main the non-preshuffle ("plain") Gluon paged MQA logits kernel has no block-paging path at all: it indexes kv_indices with the token position, which is only correct when KVBlockSize == 1. A KV cache paged at more than one token per page therefore reads the wrong pages — and nothing rejects it, because deepgemm_fp8_paged_mqa_logits only asserts KVBlockSize == 1 on gfx1250. On gfx942/gfx950 a paged cache is silently mis-scored rather than refused. The preshuffle path cannot stand in for it either: it requires KVBlockSize % 16 == 0, because the shuffled KV feeds the 16-token MFMA B operand directly and a page of 8 is half a tile.

That leaves page size 8 — what DeepSeek V4.1 decode uses for the indexer KV cache — unreachable on main on either layout.

Separately, both paths form KV and FP32-scale addresses through 32-bit strides, so a cache past the 2 GiB buffer-descriptor range wraps; and the preshuffle logits store is not bounded by max_model_len, so a short final chunk spills into the next output row.

These are all silent-wrong-answer bugs: the indexer logits feed a top-k, so a corrupted tail turns into wrong sparse-KV indices rather than a crash.

What this changes

Plain path

  • Block paging in the plain kernel. Derive the page index as token // KVBlockSize and the in-page offset as token % KVBlockSize, instead of treating the token position as a page index. The backward-shifted first tile can carry negative positions, so those lanes are clamped to token 0 of page 0 before the offset is formed, including for the scale.
  • 64-bit KV addressing on the plain path. stride_k_seq and stride_scale_seq become i64, and the K and scale reads become global loads, so a cache beyond 2 GiB still addresses correctly. The plain path builds per-token addresses from the page table, so the 32-bit stride product was the overflow site.
  • Preshuffle large offsets and tail store. Widen the page index to 64 bit before scaling by the stride, and bound the logits store by max_model_len so a short final chunk cannot reach into the next row.

Preshuffle path

Page 8 on the plain path works but is the slow layout. No new load structure is needed to reach the fast one: the per-lane page index already varies at KVBlockSize granularity, and a page shorter than ChunkK // 2 already takes the "page index per lane" branch, so the two pages behind one tile are already addressable. What was hardcoded is the shuffle group.

  • ShuffleRows = min(KVBlockSize, 16) in both _gluon_deepgemm_fp8_paged_mqa_logits_preshuffle and its _varctx twin, replacing the literal 16 in the B-operand offset. One tile is then assembled from two pages.
  • The wrapper admits 8, and only 8, below the tile size. The addressing generalises to any page that divides 16, and pages 1, 2 and 4 do run correctly — max abs error 0.0043 to 0.0058 against FP32, the same band as page 16, and faster than plain at the same page size (on a one-off probe, page 1: 271.0 us vs 398.1 us; page 4: 189.2 us vs 287.7 us). They stay rejected because no caller asks for them and the sweep does not cover them. gfx1250 preshuffle reshapes by a literal KVBlockSize // 16 for its TDM block load, so pages below 16 stay rejected there outright.
  • The row-group stride goes from a literal 16 * 128 to ShuffleRows * HiddenDim to stay consistent with the above. This is not what makes page 8 work — a page that short holds one group, so the term is zero either way — and at HiddenDim 128 the two expressions are equal. No configuration a caller can reach today changes; every caller runs HiddenDim 128.
  • The bench gets the host side of this. --kv_preshuffle used to fall back to plain whenever the page was not a multiple of 16, quietly reporting the wrong path, and it shuffled at a fixed 16 rows. It now honours the flag, derives the layout from the page size, and reports kv_tokens so a run can be turned into bandwidth. Defaults do not move: 16 preshuffled, 1 plain.

Caller-visible: a page of 8 must be shuffled in groups of its own length, shuffle_weight(kv, layout=(8, 16)), rather than the default (16, 16). Getting this wrong is not silent — shuffle_weight asserts shape[-2] % 16 == 0 on the default layout.

Performance

Measured with the bench in this PR on gfx950, heads 32 / head-dim 128, three shapes x two layouts x page 8/16, three rounds per point with the arms rotated inside a round, medians below. Round-to-round spread is under 1.9 us everywhere. The rows below carry a 286 MB working set, past the 256 MB MALL, so their TB/s is DRAM-bound; the other two shapes fit in MALL and their TB/s is not an HBM figure.

batch 16, next_n 1, 1M context:

page path latency effective BW
8 plain 431.384 us 5.125 TB/s
16 plain 410.064 us 5.382 TB/s
8 preshuffle 379.863 us 5.820 TB/s
16 preshuffle 359.784 us 6.134 TB/s

Halving the page costs 5.58% here, and 3.01% to 5.20% across the five other shape and layout pairs. Both layouts move together, so what is paid for is the page and not the shuffle: one tile's contiguous run drops from 256 B to 128 B, and the page table doubles in width. The page table is 0.18% of the byte model, which leaves the contiguity.

That cost does not change what a page-8 caller should do, because page 16 is not one of its options. Against the only alternative it has — page-8 plain — preshuffle is 11.9% faster, and it also beats page-16 plain by 7.4%. The speedup preshuffle already had is essentially kept at the smaller page: 1.096x to 1.692x over plain at page 16, 1.088x to 1.664x at page 8 across the three shapes.

Testing

op_tests/test_pa_mqa_logits_offset.py, 105 cases, all passing on gfx950 (MI35x):

  • test_paged_mqa_logits_non_preshuffle — block sizes 1 / 8 / 16 / 64 / 128 x ChunkK 64 / 256 x compact / padded page tables x the decode and MTP shapes. Compact tables expose token-indexed out-of-bounds reads; padded tables keep those reads in allocated memory and expose wrong scores instead. Output rows are sentinel-guarded on both sides so a store that walks off a row is caught.
  • test_paged_mqa_logits_preshuffle — new, and the sweep the preshuffle path never had; previously only the large-KV-offset cases reached it, all at the default ChunkK. Pages 8 / 16 / 32 / 64 / 128 / 256 x ChunkK 128 / 256 x compact / padded tables x the decode and MTP shapes. The page sizes pick out how the B tile gets assembled: 8 is half a tile and draws from two pages, 16 is exactly one, 32 through 128 are several row groups inside one page, and 256 exceeds ChunkK // 2 and so takes the one-page-per-stage branch. ChunkK 128 and 256 are the two the callers ask for — the bench runs preshuffle at 128, the indexer at 256.
  • test_paged_mqa_logits_large_kv_offsets — plain and preshuffle, including a preshuffle-B8 row, with the referenced pages placed around the 2 / 4 / 8 GiB boundaries, so the offset arithmetic is exercised without allocating a multi-GiB reference.
  • test_paged_mqa_logits_wide_output_no_tail_drop — the dense [rows, 1<<20] layout whose row 512 store lands exactly on 2**31 bytes.

Everything is compared against an FP32 reference built from the same FP8 inputs. Before the preshuffle commit, the 8 page-8 rows of the new sweep fail — rejected by the wrapper before they reach the device — and the other 40 pass unchanged.

The bench was run in all three configurations it can take — --kv_preshuffle (page 16), --kv_preshuffle --blocksize 8, and plain (page 1) — with logits_diff at 0.00046 to 0.00047 in each.

Relationship to #5614

#5614 carries the plain-path fixes plus a batch of decode-grid and persistent-CTA perf work, and its review surface has grown accordingly. This PR is page size 8 on both layouts, plus the addressing bugs in the way of it, split out so it reaches main without waiting on that perf review. The decode-grid and persistent-CTA commits stay in #5614.

The preshuffle half arrived here through #5768, which was merged into this branch rather than reviewed separately.

@zhiding512
zhiding512 requested review from a team and a lite review from Copilot September 22, 2026 07:20
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
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; main branch always runs both MI35X and MI300X
multigpu 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: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 5749 --add-label <label>

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 opt this PR out.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Critical varctx addressing and output-bound issues remain, along with an AOT artifact naming mismatch.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 High severity · 1 Medium severity

Open (3)
What changed in this PR

Fixes paged MQA logits for page size 8, large KV offsets, and preshuffle tail stores.

Changes:

  • Adds block paging and 64-bit addressing to the plain kernel.
  • Bounds preshuffle output stores by max_model_len.
  • Adds regression coverage and updates AOT artifact naming.
File Summary
op_tests/​test_pa_mqa_logits_offset.py Adds paging and large-offset regression tests, but does not cover the varctx dispatch path.
op_tests/​op_benchmarks/​triton/​bench_deepgemm_attention.py AOT artifact naming can diverge from the loader’s expected directory name. Moderate issue (3 votes).
aiter/​ops/​triton/​gluon/​pa_mqa_logits.py Updates paging and addressing; varctx preshuffle stores remain able to cross row boundaries. Critical issue (1 vote).
aiter/​ops/​triton/​attention/​pa_mqa_logits.py Updates the plain-kernel stride ABI; varctx preshuffle loads may still overflow 32-bit addressing. Critical issue (2 votes).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +303 to +307
# The plain kernel forms per-token KV addresses from the page table, so
# a cache past 2 GiB overflows a 32-bit stride product.
"stride_k_seq": "i32" if Preshuffle else "i64",
"scale_buffer": "*fp32",
"stride_scale_seq": "i32",
"stride_scale_seq": "i32" if Preshuffle else "i64",
+ gl.arange(0, ChunkKPerStage, layout=gl.SliceLayout(0, mfma_layout))
>= split_context_start,
offsets=store_cols,
mask=(store_cols >= split_context_start) & (store_cols < max_model_len),
Comment on lines +414 to +418
if (
not args.kv_preshuffle
and kv_cache_fp8.shape[0] * kv_cache_fp8.stride(0) >= 2**31
):
aot_name += "_kv64"
zhiding512 and others added 5 commits September 22, 2026 17:45
Signed-off-by: zhimding <[email protected]>
Co-authored-by: Cursor <[email protected]>
The 2 GiB threshold gave one shape two ABIs: a 32-bit stride kernel for
small caches and a 64-bit one past the buffer descriptor range, told apart
only by a _kv64 suffix on the AOT directory. Compile the non-preshuffle
kernel with 64-bit KV and scale strides for every shape instead, so one
shape maps to one binary again and the dead 32-bit load paths go away.

Measured on gfx950 at N=131072, H=32, D=128, ChunkK=256, WavePerEU=2,
median of three processes per point, arms alternating within a round.
With KVBlockSize=64 the unconditional kernel costs +16.6% at batch 1
(5.728 -> 6.677 us), +4.1% at 16, +1.8% at 64, and -0.2% at 128, where
the cache already crossed 2 GiB and the kernel is unchanged, which puts
the noise floor of that setup near 0.2%. KVBlockSize=1 moves the other
way: 247.6 -> 95.3 us at batch 16 and 1053.0 -> 463.7 us at batch 64.

The preshuffle kernels keep 32-bit stride arguments; their addressing is
handled separately.

Signed-off-by: zhimding <[email protected]>
DeepSeek V4.1 decode pages the indexer KV cache at 8 tokens per page, a size
the block-paging cases did not exercise.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: zhimding <[email protected]>
Co-authored-by: Cursor <[email protected]>
…kernel

Two defects in _gluon_deepgemm_fp8_paged_mqa_logits_preshuffle, both silent
until the KV cache is large or the context lengths are unaligned.

When ChunkKPerStage % KVBlockSize != 0, which is KVBlockSize=256 at
ChunkK=256, the K and scale addresses came from a 32-bit page-index product,
so a cache past 2 GiB wrapped into another page. Read them through a global
pointer with the index promoted to 64 bits, the way the per-lane branch
already does. Folding the page base into a buffer_load pointer also fixes the
addressing but costs a descriptor setup per stage, so it is not used here.

The per-lane branch stored its last stage across the whole tile, including
the columns past context_length that hold -inf. With an output width equal to
an unaligned context those columns land in the next row: context lengths
(3001, 513) lost the first 7 logits of row 1. Bound those three stores by
max_model_len, which the kernel's other stores already do.

Measured on gfx950 at N=131072, H=32, D=128, ChunkK=256, median of three
processes per point, arms alternating within a round:

  KVBlockSize=256, batch 128, 2.06 GiB cache: 508281/16777216 mismatched
      logits -> 0, and 449.150 -> 451.121 us (+0.44%)
  KVBlockSize=256, batch 64, 1.03 GiB cache: clean before and after, and
      250.599 -> 238.254 us (-4.93%)
  KVBlockSize=64, batch 128, 2.06 GiB cache: clean before and after, and
      464.583 -> 463.802 us (-0.17%)

The large-KV regression test now covers the preshuffle layout for
KVBlockSize=64 and 256 at the 2, 4 and 8 GiB boundaries. Its unaligned
context lengths and compact output width also cover the tail store.

Signed-off-by: zhimding <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Unresolved varctx addressing and tail-store issues, AOT lookup mismatch, and test configuration issue remain.

Review effort: Lite
Findings: 2 High severity · 1 Medium severity

Open (3)

Copilot AI review requested due to automatic review settings September 22, 2026 17:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Unresolved moderate findings remain for VarCtx addressing and stores, AOT naming, and test setup.

Review effort: Lite
Findings: 2 High severity · 1 Medium severity

Open (3)

@zufayu
zufayu requested review from a team and vgokhale September 23, 2026 01:13
zhiding512 and others added 2 commits September 23, 2026 11:25
The shuffled KV layout feeds the 16-token MFMA B tile directly, so the page
size had to be a multiple of 16. A page of 8 -- what DeepSeek V4.1 decode
allocates -- is half a tile, and the other half lives in a physically
unrelated page, so page-8 decode was stuck on the plain path.

No new load structure is needed for this. The per-lane page index already
varies at KVBlockSize granularity, and a page shorter than ChunkK // 2
already takes the "page index per lane" branch. What was hardcoded is the
shuffle group: the B-operand offset assumed 16 rows per group. Derive it as
ShuffleRows = min(KVBlockSize, 16) instead, matching the layout the host
passes to shuffle_weight, and the tile is read from 16 // KVBlockSize pages.

The row-group stride goes from a literal 16 * 128 to ShuffleRows * HiddenDim
to stay consistent with that. It is not what makes page 8 work -- a page that
short holds one group, so the term is zero either way -- and at HiddenDim 128
the two expressions are equal, so no configuration a caller can reach today
changes. Every caller runs HiddenDim 128.

gfx1250 preshuffle still reshapes by a literal KVBlockSize // 16 for its TDM
block load, so pages below 16 are rejected there rather than mis-addressed.

The benchmark could not express any of this: --blocksize applied only to the
preshuffle path and had to be a multiple of 16, Preshuffle was inferred from
it rather than taken from the flag, and the host shuffle used the default
(16, 16) layout. Those are the same assumptions the kernel drops, so drop them
there too, and record the scored token count that a bandwidth figure needs.

Measured with it on gfx950, heads 32 / head-dim 128, three rounds per point
with the arms rotated inside a round, medians below. Round-to-round spread is
under 1.9 us everywhere. These rows carry a 286 MB working set, past the
256 MB MALL, so their TB/s is DRAM-bound:

  batch 16, next_n 1, 1M context
    page 8  plain        431.384 us   5.125 TB/s
    page 16 plain        410.064 us   5.382 TB/s
    page 8  preshuffle   379.863 us   5.820 TB/s
    page 16 preshuffle   359.784 us   6.134 TB/s

Halving the page costs 5.58% here, and 3.01% to 5.20% over the five other
shape and layout pairs measured. Both layouts move together, so what is being
paid for is the page and not the shuffle: one tile's contiguous run drops from
256 B to 128 B, and the page table doubles in width. The page table is 0.18%
of the byte model, which leaves the contiguity.

That cost does not change what a page-8 caller should do, because page 16 is
not one of its options. Against the only alternative it has, page-8 plain,
preshuffle is 11.9% faster; it also beats page-16 plain by 7.4%.

Signed-off-by: zhimding <[email protected]>
Co-authored-by: Cursor <[email protected]>
Preshuffle had no page-size sweep of its own; only the large-KV-offset cases
reached it, and every one of those ran the default ChunkK. Mirror the plain
sweep instead: pages 8 through 256 across ChunkK 128 and 256, compact and
padded page tables, and the decode and MTP shapes.

The page sizes pick out the ways the MFMA B tile gets assembled. Page 8 is
half a tile and draws from two pages, 16 is exactly one, 32 through 128 are
several row groups inside one page, and 256 exceeds ChunkK // 2 and so takes
the one-page-per-stage branch. ChunkK 128 and 256 are the two the callers
ask for: the bench runs preshuffle at 128, the indexer at 256.

Against the parent commit the 8 page-8 rows fail, rejected by the wrapper
before they reach the device, and the other 40 pass unchanged.

Signed-off-by: zhimding <[email protected]>
Co-authored-by: Cursor <[email protected]>
Copilot AI review requested due to automatic review settings September 23, 2026 03:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Unresolved critical and moderate findings remain in VarCtx addressing, validation, tail bounds, AOT naming, and test placement.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 4 High severity · 2 Medium severity

Open (6)

Comment on lines +509 to +512
assert KVBlockSize % 16 == 0 or 16 % KVBlockSize == 0, (
"Preshuffle needs the KV page to be a multiple of the 16-token MFMA "
f"tile or to divide it. Got KVBlockSize={KVBlockSize}."
)
Comment thread aiter/ops/triton/gluon/pa_mqa_logits.py Outdated
# passed to shuffle_weight. A page shorter than the 16-token MFMA tile can
# only be shuffled in groups of its own length, so the tile is then read
# from 16 // KVBlockSize pages -- which the per-lane page index already does.
ShuffleRows: gl.constexpr = KVBlockSize if KVBlockSize < 16 else 16
Comment on lines +142 to +146
@pytest.mark.parametrize("block_size", [1, 8, 16, 64, 128])
@pytest.mark.parametrize("chunk_k", [64, 256])
@pytest.mark.parametrize("padded_table", [False, True], ids=["compact", "padded"])
@pytest.mark.parametrize(
"context_lengths,next_n,heads,hidden_dim",
The page-8 gate went in as "a multiple of 16, or a page that divides 16",
which also lets through 1, 2 and 4. Those do work: max abs error 0.0043 to
0.0058 against an FP32 reference, the same band as page 16, and faster than
the plain path at the same page size -- 271.0 us against 398.1 us at page 1,
189.2 us against 287.7 us at page 4, on gfx950 at batch 32 / next_n 2 / 128K
context.

They are still not worth admitting. No caller asks for a page below 8, and
the sweep covers 8 upward, so the three of them would be surface the tests
never run. Narrow the gate to 8 instead, and the bench gate with it, so what
is accepted is what is checked.

Signed-off-by: zhimding <[email protected]>
Co-authored-by: Cursor <[email protected]>
Copilot AI review requested due to automatic review settings September 23, 2026 05:59
@zhiding512 zhiding512 changed the title [Triton/Gluon] [Bugfix] Support page size 8 in non-preshuffle MQA logits and fix large KV offsets [Triton/Gluon] [Bugfix] [Perf] Support page size 8 in paged MQA logits on both layouts, and fix large KV offsets Sep 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The style CI pins ruff 0.16.0, which carries FURB136 (if-expr-min-max) in its
default rule set and rejects `KVBlockSize if KVBlockSize < 16 else 16` in both
preshuffle kernels. min(KVBlockSize, 16) is the same constexpr, is what the
commit that introduced the line already calls it in prose, and is the form the
other Gluon kernels use for this. Missed locally on ruff 0.15.18, which does
not have the rule among its defaults.

Signed-off-by: zhimding <[email protected]>
Co-authored-by: Cursor <[email protected]>
Copilot AI review requested due to automatic review settings September 23, 2026 06:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@valarLip
valarLip merged commit 781bf75 into main Sep 23, 2026
71 checks passed
@valarLip
valarLip deleted the zhiding512/mqa-logits-page8-main-20260922 branch September 23, 2026 15:08
valarLip added a commit to ROCm/ATOM that referenced this pull request Sep 24, 2026
* perf(attention): reduce V4 fused decode normalization overhead

Normalize once per head and improve occupancy for nonquantized D512 32-head tiles. Cover ragged CSR, sinks, quantized KV, and changing graph inputs with an independent reference.

* perf(attention): specialize gfx950 fused decode with shared KV panels

Use explicit MFMA layouts for BF16 D512 head tiles and reuse KV panels through LDS. Preserve the existing split and fallback paths; cover graph inputs, tile boundaries, and large KV addresses.

* Generalize V4 fused decode across CDNA3 and CDNA4

* perf(v41): page the index plane at the candidate block length

A Reindex layer scored every column of its context and then drove the ones
outside the candidate source's blocks to -inf. The blocks it keeps are exactly
a block table -- if the plane is paged at the length they are picked in -- so
the same selection is reachable by scoring `candidate_topk_blocks` blocks and
never addressing the rest.

`V41PoolGeometry.index_block_rows` declares that length, and the backend sets
it to `candidate_block_size`. The plane's bytes do not change: data and scales
are packed with nothing between them, so a row's share is 132 B at every block
length, and only the granularity at which the two regions interleave moves.
aiter supports the short page from ROCm/aiter#5749; a GPU whose scorer cannot
page that short refuses when asked, which is not a silent wrong answer.

`restrict_to_candidates` has no caller left. It is kept, renamed, as the judge
of the compaction: restating it in the test would be the same addressing
written twice.

Two conflations came out with it:

* `index_write` spelled the MFMA tile width, the shuffle group and the block
  length with one name. All three were 16 while 16 was the only page the
  scorer took. A block of 8 shuffles in groups of 8 by 16 and tells them apart;
  at 16 the new form is byte-for-byte the old one.
* a hub id reached `CheckpointReader` as a path, so V4.1's Engram loader built
  `deepseek-ai/DeepSeek-V4.1-Flash/model.safetensors.index.json` and reported a
  missing checkpoint for a name nobody had resolved. `local_model_dir` is now
  the one place that turns either spelling into a directory; the three probes
  that answered "no such tensor" for every remote checkpoint go through it too,
  and the reader refuses a non-directory by name.

Gates: unit suite 8609 passed / 3 failed, the 3 reproducing on origin/main.
GSM8K 1319 @ 3-shot, DSpark-5, TP4, --level 0: flexible 0.9227 / strict 0.9234
against a 0.9224 +- 0.005 baseline. On a 127k-token context, 225 in-forward
comparisons of the two paths over 4 ranks disagreed on nothing -- that is the
gate for the regime GSM8K cannot reach, where the candidates are a strict
subset. Scoring is 0.80% of a decode step's GPU time in a 100k/64/conc-8 trace,
which is this optimization's ceiling there; the prefill share is 6.5%.

What the change buys is not measured. The trace carries no per-layer label, so
calls cannot be attributed to producer or consumer, and an earlier attempt to
split them by duration was wrong: a compacted call in prefill still scores
16384 columns over 16384 rows and is not short. gfx1250 is untested.
fallow5 pushed a commit to fallow5/aiter that referenced this pull request Sep 28, 2026
…block-table capacity bounds)

The two-step addressing (pool coord -> block column + offset) that this
branch originally carried is already on main via ROCm#5749, together with
64-bit addressing, the negative-prologue clamp and the preshuffle tail
store -- so this commit drops the duplicate and keeps only the mask
hardening that ROCm#5749 does not have:

1. Prologue prefetch masks bound BOTH directions: the existing >= 0
   lower bound, plus context_length and the block-table row capacity
   (max_block_len * KVBlockSize pools) as upper bounds. ROCm#5749 only
   guards the lower bound, so a first split shorter than ChunkK can
   prefetch past the row's valid kv_indices columns.

2. In-loop prefetch masks + out-of-window lanes forced to block 0.
   ROCm#5749's in-loop buffer_load is unmasked and relies solely on the
   loop bound; with the masks, an out-of-contract context_length (which
   the wrapper does not validate) can only ever read block 0, never a
   garbage block id dereferenced into KV_buffer.

In-contract the window tops out at split_context_length, so the new
bounds never mask a valid lane; they only fire for out-of-contract
callers. This also answers the Copilot review's block_col bound finding.
fallow5 pushed a commit to fallow5/aiter that referenced this pull request Sep 29, 2026
…block-table capacity bounds)

The two-step addressing (pool coord -> block column + offset) that this
branch originally carried is already on main via ROCm#5749, together with
64-bit addressing, the negative-prologue clamp and the preshuffle tail
store -- so this commit drops the duplicate and keeps only the mask
hardening that ROCm#5749 does not have:

1. Prologue prefetch masks bound BOTH directions: the existing >= 0
   lower bound, plus context_length and the block-table row capacity
   (max_block_len * KVBlockSize pools) as upper bounds. ROCm#5749 only
   guards the lower bound, so a first split shorter than ChunkK can
   prefetch past the row's valid kv_indices columns.

2. In-loop prefetch masks + out-of-window lanes forced to block 0.
   ROCm#5749's in-loop buffer_load is unmasked and relies solely on the
   loop bound; with the masks, an out-of-contract context_length (which
   the wrapper does not validate) can only ever read block 0, never a
   garbage block id dereferenced into KV_buffer.

In-contract the window tops out at split_context_length, so the new
bounds never mask a valid lane; they only fire for out-of-contract
callers. This also answers the Copilot review's block_col bound finding.
k50112113 pushed a commit that referenced this pull request Oct 5, 2026
…block-table capacity bounds) (#5600)

The two-step addressing (pool coord -> block column + offset) that this
branch originally carried is already on main via #5749, together with
64-bit addressing, the negative-prologue clamp and the preshuffle tail
store -- so this commit drops the duplicate and keeps only the mask
hardening that #5749 does not have:

1. Prologue prefetch masks bound BOTH directions: the existing >= 0
   lower bound, plus context_length and the block-table row capacity
   (max_block_len * KVBlockSize pools) as upper bounds. #5749 only
   guards the lower bound, so a first split shorter than ChunkK can
   prefetch past the row's valid kv_indices columns.

2. In-loop prefetch masks + out-of-window lanes forced to block 0.
   #5749's in-loop buffer_load is unmasked and relies solely on the
   loop bound; with the masks, an out-of-contract context_length (which
   the wrapper does not validate) can only ever read block 0, never a
   garbage block id dereferenced into KV_buffer.

In-contract the window tops out at split_context_length, so the new
bounds never mask a valid lane; they only fire for out-of-contract
callers. This also answers the Copilot review's block_col bound finding.

Co-authored-by: beast <[email protected]>
gyohuangxin added a commit to ROCm/ATOM that referenced this pull request Oct 20, 2026
* feat: integrate gfx1250 FP4 MQA indexer (#2334)

* feat: integrate gfx1250 fp4 MQA indexer

* perf: use qlen1 FP4 MQA for decode

* style: format gfx1250 FP4 pool layout

* test: skip OPUS metadata tests without AITER

* Add Kimi-K3 (hybrid) LMCache KV offload to the vLLM plugin path (#2268)

* Add Kimi-K3 (hybrid) LMCache KV offload to the vLLM plugin path

AtomLMCacheOffloadConnector could not serve Kimi-K3. Two guards rejected it at
startup, and behind them sat a correctness problem: K3 is hybrid, so vLLM builds
two KV cache groups (MLA full attention plus KDA recurrent state), and a
restored MLA prefix is only valid if the KDA state at the same token boundary is
restored with it. Half a restore is not a crash and not a log line -- it is
wrong output.

The two groups are moved by two different mechanisms, and the asymmetry is
forced, not chosen. The MLA group keeps the existing DenseKVByteCodec path
untouched. The KDA group cannot be read positionally at all: in
--mamba-cache-mode align a mamba block table is not append-only (a superseded
state block is freed and nulled, speculative blocks relocate in place), so
indexing it by token // block_size can persist a null, freed, or live
speculative block under a valid prefix hash. The only safe source is vLLM's
explicit hand-off, which names the exact block holding a committed boundary
state. The pinned vLLM 0.28 ships it flat on the scheduler output as
SchedulerOutput.partial_tail_offloads, fed by
KVCacheManager.take_partial_tail_offloads; 0.29 moves the same
{req_id: [(group_id, block_id, boundary_tokens)]} payload under
kv_connector_block_state.boundary_state_offloads. step_boundary_offloads reads
whichever spelling the running vLLM provides, so the connector keeps working
across that upgrade rather than going silently hit-less on one side of it. The
hand-off is taken off the KV cache manager once, while the step is built, so it
is consumed in the step it arrives. Each accepted boundary is pinned via the
bound GPU block pool and released on rank quorum.

Correctness of the pair is enforced on lookup, not on save: the reported
external hit is capped at the largest chunk boundary the state index still
claims, so a state that was never stored or was evicted shortens a prefix
instead of corrupting it. That removes the need for any cross-group save
parking. A KDA miss additionally invalidates the attention blocks the dense leg
filled, so vLLM cannot cache an MLA prefix whose state never arrived.

Hybrid models also require vLLM's hybrid memory allocator, which vLLM
auto-disables for a connector that does not declare SupportsHMA -- without that
declaration K3 plus --kv-transfer-config does not mis-save, it does not boot.
The connector now declares it and implements request_finished_all_groups, which
retires request_finished for every model. SupportsHMA, bind_gpu_block_pool and
request_finished_all_groups are all present in the pinned 0.28
(atom/plugin/vllm/vllm-version.env, 2cf0a6915 = v0.28.0), so nothing here waits
on the 0.29 upgrade.

supports_divergent_local_hybrid_hits stays False: the reconciled cross-group
boundary vLLM then reports is the conservative one, and this connector caps the
external hit on its own.

Stays on the pinned LMCache version. The 0.5.5 upgrade was permitted, not
required, and nothing here needs it; measured on the GLM-5.2 arc, 0.5.5rc4 lost
to 0.4.5 by 5.72%, with ~97% of chunk cost host-side.

Verification: the CI unit scope (--ignore=tests/plugin) is 3 failed / 5519
passed with the 38 new tests included, and those three failures reproduce
unchanged on origin/main in a clean worktree, so none of them is this change.
Seven further modules (tests/diffusion, tests/test_attn_family.py) cannot be
collected on this host at all -- Python 3.10 has no typing.Self or enum.StrEnum
-- which is the interpreter, not the change; CI runs a newer one. The tests were
mutation-checked: ten real degradations of the earlier work (uncapped hit, each
collect_stores filter removed, quorum of one, indexing despite a failed rank,
boundary_hash off-by-one, dropping an unresolvable load, silently dropping an
unmapped layer) each turn them red, and so does dropping either spelling from
step_boundary_offloads, while reordering the two spellings -- an equivalent
mutation -- leaves them green. black and ruff pass on every touched file.
Nothing has been run on hardware yet: boot, two-pass accuracy against the
0.9507 / 0.9500 baseline, and hit rate are still outstanding, and the recipe
says so rather than implying measured numbers.

Co-Authored-By: Claude Opus 5 <[email protected]>

* Fix three K3 offload defects found on the first hardware boot

The connector had never been run against a real engine. Three defects showed
up, two of them loud and one that would not have shown up at all.

1. Multi-group recurrent state. vLLM does not build one KV cache group per
   layer family; it builds equal-sized groups. K3's attention bucket is 29
   layers and its KDA bucket is 69, so the group size is 29 and the recurrent
   state lands in THREE groups (23 layers each), not one. The recurrent leg now
   reads the grouping off the engine instead of assuming a single group, and
   treats all mamba groups as one logical state: one token boundary, one block
   id per group, stored as those groups' bytes concatenated in group order.
   None of the groups is restorable alone.

2. `split_kv_caches_by_group` returns a list indexed by group id, and
   `_init_kda_tier` called `.get()` on it, so every worker died with
   `'list' object has no attribute 'get'`. Extracted `gather_group_tensors`,
   which is what the two functions were missing: nothing in the suite fed one
   to the other, so the seam had no coverage at all. It has four tests now,
   including the ordering contract -- vLLM's own `layer_names` order, never
   `sorted()` -- because a page image is readable only by a run that rebuilds
   the same order.

3. The dense leg strided every segment by a token, not by a block. This one is
   silent. `DenseKVByteCodec` derives each segment's per-block byte stride as
   `numel // num_blocks`, and `register_kv_caches` took `num_blocks` from the
   registered tensor's leading dimension. That is the block count only when the
   attention backend's kernel block size equals the group's block size. ATOM's
   MLA backend declares `get_supported_kernel_block_sizes() == [1]`, so vLLM
   allocates one row per token and expands manager block id `b` into kernel ids
   `b*n .. b*n+n-1`, while the ids a KV connector receives stay manager ids. On
   K3 -- 1536-token blocks -- that made the stride 1536x too fine: every block
   id still in range, every transfer reported success, bytes restored from the
   wrong rows, nothing logged. `DenseKVByteCodec`'s own docstring says the
   leading dimension is not the block count on token-major MLA.

   `resolve_block_count` now takes the count from `KVCacheConfig.num_blocks`
   and reconciles it against the tensor: the leading dimension must be a whole
   number of blocks, and the implied kernel blocks per block must divide the
   block size. It is an identity wherever the two already agree, which is every
   model shipped on this path so far (GLM-5.2 measured `num_blocks=8192`
   against `tail_shape=(64, 576)`), so the mismatch is K3's alone.

   No reshape is needed: a manager block's kernel blocks are contiguous and
   consecutive, so its bytes are one unbroken run either way.

The recurrent leg bounds-checks a block id against its own tensors and so would
have failed loudly on the same mistake. The dense leg has no such check, which
is why (3) needed a test rather than a boot.

Boot verified on 8xMI355 TP8: three mamba groups on 0,1,2 and attention on 3,
hybrid memory allocator left on, deterministic smoke answer correct.

Co-Authored-By: Claude Opus 5 <[email protected]>

* Record the validated K3 boot, and make its log readable

The boot passed on 8xMI355 TP8, so the recipe's Status section is now a
measurement rather than a requirement. Three things it said were wrong, and
each one was wrong in the direction that reads as "fine":

- "vLLM builds two KV cache groups". It builds equal-sized groups, so K3's 29
  MLA and 69 KDA layers come out as four: one attention group of 29 and three
  mamba groups of 23. The recipe's own verification greps were written against
  the two-group picture.
- "LMCACHE_CHUNK_SIZE=128 # must equal --block-size". The block size is not the
  one you pass. vLLM raises it to 1536 so the attention page is at least the
  mamba page, and `--block-size 128` does not prevent that -- it fixes only the
  requested size, and the hybrid alignment step overrides it afterwards. A
  chunk of 128 is not a multiple of 1536 and the connector refuses to start.
- The "did the recurrent leg come up" grep named one line and said it appears
  once per worker and once in the EngineCore. There are two different lines
  from two different processes: workers print `recurrent state tier up`, the
  EngineCore prints `recurrent state leg on group(s)`. The documented grep
  returns nothing on a healthy boot, which reads as "the leg is off".

Status now carries the measured geometry to diff a future boot against, and
calls out the two quantities that fail silently -- `bytes_per_block`, which
must be `block_size x bytes_per_token`, and `leading dim`, which is 1536x
`num_blocks` on this backend -- plus the tier arithmetic, since at the
documented defaults the tier is 5x smaller than the HBM pool and can only
measure a null result.

`summarize_layout_id` run-length encodes the per-layer tail of the layout id
for the log: 69 identical entries, 1,877 characters on one line per worker and
36 KiB per boot, which left the grep the recipe prescribes scrolling past its
own answer. 1,877 -> 112 characters. The encoding is lossless and order
preserving, and it is deliberately NOT what `build_layout_id` folds into the
storage key -- shortening what a human reads must not shorten what separates
one layout's bytes from another's, so a test pins the two apart.

Co-Authored-By: Claude Opus 5 <[email protected]>

* Size the K3 offload measurement from the trace instead of from a guess

The tier-sizing paragraph derived the HBM pool from `GPU KV cache size`, which
is `max_concurrency x max_model_len` and not a capacity at all -- the same
quantity this file already warns is not a pool. Replace it with the pool
arithmetic that the boot line `num_blocks / Maximum concurrency` confirms
(55 blocks per request = 43 attention + 3 x 4 mamba, the mamba term independent
of max_model_len in align mode), and with the reuse-distance band measured
offline from two independent K3 agentic runs.

That measurement changes the recommendation. The band `[pool, tier)` holds only
2-3% of turns at the default 1584 blocks, so that arm could only ever return a
null result. At 1100 blocks it holds 44-45% -- and the default 20 GiB/rank tier
is already the larger end, so the experiment needs no extra host memory, where
growing the tier past the default pool would have wanted ~853 GiB pinned.

Also records why max_model_len must not be lowered to shrink the pool: this
trace's median input sequence already runs past the 65,536 window, so a shorter
one truncates the workload rather than the pool.

Co-Authored-By: Claude Opus 5 <[email protected]>

* Measure the lane scaling within K3 instead of across models

The sizing section claimed reuse distance grows sub-linearly in lanes, on the
strength of an 8x-lanes-to-2.3x-distance comparison. That pair was a K3 run
against a GLM-5.2 run, so it varied block size, bytes per token and the
prompt-length distribution at the same time as the lane count, and credited the
product to lanes.

The same sweep that supplied the 4-lane distribution also has an 8-lane run,
which gives a within-model axis at fixed workload: distance moves x1.90 at p75
and x1.97 at p50, i.e. close to linear, against ISL distributions 7% apart. The
1-lane point in that sweep is unusable for the same reason the cross-model pair
was -- its median input sequence is 1.8x the others.

Extrapolating one doubling from the 8-lane run puts the band at 16 lanes, which
moves the default row from 2-3% to 8-16% and leaves 1100 blocks at 36-46%. The
recommendation is unchanged; the reason it is safe is now measured rather than
assumed.

Co-Authored-By: Claude Opus 5 <[email protected]>

* Store KDA boundaries vLLM's hand-off can never name

The recurrent leg reported exactly zero external hits on Kimi-K3 --
3,956,629 queries, 0 hits, over 900 seconds -- and nothing said why.

Two acceptance domains that cannot intersect. vLLM's boundary hand-off
is a *partial tail* by definition: `_cache_partial_tail_block` returns
early when `num_tokens % block_size == 0`, and earlier still when
`block_size == hash_block_size`. This planner accepts only boundaries
that are whole mamba blocks *and* chunk-aligned, because `cap_hit`
descends in chunk steps and can select nothing else. On K3 both block
sizes are 1536 (vLLM raises the attention block size to satisfy
"attention page >= mamba page", and the hash block size is their gcd),
so the hand-off is empty -- and every boundary it could ever carry is a
non-multiple of the chunk size, so widening the filter would not have
helped either.

Take the boundaries from the block pool's own content-addressed cache
instead, the map vLLM uses to serve a local mamba hit. Resolving by
hash rather than by row is what makes it safe where a positional read
is not: an align-mode mamba block that was superseded, freed, nulled or
relocated is no longer registered under that hash, so the failure the
module docstring warns about -- wrong bytes under a valid prefix hash --
cannot occur. `get_cached_block` spans every mamba group in one call and
returns nothing unless all of them are present, which is the
all-or-nothing this state needs anyway. The hand-off is still read, for
models where it does carry something.

The 900 silent seconds were the second defect. Every explanation on this
leg was `logger.debug`, `stats()` had no call site, and the plugin path
exports no `lmcache_*` metrics, so a by-construction null looked exactly
like a tier with nothing to do -- which is the trap `StateOffloadIndex`
documents in its own comment and added `stores_refused` for. Counters
now name each reason a boundary was not stored, and one INFO line a
minute prints them.

Co-Authored-By: Claude Opus 5 <[email protected]>

* [Doc] Report the measured K3 LMCache offload pair in the recipe

The LMCache section said "accuracy and hit rate: not yet run" and left the
sizing table's 1100-block recommendation as the last word. Both are now
replaced by the pair that was actually run.

Measured, 1800 s per arm, TP8, conc 16, seed 1234, pool pinned to 320 blocks
(381,300 tokens) and tier 40 GiB/rank: +10.81% req/s, +13.24% output token
throughput, TTFT p50 -59.1%, preemptions 35 -> 2. Prefill recompute falls from
64.01% to 16.27% of prompt tokens, which is the whole mechanism.

Three things are written down because they are easy to get wrong later:

- the promised / delivered / counted rulers disagree, and the promised-to-
  delivered gap must be summed as sum(required - retrieved) over every rank
  line. The per-event shortcut misses partial retrievals and overstated it 39%.
- GLM-5.3's start-cut sweep is not licensed here: the OFF arm drifts -17.1%
  across cuts, so no steady-state row is quoted. The ratio's stability across
  eight cuts is what says the full-window figure is not a window artefact.
- the sign of the tier's benefit follows tier/pool, with the 792-block pair
  (-3.59%) as the counter-example.

Limits are stated rather than hidden: n=1 per arm, ISL/OSL not held fixed
across arms, host MemFree differed at launch, and the tier is deliberately
under-sized (8,847 allocation failures on the ON arm).

Co-Authored-By: Claude Opus 5 <[email protected]>

* [Doc] Move K3 LMCache offload into its own recipe

Kimi-K3.md had grown a 340-line LMCache section that was longer than the rest
of the recipe put together, and unlike M3 and GLM-5.2 it had no file of its own
to point people at. Split it out as Kimi-K3-LMCache-Byte-Offload.md, matching
the naming the other offload recipes already use, and leave a short pointer in
Kimi-K3.md carrying the one number a reader needs to decide whether to open it.

Content is moved, not rewritten. The cross-references that said "above" and
pointed at sections no longer in the same file now name Kimi-K3.md and its
anchor. Two things are corrected in passing: the launch block declared a 20
GiB/rank tier while the measured pair ran 40, and the GLM-5.3 offload recipe is
referenced by name rather than linked, because it is not on main yet.

Co-Authored-By: Claude Opus 5 <[email protected]>

* [Doc] Align the K3 offload recipe's structure with GLM-5.3's

The split file kept the section order it had inside Kimi-K3.md, which is not
the shape the other offload recipes use. Reorganise it onto GLM-5.3's skeleton
so the two can be read side by side: Server / Sizing the tier / Client /
Measured / Related, with the "why this model needs more than the M3 path"
material moved into the intro, where GLM-5.3 puts its mirror-image claim that
no model-specific code exists.

Content is moved, not rewritten; the only lines that disappear are a duplicated
intro paragraph left behind by the split and the five retitled headings.

Two sections are new rather than moved:

- Client is now its own top-level section instead of a code block buried in
  Measured, with the four load-bearing flags called out the way GLM-5.3 calls
  out its own. It also records that the base launch does not pass
  --enable-prompt-tokens-details, which is why aiperf's prompt-cache columns
  are empty and every hit rate in Measured is read from /metrics instead.
- "Verify it booted right" keeps K3's boot geometry as a sub-section of Server,
  since it has no GLM-5.3 counterpart and is a server-side check.

The "accuracy not yet run" note moves to the end of Measured, next to the
limits of what was measured, rather than sitting in the boot-check section.

Co-Authored-By: Claude Opus 5 <[email protected]>

* recipes: report the GLM-aligned K3 offload pair as the null it is

Replaces Measured with the pair that actually matches the launch in Server
(no --num-gpu-blocks-override, 64 GiB/rank, ATOM_SLRU read back from the
rank-0 config dump, --enable-prompt-tokens-details on).

The result is that the tier supplies 0.30% of prompt tokens and the
throughput difference is not measurable: aiperf's req/s says +0.21% and a
recomputation over each arm's record span says -3.73%, with n=1 per arm and
no noise floor, so the sign is undetermined. It is written up that way
rather than quoting the +3.08% out-tok/s.

The cause is structural, not a sizing error. With the pool unpinned vLLM
answers 85.05% of prompt tokens itself, and on the plugin path the connector
is only asked about what the pool missed, so the tier bids for the leftover
15% and wins 2.01% of it. The band model in Sizing promised 18.7%; the 62x
gap between that bound and the delivered 0.30% is now recorded next to it.

Sizing also gains GLM-5.3's cheaper cross-check (tier ~1.5x the reusable
working set): 20 distinct conversations x their largest ISL x 56,448 B =
30.5 GiB/rank, so 64 is 2.10x the set, above the rule rather than below it.
GLM-5.3's own 256 GiB/rank is 1.57x its 163 GiB set at TP4 and cannot be
copied to K3: at TP8 it would pin 2048 GiB against a ~90 GiB/rank ceiling
on this host.

Kimi-K3.md's pointer said +10.81% without saying that number needs a pinned
pool; it now leads with the default-pool null.

Co-Authored-By: Claude Opus 5 <[email protected]>

* Keep a failed tier load from killing the engine on a hybrid model

vLLM's KV-load-failure recovery assumes a single KV cache group:

    (req_block_ids,) = self.kv_cache_manager.get_block_ids(req_id)

under a `# TODO (davidb): add support for hybrid memory allocator` in
`Scheduler._update_requests_with_invalid_blocks`. Kimi-K3 is hybrid (MLA
full-attention plus KDA recurrent layers), so `get_block_ids` returns one
list per group and the unpack raises inside EngineCore. That is not a
degraded request: it is `EngineDeadError`, every in-flight request 500s,
and the server shuts down. The path is reachable exactly when this
connector is in use with `"kv_load_failure_policy":"recompute"`, which
the K3 recipe requires -- the default `fail` turns a tier miss into a
user-visible 500 instead.

Rather than patch vLLM in place, select a subclass through the public
`scheduler_cls` config knob from ATOM's platform hook. The blast radius
is then one engine's scheduler instead of every `Scheduler` in the
process, and a mismatch with a future vLLM fails loudly at boot instead
of silently reverting behaviour. Be honest about what it does not buy:
the overridden method is private either way, so the version coupling is
the same as a monkeypatch's.

Two subclasses, because `get_scheduler_cls` consults `async_scheduling`
only while `scheduler_cls` is None; once set, the named class is
returned as-is, so returning a plain `Scheduler` would silently disable
async scheduling. `select_scheduler_cls` reads the already-resolved
`async_scheduling` bool -- the platform hook runs after vLLM decides it.

The override is skipped when vLLM's own method no longer contains the
single-group unpack, so this retires itself when upstream fixes it. It
is gated on a KV connector being configured (without one no load can
fail), not on the model being hybrid: group counts are not known at
config time, and the override handles a single group exactly as vLLM
does. Selection failure is logged, never fatal.

Not unit-tested: the CI unit job has no vLLM and both the subclasses and
the platform hook need it to import. Checked instead by the sweep's
preflight, which asserts the bases, the upstream-source probe, that the
hook is actually called from `check_and_update_config`, and that both
`async_scheduling` values resolve to the right qualified name.

Co-Authored-By: Claude Opus 5 <[email protected]>

* Record the controlled-prefix working point in the K3 offload recipe

The recipe's Measured pair reports the tier supplying 0.30% of prompt tokens
and no measurable throughput difference. That is a property of the client used
there, not of an unpinned HBM pool: its reuse falls inside what HBM keeps, so
the connector only ever sees a 15% miss tail.

Re-measured at the same unpinned pool (both arms report the pool within 0.06%,
1,887,436 vs 1,886,245 tokens) with a controlled-prefix synthetic client whose
reuse distance is chosen to land in the band Sizing the tier defines, the tier
supplies ~82% and throughput gains +20.5 / +22.4 / +27.8% at conc 16 / 20 / 24
over 1800 s windows. Deltas are taken from request counts, not from aiperf's
two-decimal req/s. Every arm is n=1; there is no noise floor and the section
says so.

Three knobs differ between the two working points -- client, tier 64 -> 90
GiB/rank, and atom_head -- so nothing is isolated to one of them; the section
enumerates them rather than attributing the result to the tier.

The band arithmetic already in Sizing the tier predicts both the result and its
trend: d = 483,840 tokens sits above the reusable prefix (270,336 at conc 16,
falling to 101,376 at conc 24) and below the tier (1,711,961 tokens at 90
GiB/rank), and the lower edge drops as lanes are added, which is the direction
the gain moves.

Also qualified in place: the "factor of 62" paragraph, which read as a property
of unpinned pools; the 64 GiB/rank knee, which is that workload's; and the
pointer in Kimi-K3.md, which stated the null without its precondition.

Co-Authored-By: Claude Opus 5 <[email protected]>

* Keep a KDA offload hit from serving another prefix's state

Copy the boundary page only after the forward and mamba postprocess
have written the accepted state, retry a boundary the pool does not
hold yet, and fail a load that does not end on a mamba block or cannot
name the attention blocks to invalidate.

Co-authored-by: Cursor <[email protected]>

* Record the conc-32 ON arm and close the sweep's open prediction

The 2026-09-22 sweep left conc 32 with an OFF arm only: wait_for_gpus.sh gates
on 756 GiB of raw MemFree and the host sat at 553.  The GPUs were idle; the
memory was 1,068 GiB of K3 weights that each arm's NFS re-read had left in the
page cache, measured per-file with fincore and released with posix_fadvise
DONTNEED (clean pages, no drop_caches).  MemFree 467 -> 1539 and the arm ran.

It confirms the prediction the section already carried.  conc 32 is where the
reusable-prefix formula goes negative, so no prefix survives between turns and
every reuse must come from the tier: tier 87.73% of prompt tokens against
81.6-82.7% at the other three points, HBM local hit 5.70% against 10.4-11.1%,
and the largest gain of the set at +32.6% (3028 vs 2283 requests over identical
1800 s windows).  Recompute is what moves -- 6.57% ON against 19.96% OFF.

Also noted, so a reader does not have to re-derive it from server.log: that
arm's EngineDeadError is the driver's own SIGTERM racing AsyncLLM's output
handler at teardown, five seconds after a healthy engine log and after aiperf
had finished; was_cancelled=False and error_summary is empty.

The gain still carries no error bar (every arm is n=1) and the rising trend runs
with the fixed-pool bias run_sweep.sh documents, not against it.  Both limits
are stated in the section rather than left to the reader.

Co-Authored-By: Claude Opus 5 <[email protected]>

---------

Co-authored-by: perzhang <[email protected]>
Co-authored-by: Claude Opus 5 <[email protected]>
Co-authored-by: Cursor <[email protected]>

* perf(decode): fold the graph's padded tail into the deferred-id kernel (#2368)

A decode step wrote `input_ids` in two launches: one Triton kernel filling
each carried-over request's span, then a `zero_()` over the rows a replayed
graph reads but the batch never scheduled. The second is a 5.6us dispatch
floor for ~1.5KB, and it fires on every step -- `bs` sits between two capture
buckets on all but the exact-fit ones.

The two regions are disjoint by construction: the tail starts where the last
request ends, so nothing orders them and one launch can do both. Programs past
`num_requests` zero `[cu[bs], width)` instead of filling a span.

`cu` stays the only statement of where requests end -- the padding programs
read `cu[bs]` themselves rather than taking a second copy of it from the host,
so the two cannot disagree. `width` is a required argument, because a caller
that forgets it leaves the padded rows carrying the previous step's ids, and
the MoE path does consume them.

`BLOCK_PAD` is one value so the tail costs one JIT specialization rather than
one per capture bucket, and the three new runtime ints are `do_not_specialize`
for the same reason.

Verified: GSM8K 1319 @ 3-shot on DeepSeek-V4.1-Flash DSpark-5, TP4, bf16 KV,
index fp8 -- flexible 0.9174 / strict 0.9166 against a 0.9224 baseline mean
(sigma ~0.005). Unit suite 8512 passed, unchanged from before the change.

* (recipe) add Kimi-K3 AgentX recipe (#2131)

* (recipe) add Kimi-K3 AgentX recipe

Document the per-concurrency ATOM serving bands for the Weka AgentX workload.

* (recipe) tune Kimi-K3 AgentX ReplaySSM and AITER comm reuse

Turn ReplaySSM off at C1/C2/C4 and on at C16, and keep AITER comm-group reuse only on C56/C64.

* (recipe) document container prerequisites and add the C14 point

Two container-level facts decide whether this recipe reproduces its own
numbers, and both of them fail quietly, so add a prerequisites section
covering each:

- triton must be 3.7.x. The kimi_k3_agentic_0903 image shipped 3.8.0, which
  costs ~2.1x on prefill TTFT here (C1 p50 0.79s -> 1.5s) while leaving decode
  untouched. Measured across eleven runs: the gap survives swapping aiter's
  .so between revisions, swapping the ATOM checkout, and switching between a
  full CI prebuild and a lean JIT build, so triton is the only variable that
  moves it.
- DRAFT_MODEL_PATH must name a local directory. The default is a Hugging Face
  repo id the image has no cache entry for, so leaving it unset makes every
  rank fetch the same 7 GB checkpoint with no error printed, the log stopped
  after "Loading drafter model...", and every GPU at 0%. Document the symptom
  next to the fix, because the hang is otherwise indistinguishable from a
  wedged server.

C14 was in the benchmark scripts but never in the recipe. It reuses the C16
server recipe verbatim, including a CUDA-graph width pinned to 32; deriving it
from 2*CONC gives 28 and the server fails during CUDA-graph warmup. Routing
GRAPH_MAX through CUDAGRAPH_MAX_NUM_SEQS lets the C14 arm pin it while every
other concurrency keeps the 2*CONC default unchanged.

Verified against run_kimik3_atom_dspark_server.sh: all eleven concurrencies now
agree item by item across DCP, max-num-seqs, batched tokens, GPU utilization,
LMCache, ReplaySSM, spec tokens, acceptance length, AITER comm reuse and the
recomputed graph_max.

* (recipe) set ATOM_GDN_SSM_DTYPE=fp16 for Kimi-K3 AgentX

Apply the KDA temporal state dtype optimization from ATOM #2130.

Co-authored-by: Cursor <[email protected]>

* (recipe) Kimi-K3 AgentX: per-concurrency params from the 12-point MI355X sweep (#2208)

* (recipe) Kimi-K3 AgentX: band params from the 12-point MI355X sweep

Replaces the per-concurrency values with the ones a full 12-point AgentX
sweep actually ran on MI355X (8x, ATOM 97c15a73 + aiter 6b3f14b5f,
aiperf 0.12.0, 3600 s profiling window per point).

  * GPU util 0.88/0.86 -> 0.90 at every band. Measured on this box as
    available_for_kv 39.42 -> 51.11 GB, a +40.6% KV sub-pool.
  * max-num-batched-tokens 4096 -> 8192 at C8 and C12, so it is now 8192
    everywhere. Cross-round TTFT p50 deltas move monotonically through
    zero across C8..C56, consistent with the larger prefill chunk.
  * AITER_REUSE_IDENTICAL_COMM_GROUPS is now a DCP rule rather than two
    hardcoded branches: 1 at every DCP=8 band, 0 at DCP=1. C32/C40/C48
    measured faster with it on; C1 measured 3.3-3.9% WORSE ITL with it
    on, which is why the DCP=1 bands keep it off. C8-C16 are still under
    A/B and may move in a follow-up.
  * Adds the missing C48 band (max-num-seqs 96, graph_max 96). It was in
    neither the table nor the case, so CONC=48 hit the unsupported exit.
  * Pins ATOM_USE_FLYDSL_GATHER_KV_B_PROJ=1. It already defaults to 1
    (atom/utils/envs.py), so this changes nothing today -- it is set
    explicitly so the recipe keeps reproducing the measured numbers if
    the default flips.

DCP, spec tokens, acceptance length, LMCache sizes, ReplaySSM,
max-num-seqs and graph_max are unchanged; every row was re-verified
against the sweep's own launcher.

* (recipe) Kimi-K3 AgentX: hoist band-invariant values out of the case

The per-concurrency case repeated nine values that are now identical across
every band, so a single-band change had twelve places to go wrong. Hoist the
shared defaults above the case and leave only the genuine per-band deltas
inside it: 119 lines -> 51.

Behaviour is unchanged. All twelve concurrencies were evaluated before and
after and every field -- DCP, max-num-seqs, batched tokens, GPU util,
ENABLE_LMCACHE, LMCache size, ReplaySSM, reuse, spec tokens, acceptance
length, CUDAGRAPH_MAX_NUM_SEQS and the derived graph_max -- is byte-identical.

max-num-seqs is now derived as 2*CONC on the throughput bands rather than
written out five times; it was already exactly 2*CONC there. The two bands
that genuinely deviate keep explicit overrides with the reason attached: C12
at 24, and C14's pinned CUDAGRAPH_MAX_NUM_SEQS=32.

LMCACHE_MAX_LOCAL_CPU_SIZE now carries its 128 default on the DCP=1 bands
too. That is inert: it is only exported inside the ENABLE_LMCACHE==1 branch,
which those bands do not take.

* (recipe) trim the ATOM_USE_FLYDSL_GATHER_KV_B_PROJ comment

* (recipe) Kimi-K3 AgentX: comm-group reuse off below C56

A seven-point A/B on MI355X (C8/12/14/16/32/40/48, one reuse=1 leg and one
reuse=0 leg each, identical builds) measured reuse=0 faster at every point:
ITL p50 -7.3% at C8 narrowing to -1.9% at C48, total tok/chip +3.8% to +1.2%.
Split into 10-minute buckets, 39 of 42 buckets favour reuse=0 (one-sided
p ~ 3e-9), which is well clear of the ~7% run-to-run noise floor that makes
any single full-window comparison on this workload unreliable.

The advantage shrinks monotonically as the KV pool tightens -- reuse=0 gives
up roughly 13k blocks, and its peak KV usage climbs from 77.6% at C8 to 97.6%
at C48, where it is the first point to spend any time above 95% and where
maxRunning starts being pushed back. C56/C64 were not measured and use a
larger LMCache tier and max-num-seqs, so they keep the previous setting.

This also removes the claim that the 12-point sweep measured enabling reuse at
C32/C40/C48 as a gain. That reading came from single-run full-window
aggregates and does not survive the paired A/B.

* (recipe) Kimi-K3 AgentX: C72 + C80 bands, drop the C14 CUDA-graph pin (#2213)

* (recipe) Kimi-K3 AgentX: add the C72 throughput band

Same shape as C64 -- DCP=8, no spec, 192 GiB LMCache, ReplaySSM off -- with
max-num-seqs following the 2*CONC rule every band from C32 up obeys, so 144,
and graph_max 144 with spec disabled.

Measured on MI355X against the C64 band it extends: total tok/chip 12794 vs
12221, so C64 is not the throughput plateau. ITL p50 moves 77.11 -> 88.60 and
P90 interactivity 9.9 -> 8.4, which is the trade the band exists to expose.
maxRunning reached 119, so the wider capture range is genuinely reached rather
than captured and left unused.

Reuse stays enabled here: the CONC >= 56 gate already covers C72, and a paired
A/B measured reuse=1 ahead at C72 by a wider margin than at C64 (ITL bucket
mean +4.5% and total tok/chip +3.1% in its favour, 6 of 6 ten-minute buckets
agreeing), consistent with C72 sitting further past the C56 crossover.

* (recipe) Kimi-K3 AgentX: drop the C14 CUDA-graph pin

C14 pinned CUDAGRAPH_MAX_NUM_SEQS=32 with the justification that deriving
graph_max from 2*CONC "would give 28 and the server fails during CUDA-graph
warmup". That is false on ATOM 97c15a73, and the pin has no effect.

Capture sizes are SEQUENCES, not tokens. ModelRunner truncates the declared
ladder to max_schedulable_decode_bs() = min(max_num_seqs, max_num_batched_tokens
// full_q_len) (atom/model_engine/model_runner.py:142) -- it divides the
speculative width out, while the launcher multiplies it in. For C14 that is
min(32, 8192//4) = 32, independent of CUDAGRAPH_MAX_NUM_SEQS. Sizes above the
bound are dropped with a warning, not asserted on; a batch past the ladder just
falls back to eager.

So both settings capture exactly bs=2..32:

  pinned   CGMS=32 -> declared [2..128] -> "= 2048) = 32; dropping" x8 ranks
  default  CGMS=28 -> declared [2..112] -> "= 2048) = 32; dropping" x8 ranks

Measured on 8xMI355X, AgentX 3600 s, C14, AITER_REUSE_IDENTICAL_COMM_GROUPS=0
both legs, ATOM 97c15a73 / aiter 6b3f14b5f / triton 3.7.0:

               TTFT p50  TTFT p90  ITL p50  ITL p90  Inter p90  tot tok/s
  CGMS=32         804.3    2140.0    12.42    19.18       52.1      57148
  CGMS=28         775.8    2028.4    12.36    19.18       52.1      57060

ITL p90 and Inter p90 are equal to the digit; throughput differs by -0.15%.
Ten-minute buckets have identical n per bucket and ITL deltas of
-5.4/+1.2/+0.2/-0.9/-1.0/+3.6 %, three each way, all inside the ~7% run-to-run
noise floor. The server reached READY in ~330 s unpinned.

The table's graph_max for C14 becomes 2*14*(1+3) = 112. With the pin gone, every
row now satisfies the stated rule graph_max = 2 * CONC * (1 + spec); C14 was the
only exception.

Co-Authored-By: Claude <[email protected]>

* (recipe) Kimi-K3 AgentX: add the C80 throughput band

C80 is the same shape as C64/C72 -- DCP=8, no spec, 192 GiB LMCache,
max-num-seqs following the 2*CONC rule (160). It needs no new branch: the
existing `CONC -ge 56` guards already pick up the larger CPU tier and
AITER_REUSE_IDENTICAL_COMM_GROUPS=1.

Measured on 8xMI355X, AgentX 3600 s, ATOM 97c15a73 / aiter 6b3f14b5f /
triton 3.7.0, reuse=1:

  CONC  TTFT p50  TTFT p90  ITL p50  ITL p90  Inter p90  tot tok/chip  out tok/chip
    64    1356.1    3802.3    77.11   100.66        9.9         12221         88.56
    72    1489.8    3963.2    88.60   119.50        8.4         12794         89.42
    80    1549.8    4405.3   103.07   130.43        7.7         12839         95.75

**Total throughput plateaus at C72.** C64 -> C72 is +4.7% on tokens/chip;
C72 -> C80 is +0.35%, well inside the ~7% run-to-run noise floor, while ITL p90
rises 9% and Inter p90 falls from 8.4 to 7.7.

Read `tot` with care at the top of the ladder. C80's ISL drops to 107777 (vs
C72's 116894) because the trace serves more, shorter requests (3443 vs 3165), so
output throughput still climbs +7.1% (715 -> 766 tok/s) while total flattens.
The two agree at every band from C8 to C72 and diverge for the first time here.

Saturation is unambiguous across three independent signals:

              KV usage samples >=95%   KV max   maxRunning
  C64                      2/528        96.5%           84
  C72                     17/545        96.2%          119
  C80                     48/556        99.7%          114

maxRunning stops rising at C80 while KV hits 99.7% -- the scheduler is bounded
by the KV pool, not by the concurrency parameter. This is the same ordering
variable that decides the AITER_REUSE_IDENTICAL_COMM_GROUPS crossover at C56.

C80 is included for completeness of the band table. C72 is the knee.

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>

---------

Co-authored-by: xytpai <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: gbyu-amd <[email protected]>
Co-authored-by: Claude <[email protected]>

* feat(v41): enable TP2 DSpark and add AgentX recipe (#2373)

* feat(v41): enable TP2 DSpark and add AgentX recipe

* fix(v41): admit fixed acceptance schedules without an opt-in gate

* docs(v41): simplify AgentX recipe and remove auxiliary CSV

* docs(v41): present TP2 and TP4 performance in separate tables

* docs(v41): use direct server and client recipe commands

* style(v41): format DSpark runtime admission test

---------

Co-authored-by: ZhangLirong <[email protected]>

* [MiniMax-M3] Route the paged decode to aiter's FlyDSL kernel with work planner (#2366)

* [MiniMax-M3] Make the dense paged-decode split cap overridable

`PA_DENSE_SPLIT_MAX = 32` is not a tuned value. It is the smaller of two
unrelated bounds that happen to agree near there: production aiter does not
build the C++ PS reduce past 64 and has no working fallback under it, and
`temporary_output` is bf16, so each extra split adds a round trip through the
PS combine.

aiter #4332 removes the first bound. Deciding whether the second one still
binds needs the cap measured against the shipping value on the same tree,
which a constant cannot express. `dense_decode_splits` computes
`min(PA_DENSE_SPLIT_MAX, cdiv(128, running_bs))`, so the cap only binds at
`running_bs <= 2` -- the difference is invisible without an A/B at that shape.

Default stays 32 and behaviour is unchanged. Raising it on production aiter
still fails at engine init rather than at runtime.

`int(os.getenv(...) or 32)` rather than a getenv default: an exported-but-empty
variable would otherwise raise `int('')` at import and take the engine down
before it starts.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* [MiniMax-M3] Route the paged decode to aiter's FlyDSL kernel behind an env

ATOM_PA_FLYDSL=1 sends the paged decode to aiter's FlyDSL implementation
(aiter PR #4332) where FlyDSL's domain covers the call, and to gluon
otherwise. A measurement switch, not a shipping default: the two take the
same arguments and compute the same thing, and the env exists to A/B them
without maintaining two ATOM trees. Default 0, so nothing changes until an
operator opts in on an aiter that carries #4332.

_flydsl_pa_decode_num_seqs mirrors the kernel's own validation -- alibi,
sinks, externally quantized FP8 queries, ps=False, a positive sliding window,
a non-256 tile, a partition count outside [1, 256], an unsupported head dim,
and any cache that is not [nb, Hkv, D//16, page, 16] at 1 byte per element are
all hard rejects in aiter, not preferences. Enabling the env therefore cannot
turn a working configuration into an exception.

The returned count is the substance. ATOM pads two axes independently:
context_lens to running_bs for CUDA-graph identity, with
[scheduled_bs:running_bs] zeroed, and q to running_tokens for the MoE
all_gather. forward_context.Context stores both "because the ratio is not
always max_seqlen_q" and asserts no rectangle between them. gluon absorbs the
mismatch by deriving its batch as q.shape[0] // query_length and letting the
surplus zero-length rows do no work; FlyDSL demands the rectangle and raises

    ValueError: query.shape[0] (12) must equal
                context_lengths.shape[0] * query_length (4 * 4)

on an ordinary step. Recovering the count the way gluon does and slicing the
five per-sequence arguments to it hands FlyDSL the same rectangle, dropping
exactly the zeroed tail. All slices are views on dim 0.

The gate is deliberately not restricted to max_seqlen_q == 1. The dense path
is where FlyDSL's headroom over gluon lives, it runs max_seqlen_q ==
num_spec + 1, and FlyDSL carries a query_length == 4 MTP4 grid split tuned for
exactly that shape.

ATOM_PA_FLYDSL_PLAN=1 additionally opts into aiter #5546's GPU work planner.
The plan and its scratch are allocated once and only refreshed: allocation is
illegal inside graph capture and a captured graph bakes in the pointers, and a
planned call does not use the caller's static buffers -- planned partials are
packed as [kv_heads, capacity, query_rows(, D)] against the static API's
[num_seqs, kv_heads, partitions, query_rows(, D)]. The planner refuses batches
past 4096 while M3's sparse call site folds query tokens into num_seqs and
reaches 32768 on a prefill-as-decode step, so those fall back to the static
path rather than raising.

Measured negative on this workload and defaulted off: against the same tree
with the planner off it costs 3.86% at conc 1, 11.50% at conc 10 and 18.28% at
conc 20. The cause is not batch uniformity -- 31% of decode steps have max/min
KV length >= 4 -- but the split count, which plan_pa_decode and pa_decode
share: dense_decode_splits gives 16 at running_bs 5 and 8 at running_bs 24,
and at those counts a batch skewed 2.5x and one skewed 120x both measure
1.00x. #5546's own conclusion is that the data "support using dynamic plans
for uneven KV work, not enabling them universally".

Both routes are logged once per shape signature. A run where the env is set
but every call still lands on gluon is otherwise indistinguishable from one
where FlyDSL simply did not help.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* [MiniMax-M3] Give the FlyDSL work planner its own partition ceiling, and keep it off the sparse call sites

`_flydsl_work_plan` handed `plan_pa_decode` the static split count from
`dense_decode_splits`, overwriting that argument's own default. The two are
different quantities: `get_recommended_splits` gives every request the same
count and documents itself as "not a variable-work scheduler", while the plan's
`max_partitions` is a per-request ceiling it then divides under a workgroup
budget. Clamping the ceiling to the static count leaves a long request with the
same share as a short one, which is the planner's entire mechanism. Read back
from `plan.reduce_info`: a 5-request batch at ceiling 16 splits [16,4,4,4,4]
with the long request pinned at the ceiling, and at the default 256 it splits
[256,20,21,20,21].

`ATOM_PA_FLYDSL_PLAN_MAX` now carries that ceiling, 0 meaning "omit the
argument and take aiter's default". Do not read the ceiling off aiter's unit
test: it is the only caller of `plan_pa_decode` in that tree and it binds the
two deliberately, building the plan from the same count it hands `pa_decode` so
the paths must agree numerically. That makes it a correctness test which cannot
see the conflation.

The planner was also a global switch inside `run_pa_decode_gluon`, so enabling
it reached the two sparse call sites as well -- 57 of the 63 `pa_decode` calls
per step. Their context is a fixed topk window, so there is no unevenness to
rebalance and only the refresh and the task packing remain. On uniform batches
the planner is a loss that the ceiling cannot rescue: 0.56x at B8/257 and 0.84x
at B200/200000, flat from ceiling 4 through 256. `allow_work_plan` moves that
choice to the caller, where the split policy already lives, and only the dense
site opts in -- the same boundary `dense_decode_splits` already draws.

A plan build now logs its shape once per cached key, which is the only evidence
that the planner went where it was meant to rather than being assumed to.

Measured at conc 20 on the agentic trace (one operating point), single-user
output throughput 157.19 -> 178.49 tok/s and ITL 7.97 -> 6.96 ms, against 139.20
for the same arm before these changes. Prefix hit 96.56 vs 96.63, input length
+1.6%, request count +1.0%.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* [MiniMax-M3] Build the FlyDSL work plan once per forward, and fold four env switches into one

The plan is a function of `context_lens` alone, so every layer of one forward
wants the same one. Building it inside the attention op re-ran the planner
kernel for each of M3's three dense layers, and the module-level cache that
existed to paper over that had to key itself on shape to stay correct. It now
lives where the rest of the per-forward metadata is built: `prepare_decode`
attaches it, `prepare_mtp_decode` refreshes it for each draft pass (their
context lengths differ by a token, so reusing the target's plan would point the
kernel at the wrong KV ranges -- wrong output, not merely slower), and the op
reads it off `get_forward_context().attn_metadata`.

Measured before the move: 6 planner kernels per step, and `envs.__getattr__` on
all 63 `pa_decode` calls rather than the 6 that could use a plan. After: 4 and
1. The env read is the larger of the two -- one `__getattr__` costs ~0.97 us and
63 of them are ~0.5% of a 12.8 ms step.

Scratch allocation stays in the op. It is sized from the query tensor the op is
holding and happens once per shape, so only the per-step work moved out.

The env surface collapses to `ATOM_PA_FLYDSL_PLAN`, now on by default:

  * ATOM_PA_FLYDSL is gone. It was a measurement switch for A/B-ing FlyDSL
    against gluon without two trees; FlyDSL is the decode path. The capability
    check that falls back to gluon for shapes outside FlyDSL's domain stays --
    it mirrors the kernel's own validation and is not a switch.
  * ATOM_PA_FLYDSL_PLAN_MAX is gone, and the call now omits `max_partitions`
    entirely so `plan_pa_decode` takes its own default. The one time this tree
    chose the ceiling it chose the static split count, which clamps every
    request to the same share and removes the planner's mechanism.
  * ATOM_PA_DENSE_SPLIT_MAX is gone and PA_DENSE_SPLIT_MAX is a constant again.
    With the planner on, a planned call is told `plan.max_partitions`, so the
    cap no longer sets the production partition count; it survives for the
    gluon fallback, where both halves of its bound still hold. Raising it would
    only enlarge the static scratch a planned call never reads.
  * ATOM_PA_FLYDSL_PLAN defaults to 1. On the agentic trace, SA-convention
    interactivity (1/itl_p90) is +24.6% at conc 20 and +8.4% at conc 10, and
    the gain runs monotonically from the slow tail to the fast one (p10 +24.6%,
    p50 +19.3%, p90 +5.0%) -- it lifts the floor, which is the end the metric
    watches.

The routing log no longer hangs off the deleted env, and is unconditional: with
FlyDSL as the default path, which route a call took is worth always recording.

tests/test_paged_attention_dispatch.py: 74 passed.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* [MiniMax-M3] Trim the FlyDSL work-plan comments

Prose cut, facts kept. What stays is the four things a reader would otherwise
re-derive the hard way: the ceiling must not come from the static split count,
each draft pass needs its own refresh (reusing the target's plan points the
kernel at the wrong KV ranges -- wrong output, not merely slower), scratch is
allocated in the op because its shapes come from the query tensor, and the
FlyDSL/gluon split is a capability check rather than a switch. The measured
numbers move to the one place they inform a decision: why the planner defaults
on.

Also fixes a contradiction left by the previous commit. `run_pa_decode_gluon`
still described itself as a "MEASUREMENT SWITCH, not a shipping default" after
FlyDSL had become the path.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* [MiniMax-M3] Make the per-forward work plan survive cudagraph capture

Review found the previous commit's premise broken: decode runs from captured
graphs (cudagraph_mode=FULL), and `build_for_cudagraph_capture` never attached
a plan, so the op saw None at capture time and the STATIC path is what got
recorded. Every later refresh then worked on a graph that does not read it --
no error, no slowdown, just a planner that quietly does nothing and an
end-to-end number that looks fine.

The capture flow (model_runner.py) is what makes the fix possible:

    3857  build_capture(bs)           outside the graph -- first plan allocated
    3913  self.model(...)             warmup, eager; the op sees the plan
    3969  with torch.cuda.graph(...)  capture; the plan is already there

So the plan is attached in `build_for_cudagraph_capture` too, and the builder
keeps one per (batch, kv_heads, device) instead of a single slot. The single
slot was the more dangerous half: `build_capture` runs once per capture-ladder
size, so the second rung replaced the first rung's plan while the first rung's
graph had already baked in its pointers.

Two more from the same review:

  * The plan was built from `context_lens[:scheduled_bs]` while the op derives
    its own batch as `q.shape[0] // max_seqlen_q`, which is `running_bs`.
    aiter validates `reduce_info.shape == (num_seqs, 2)` and raises, so any
    step whose batch was not exactly on the ladder would have killed the
    worker. `context_lens` is already `running_bs` long with the tail zeroed.
  * `prepare_mtp_decode` dropped the refresh result and relied on the returned
    object being the same one. It now publishes through `workinfos`, which the
    caller splats into the metadata, so a None result clears a stale plan
    rather than leaving it in place.

`flydsl_plan_matches` is extracted rather than inlined so the guard is
testable: a plan built for another batch now falls back to the static path
instead of reaching aiter's validate.

tests/test_paged_attention_dispatch.py: 74 -> 83. Eight of the nine are
falsifiable by reverting the behaviour they describe, each reddening exactly
one test; the ninth is a source check on the capture attach, labelled as such,
because driving a real capture needs a model runner and what it guards fails
silently.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* [MiniMax-M3] Put the FlyDSL decode kernel back behind an env, gluon by default

aiter #4332 is unmerged and the kernel is not fully tested, so gluon goes
back to being the shipping decode path and FlyDSL becomes the opt-in:
ATOM_PA_FLYDSL=1, off by default. The two gates run in series -- the env,
then the capability check that mirrors the kernel's own validation -- and
the `and` short-circuits, so with the env off the check does not run.
Shapes outside FlyDSL's domain still fall back to gluon either way.

The work planner (aiter #5546) only feeds the FlyDSL kernel, so it now
requires ATOM_PA_FLYDSL=1 as well. Without that, a plan would be built and
refreshed every step for a kernel that never reads it, and the "flydsl work
plan" log line -- what an A/B arm is checked with -- would show up on a run
that is entirely gluon.

Tests 84 -> 86: the default must be off, the dispatch must consult the env
before the capability check, and the builder must not plan with FlyDSL off.
Each of the three goes red on its own reversion.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* [MiniMax-M3] Rename allow_work_plan to allow_flydsl_plan, trim comments

The parameter now matches the env that controls it, ATOM_PA_FLYDSL_PLAN.
"work plan" is aiter's own term for the object, but on its own it does not
say the plan belongs to the FlyDSL path -- which matters now that gluon is
the default and FlyDSL is the opt-in.

Comments trimmed throughout: the _flydsl_pa_decode_num_seqs docstring keeps
why it returns a count rather than a bool (ATOM pads its sequence and row
axes independently, so the two disagree by a padding slot on an ordinary
step; gluon absorbs that, FlyDSL raises) and drops the shape algebra and the
verbatim traceback.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Fix format

* Update docs

* Fix review comments

* Address PR #2366 review: capability gate, plan lifetime, ROCR device binding

Two gates in series guard the FlyDSL paged decode: ATOM_PA_FLYDSL is the
opt-in, and _flydsl_pa_decode_num_seqs mirrors aiter's own rejects so an
unsupported call falls back to gluon instead of raising inside the kernel
and killing the worker. The gate was missing several of those rejects --
q/output dtype and shape agreement, both head_dim stride checks, the
q-heads-over-kv-heads divisor, the v_cache dtype, and contiguity of the
two caches and the two per-sequence arrays.

Plans are now only ever minted during cudagraph capture. aiter's planner
takes batch as a tl.constexpr, so a runtime batch that no graph replays
would cost a cold kernel specialization and a plan nothing can free; the
static path is the right answer for it. Runtime only refreshes in place.
The one-shot "no plan for this batch" notice waits until a capture has
happened, since before that every call legitimately lands there and the
notice would be spent on a step that says nothing.

max_partitions stays unset, at plan_pa_decode's own default: every number
measured on this branch was measured there, and the review's suggestion to
clamp it to 64 is a perf claim nothing here backs. Measuring instead, on
the planned path, across nine cells spanning the trace's p50/p90/p99
contexts at batch 1/8/24: drift from an fp32 reference does not grow with
the split count anywhere, and the ceiling only ever binds at batch 1. The
plan's capacity is min(batch * max_partitions, max(batch, 2 * CU /
kv_heads)) = 512 here, so each sequence's share is about 512/batch and a
64 ceiling would have changed nothing above batch 2 while capping the one
place the planner has the most to rebalance.

numa_utils and the mooncake connector now read ROCR_VISIBLE_DEVICES first.
ROCR filters and renumbers before HIP indexes the result, so setting both
cut the visible device count twice; dropping HIP from the recipe left the
NUMA binding reading nothing and put all four ranks on one node.

Tests go from 86 to 127. The call-site contract is now checked by walking
the AST of all three builders and comparing the value of `create`, not its
presence in one file -- a sed that moved `create=True` onto a runtime path
had left every test green.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>

* [ATOM][PD]: Transfer prefill prompt token ids to decode (#2331)

* feat(pd): relay prefill prompt token ids to decode

Decode was re-rendering and tokenizing the same prompt prefill already
tokenized. Prefill echoes the ids, atomesh carries them in
kv_transfer_params, and decode skips tokenize.

Co-authored-by: Cursor <[email protected]>

* perf(pd): avoid redundant prompt token ID serialization

Serialize completed OpenAI responses through JSONResponse to avoid
FastAPI recursively visiting every prompt token ID. After validating the
prefill IDs on decode, remove the duplicate prompt from KV metadata before
engine IPC while preserving the original request and other transfer fields.

Cover HTTP response compatibility, prompt-ID round trips, and metadata
forwarding for chat/completions, streaming, and fanout requests.

Validation: 103 passed in the prompt-token-ID and protocol tests.

* docs(pd): simplify token ID comments and drop recipe changes

Shorten token ID comments and docstrings across the API, router, and tests.
Restore the PD disaggregation recipe to origin/main without changing runtime
behavior.

Validation: 103 related tests passed; Black passed; no new Ruff findings.

* simplify the test cases

Signed-off-by: Mengqing Cao <[email protected]>

---------

Signed-off-by: Mengqing Cao <[email protected]>
Co-authored-by: Cursor <[email protected]>

* feat(moe): prefill-only mega combine wire (#2347)

* feat(moe): prefill-only mega combine wire

* fix(moe): DP-agree the mega combine wire

* refactor(moe): move combine wire env to envs.py

---------

Co-authored-by: honglie <[email protected]>

* fix(offload): one tier lookup per waiting request, not one per step (#2305)

`get_num_new_matched_tokens` runs before allocation and is gated only on
`num_computed_tokens == 0`, so a request that fails to allocate goes back
to the head of the waiting queue and is asked the identical question next
step. On a full KV cache that turns one lookup into one lookup per
scheduler step: a prompt copy, ~5k chunk hashes and a blocking round trip
to the tier worker, all on the scheduler thread.

Memoize the one expensive input -- the tier `hit` -- and re-derive the
answer from it on every call. The frontier is not part of the question:
how much of the prompt the tier holds is a property of the prompt, and the
frontier only decides how much of that hit is still worth transferring.
Nothing tells the connector when the tier's answer changes, so the memo is
a bounded optimisation rather than a cache: a hit is replayed at most
`OFFLOAD_LOOKUP_MEMO_STEPS` times and a non-answer backs off for
`OFFLOAD_LOOKUP_RETRY_STEPS` (both default 32).

A memo-served answer carries no pin, and an answer needs none -- the
request only waits. A transfer does. `build_connector_meta`'s load-emit
loop is the single choke point where a retrieve reaches the worker on both
the native and the plugin path, so the pin is re-taken there, confirm-only:
the tier is asked again and the load is dropped as `tier_lost_prefix` if it
no longer holds what the spec promised. That is one lookup per load
actually dispatched.

The MP client's `lookup` now returns `None` on deadline expiry instead of
0: "the worker did not answer in time" is not a hit of zero and must not be
remembered as one.

Applied to both `ChunkedOffloadSchedulerBase` and `DSV4OffloadScheduler`.
The latter releases its pins each step, so it always answers
`_ensure_lookup_pin` with a fresh lookup.

Co-authored-by: perzhang <[email protected]>
Co-authored-by: Claude Opus 5 <[email protected]>

* ci: check container model mount in atom test (#2372)

* perf(v41): page the index plane at the candidate block length (#2377)

* perf(attention): reduce V4 fused decode normalization overhead

Normalize once per head and improve occupancy for nonquantized D512 32-head tiles. Cover ragged CSR, sinks, quantized KV, and changing graph inputs with an independent reference.

* perf(attention): specialize gfx950 fused decode with shared KV panels

Use explicit MFMA layouts for BF16 D512 head tiles and reuse KV panels through LDS. Preserve the existing split and fallback paths; cover graph inputs, tile boundaries, and large KV addresses.

* Generalize V4 fused decode across CDNA3 and CDNA4

* perf(v41): page the index plane at the candidate block length

A Reindex layer scored every column of its context and then drove the ones
outside the candidate source's blocks to -inf. The blocks it keeps are exactly
a block table -- if the plane is paged at the length they are picked in -- so
the same selection is reachable by scoring `candidate_topk_blocks` blocks and
never addressing the rest.

`V41PoolGeometry.index_block_rows` declares that length, and the backend sets
it to `candidate_block_size`. The plane's bytes do not change: data and scales
are packed with nothing between them, so a row's share is 132 B at every block
length, and only the granularity at which the two regions interleave moves.
aiter supports the short page from ROCm/aiter#5749; a GPU whose scorer cannot
page that short refuses when asked, which is not a silent wrong answer.

`restrict_to_candidates` has no caller left. It is kept, renamed, as the judge
of the compaction: restating it in the test would be the same addressing
written twice.

Two conflations came out with it:

* `index_write` spelled the MFMA tile width, the shuffle group and the block
  length with one name. All three were 16 while 16 was the only page the
  scorer took. A block of 8 shuffles in groups of 8 by 16 and tells them apart;
  at 16 the new form is byte-for-byte the old one.
* a hub id reached `CheckpointReader` as a path, so V4.1's Engram loader built
  `deepseek-ai/DeepSeek-V4.1-Flash/model.safetensors.index.json` and reported a
  missing checkpoint for a name nobody had resolved. `local_model_dir` is now
  the one place that turns either spelling into a directory; the three probes
  that answered "no such tensor" for every remote checkpoint go through it too,
  and the reader refuses a non-directory by name.

Gates: unit suite 8609 passed / 3 failed, the 3 reproducing on origin/main.
GSM8K 1319 @ 3-shot, DSpark-5, TP4, --level 0: flexible 0.9227 / strict 0.9234
against a 0.9224 +- 0.005 baseline. On a 127k-token context, 225 in-forward
comparisons of the two paths over 4 ranks disagreed on nothing -- that is the
gate for the regime GSM8K cannot reach, where the candidates are a strict
subset. Scoring is 0.80% of a decode step's GPU time in a 100k/64/conc-8 trace,
which is this optimization's ceiling there; the prefill share is 6.5%.

What the change buys is not measured. The trace carries no per-layer label, so
calls cannot be attributed to producer or consumer, and an earlier attempt to
split them by duration was wrong: a compacted call in prefill still scores
16384 columns over 16384 rows and is not short. gfx1250 is untested.

* [DCP] Allow query replication (QREP) with MTP (#2290)

* [DCP] Allow query replication (QREP) with speculative decode; fix stale sparse+MTP docs

qrep_unsupported_reason() unconditionally disabled QREP whenever
speculative_config was set, on the suspicion that QREP's full-group-head
q_out might conflict with the cprr round-robin MLA kernel MTP's qlen>1
verify path uses. Auditing the original commit and the two code paths shows
this was first-cut caution ("not yet wired"), not an observed conflict:
QREP only changes how q_out is produced (load-time replicated q_proj vs. a
runtime AllGather), and cprr's mask keys off KV-side round-robin position,
with no dependency on q_out's provenance.

Validated on GLM-5.2-FP8 (sparse DSA), TP8/DCP8, fp8 KV, MTP=3, gsm8k
nshot=20, same commit, only enable_query_replication differing:
  QREP off: flexible-extract 0.9492 +/- 0.0060, strict-match 0.9492 +/- 0.0060
  QREP on:  flexible-extract 0.9469 +/- 0.0062, strict-match 0.9477 +/- 0.0061
Delta is within combined stderr; both arms completed all 1319 requests
without error.

Also fixes docs/context_parallel_guide.md, which still claimed sparse DSA +
DCP + MTP was rejected by an assert -- that restriction was already lifted
(the sharded index cache's candidate exchange handles qlen>1 directly) but
the docs were never updated to match.

Dense MLA + MTP + QREP was not independently re-validated this round; the
mechanism argument applies equally but flagging the gap for reviewers.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* [DCP] Gate QREP per-layer on actual q_proj width, not just the config flag

Removing the speculative_config gate (previous commit) made QREP reachable
for every model that runs under DCP, but only DeepSeek/GLM's decoder layer
and Kimi-K3's main model actually build q_proj with qrep_tp_override. Three
q_proj construction sites never opted in and would have silently misread a
plain per-rank-width q as the wide QREP layout, or crashed:
  - atom/models/eagle3_deepseek_mla.py (eagle3 draft, its own MLAModules)
  - atom/models/kimi_k3_dspark.py (DSpark draft, its own MLAModules)
  - atom/models/glm5_next.py (GLM-5.3-Flash; q_proj wrapped in _ZeroRopePad,
    which has no .weight at all)

All three used to be protected incidentally by the speculative_config gate
(eagle3/DSpark always set it; GLM-5.3 + MTP would too), so removing that
gate without this fix would have made them reachable and broken.

Fix: MLAAttention now…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants