Skip to content

[Feat] [AMD] mamba: Store hicache checkpoints without a GPU slot - #44718

Merged
HaiShaw merged 23 commits into
sgl-project:mainfrom
chien-an-chen:chienach/mamba-host-only-checkpoint
Oct 31, 2026
Merged

HaiShaw merged 23 commits into
sgl-project:mainfrom
chien-an-chen:chienach/mamba-host-only-checkpoint

Conversation

@chien-an-chen

@chien-an-chen chien-an-chen commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Mamba radix checkpoints donate a GPU slot for every matched prefix. On a Kimi-K3 c=48 recipe that floor is max_running_requests * 5 (480), so the GPU mamba pool stays large even when the checkpoint only needs to be reloaded from host.

Modifications

Set SGLANG_OPT_MAMBA_HOST_ONLY_CHECKPOINT=1 (default off). It requires --enable-hierarchical-cache and rejects --enable-int8-mamba-checkpoint. This is an environment variable, not a server argument.

With the variable unset, the server keeps the previous path: the same mamba ratio, the same donated GPU slot, the KDA ReplaySSM ring indexed by the mamba slot, a single in-flight load-back receipt, and a device match that follows GPU mamba slots. The new InsertParams.allow_missing_mamba bit stays false, so an insert that omits mamba still panics.

With the variable set:

  • A finished request copies its flushed state into the hicache host pool and does not keep or donate a GPU slot.
  • The mamba ratio drops to the live request plus the ping-pong tracking slots the extra-buffer kernel still writes. With extra buffer and overlap that is 3 (1 active + 2 ping-pong), so a 96-wide decode pool is 288 slots. no_buffer with page size 1 returns 1.
  • The KDA ReplaySSM ring covers live requests (max_running_requests // attn_dp + 1) instead of every mamba slot. Padding rows are -1.
  • The Rust insert accepts mamba_host_value without a donated mamba_value. A repeat insert that already found a checkpoint may omit both values; that permission is on the insert params and applies only to that insert.
  • Under HiCache, a host checkpoint still counts as a device-prefix match, so the Full KV indices in front of it stay reachable. Load-back copies into the request slot and leaves the node on the host tier.

Memory

Per-rank GPU, MI355, Kimi-K3 c=48, 96 running requests, page size 32, extra buffer, overlap, DCP 8, ReplaySSM on. The env-on pool is the size the ratio allows; max-mamba-cache-size has to be lowered with it. Leaving the pool at 480 keeps the 13 GB allocation and only raises the running-request cap.

Env off Env on
Mamba conv + ssm 13.00 GB (480 slots, ratio 5) 7.81 GB (288 slots, ratio 3)
KDA ReplaySSM ring 9.14 GB (one row per mamba slot) 1.84 GB (97 rows, one per live request)

Env off is the earlier 0.87 log: conv 0.85 GB + ssm 12.15 GB, ring 9.14 GB. Env on conv + ssm is ci355_ix_20261015_213315_c20e (max-mamba-cache-size 288): conv 0.51 GB + ssm 7.30 GB. The same class of boot with request_ring=True keeps that 7.81 GB pool and sizes the ring at 97 rows (d = k = rawv = rawk = 0.306 GB, g = 0.613 GB, beta = 0.005 GB). The intermediate conv window stays 0.86 GB in both measurements. The checkpoint itself sits in the existing hicache host pool.

Tests

Python:

  • test_flag_off_restores_original_ratios, test_flag_on_drops_base_but_keeps_no_buffer, test_host_only_drops_gpu_prefix_floor: ratio is 3 / 4 / 5 with the flag off, and 1 / 2 / 3 with it on.
  • test_flag_off_keeps_a_donated_gpu_slot, test_host_only_no_buffer_frees_the_request_slot.
  • test_kda_host_only_ring_follows_requests: flag off charges every mamba slot; flag on charges max_running_requests + 1 rows.
  • test_inflight_anchor_still_loads: an anchor already in ongoing_load_back still load-backs. Moved out of the ratio file.
  • test_host_only_load_back_fills_request_slot_without_node_slot, test_host_only_second_load_back_on_inflight_anchor_retries.

Rust (sglang-radix-tree mamba component):

  • missing_mamba_insert_keeps_the_existing_checkpoint_when_allowed
  • insert_host_only_checkpoint_keeps_no_gpu_slot
  • host_only_checkpoint_keeps_the_device_kv_prefix
  • host_only_checkpoint_counts_gpu_kv_in_front_and_host_kv_at_the_boundary
  • host_only_anchor_bumps_the_mamba_host_hit
  • host_only_load_back_build_copies_into_the_request_slot_only
  • host_only_load_back_commit_keeps_the_node_off_the_device_tier
  • host_only_mamba_anchor_disables_branching_under_hicache

On mi355, test_mamba_donated_alloc_ratio.py (18), test_mamba_path_state_cap.py (10), test_replayssm_ring_accounting.py (4), and TestInflightAnchorStillLoads passed. cargo test --lib for sglang-radix-tree passed 949 tests.

Accuracy Tests

No model-output change when the variable is unset. With it set, load-back still restores the request slot from the host checkpoint; the GPU tests above cover that copy.

Speed Tests and Profiling

The memory table above is the measured effect. This PR does not include a new throughput number.

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): ✅ Run #40877021617
Latest PR Test (Extra): ✅ Run #40877021430
Latest PR Test (AMD ROCm 10): ✅ Run #40877021529

chien-an-chen and others added 5 commits October 22, 2026 12:41
Host-only mode keeps prefix checkpoints in the hicache host pool and drops the donated GPU slot from the mamba ratio. A later match still returns the Full KV indices for those nodes.

Co-authored-by: Cursor <[email protected]>
Host-only checkpoints keep the ring on req_pool_idx instead of every mamba slot, and padding rows no longer alias request 0.

Co-authored-by: Cursor <[email protected]>
A match that stands on a host mamba checkpoint was dropping the contiguous GPU Full prefix in front of it, so those pages were recomputed instead of reused.

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

A repeat insert was copying a full GPU slot and then dropping the new host index.

Co-authored-by: Cursor <[email protected]>
A host-only checkpoint has no device value. Load-back was still restoring a node slot and committing the request slot back onto the node, so each hit paid two H2D copies and re-pinned a GPU slot. Concurrent hits on the same anchor then collided in ongoing_load_back. Skip the node restore, leave the node on the host tier, and retry admission while that anchor's load-back is still in flight.

Co-authored-by: Cursor <[email protected]>
@chien-an-chen
chien-an-chen force-pushed the chienach/mamba-host-only-checkpoint branch from 97fd5d3 to cd3d6fc Compare October 22, 2026 04:47
chien-an-chen and others added 5 commits October 22, 2026 21:00
InsertParams requires mamba_host_value. The unevict and commit walks set it, but the overlap step did not, so the radix-tree crate failed to compile.
The in-flight load-back guard ran with the flag off and could block admission. Host-only copies now use the hicache transfer engine, and a finished no-buffer request frees the GPU slot it only copied.
The flag stays cached on the mamba component, and a missing mamba value is allowed only for the insert that already found a checkpoint.

Co-authored-by: Cursor <[email protected]>
The host-only walk already passes the layer it evicts, and the fixture has to record that call.

Co-authored-by: Cursor <[email protected]>
The load-back file already imported it, and a second import fails the unused-import lint.

Co-authored-by: Cursor <[email protected]>
@chien-an-chen chien-an-chen changed the title [Mamba] Store hicache checkpoints without a GPU slot [Feat] mamba: Store hicache checkpoints without a GPU slot Oct 28, 2026
Clippy rejects the stacked negations around the host-only exception.

Co-authored-by: Cursor <[email protected]>
@chien-an-chen chien-an-chen changed the title [Feat] mamba: Store hicache checkpoints without a GPU slot [Feat] [AMD] mamba: Store hicache checkpoints without a GPU slot Oct 28, 2026
@chien-an-chen
chien-an-chen marked this pull request as ready for review October 28, 2026 11:46
@bingxche bingxche added the run-ci-nv-extra CI: NVIDIA/shared Extra suite (requires run-ci) label Oct 29, 2026
chien-an-chen and others added 2 commits October 29, 2026 10:28
Host-only ring indices are read only when that ring is on, empty layer maps no longer index the first entry, and the MLA view publishes the staging buffer HiCache already reads.

Co-authored-by: Cursor <[email protected]>
Keep main's MLA hicache staging type, which already covers a single tensor or a K/V pair.

Co-authored-by: Cursor <[email protected]>
@chien-an-chen

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@chien-an-chen

Copy link
Copy Markdown
Contributor Author

@amd-bot ci-status

# Conflicts:
#	python/sglang/srt/mem_cache/kv/router.py
@bingxche

Copy link
Copy Markdown
Collaborator

@chien-an-chen

CI Status for PR #44718

Verdict (1–2 sentences): No test job has failed on head 3525d734 so far, so there is nothing to attribute to this PR. PR CI is not complete: AMD stage-a, AMD extra, NVIDIA, NPU, Xeon and XPU jobs were still running or queued when I checked (2026-10-29 ~13:05 UTC).

Warning

PR CI is incomplete, so a green result can't be assumed yet. The jobs most relevant to this PR's change (an AMD-side mamba hicache change) haven't finished:

Executed failures: AMD: 0 (0 related) · Others: 0 (0 related)

Gate jobs that failed (no verdict; these are not test failures)

  • call-gate / pr-gate in pr-test-mlu.yml. The PR doesn't have the opt-in label run-ci-mlu. Log message: Missing required label 'run-ci-mlu' (in addition to 'run-ci'). This is expected for a PR that hasn't opted into MLU CI.
  • xeon-extra / pr-gate / pr-gate in pr-test-extra.yml. It hit the rate limit. Log message: User 'chien-an-chen' already triggered 'PR Test Extra' via 'pull_request' at 2026-10-29T12:53:19Z. Please wait 120 minutes before triggering again. As a result, the Xeon extra suite was skipped for this head. If it's wanted, it can be re-triggered after the cooldown.

What to do before merge

  • Wait for the in-progress AMD runs (40877021529, 40877021200) and the NVIDIA run 40877021617 to finish, then re-run this check.
  • Pay particular attention to the registered unit tests this PR touches: test/registered/unit/mem_cache/test_mamba_donated_alloc_ratio.py, test_mamba_path_state_cap.py, test_replayssm_ring_accounting.py, test_hicache_load_back_timing.py, unified_radix_cache/test_unified_radix_cache_load_back.py, and the KDA/GDN kernel graph tests.

Generated by amd-bot using Claude Code CLI

@chien-an-chen

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

1 similar comment
@chien-an-chen

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@bingxche bingxche removed the run-ci-extra CI: also run the extra suite (requires run-ci) label Oct 30, 2026
@chien-an-chen

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@chien-an-chen

Copy link
Copy Markdown
Contributor Author

@amd-bot ci-status

@bingxche

Copy link
Copy Markdown
Collaborator

@chien-an-chen

CI Status for PR #44718

Verdict (1–2 sentences): None of the executed failures was caused by this PR. Five jobs failed in the CI health-check step because the GitHub API returned an HTTP 502, so no tests ran in them. The two Xeon unit-test failures happen because the Xeon image installs sglang from the PR branch, which is behind main, while the tests come from the merge with a newer main. PR CI is incomplete: the NVIDIA jobs listed below never ran their tests.

Warning

PR CI is incomplete. In pr-test.yml run 40877021617, base-c-test-4-gpu-b200, base-c-test-4-gpu-gb300 (0) and base-c-test-8-gpu-b300 (0) stopped in the health-check step before any test ran. So did extra-a-test-1-gpu-large (2) in pr-test-extra.yml run 40877021430. The gate jobs pr-test-finish and pr-test-extra-finish are red as a result. Every AMD workflow that ran passed: pr-test-amd.yml (26 jobs) and pr-test-amd-extra.yml (10 jobs). pr-test-amd-mori.yml was skipped.

Executed failures: AMD: 0 (0 related) · Others: 7 (0 related): 5 health-check 502s and 2 Xeon unit tests

Other Executed Failures

Job Test Failure On main Related? Why
extra-a-test-1-gpu-large (2) none (no test ran) ##[error]Unhandled error: HttpError: Server Error (status: 502 on GET …/actions/runs/40877021430/jobs?per_page=100) in step 5 check-pr-test-health, log no completed main runs in the pack (G2) 🟢 [FACT] The job failed in the health-check script on a GitHub API 502, before checkout or tests. The PR changes no .github/, scripts/ci/ or docker files; the diff only touches python/sglang/**, rust/sglang-radix-tree/** and test/registered/**. The same 502 hit 4 more jobs in another workflow (next rows).
base-c-test-4-gpu-b200 0 · 1 none (no test ran) the same 502 on the …/runs/40877021617/jobs listing in step 5 check-pr-test-health not checked 🟢 [FACT] Same health-check API 502 at 14:19 and 14:23 UTC on different runners (b200-cirrascale4-0123, b200-fin03-4-4567). These jobs are not in the evidence pack because of gap G1; I downloaded their logs myself. No CI file changed in the PR.
base-c-test-4-gpu-gb300 (0) none (no test ran) the same 502 in step 5 check-pr-test-health (16:11 UTC) not checked 🟢 [FACT] Same mechanism as the rows above.
base-c-test-8-gpu-b300 (0) none (no test ran) the same 502 in step 5 check-pr-test-health (19:29 UTC) not checked 🟢 [FACT] Same mechanism as the rows above.
build-test (xeon-spr, spr, stage-a-test-cpu-intel,stage-b-test-cpu-intel, spr2, 2, 3, 4) test/registered/unit/managers/test_msgpack_ipc_roundtrip.py (import at module load) ModuleNotFoundError: No module named 'sglang.srt.managers.incremental_detokenize', assertion_or_exception, 1 attempt, log main runs F2.M1–M6 were cancelled or did not include the job, so there is no baseline 🟢 [FACT] Version skew in CI. The tests come from /sglang-checkout at merge 14a5d4d (PR head merged into 5d4a6f49). The installed package in /opt/.venv is built from PR_REPO=chien-an-chen/sglang, PR_HEAD_REF=chienach/mamba-host-only-checkpoint (.github/workflows/pr-test-xeon.yml:128-132). The module was added on main by #47338 (add6f6d0). That commit is an ancestor of 5d4a6f49 but not of the PR head 3525d734, which has no incremental_detokenize* file. The PR does not touch the detokenizer or this test.
same job as above test/registered/unit/managers/test_scheduler_pause_generation.py::TestSchedulerPauseGeneration::test_pd_decode_retract_requeues_for_rebootstrap AssertionError: Lists differ: [10, 11] != [10, 11, 12], then retry() exceed maximum number of retries., log no baseline (same as above) 🟢 [FACT] Same skew. On the merged tree, the assertion output_ids == [10, 11, 12] (test line 662) was added by #47366 (03aba9e6). That commit removed req.output_ids.pop() from Scheduler.pause_generation in scheduler.py. It is in 5d4a6f49 but not in the PR head, so the installed (PR-branch) scheduler.py still pops the last id. The PR does not change scheduler.py. Counter-evidence: the PR does touch disaggregation/decode.py (D20, D21), but only to add a replayssm_request_ring constructor kwarg and pass it through. The test mocks disagg_decode_prealloc_queue, so that code is not on the test's path.

The gate jobs pr-test-finish, pr-test-extra-finish and pr-test-mlu.yml call-gate / pr-gate are gates and get no verdict of their own. Two Xeon build-test legs were cancelled.

What to do before merge

  • The 5 health-check 502 jobs: rerun only the failed jobs in 40877021617 and 40877021430. These are the only runs of the NVIDIA 4-GPU and 8-GPU base-c suites on this PR, and none of their tests ran. A clean pass would close the coverage gap; a real test failure would need its own triage. In-flight fix for the flaky step: ✅ #45169 "check-pr-test-health: Retry transient GitHub API errors" (open since 2026-10-19) and #45906 (open since 2026-10-22). Chase reviewers on those rather than opening a duplicate.
  • The 2 Xeon failures: suggested triage is to rebase or merge main into chienach/mamba-host-only-checkpoint so it contains add6f6d0 and 03aba9e6, then rerun pr-test-xeon.yml. If both tests pass, the skew explanation is confirmed. If test_pd_decode_retract_requeues_for_rebootstrap still fails, look at the PR's disaggregation/decode.py change again. The underlying mismatch is that pr-test-xeon.yml installs the PR branch head while the tests come from the merge ref; that is a CI design issue, not something this PR introduced.

Generated by amd-bot using Claude Code CLI

@chien-an-chen

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

3 similar comments
@chien-an-chen

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@chien-an-chen

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@chien-an-chen

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@HaiShaw HaiShaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@HaiShaw

HaiShaw commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator

PR Test Base, PR Test Extra all good.

@HaiShaw
HaiShaw merged commit 2f6e7f3 into sgl-project:main Oct 31, 2026
832 of 951 checks passed
JackChuang added a commit to JackChuang/sglang that referenced this pull request Nov 6, 2026
Main's sgl-project#44718 made _can_run_dspark_cutedsl_mtp read self.state_pool (a
request-scoped ReplaySSM ring keeps the Triton path). The gate test builds
the backend with __new__, so __init__ never sets that field and the merge
with main fails with AttributeError. Set it to None: no state pool, so the
gate goes on to the capability check the test pins.
weireweire added a commit to weireweire/sglang that referenced this pull request Nov 9, 2026
…tegrated

Conflicts resolved:
- components/base.py, mamba.py / unified_tree_core.rs, components/mamba.rs:
  main added host-only Mamba checkpoints (sgl-project#44718) to the per-path cap walk
  this PR moved into the shared TreeComponent._evict_path_states_beyond_cap /
  UnifiedTreeCore::evict_path_states_beyond_cap_. The shared walk gains a
  count_host_only flag carrying main's host-only holder logic (host-only
  holders count toward the cap, skip on host lock, evict from host, cascade
  with the same layer). Mamba passes its host-only setting; SWA passes false,
  so SWA behavior is unchanged.
- unified_tree_core.py / unified_tree_core.rs: keep the PR's dispatch by the
  action's component_type instead of main's TREE_STATE / Family::State lookup.
- rust_tree_core/adapter.py: keep both mamba_host_only_checkpoint and
  swa_max_states_per_path; gate the SWA cap on TREE_WINDOW in families
  (main's slot model); translate component ids through main's _CoreIds both
  ways (ids.core() on the binding call, ids.tree() when decoding the
  evict_excess_path_states tagged action).
- python_bindings.rs, CacheInitParams (Rust): keep both new fields and
  pyo3 kwargs.
- swa.py: keep main's _evict_device_collapse_leaves and storage_and_sub_pool
  in apply_component_action, plus the PR's cap field and
  EvictExcessPathStates branch.
- field_order.py: append swa_max_states_per_path after main's new fields.
- test kit fixtures.py: drop draft_swa_window (moved into tree_slots on
  main), keep swa_max_states_per_path.
- tests: base.rs takes main's imports with EvictExcessPathStates;
  test_mamba_path_state_cap.py takes main's ComponentType import path.

Follow-ups for main changes outside conflict hunks:
- tests/components/mamba.rs: pass MAMBA to main's new
  evict_excess_path_states_counts_host_only_checkpoints call.
- test_swa_path_window_cap.py: import from where names are defined
  (unified_tree_core, component_type); the fake tree core gains joint_lru /
  joint_window_type and the target arg of _cascade_evict, as on main.

Validation (gb300-oci-jhb, GB300, sglang nightly-dev-cu13-20261106-858073e4,
torch 2.14.1, Rust TreeCore built from this tree via the loader's
fingerprinted cargo build, production and inspection variants):
- test_swa_path_window_cap.py: 10 passed (Python and Rust TreeCore)
- test_mamba_path_state_cap.py: 10 passed
- test_rust_tree_core_integration.py: 580 passed
- test_rust_tree_core_errors.py 25, test_tree_core_registry.py 34,
  test_hicache_write_back_ordering.py 2, test_mamba_donated_alloc_ratio.py 20,
  test_hicache_sidecar_restore.py 6, test_unified_cache_linker.py 88,
  test_swa_unittest.py 24, test_mamba_unittest.py 14: all passed
- unified_radix_cache/ core 468, hicache 295, insert_walk 46, kv_events 17,
  load_back 66, storage 224 passed (skips are the suites' own gates);
  test_unified_radix_cache_rust.py (unittest): 1297 ran, OK (181 skipped)
- cargo test --locked in rust/sglang-radix-tree: 969 passed, 0 failed,
  1 ignored
- pre-commit on the changed files: pass (clippy rust/ workspace hook not
  runnable on macOS: turbojpeg-sys build)
kkHuang-amd pushed a commit to sgl-project/sgl-amd-mono that referenced this pull request Nov 27, 2026
…te safely (#132)

## Motivation

- Serve `amd/Kimi-K3-Quark-MXFP4-AttnFP8` on Kimi-K3's gfx950 launches
(the AgentX c1 recipe).
- Attention projections are Quark per-channel FP8; experts are native
MXFP4.
- KDA state is bf16 (`--mamba-ssm-dtype bfloat16`), with slot-scoped
ReplaySSM.
- On `main` the launches refuse its FP8 projections, so it is served
with `--enable-amd-monokernel` off.
- Standalone against `main`; includes the Kimi-K3.1 bf16 guard from
#131.

| Input | Before | This PR |
| --- | --- | --- |
| K1 `in_proj` weight | bf16 | bf16, or Quark FP8 (row-major or
AITER-preshuffled) |
| Layer-launch `o_proj` weight | bf16 | bf16, or Quark FP8 (row-major or
AITER-preshuffled) |
| KDA state dtype | fp32 | fp32 or bf16 |
| ReplaySSM slot-scoped ring (k / v / gate / beta rows) | fp32 state |
fp32 or bf16 state |
| ReplaySSM request-scoped ring (sgl-project/sglang#44718) | not checked
| declined: SGLang's path |

### Dependency

- FP8 K1 needs sgl-project/sglang#44362 (open), which merges Quark FP8
`[q,k,v,g | f_a | b]` into `fused_qkvg_proj`.
- When SGLang sets `_qkvgbfa_in_qkvg_proj`, K1 reads
`fused_qkvg_proj.weight` with the merged FP8 `[f_a | b]` tail.
- SGLang `main` has `fused_qkvg_proj` but neither that tail nor the
flag.
- K1 also needs the bf16 `f_b` copy (`_bfa_f_b_w`); a checkpoint restore
without it takes SGLang's KDA path.
- Without it, K1 logs `not built for the KDA layers` and only the layer
launch's FP8 `o_proj` runs.
- Open item: on SGLang `91a841a004` (an AgentX stack with an earlier
#44362 revision), K1 was still not built here.
- SGLang reserved no FP8 tail rows at init; still to be checked against
#44362's head `3492e17401`.
- `test_k1_runs_the_fp8_in_projection` fails until K1 engages, so the
gap cannot pass silently.
- CI: `kimi_k3_quark` is marked `blocked` until #44362 merges, so the
AMD gate does not fail on the missing merge.
- The gate reads `scripts/ci/models.py` from the base branch; run the
Quark suite directly until then.

## Modifications

```mermaid
flowchart LR
  W["Quark FP8 weight<br/>+ fp32 row scale"] --> F["stages/wfmt.py<br/>FP8 -> bf16 in registers"]
  F --> K1["K1 in_proj GEMV"]
  F --> O["layer launch o_proj"]
  S["committed KDA state<br/>(bf16 or fp32)"] -->|read| KDA["attention/kda.py"]
  K1 --> KDA
  KDA -->|"no ReplaySSM: per-token snapshots"| P["intermediate state pool"]
  KDA -->|"ReplaySSM: k / v / gate / beta rows"| R["slot-scoped ring"]
```

- FP8 attention weights
  - `stages/wfmt.py`: one shared path for K1 `in_proj` and `o_proj`.
- FP8 widened to bf16 in registers; the fp32 row scale applies to the
fp32 sum.
- The `wfmt` refactor compiles all 81 exercised kernels to
byte-identical ISA.
- `f_b` comes from the bf16 copy SGLang keeps for its fused decode
(`_bfa_f_b_w`).
- KDA state (`attention/kda.py`, `k1.py`)
- bf16 or fp32 state, as SGLang resolves it (`--mamba-ssm-dtype` or
`SGLANG_MAMBA_SSM_DTYPE`).
- With ReplaySSM, K1 writes ring rows (raw k / v, gate, beta) that
SGLang's commit replays.
- A request-scoped ring is declined: it is indexed by request, not by
the slot K1 stores at.
- Safety checks (`spec.py`, `k1.py`)
- Validate dtype (E4M3), scales, layouts and native MXFP4 expert shapes;
accept interleaved or separated experts.
- Refuse a non-SiTU MoE, SiTU parameters other than K2's (4.0, 25.0),
and a static-input Quark FP8 projection.
- Kimi-K3.1 (`kimi_k31/spec.py`): monokernels refuse to start with a
non-bf16 KDA `in_proj` or `o_proj`,
or a non-fp32 KDA state, even for narrow-only serving: the wide launch
reads them as bf16 / fp32.
- Optional SGLang names (`_qkvgbfa_in_qkvg_proj`,
`SGLANG_OPT_HIP_K3_AITER`) stay out of `SGLANG_READS`.
- Tests
- CPU spec tests and K1 GPU tests for the new formats and state dtypes.
- TP8 harness pins `AITER_SITUV2_A4W4=1`, the MoE numerics the launch
implements.
- FP8 `o_proj` seam bounds (`k2_fp8.*`): prefix and `x` cosine > 1 -
1e-6.
- Measured vs check_k2's torch reference (E4M3 weight x unquantized
activation): prefix cos 1 - 1.19e-7
      accumulating, exactly 1 resetting.
- K1 ring test also runs the Quark recipe's variant (preshuffled FP8
in_proj, bf16 state): fold cos 0.999997.
- Check mode (`SGLANG_AMD_MONO_CHECK=1`) logs any metric without a bound
instead of skipping it.
- Follow-up: check mode scores the whole ReplaySSM ring, stale rows
included; scoring only the step's rows
needs a check-mode run where FP8 K1 engages to recalibrate the
`k1_fp8.ring_*` bounds.
- E2E and CI
  - `test_kimi_k3_quark_server.py` on the Quark checkpoint:
- Reused from `test_kimi_k3_server.py`: the routing line and the
cache-flushing KL check.
- Replaced: few-shot GSM8K by sgl-eval GSM8K. Not repeated: the fault
test (checkpoint-independent).
- Added: K1 engages on the FP8 in-projection; KL after a radix-cache
prefix hit.
- Recipe `kimi_k3_quark_server.py`: derived from the AgentX c1 server;
it keeps SGLang's default `fcfs`
      scheduler where AgentX sets `--schedule-policy lpm`.
- `test_kimi_k3_server.py`: `_launch` and the test class take the
recipe, so the Quark test reuses them.
- New `kimi_k3_quark` entry in `scripts/ci/models.py`: `blocked` on
sgl-project/sglang#44362 and `pr: False`.

## Accuracy Tests

- Unit: `test/unit` 685 passed on SGLang `main@2005571ac1` (39 in the
two Kimi spec files), after merging main.
- New E2E checks, this branch, on SGLang `91a841a004` (AgentX stack), 8x
MI355X, monokernels on.
- K1 was not built in this run (see Dependency), so these cover the FP8
`o_proj` launch and SGLang's KDA.

| Check | Result | Bound |
| --- | ---: | ---: |
| GSM8K, sgl-eval 0.1.3, 200 questions, thinking, temperature 1.0, top_p
0.95, 16k tokens | 0.98 | > 0.95 |
| Mean KL, decode vs prefill, cache flushed (48 prompts x 32 tokens) |
0.0096 | 0.03 |
| Mean KL after a radix-cache prefix hit (32 prompts x 512 tokens, 31
hits scored) | 0.0117 | 0.03 |
| K1 engaged | **no** | must engage |

### Earlier results (author's runs)

- GSM8K, sgl-eval 0.1.3, 1,319 questions, max tokens 16384, monokernels
on vs off, same server.
- Server: c1 AgentX recipe, `Kimi-K3-Quark-MXFP4-AttnFP8`, TP8, DSpark
block 7, ReplaySSM, bf16 state.
- Build: SGLang `fb19a76c70`, AITER `9ab94e438f`, this PR at `d31bc07`.

| Monokernels | Accuracy | Correct |
| --- | ---: | ---: |
| Off | 97.35% | 1284 / 1319 |
| On | **97.42%** | 1285 / 1319 |

- McNemar p = 0.75 (no significant difference).
- E2E bounds of the earlier `test_kimi_k3_quark_server.py` (few-shot
GSM8K, 200 questions, x3).
- Build: SGLang `de0f491836`, AITER `5405ee0026`, FlyDSL 0.5.0, this PR
at `c06024c`.
- That SGLang lacks #44362, so K1 was not built; these cover the FP8
`o_proj` launch only.

| Run | GSM8K (bound 0.95) | KL (bound 0.03) |
| --- | --- | ---: |
| Monokernels on (routing line present) | 0.985 / 0.98 / 0.97 | 0.0105 |
| Monokernels off | 0.99 / 0.98 / 0.985 | 0.0060 |
| On + `ROCM_QUICK_REDUCE_QUANTIZATION=INT4` | 0.99 / 0.99 / 0.985 |
0.0100 |

- The recipe leaves INT4 quick-reduce out; whether it dispatched in that
run was not recorded.
- Kernel tests on MI355X:

| Test | Result |
| --- | --- |
| TP8 harness | 3 tests, 2 subtests passed; layer cos 0.999995 (bf16,
FP8, FP8-preshuffled); MoE cos 0.99997 |
| K1 (`test_kimi_k3_k1.py`) | 17 passed; FP8 in-projection cos 0.999999;
ReplaySSM fold cos 0.999997 |

## Speed Tests and Profiling

- `sglang.benchmark.serving`, random 8k in / 1k out, same node and
build, monokernels on vs off.

| Client concurrency | Median TPOT off (ms) | Median TPOT on (ms) |
Output tok/s off | Output tok/s on |
| ---: | ---: | ---: | ---: | ---: |
| 1 | 2.62 | **1.78 (1.47x)** | 314.1 | **433.8** |
| 2 | 3.41 | 3.43 | 488.8 | 494.2 |

- c1: 1.47x faster TPOT with the monokernels on; c2 is neutral.
- This run's server flags and verify widths are not recorded here.
- Not attached: an on/off comparison past the launches' 8-row width
(wider steps take SGLang's path).

## Checklist

- [x] `pre-commit run --all-files` passes.
- [x] Tests under `test/` cover the change.
- [x] The SGLang commit tested against is named above.
- [x] Accuracy and speed results are attached.
- [ ] CODEOWNERS line: not applicable (extends Kimi-K3 / K3.1).

## Review and Merge Process

1. The `lint` and `Check PR title` checks must pass.
2. Ask a `kimi_k3` / `kimi_k31` code owner from `.github/CODEOWNERS` to
review.
3. Merge with "Squash and merge": the PR title becomes the commit title
on `main`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

amd documentation Improvements or additions to documentation hicache Hierarchical Caching for SGLang jit-kernel memory-pool run-ci CI: run the baseline test suite on this PR run-ci-amd-extra run-ci-nv-extra CI: NVIDIA/shared Extra suite (requires run-ci) unified-radix-cache

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants