Skip to content

[AMD] Use SHUFFLE KV and AITER sparse attention for MiniMax-M3 - #41998

Open
zijiecode wants to merge 6 commits into
sgl-project:mainfrom
zijiecode:pr/minimax-m3-aiter-sparse-pa
Open

zijiecode wants to merge 6 commits into
sgl-project:mainfrom
zijiecode:pr/minimax-m3-aiter-sparse-pa

Conversation

@zijiecode

@zijiecode zijiecode commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

MiniMax-M3 stores sparse K/V in NHD and gathers selected blocks for AITER prefill. This PR stores sparse-layer K/V in the layout AITER paged attention reads directly, removing that gather and using the same consumer for prefill, decode and verification.

Modifications

  • Store sparse K/V in separate page16 SHUFFLE planes within the existing allocation, while keeping allocator pages at 128 tokens.
  • Feed the AITER indexer's page tables into pa_decode_gluon and reuse selections across the existing layer groups.
  • Enable the writer and consumer together for supported gfx950 FP8 HD128 configurations without PD disaggregation. Dense layers and index-K retain NHD storage.
  • With HiCache, keep the SHUFFLE layout when pages move through --hicache-io-backend kernel with --hicache-mem-layout layer_first, which copies whole 128-token pages. Other HiCache transfers keep NHD.
  • Add backend, cache-layout, scaling, long-context, graph-replay and HiCache host-pool regressions.

Depends on #41708. Set SGLANG_M3_USE_AITER_SPARSE_PA=0 to disable this path.

Accuracy Tests

amd/MiniMax-M3-MXFP4, MI355X, TP4/EP1, full 5-shot GSM8K (1,319 questions), chat-completions, 16384-token output budget, temperature 0, real EAGLE3 verification, 8 concurrent requests.

Configuration Strict-match Flexible-extract
SGLANG_M3_USE_AITER_SPARSE_PA=0 96.74% 96.66%
This PR 96.36% 96.36%
This PR, HiCache (kernel, layer_first) 97.04% 96.97%

Repeated runs of the same server vary by up to 7 answers.

25 GPU regression tests passed on MI355X with the enable flags unset: 10 sparse-PA, 9 indexer and 6 HiCache host-pool tests. Tested with AITER e7d2453f25.

Benchmarking and Profiling

AgentX on MI355X, TP4/EP1, C32, no KV offload, 3600 seconds per run, and 10 warmup requests per lane. Both sides use EAGLE3 with simulated acceptance length 2.78, HD128 ASM prefill and AITER FP8 index selection; the candidate adds only SHUFFLE KV and sparse PA.

Metric Baseline This PR Change
Standard p90 interactivity (tok/s/user) 43.45 49.99 +15.06%
Total throughput (tok/s/GPU) 37526.46 39944.68 +6.44%
Output throughput (tok/s/GPU) 242.68 256.17 +5.56%
TPOT mean (ms/token) 12.620 12.111 -4.04%
TPOT p50 (ms/token) 9.656 8.653 -10.39%
ITL p99 (ms/token) 74.364 96.477 +29.74%

Both formal runs had zero request errors. Grace-period cancellations were 1 / 0 and warmup errors were 1 / 0 for baseline / candidate.

Checklist

  • Format your code according to the Format code with pre-commit guide.
  • Add unit tests.
  • Update documentation.
  • Provide accuracy and speed benchmark results.
  • Follow the SGLang code style guidance.

CI States

Latest PR Test (Base): 🚫 Run #38822159998
Latest PR Test (Extra): ❌ Run #38822159932
Latest PR Test (AMD ROCm 10): ❌ Run #38822160217

Preserve both AITER and CP initialization. Let explicit indexer CP own decode and linear verify while retaining AITER prefill and cross-layer top-k reuse. Add regressions for dispatch priority and verify metadata.
AITER sparse paged attention over page16 SHUFFLE K/V for the sparse layers,
behind SGLANG_M3_USE_AITER_SPARSE_PA (on where supported). The pool stores
sparse layers' K/V in the SHUFFLE layout once the backend selects both
consumers; with HiCache this needs the kernel / layer_first transfer.
@zijiecode
zijiecode force-pushed the pr/minimax-m3-aiter-sparse-pa branch from 023ef2c to 354d18e Compare October 15, 2026 23:12
kevin-mii pushed a commit to sgl-project/sgl-amd-mono that referenced this pull request Oct 18, 2026
## Motivation

Adds MiniMax-M3 to the AMD monokernel backend: each sparse MoE layer of
a decode or EAGLE3 verify step runs as one launch.

## Modifications

- `sgl_amd_mono/minimax_m3`: the spec and its forward. The embedding,
the 3 dense layers and the final norm run SGLang's modules; each of the
57 sparse MoE layers is one launch. TP4, MXFP4 experts, 1 to 16 rows a
step (EAGLE3: up to 4 requests of 4 tokens).
- One launch runs K1 (input norm, fused qkv / index projection, q / k
norms, RoPE, K / V and index-K writes, index scores) and then block
selection, sparse attention, o_proj, the router, the MXFP4 MoE and both
all-reduces. Every wait goes through `common/guard`.
- Weight copies made at startup and logged: per-channel FP8 qkv / index
and o_proj (the checkpoint keeps them in bf16), the bf16 router gate,
the fp32 routing bias and one bf16 RoPE table, 1.7 GiB a rank.
- `SGLANG_AMD_MONO_CHECK=1` compares every launch with SGLang's layer on
the same input in eager steps; the spec's bounds come from it.
- Tests: `test/unit` (spec, refusals on meta-device layers),
`test/kernels` (row tables, every width compiles), `test/e2e` (EAGLE3
verify server, HiCache decode server, check mode, fault injection).
README.

Needs SGLang's page16 SHUFFLE K / V, sgl-project/sglang#41998 on #41708.
Until both merge, `--monokernel-backend amd` refuses MiniMax-M3 and
names them; their three switches are read with a fallback and move into
`SGLANG_READS` after the merge. SGLang's `sgl-amd-mono` pin needs a bump
for M3 to ship.

## Accuracy Tests

MI355X, TP4, SGLang main a038a0dca0 + sgl-project/sglang#41998
(544bfad891).

`amd/MiniMax-M3-MXFP4`, full 5-shot GSM8K (1,319 questions), chat
completions, 16384-token budget, temperature 0, real EAGLE3
verification, 4 concurrent requests so every verify step runs the
monokernels:

| | Run 1 | Run 2 |
|---|---:|---:|
| Monokernels off | 96.36% | 96.89% |
| Monokernels on | 96.51% | 96.82% |


- `test/e2e`: 9 passed.
- `test/unit`: the MiniMax-M3 tests and contract items pass on SGLang
main and on main + #41998. On SGLang main alone, `--monokernel-backend
amd` refuses MiniMax-M3 at startup, naming #41998 and #41708.

## Speed Tests and Profiling

AgentX on MI355X, TP4, EAGLE3, 3600 seconds per run.

| Concurrency | p90 interactivity (tok/s/user), off → on | Total
throughput (tok/s/GPU), off → on |
|---|---:|---:|
| C1 | 289.2 → 409.8 (+41.7%) | 4,802 → 5,771 (+20.2%) |
| C4 | 246.4 → 330.3 (+34.1%) | 7,711 → 8,601 (+11.5%) |
| C38, HiCache | 50.3 → 54.4 (+8.0%) | 47,040 → 47,720 (+1.4%) |

### Review fixes (on top of 374860b)

- main is merged in (GLM-5.3-Flash #6, the DeepSeek-V4.1 fixes #10 and
GLM-5.3 #7). The README, the registry and CODEOWNERS keep every model.
- The kernel cache key holds the sources digest, as the other models'
do. So an edit to `common/`, to `minimax_m3/gfx950` (including
`layout.py`'s dict-valued stage bases) or to an imported aiter helper
rebuilds the kernels.
- New startup refusals:
- experts whose gate and up rows SGLang interleaves (a SiTU activation,
A16W4). They are marked shuffled and have the separated layout's sizes,
while the kernels read separated rows.
  - `--enable-hisparse`;
  - `--expert-distribution-recorder-mode`;
  - SGLang's benchmark routing overrides.
- `spec.py`'s `SGLANG_READS` lists what `spec.py` reads: the parallel
sizes, the shape key fields, the `"target_verify"` literal, the layer
modules, `forward_native`, `out_cache_loc` and `text_config`. It no
longer lists names that only `weights.py` reads.
- Code that nothing called is removed: `post_attn.py`'s `_f32`,
`index_score.py`'s `q_frag_from`, and two runner fields.
- Cleanup:
  - two refusals say what they need;
- the docs match the code: the MoE is MXFP8 x MXFP4 (a8w4), and the
attention projections run in FP8 (now also in the numerics note and the
README);
  - CODEOWNERS adds `**/*minimax_m3* @zijiecode`.
- Tests:
- Setup: MI350X, TP4, SGLang main + sgl-project/sglang#44601 + #41998
(which carries #41708).
- `test/unit`: 119 passed with and without #41998, on main with every
model.
- `test/e2e`: the decode server's 3 tests passed. On 2c6213a, the final
M3 code (8b37f17 adds only main's other models), mean KL was 0.081
(bound 0.12) and GSM8K-200 was 0.885 (bound 0.87), and the tested
batches ran the monokernels. Before the fixes (f6ec322) they were 0.074
and 0.895, 2 questions apart.
- Not executed here: the EAGLE3 verify, check-mode and fault tests.
Their EAGLE3 draft's rotary fails on this host's sgl_kernel, which lacks
main's f32 cos/sin cache, before the monokernels run.
- Not in this PR: the unreachable context-parallel index path (about 220
lines across five kernel files) and the runner helpers duplicated from
DeepSeek-V4.1.

## Checklist

- [x] `pre-commit run --all-files` passes.
- [x] Tests under `test/` cover the change.
- [x] The SGLang commit or PR this was tested against is named above.
- [x] Accuracy and speed results are attached when kernel or forward
code changes.

---------

Co-authored-by: Zijie Chen <[email protected]>
Co-authored-by: Kevin Mi <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
kevin-mii added a commit to sgl-project/sgl-amd-mono that referenced this pull request Oct 19, 2026
## Motivation

FlyDSL's disk cache keys a launcher on a narrow set of inputs:

- its own source;
- plain helper functions in the launcher file's own directory;
- the scalar values it closes over (dicts, Structs and dataclasses are
dropped);
- the FlyDSL install.

It misses `common/`, `module.func` calls (even within the same
directory), functions defined inside a kernel body, helper classes and
the builder code. So each kernel closes over a sources digest as
`keyed`, and that digest had three problems:

- **It was copied per model.** Each model had its own `sources.py`.
Nothing checked that a new launcher actually reads the digest. A
launcher that misses it keeps serving kernels built from old code.
- **It was coarse.** It hashed every file under `common/` and
`<model>/gfx950/`, so a `runner.py` or `weights.py` edit rebuilt every
kernel of the model. It also missed modules that aiter's helpers
themselves import.
- **GLM-5.3 and MiniMax-M3 keyed only the digest.** Their build
arguments reached the key only as closure scalars.

FlyDSL has no supported way to add to one kernel's key: `@flyc.jit`
takes no arguments. ROCm/FlyDSL#1206, still open, asks for an opt-in key
protocol for captured traits; source dependencies would fit the same
hook. The two other routes were rejected:

- `EXTRA_SOURCE_DIRS` applies to the whole process. It changes every
kernel's key, so aiter's bundled AOT cache misses.
- Keying on the traced IR needs a trace on every start, and a trace
costs more than a compile.

## Modifications

`common/plan.py`:

- `kernel_sources(module)` replaces `source_digest` and the four
`sources.py` files.
- It hashes `module` and every `sgl_amd_mono` and
`aiter.ops.flydsl.kernels` module it imports, transitively. Imports
inside functions count.
- It hashes parsed code without comments or docstrings. FlyDSL still
hashes each jit and kernel function's own source, comments included, so
this only spares edits outside those functions.
- Modules are found on disk under each package's directory, with no
imports. Each is parsed once per process.
- `key_tuple` also takes a builder's `locals()`, allows `None`, and
flattens nested Structs and dataclasses.

Kernel modules:

- Each one takes `SOURCES = kernel_sources(__name__)` at import, so the
digest is of the code that runs. A digest read at the first build would
pair an edit made since import with the code already loaded.
  - `deepseek_v41/gfx950/layer.py`
  - `deepseek_v41/gfx950/indexer/k2i.py`
  - `glm53/gfx950/kernel.py`
  - `glm53_flash/gfx950/kernel.py`
  - `minimax_m3/gfx950/post_attn.py`
- GLM-5.3 and MiniMax-M3 key their launch on every builder argument:
`keyed = key_tuple(locals(), SOURCES)`. DeepSeek-V4.1 and GLM-5.3-Flash
already did this through their build Structs.

`test/unit/test_source_digest.py` has two tests:

- Every `@flyc.jit` launcher reads a `keyed` built from its module's
import-time `SOURCES` and every build parameter, directly or through a
`@flyc.kernel` it calls.
- The digest changes when imported code changes. That includes an aiter
helper, an attribute import, `import a.b`, and a level-2 relative import
inside a function. It stays the same for an unimported module or a
comment.

What a kernel's digest covers, on this tree:

| Kernel module | Plugin modules | aiter modules |
|---|---|---|
| `deepseek_v41.gfx950.layer` | 22 | 4 |
| `deepseek_v41.gfx950.indexer.k2i` | 11 | 4 |
| `glm53.gfx950.kernel` | 11 | 4 |
| `glm53_flash.gfx950.kernel` | 11 | 4 |
| `minimax_m3.gfx950.post_attn` | 15 | 6 (adds `act` and its import
`tensor_shim`) |

Effects:

- An attention edit no longer rebuilds K2i, and an indexer edit no
longer rebuilds the layer kernels.
- `runner.py`, `weights.py`, `packing.py` and `peer.py` are in no
digest. The build arguments they choose are keyed directly.
- Every key changes once, so the first start after this PR rebuilds
every kernel.

## Accuracy Tests

MI350X, TP4, the plugin's serving tests on the final commit 397b87f.
SGLang main da414adda7, except MiniMax-M3, which ran on main 6c3db0f520
+ sgl-project/sglang#44601 + sgl-project/sglang#41998:

- DeepSeek-V4.1 (`test/e2e/test_deepseek_v41_server.py`): 9 passed.
- GLM-5.3-Flash (`test/e2e/test_glm53_flash_server.py`): 4 passed.
- MiniMax-M3 decode (`test/e2e/test_minimax_m3_server.py -k
TestMonokernelDecode`): 3 passed.
- GLM-5.3 needs 8 GPUs to serve. Instead, its launch was compiled on one
GPU with `runner.py`'s arguments, for a dense and an indexer layer. Cold
compiles took 6.0 s and 9.0 s; a second build loaded from the disk cache
in 0.2 s.
- `test/unit`: 120 passed.

Mutation checks; each one fails a unit test:

- GLM-5.3 keyed on the digest only;
- the digest taken in a builder instead of at import;
- K2i dropping `tokens` from its key;
- a launcher dropping `_ = keyed`;
- walking only top-level imports;
- hashing raw bytes;
- leaving aiter out;
- not following a `from m import x` module.

## Speed Tests and Profiling

No kernel code changes. Only the cache key changes. The digests take
milliseconds at import: each shared module is parsed once per process.

## Follow-ups (not in this PR)

- Upstream: an opt-in key on `@flyc.jit`, the protocol ROCm/FlyDSL#1206
asks for, extended to source dependencies. Once it ships, the `_ =
keyed` lines and the guard test can go.
- The four runners each carry a copy of `ensure_writable_flydsl_cache`.
On a read-only aiter install it repoints `FLYDSL_RUNTIME_CACHE_DIR` for
the whole process, so aiter kernels first called after it miss aiter's
bundled cache. It could be one helper in `common/`, scoped to the
plugin's compiles.

## Checklist

- [x] `pre-commit run --all-files` passes.
- [x] Tests under `test/` cover the change.
- [x] The SGLang commit or PR this was tested against is named above.
- [x] Accuracy and speed results are attached when kernel or forward
code changes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Kevin Mi <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
kevin-mii added a commit to sgl-project/sgl-amd-mono that referenced this pull request Oct 23, 2026
…not show (#46)

## Motivation

The MiniMax-M3 package's comments and docstrings, trimmed as
#43 and #44 did for DeepSeek-V4.1 and `common`:
a comment is the constraint, cause or failure mode the code cannot show,
a docstring a summary and at most a paragraph. A few docstrings and
comments no longer described their code; those now match it.

## Modifications

Comments and docstrings only, in `sgl_amd_mono/minimax_m3/**` and the
MiniMax-M3 tests (16 files, 372 insertions, 565 deletions; one commit
for `post_attn.py`, one for the rest).

- Kept wherever stated: why an order, rounding or layout matches SGLang
/ aiter bit for bit, the mailbox and cross-rank invariants, LDS and
load-order constraints, upstream anchors (sgl-project/sglang#41998,
#41708), attribution, and in tests the measured values that justify a
bound (GSM8K 0.905 / 0.920 vs 0.905 / 0.905, NIAH, KL, `NUMERICS`'
medians and tails).
- Removed: history, comments that restate the code, timings in code.
- Now match the code:
- `post_attn.py`'s module docstring: mailbox ``a`` holds the rank sum s,
not bf16(s) + h (the router adds h in f32).
- `route_top4` writes `route[8k : 8k+5]` (slot 4, the shared expert);
`wug_load` names `UG_PER_SLOT`.
- `index_score.py`'s module docstring claimed no task needs the CTA,
which the many-task path contradicts.
- `_config_disable_reasons` refuses every KV offload (LMCache, FlexKV,
decode KV offload), not only HiCache.
- The "scores" region's pair formula, the clamped B / o_proj columns,
`AG_RS_FROM`'s two all-reduces, the router's three-spec poll and the
`ws` thread bound.

## Accuracy Tests

The code is unchanged: for every edited file, the module parses to the
same AST as before once docstrings are dropped, and every pragma comment
is kept.

- `test/unit`: 129 passed. `pre-commit run` on the 16 files: clean.
- MI350X, SGLang main 5e79333c95:
`test/kernels/test_minimax_m3_compile.py` (every served width) and
`test_minimax_m3_rows.py` running; results to follow here.

## Speed Tests and Profiling

Not applicable: no code change.

## Checklist

- [x] `pre-commit run --all-files` passes.
- [x] Tests under `test/` cover the change.
- [x] The SGLang commit or PR this was tested against is named above.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Kevin Mi <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
jhinpan added a commit to sgl-project/sgl-amd-mono that referenced this pull request Oct 27, 2026
## Motivation

Without CUDA graphs, every launch of the DeepSeek-V4.1, GLM-5.3,
GLM-5.3-Flash and MiniMax-M3 runners goes through FlyDSL's JIT dispatch
(`JitFunction.__call__`): it binds the signature, checks the globals and
builds the full cache key at each launch. For GLM-5.3-Flash's launchers
(50 integer arguments), that costs 182 µs of host time a launch, so an
eager decode step is host-bound. This PR reuses AITER's
compiled-dispatch helper: it keeps the first real launch's
`CompiledFunction` and calls it after that.

A replayed CUDA graph does not call the launchers, so decode with CUDA
graphs (the default) does not change.

## Modifications

- These launches use `_run_compiled` from
`aiter.ops.flydsl.kernels.tensor_shim`, with the runtime addresses,
scalars and stream passed positionally:
  - DeepSeek-V4.1: K1, K2, FFN and K2i.
  - GLM-5.3: the layer.
  - GLM-5.3-Flash: the layer and the head.
  - MiniMax-M3: the launch.

  MiniMax-M3.1 already caches its compiled FFN callable.
- `compile_only` in the four runners uses AITER's `_preload_compiled`.
AITER handles the no-dispatch preload and restores the environment.
- The GLM runners import both helpers where they use them. AITER probes
the GPU when it is imported, and `test/unit` imports these modules on
CPU.
- `test/kernels/test_compiled_dispatch.py` checks the dispatch that the
runners rely on:
  - a preload never runs the kernel;
  - the first real call runs it once;
  - later calls skip JIT dispatch, also inside a graph.
- AITER requirement: `_preload_compiled`, from ROCm/aiter#5346
(`354e278e5`) onwards. ROCm/aiter#6946 is not needed, because this
repository never calls `_run_compiled` while `COMPILE_ONLY` is set.

## Accuracy Tests

The kernels and their arguments do not change, and the outputs are
bitwise equal to main's:

- GLM-5.3-Flash: the eager step of layers 3-43 at TP4, 4 and 8 rows, on
every rank.
- DeepSeek-V4.1 K1 through `DSV41MonoRunner.k1`: at TP2; widths 1, 6, 24
and 48; fold, settled and index. The outputs match after the first and
third eager call and after a graph replay, in 24/24 cases.

E2E on MI355X:

- `test_glm53_flash_server.py` (TP4): 5/5. GSM8K past the largest width
scores 0.995.
- `test_glm53_server.py` (FP8, TP8): 8/8. GSM8K scores 0.99 for decode
and 0.99 with MTP, with an accept length of 3.3-3.4.
- `test_minimax_m3_server.py` (TP4, with sgl-project/sglang#41998): 7/9.
GSM8K scores 0.925 with EAGLE3 and 0.885 for decode. The 2 failing cases
also fail on main: the test expects the spec name `minimax_m3_hip`, but
the spec has been named `minimax_m3_family_hip` since #56.

After the GLM import change, CPU-only `test/unit` gives the same result
as on main, and GLM-5.3-Flash stays bitwise equal to main at TP4.

## Speed Tests and Profiling

MI355X at TP4, with a fresh server for each arm and two rounds. The load
is random 2048 tokens in and 256 out. The table gives median TPOT in ms,
main -> this PR:

| Model | CUDA graphs, c1 / c4 | `--disable-cuda-graph`, c1 / c4 |
| --- | --- | --- |
| GLM-5.3-Flash | 2.520 -> 2.523 / 3.032 -> 3.029 | 11.28 -> 2.72 /
11.75 -> 3.19 |
| GLM-5.3 (FP8) | 6.812 -> 6.812 / 9.351 -> 9.342 | 20.06 -> 7.05 /
20.43 -> 9.39 |
| MiniMax-M3 + EAGLE3 | 1.430 -> 1.426 / 4.118 -> 4.174 | 6.29 -> 3.31 /
9.58 -> 6.38 |

- **With CUDA graphs**, TPOT does not change (within ±1.4% at every
covered width). The gain applies only to steps that run without a graph.
- **Host time** of a GLM-5.3-Flash launch goes from 182 µs to 14.7 µs.
An eager step of layers 3-43 goes from 7.50 ms to 2.54 ms, which equals
the step's graph replay time.

Setup: image `rocm/sgl-dev:v0.5.22-rocm10-mi35x-20261026`, with SGLang
`5ef99013ac`, AITER `285579b62` and FlyDSL 0.4.0.

## Checklist

- [x] `pre-commit run --all-files` passes.
- [x] Tests under `test/` cover the change.
  - The dispatch: `test_compiled_dispatch.py`.
- DeepSeek-V4.1 FFN and K2: `test_deepseek_v41_kernels.py`. K2i:
`test_deepseek_v41_k2i.py`.
  - GLM-5.3-Flash: `test_glm53_flash_kernels.py`.
  - MiniMax-M3 `compile_only`: `test_minimax_m3_compile.py`.
  - Only the e2e tests reach the GLM-5.3 and MiniMax-M3 launches.
- No committed test reaches `DSV41MonoRunner.k1`, because `check_k1.py`
calls the K1 launcher directly. K1 was checked bitwise against main, as
described above.
- [x] The SGLang commit or PR this was tested against is named above.
- [x] Accuracy and speed results are attached.
- [ ] A new model adds one line to `.github/CODEOWNERS` that names its
owner. (No new model.)

---------

Co-authored-by: Jin Pan <[email protected]>
bingxche added a commit to sgl-project/sgl-amd-mono that referenced this pull request Nov 10, 2026
…es, per PR and nightly (#107)

## What

CI on two dedicated MI355X nodes that runs the checks of the PR review
guideline, split in two:

- **PR test** (`pr-test-amd.yml`), maintainer-gated, for each model a PR
touches: its unit, kernel and serving tests, the kernel-only timing
scripts, GSM8K with the monokernels on and off, and InferenceX
fixed-length speed against the base branch. The workflow posts the
result as an `AMD PR test` commit status and keeps one PR comment
updated with a checklist in the guideline's order (rules, scope,
accuracy, kernel microbenchmark, E2E performance, tests, doc).
- **Nightly** (`nightly-amd.yml`), on main and the newest SGLang ROCm
image: for each Phase 1 model, GSM8K, GPQA (and MMMU-Pro for vision
models) and the speed test with the monokernels on, held to the model's
fixed baseline. Saturday's **weekly** run adds AIME26 ×4 and runs every
benchmark with the monokernels on and off.

## Why

The guideline asks reviewers to approve only when these checks pass,
plus a ≥5% gain for performance work. Today authors run the checks by
hand and paste the numbers. The long benchmarks would make every PR run
take most of a day, so GPQA runs nightly and AIME26 ×4 (~23K tokens per
answer, the costliest) runs weekly. A PR run keeps only the checks that
can block a merge.

## How it works

- Trigger: a maintainer adds the `run-ci` label, or runs the workflow
with a PR number. `run-ci-extra` does the same and adds GPQA, which
catches long-context accuracy losses that GSM8K's short answers can't
show. It's meant for PRs that touch attention, the KV cache or long
sequences. The run removes the label and pins the PR head SHA it saw, so
any later push needs a maintainer again.
- Scope (`scripts/ci/scope.py`): a model whose own package or tests
changed runs the full tier. A change to `common/`, `__init__.py` or
`pyproject.toml` runs every other model's smoke tier (tests, plus speed
at the covered widths only) and `common` (the unit tests and the
guard/dispatch kernel tests). The CI's scripts and `models.py` come from
the base branch, so a model package that `models.py` there doesn't list
(a model new in the PR) isn't run: the report warns ("New model"), and
the author gives its results by hand until its entry merges.
- Sides (`scripts/ci/run_model.py`): every server is the model's
`test/e2e` recipe from the PR. **base** is the PR's merge-base with its
base branch, monokernels on, used for speed only. **on** is the PR with
monokernels on. **off** is the same build with monokernels off, i.e.
SGLang's own path. The off side doesn't depend on the package, so the
weekly run's off result for the model's recipe is kept as the
**monokernel-off reference** (`$CI_SHARED_DIR/monokernel_off_ref`, on
shared storage so either node can read it): the PR test and the nightly
compare against it, a PR runs off itself only when the reference has no
entry yet, and only a weekly run writes it. The container mounts it
directly, writable in a weekly run and read-only in the PR test and the
nightly, so PR code can't change it.
- With monokernels on, an eval sends no more concurrent requests than
the launches cover (for Kimi-K3, one request; for DeepSeek-V4.1, eight).
A wider step falls back to SGLang's path, and the score would not
measure the kernels.
- Gate (`scripts/ci/report.py`):
- GSM8K (all 1319 questions, plus GPQA with `run-ci-extra`) is compared
on vs off question by question with an exact one-sided McNemar test, and
a significant loss with monokernels on (p < 0.05) fails;
- a median-TPOT (p50) loss of more than 2% vs base fails at a covered
concurrency and warns at the model's other concurrencies;
`[Perf]`/`[Feat]` PRs also need a ≥5% gain at a covered concurrency of
one of the PR's models. Output throughput is reported next to it and
warns on a loss over 2%. Other serving metrics swing too much with the
monokernels, so the report leaves them out;
- failed tests fail, and so do a server that logs no monokernel routing
and a step of the run that raises an error;
- edits to existing `.github/CODEOWNERS` lines fail, while an added
owner line for a new model is only a warning.
- The nightly holds each on score to a per-model `baseline` in
`models.py` (GSM8K below it fails, the rest warn). Each weekly report
suggests baselines from its off scores; the baselines start empty and
get set from the first weekly run. The weekly run gates on the paired
GSM8K test like a PR run; GPQA and AIME26 ×4 warn when they fall 5 and 3
points below the off run (Zijie's numbers), and MMMU-Pro 3 points.
- Before installing main, the nightly also checks the sgl-amd-mono the
SGLang image pins (`/sgl-workspace/sgl-amd-mono`): its
`test_contract.py`, and a server per model with the monokernels on
answering a few requests. A field SGLang adds to an op that the pinned
commit doesn't set fails that check the day the image picks it up (Kk's
case).
- Isolation: the PR workflow uses `pull_request_target`, and the scripts
that run outside the container come from the base branch. PR code runs
only inside the SGLang ROCm container. The cluster job fetches both
commits itself.

## Notes for the reviewer

- max-tokens leaves room for thinking models: 16384 for GSM8K, 64K for
GPQA and AIME26.
- Phase 1 nightly models: DeepSeek-V4.1-Flash, GLM-5.3, GLM-5.3-Flash,
Kimi-K3, Qwen3.8-Flash-Next.
- GLM-5.3-Flash and Qwen3.8-Flash-Next: their MXFP4 checkpoints aren't
on shared storage, but they were downloaded straight into both nodes'
mirror, so the nightly serves them (their completeness hasn't been
checked by a run yet).
- MiniMax-M3 is marked blocked until sgl-project/sglang#41998 and #41708
merge, because SGLang refuses `--enable-amd-monokernel` for it without
them.
- Kimi-K3.1, MiniMax-M3.1 and Muse-Spark run their unit and kernel tests
only, until their SGLang support lands.
- Not in CI: OCRBench and LiveCodeBench (sgl-eval doesn't run them yet).
SWE-bench stays with the author.
- GPQA is a gated dataset: the job fills the dataset cache with the HF
token in the runner account's `~/.sgl_amd_mono_ci/hf_token` (set up on
the cluster) before any PR code runs.
- Setup: the `run-ci` and `run-ci-extra` labels exist and the runners
are registered. Optionally, a repo admin can make `AMD PR test` a
required status after merge.
- Nodes: a job takes whichever of the two CI nodes is free;
`slurm_launch.sh` keeps jobs off the shared partition's other nodes with
a versioned `SLURM_EXCLUDE` list. A runner's `.env` must not pin a node:
Spur's `sbatch` honors `SBATCH_NODELIST` and ignores `SLURM_NODELIST`
(tested on the nodes; the stale `SLURM_NODELIST` lines in r1/r2's `.env`
are removed).
- Runners: r1/r2 (`sgl-project/sgl-amd-mono`) on the
`crs-m2m-cpu-spur-arc-016` runner VM, account `z1_sglangci`; each node
keeps its checkouts, checkpoint mirror and caches under
`/mnt/m2m_nobackup/sgl-amd-mono-ci`. r3/r4 are temporary runners on the
fork for the end-to-end trials below; unregister them after merge.
- A run of the nightly workflow with `weekly` ticked rewrites the
monokernel-off reference from whichever branch it runs, so run it by
hand on `main` only.

## Test plan

End-to-end on the fork (michaelzhang-ai/sgl-amd-mono) with this PR's CI
on top of current `main` (fork branch `e2e-base`), on the two MI355X
nodes, with the full settings (all 1319 GSM8K questions, every
concurrency):

- [PR
test](https://github.com/michaelzhang-ai/sgl-amd-mono/actions/runs/42789607786)
with `run-ci-extra` on [fork PR
#2](michaelzhang-ai#2) (a
`deepseek_v41`-only change), CI at d356704: label trigger and removal,
scope, merge-base base side, base speed test and timing script,
unit/kernel/serving tests, the on server (both launches routed:
target_verify steps of batch size 1–8), the off side, the report, the PR
comment and the `AMD PR test` status all ran. GSM8K on vs off: 0.9666 →
0.9666, 5 lost / 5 gained, p = 0.623. Median TPOT base → PR within ±1%
at the covered concurrencies. The status is red for reasons outside this
PR: GPQA could not be loaded (the HF token cannot fetch
`Idavidrein/gpqa`; f1eec28 now reports that as not run instead of an
error), main's known unit failures, and one serving test that imports
`sglang.srt.utils.hf_transformers_utils`, which SGLang moved in
sgl-project/sglang#48781.
- [Weekly
run](https://github.com/michaelzhang-ai/sgl-amd-mono/actions/runs/42789589746)
(`common` + `deepseek_v41`): the pinned-mono check correctly fails (the
11-09 image pins sgl-amd-mono e52803f, which lacks #118, so
DeepSeek-V4.1 cannot start with the monokernels on that image); on and
off with GSM8K and AIME26 ×4 ran. Writing and then reading the
monokernel-off reference (weekly → nightly) is still running.
- Cancelling a run cancels its cluster job
([run](https://github.com/michaelzhang-ai/sgl-amd-mono/actions/runs/42771116642),
on earlier CI code).
- Kernel compilation dominates the kernel tests (DeepSeek-V4.1's took 1
h 38 min, mostly FlyDSL JIT on a cold cache); persisting the compile
caches is a follow-up.

Also:

- Ran `scope.py` against the file lists of #95, #96, #97, #101, #103 and
#105; the models and rule results match what each PR touched (#96 and
#103 trip the CODEOWNERS rule).
- `report.py` produced the expected verdicts on synthetic results
(paired GSM8K: 7 of 7 discordant lost fails at p = 0.008, a 1/1 split
passes), and the review fixes were checked with mocks (step isolation,
PR runs not writing the reference, the PR-wide speed gain). The
reference's direct mount was tested on v3-060 with the SGLang image: a
weekly-mode write and read-back, a read-only mount refusing the write
(EROFS) while reads work, and the files handed to the runner account.
- Every supported checkpoint the cluster has (16 of 17;
`moonshotai/Kimi-K3.1` isn't on HF or the cluster) is mirrored to both
nodes' NVMe.

---------

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

This branch has not been deployed

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

Labels

amd memory-pool run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants