Skip to content

[feature] LeapQuant for GDN: int8 recurrent state, with prefix caching and MTP - #3101

Open
haoyangli0109 wants to merge 5 commits into
ROCm:mainfrom
haoyangli0109:lhy/leapquant_gdn
Open

haoyangli0109 wants to merge 5 commits into
ROCm:mainfrom
haoyangli0109:lhy/leapquant_gdn

Conversation

@haoyangli0109

@haoyangli0109 haoyangli0109 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

What it does

Adds LeapQuant (Pan et al., arXiv:2609.38166) as an opt-in storage format for the GDN recurrent state, ATOM_ENABLE_LEAPQUANT=1, including prefix caching and MTP speculative decoding, and fixes a prefix-caching bug that any state other than bf16 runs into. On main d325160e9. Five commits, each reviewable on its own:

  1. feat(gdn): LeapQuant int8 recurrent state for single-token GDN decode
  2. test(gdn): LeapQuant kernel and startup-refusal tests
  3. feat(gdn): LeapQuant with prefix caching
  4. feat(gdn): LeapQuant with MTP speculative decoding
  5. fix(state): clear a checkpoint unit before it goes back to KV

Without the flag nothing changes, with two exceptions: under plain ReplaySSM the fork transfer no longer keeps a checkpoint at a generation position (commit 3), and every PAGE-copy backend clears a recycled checkpoint unit before it goes back to KV (commit 5).

LeapQuant (commits 1 and 2)

Between window flushes each head's state is held as

S_0 = diag(c) · Z · diag(b) + Kcᵀ · Uc

Z is an int8 residual, b and c are fp32 per-column scales and per-row smoothing, and Kc, Uc are r = 4 fp16 compensator tokens, fitted by power iteration to take the outlier rows and columns that would otherwise set the int8 range. A slot holds 1.19 bytes per state element instead of 4, and the state is re-quantised once per window (p = 16 tokens) instead of rounded every token, so the rounding error does not compound over long generations.

It is built on ReplaySSM, whose record buffer (replay_buf_k/u/g, cursor write_pos) already is the per-window form; LeapQuant only changes what the boundary checkpoint is.

  • fla_ops/leapquant.py: Triton kernels.
    • Decode reads the boundary state as b ⊙ (Zᵀ(c ⊙ x)) + Ucᵀ(Kc x) and replays the window's records on top; the int8 matrix is never dequantised.
    • The fold (window flush) replays the records onto the boundary state and re-quantises it. One launch covers every layer, since the cursor is shared, and it runs before the layer kernels, so no layer kernel overwrites a record another program is still reading (the race Fix ReplaySSM flush record ordering #3618 fixed in ReplaySSM's in-kernel flush).
    • Prefill dequantises the state it resumes from and quantises the one it ends with.
  • GDNStateMixin (gdn_attn.py): an int8 mamba_v_cache with leapquant_scale / leapquant_comp side buffers, sized into the state pool, and fp16 window records (cache_len = p + 1 = 17). The step's fold runs in _attach_replayssm right after replayssm_commit, outside the captured graph, so the per-layer kernels only decode. slot_indexed_caches lists the side buffers, so slot movers carry them with the state; LMCache's PAGE layout leaves them out with the other recurrent planes.
  • GatedDeltaNet (attention_gdn.py): the prefill load / store and the decode branch.

Knobs: ATOM_LEAPQUANT_RANK (r, default 4) and ATOM_LEAPQUANT_WINDOW (p, default 16). LeapQuant turns ReplaySSM on. It refuses at startup KDA (per-channel gates) and ATOM_ENABLE_REPLAYSSM=0; commit 1 also refuses prefix caching and speculative decoding, which commits 3 and 4 lift.

Prefix caching (commit 3)

A LeapQuant slot's state is the int8 residual together with its scales and compensators; the int8 plane alone is no state. All three now travel wherever a prefix-cache checkpoint goes:

  • PAGE images (Qwen3-Next / Qwen3.5): _checkpoint_plane_shapes / _checkpoint_plane_tensors list the scale and compensator planes after conv and ssm, the layout id names them and the int8 ssm dtype (order=conv-all-layers,ssm-all-layers,scale-all-layers,comp-all-layers:leapquant=r4), the image is priced before the pool exists, and state_entry_views (the offload tier) walks the same planes in the same order.
  • Midstep checkpoints (ATOM_GDN_STATE_MIDSTEP=1): the SSM half quantises the chunk state into its slot (leapquant_write_checkpoints) instead of copying h into the int8 pool; write_state_checkpoints(copy_ssm=False) still writes the conv half.
  • State forks (the FORK transfer, Qwen4Exp's): _attach_replayssm seeds all three planes of a fork's write slot from its source, every layer at once, outside the graph.

Where a checkpoint may be kept follows #3404's StateTransfer.decode_keep:

  • A PAGE copy builds a decode boundary's image from conv and SSM (KEEP_SNAPSHOT). LeapQuant's scale and compensator planes have no such builder, so _decode_keep gives a LeapQuant image KEEP_NONE, as it does for any image with more planes, and LeapQuant keeps checkpoints at prompt positions only.
  • The fork transfer gets the field too. Between two decode steps a ReplaySSM slot is its checkpoint plus the records since the last flush, and a fork hands over the checkpoint without them: a checkpoint kept there resumes from the state at the last flush, and the generating sequence itself continues from it. Under ReplaySSM, and so LeapQuant, GDNStateMixin.state_transfer returns KEEP_NONE where main keeps KEEP_SETTLED. This changes plain ReplaySSM on the fork transfer (Qwen4Exp, and Qwen3.5 under PP or RapidServe); measured below.

MTP (commit 4)

A verify window of T = num_speculative_tokens + 1 tokens reads, for each token, the state after the tokens before it, which the T = 1 kernel's two contractions of the boundary state cannot give. _leapquant_verify_kernel materialises S_h once in fp32 (the boundary decayed by e^C plus the committed records), walks the window as ReplaySSM's serial route does, and appends every token's record; replayssm_commit keeps the accepted ones. It launches like ReplaySSM's serial kernel: one warp per program and a 32- or 64-wide V slice by batch size.

The flush predicate is h + 2T > cache_len for the configured T in the fold, the kernels and the commit alike, and the record buffer is p + 2T - 1 long, so a fold still lands every p committed tokens (p + 1 = 17 for plain decode, as before).

The checkpoint-unit fix (commit 5)

A PAGE image lives in KV pool units, and paged decode reads V rows it then weighs by zero: a fresh block's rows past the context, and the block a block-table row's zeroed tail names. #3508 keeps images out of the second, physical block 0. The first remains: a unit an image releases goes back on the free list still holding the image, and the request that takes it as a KV block reads those bytes under a zero weight. A bf16 state over a bf16 cache is finite there; fp32 or int8 state bytes read as bf16 include NaN and Inf patterns, and 0 * NaN is NaN. Once the pool fills and images start trading places with KV, every running request turns to noise at the same step.

BlockPool marks the units an image releases and reports a marked block through KVBlockPool.take_dirty; the split UMBP pool asks its private part, where PAGE units live, and a pool without raw units has none. BlockManager._fresh_block sends a marked block to StateMaintenanceOps.cleared_units, and the batch that first writes it zeroes the whole unit before its stores, restores and block copies, since a unit cleared there may be a copy's destination. The zeroing is a copy out of a unit of zeros through the existing descriptor, kernel and fenced staging, so every PAGE-copy backend gets it.

Measured

Qwen3.5-9B, TP1, MI355X (gfx950), unless noted. The prefix-caching and MTP correctness runs are on main d325160e9 with this PR (aiter fc623e745, FlyDSL 0.5.0); the accuracy, speed and memory tables were measured on earlier bases, named per section, and the LeapQuant kernels have not changed since. The runs carried bench-only changes that are not part of this PR: the dense Qwen3.5 MTP loader fix (get_expert_mapping without routed experts), a switch for an FP32 state, and a switch that forces the fork transfer.

About the baseline. Upstream stores Qwen3.5's GDN state in the model dtype (BF16): GDNStateMixin._state_dtypes ignores the checkpoint's mamba_ssm_dtype: float32. That costs 15 points on GPQA-Diamond (below). The FP32 rows use a one-line change that honours mamba_ssm_dtype; I will send it as a separate fix. Qwen3.8-Flash-Next already runs its state in FP32.

Accuracy

606aceb11, no prefix caching. Thinking mode, model-card sampling (temperature 1.0, top_p 0.95, top_k 20), 3 samples per question, up to 81,920 tokens. GSM8K is lm_eval, all 1,319 questions, 5-shot chat, max_gen_toks 4096.

Qwen3.5-9B, TP1:

GDN state GSM8K (flexible) AIME 2026 GPQA-Diamond
FP32 76.9 90.0 81.0
upstream default (BF16, rounded every step) 72.6 62.2 66.3
ReplaySSM (BF16 checkpoint, rounded every 15 tokens) 77.9 88.9 81.6
LeapQuant 78.1 88.9 80.8

Per-question sign tests against FP32: LeapQuant p ≥ 0.34 on all three, BF16 p ≤ 0.001. The paper's Qwen3.5-9B GPQA-Diamond: FP32 81.3, BF16 66.2, LeapQuant 81.8.

Qwen3.8-Flash-Next, TP2 + EP (the paper only ran a truncated 8-layer model, for efficiency):

GDN state GSM8K (flexible) AIME 2026 GPQA-Diamond
upstream default (FP32) 97.7 95.6 90.2
ReplaySSM (FP32 checkpoint) 97.9 95.6 90.6
LeapQuant 97.6 95.6 90.4

Sign tests against the default: p ≥ 0.62.

Accuracy on long reasoning, with prefix caching and MTP

1d37f8662 with this PR. AIME 2026 (30 questions, 16 samples each) and GPQA-Diamond (198, 8 each), prefix caching on with a checkpoint every 1,024 tokens, temperature 1.0, up to 81,920 tokens, 64 concurrent requests a task.

GDN state AIME, no MTP → MTP 3 GPQA, no MTP → MTP 3 MTP 3: runs to the cap (AIME / GPQA) MTP 3 acceptance
FP32 88.3 → 87.9 80.8 → 81.4 28 / 43 64.3%
LeapQuant 86.5 → 86.7 81.4 → 81.4 23 / 50 64.1%
ReplaySSM (bf16 checkpoint) 86.7 → 81.2 80.1 → 78.4 76 / 127 64.2%
  • Under MTP 3, LeapQuant − FP32 is −1.25 points on AIME (bootstrap 95% interval over questions −2.92 to +0.21) and +0.06 on GPQA (−1.52 to +1.64). MTP does not move LeapQuant on either.
  • ReplaySSM − FP32 under MTP 3 is −6.67 on AIME (−12.29 to −2.08) and −2.97 on GPQA (−4.99 to −1.01), with nearly three times as many answers running to the cap. That base predates Fix ReplaySSM flush record ordering #3618, the ReplaySSM flush race it fixed is a likely cause, and I have not re-measured it.
  • ReplaySSM's no-MTP column has 3 samples a question.

Decode step

606aceb11. benchmark_serving, random 4096 in / 1024 out, one wave of requests per concurrency. The step time is the mean ITL after the last request's first token, so it includes the window flushes.

Qwen3.5-9B, ms:

concurrency FP32 BF16 (default) ReplaySSM LeapQuant vs FP32 vs ReplaySSM
32 6.59 6.33 6.11 6.09 1.08× 1.00×
64 8.46 7.96 7.65 7.48 1.13× 1.02×
128 13.12 12.12 11.51 11.27 1.16× 1.02×
256 22.17 20.16 19.03 18.21 1.22× 1.05×
512 39.56 35.40 33.44 31.70 1.25× 1.05×

The paper reports 1.02 / 1.13 / 1.23× over FP32 at 32 / 128 / 512 on B200. The GDN kernels alone (the 9B's 24 layers, flushes amortised) are 2.84 / 3.04 / 2.84× faster than the FP32 kernel at batch 32 / 128 / 512. GDN is 23–35% of an FP32 step, and subtracting the kernel saving from the FP32 step lands within 1.1 ms of the measured LeapQuant step.

Qwen3.8-Flash-Next, TP2 + EP:

  • While every request fits, LeapQuant is 1.07 / 1.10 / 1.12× faster than the FP32 default at concurrency 32 / 64 / 128.
  • At 4K context (3072 in / 1024 out) and --gpu-memory-utilization 0.98, where all modes fit 512 requests, it is 1.13 / 1.19× faster at 256 / 512.
  • At the default 0.9 the state decides the KV pool. At concurrency 256 (4096 / 1024), LeapQuant decodes all 256 requests together while the default admits them in waves: 3,796 against 1,847 output tok/s.

With MTP 3 (1d37f8662), output ms per token on the model's own reasoning (GSM8K questions in thinking mode, 1,024 tokens each, temperature 1.0), 2× the concurrency in requests:

concurrency BF16, MTP 3 ReplaySSM, MTP 3 LeapQuant, MTP 3 LeapQuant, no MTP
1 2.29 2.31 2.39 5.50
8 2.54 2.48 2.56 5.62
32 3.73 3.68 3.91 5.59
128 7.81 7.83 7.94 8.85

With MTP the state is read once per verify window, so LeapQuant's bandwidth saving shrinks by the tokens per forward while its fold still costs the same per committed token (1.1 ms a step at 128 sequences, all 24 layers). Kernel alone (one layer, T = 4, Qwen3.5-9B heads): 153 µs against ReplaySSM's 152 µs at 128 sequences, 266 against 276 at 256.

Memory

Qwen3.5-9B, per request Qwen3.8-Flash-Next, per request per GPU Qwen3.8-Flash-Next, KV pool per GPU at 0.9
FP32 49.1 MiB 55.2 MiB (default) 15.8 GB
BF16 (Qwen3.5 default) 25.1 MiB
ReplaySSM 31.2 MiB 62.0 MiB 12.4 GB
LeapQuant 21.8 MiB 24.5 MiB 31.2 GB

Per Qwen3.5-9B layer, LeapQuant holds conv 48 KiB, the int8 residual 512 KiB, scales 32 KiB, compensators 64 KiB and 17 fp16 records 274 KiB. One prefix-cache image is 16.1 MB with LeapQuant against 26.3 MB for ReplaySSM's bf16 checkpoint (51.5 MB with the fp32 state).

Dataset-level throughput (the paper's Figure 9 method)

606aceb11. Qwen3.5-9B, replaying FP32's own output lengths for GSM8K (1,319), MMLU-Pro (50 per category) and GPQA-Diamond (594 replies): all requests at once, ignore_eos, each mode paired with LeapQuant on the same GPU, four GPUs. LeapQuant's output throughput over the makespan is 1.06 / 1.08 / 1.09× FP32's, and 1.11–1.15× while 64 or more requests run. The paper reports 1.23 / 1.30 / 1.44× on B200. Memory does not explain the gap: the paper's own code (leapquant/LeapQuant, a vLLM plugin) serves without prefix caching and keeps vLLM's FP32 state slots, so its end-to-end gain can only come from the decode step, and with its serving settings ATOM measures 1.05–1.06× (1d37f8662). With prefix caching and a B200-sized KV budget (gpu-memory-utilization 0.6, 1d37f8662), LeapQuant is 1.15 / 1.15 / 1.07× FP32, and on GPQA at two samples a question (396 requests, 0.6, no prefix caching) 1.17×. Against ReplaySSM the gain is the memory: in the same runs LeapQuant is 1.025 / 1.023 / 1.016× and 1.062× ReplaySSM with its bf16 checkpoint (1.4× LeapQuant's state per request), and 1.063 / 1.111 / 1.040× and 1.232× ReplaySSM with an fp32 one (2.5×).

Prefix caching: does a resumed request continue from the right state?

d325160e9. Twelve ~3,100-token prompts, one request at a time, greedy, logprobs on. Each prompt is sent twice; the first request's prefill is cut at its prompt-end anchor and checkpointed there, and the repeat resumes from that checkpoint and computes the same suffix. Then a second turn (prompt + answer + follow-up), twice: the first resumes at turn 1's anchor, the second at its own.

setup repeat matches the first request second turn matches
LeapQuant, PAGE 12/12, all 64 tokens, logprobs bit-identical 12/12
LeapQuant, PAGE + MTP 3 12/12, bit-identical 12/12
ReplaySSM, PAGE 12/12, bit-identical 12/12
ReplaySSM, PAGE + MTP 3 12/12, bit-identical 12/12
LeapQuant, PAGE, midstep (cccc96a03) 10/12 over 64 tokens; first-token |Δ logprob| ≤ 0.0012 10/12 over 64 tokens

Midstep checkpoints come from the chunk kernel's bf16 intermediate states, so they are close rather than bit-exact, as main's are: ReplaySSM's midstep keeps both turns for 7/12 prompts with this PR and 8/12 on main.

Prefix caching under memory pressure

GPQA-Diamond, 198 questions, one sample, up to 32,768 tokens, 128 concurrent, a checkpoint every 1,024 tokens. A generation counts as garbled when most of its last 2,000 characters sit in runs of more than 20 characters without a space.

state, gpu-memory-utilization without commit 5 (main + #3508, cccc96a03) this PR
FP32, 0.9 (no preemption) 109 garbled, 18.2% 0, 60.1%
FP32, 0.45 (preemption) 89 garbled, 1.0% 0, 59.6% (cccc96a03)
LeapQuant, 0.35 (preemption) 105 garbled, 9.6% 0, 59.1%
  • Without prefix caching the same pass scores 61.1% with FP32 and 60.6% with LeapQuant.
  • One LeapQuant generation in the last column is flagged: it quotes the question's DNA sequence over and over, which is no garbage.
  • Both ways in need closing. On an earlier base, clearing units without keeping block 0 out still left 94 of 198 garbled at 0.9.
  • bf16 and ReplaySSM states were never affected: their images are finite bf16.

Prefix caching: accuracy with real reuse

GSM8K-CoT (lm_eval gsm8k_cot, 8 fixed exemplars, so every question shares one prefix; 1,319 questions, chat, multiturn, max_gen_toks 4096). lm_eval's gsm8k samples its shots per question and shares almost nothing, so it does not exercise resumes. Prefix-cache hit rate 91.5%. Strict / flexible:

setup d325160e9 cccc96a03
BF16 default (main) 77.10 / 77.18
ReplaySSM, main 78.62 / 78.92
ReplaySSM, this PR 79.08 / 79.08
ReplaySSM + MTP 3 78.24 / 78.39 80.89 / 81.20
LeapQuant 79.91 / 80.06 79.76 / 79.91, 78.62 / 78.77
LeapQuant + MTP 3 79.30 / 79.45 78.92 / 79.15
LeapQuant, midstep 77.86 / 78.17, 79.38 / 79.45
ReplaySSM, midstep, main / this PR 78.01 / 78.17, 78.92 / 79.38

One configuration moves by 1–1.5 points from run to run (the repeated rows), so the rows do not separate.

Generation checkpoints

--state-checkpoint-interval-tokens 64, so generation keeps checkpoints where a backend does. Turn 1 generates 320 tokens greedily; turn 2 sends the prompt plus the first 288 of them as token ids and generates on. Resumed correctly, it reproduces turn 1's tokens 288 onwards. Twelve GSM8K questions; a turn 1 shorter than 312 tokens is skipped.

resumes at turn 2 follows turn 1 for 24 tokens
ReplaySSM, PAGE (#3404's decode image) a generation checkpoint (304–384) 11/11
LeapQuant, PAGE the prompt (48–128) 11/11
ReplaySSM, FORK, this PR the prompt 11/11
ReplaySSM, FORK, main (cccc96a03) a generation checkpoint turn 1 itself changes: 7 of the 12 answers stop at 66–282 tokens, and 4 of the other 5 leave turn 1 after 2–13 tokens
LeapQuant, FORK (cccc96a03) the prompt 11/11
BF16 default, PAGE (cccc96a03) a generation checkpoint 11/11

Qwen3.8-Flash-Next (the FORK transfer)

1d37f8662. TP2 + EP; Qwen4Exp checkpoints by forking state slots. GSM8K-CoT strict / flexible:

GDN state no prefix caching prefix caching (hit 89–91%) prefix caching + MTP 3
ReplaySSM 95.98 / 97.27 95.91 / 97.50
LeapQuant 95.22 / 97.35 96.13 / 97.19 95.75 / 96.82

GSM8K (5-shot) with MTP 3: LeapQuant 96.97 / 97.50, ReplaySSM 97.57 / 97.57, at 2.92 and 2.90 tokens a forward.

Prefix caching under the FORK transfer, on Qwen3.5

1d37f8662. Qwen3.5 forks too under PP or RapidServe; these runs force the transfer in a bench-only build. The first requests' outputs under fork equal those under PAGE bit for bit (12/12 prompts, 64 tokens, logprobs). GSM8K-CoT under fork depends on scheduler timing, upstream included: upstream ReplaySSM 79.53, 79.53, 79.00; this PR's ReplaySSM 78.17, 78.32, 78.09 and LeapQuant 78.47, 78.70; PAGE 80.21 for all of them. The checkpoint decisions are identical in every run, and instrumented runs ruled out a resume, a slot read and written by different rows in a forward, a fork on a decode step, a stale fork source, CUDA graphs, and aborts or preemption. I have not found the cause; it predates this PR, and Qwen3.8 does not show it.

Tests

  • tests/test_leapquant_gpu.py (GPU, skipped without one):
    • the quantiser matches a torch mirror of _lq_quantize and beats plain INT8;
    • decode across windows follows a shadow running exact fp32 steps from the kernel's own boundary state, the error against the exact trajectory does not grow from window to window, and every fold's boundary is the shadow's state up to one quantisation;
    • verify windows of 2 and 4 tokens, random lengths and random accepts, against the same shadow through several flushes, at both V slices;
    • one stacked fold over every layer is the per-layer fold, bit for bit; exactly low-rank, zero and tiny states store and fold to finite values; every kernel returns the same bytes run after run;
    • a fork seeds all three planes of its write slot in every layer and touches no other slot;
    • a prefill checkpoint is the chunk state it names, byte for byte what a prefill ending there stores.
  • tests/test_leapquant_refusal.py: KDA and ATOM_ENABLE_REPLAYSSM=0 refuse; prefix caching and speculative decoding start, with the record buffer sized for the verify window.
  • tests/test_kda_checkpoint_slot_copy.py: a LeapQuant PAGE image carries all four planes through a store and restore into another slot, and state_entry_views names the same bytes in the same order.
  • tests/test_gdn_page_checkpoint.py: the layout id names the LeapQuant planes and the int8 state; a LeapQuant image keeps KEEP_NONE at a decode boundary, midstep or not; the fork transfer keeps KEEP_NONE under ReplaySSM or LeapQuant and KEEP_SETTLED otherwise; clearing units zeroes every region of each, past image_bytes too, and touches no other block (GPU).
  • tests/test_state_checkpoint.py, tests/test_state_transfer.py: a fork's decode_keep round-trips the wire and a fork cannot build a decode snapshot; a records backend keeps no generation checkpoint under either transfer while its prompt rungs stay; the batch that takes a block an image released clears it, once, and a block no image held is not cleared.
  • tests/test_page_unit_checkpoint.py, tests/test_umbp_block_pool.py: a released unit is dirty until KV takes it, reported once, a store that takes it back clears the mark, and the split UMBP pool reports its private part's.
  • Stubs that size the state pool gain _pool_state_dtypes and _leapquant_bytes_per_slot (test_state_transfer_slots_wiring.py, test_gdn_page_checkpoint.py, whose spare-slot stub also gains the state_transfer_slots feat(pd): free a finished request's KDA slot on P through state transfer slots #3571 started calling). Builders made without _init_gdn_state read leapquant as off from a class default, so the tests that build them that way are unchanged.

Each commit passes the GDN / ReplaySSM / KDA / state-checkpoint / UMBP-pool tests on its own on MI355X, apart from two that fail the same way on main there (test_qwen4_exp_mtp.py::test_qwen_replay_uses_shared_record_dtype_and_preserves_state_dtype, and test_kda_midstep_checkpoints.py::test_the_state_pool_lends_scratch_only_where_it_is_borrowed once aiter is importable). black and ruff check are clean. In a CPU-only environment set up like Pre Checkin (CPU torch, no triton, no aiter), the suite passes except test_atomesh_spur_dispatch.py, whose script times out the same way on main on this machine. On MI355X the full suite fails the same tests as main there, most of them because that machine's aiter predates main's.

Not in this PR

  • KDA.
  • Decode images for LeapQuant: a builder that folds the records into the int8 plane, scales and compensators would let LeapQuant keep generation checkpoints as ReplaySSM now does.
  • ReplaySSM's accuracy on long reasoning under MTP (above).
  • The fork transfer's timing dependence on Qwen3.5 (above), which upstream ReplaySSM has too.
  • Two upstream fixes to send separately: Qwen3.5's mamba_ssm_dtype, and the dense Qwen3.5 MTP loader.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every eligible PR before approval:

  • ✅ Pre Checkin: Black, Ruff, catalog schema validation, non-GPU unit tests

Heavy model tests:

  • ✅ Run after the PR is approved and Pre Checkin passes
  • ✅ Run immediately when an approval review is submitted
  • ✅ Can be requested before approval with labels
Label Tests
ci:full Run all heavy PR model tests: native ATOM, vLLM, and SGLang
ci:atom Run native ATOM model accuracy tests
ci:vllm Run ATOM vLLM OOT model accuracy tests
ci:sglang Run ATOM SGLang model accuracy tests

Heavy jobs are skipped when the PR is not approved and no matching ci:* label is present.
Add labels via the sidebar or gh pr edit 3101 --add-label <label>

@haoyangli0109 haoyangli0109 changed the title [WIP] leapquant gdn [feature] add leapquant gdn Nov 9, 2026
LeapQuant (Pan et al., arXiv:2609.38166) stores each GDN head's state
between window flushes as

    S_0 = diag(c) Z diag(b) + Kc^T Uc

Z is an int8 residual, b and c are fp32 per-column scales and per-row
smoothing, and Kc, Uc are r fp16 compensator tokens fitted by power
iteration to take the outlier rows and columns that would otherwise set
the quantisation range. A slot holds ~1.19 bytes per state element
instead of 4, and the state is re-quantised once per window instead of
being rounded every token, so the rounding error does not compound.

It is built on ReplaySSM, whose record buffer already is the per-window
form; LeapQuant only changes what the boundary state is.

- fla_ops/leapquant.py: Triton kernels for decode (which never
  dequantises the matrix), the window fold (every layer in one launch),
  and the prefill quantise / dequantise.
- GDNStateMixin: an int8 `mamba_v_cache` with `leapquant_scale` /
  `leapquant_comp` side buffers and fp16 window records. The step's fold
  runs in `_attach_replayssm` after the commit, outside the captured
  graph, so the layer kernels only decode.
- GatedDeltaNet: a prefill dequantises the state it resumes and
  quantises the one it ends with; decode calls
  `leapquant_gated_delta_rule`.

Opt in with ATOM_ENABLE_LEAPQUANT=1 (ATOM_LEAPQUANT_RANK, default 4;
ATOM_LEAPQUANT_WINDOW, default 16). It turns ReplaySSM on and covers
non-speculative GDN decode only: KDA, speculative decoding and prefix
caching are refused at startup.

Signed-off-by: Haoyang Li <lihaoyang0109@gmail.com>
GPU tests (tests/test_leapquant_gpu.py) pin the kernels against torch
references of the same algorithm:

- the quantiser is a torch mirror of `_lq_quantize` and beats plain INT8;
- decode across windows follows a shadow running exact fp32 steps from the
  kernel's own boundary state, and the error against the exact trajectory
  does not grow from window to window;
- one stacked fold over every layer is the per-layer fold, bit for bit;
- exactly low-rank, zero and tiny states store and fold to finite values,
  and a rank-1 window on top of them refits to fp16 rounding;
- every kernel returns the same bytes run after run.

The degenerate-state cases fail on both bugs fixed during bring-up: the
fp16 key overflow of a plain-norm `_lq_unit`, and the warm start that fell
back to the old key (3.4e-3 instead of 1e-7 on a zero state).

tests/test_leapquant_refusal.py covers the startup checks: KDA,
speculative decoding, prefix caching and ATOM_ENABLE_REPLAYSSM=0.

Signed-off-by: Haoyang Li <lihaoyang0109@gmail.com>
A LeapQuant slot's state is its int8 residual together with its scales
and compensators; the int8 plane alone is no state. Carry all three
wherever a prefix-cache checkpoint goes:

* PAGE images hold the scale and compensator planes after conv and ssm.
  The layout id names them and the int8 ssm dtype, the image is priced
  before the pool exists, and the offload tier's state_entry_views walks
  the same planes in the same order.
* Midstep checkpoints (ATOM_GDN_STATE_MIDSTEP=1) quantise the chunk
  state into their slot instead of copying h into the int8 pool; the
  conv half is written as before (write_state_checkpoints(copy_ssm=False)).
* A state fork (the FORK transfer of Qwen4Exp) seeds all three planes of
  its write slot from the source, every layer at once, outside the graph.

Checkpoints are kept at prompt positions only. Between two decode steps
a ReplaySSM slot is its checkpoint plus the records since the last
flush, and neither an image nor a fork carries the records, so a
checkpoint kept there resumes from the state at the last flush; under
FORK the generating sequence itself continues from that state. Add
StateTransfer.decode_checkpoints, False for both GDN transfers under
ReplaySSM, and have BlockManager.checkpointers_at keep nothing at a
generation position for such a backend. This changes plain ReplaySSM
too, which kept those checkpoints; Kimi's KDA transfer is unchanged.

Drop the prefix-caching refusal. Speculative decoding still refuses.

Signed-off-by: Haoyang Li <lihaoyang0109@gmail.com>
A verify window of T = num_speculative_tokens + 1 tokens reads, for each
token, the state after the tokens before it, which the T == 1 kernel's
two contractions of the boundary state cannot give. The new verify
kernel materialises S_h once in fp32 (the boundary decayed by e^C plus
the committed records), walks the window as ReplaySSM's serial route
does, and appends every token's record; replayssm_commit then keeps the
accepted ones.

It launches as ReplaySSM's serial kernel does: one warp per program, so
each token's contractions over K reduce inside it, and a 32- or 64-wide
V slice by batch size. Four warps measured 3.4x slower at 128 sequences.

The flush predicate is h + 2T > cache_len for the configured T, in the
fold, the kernels and the commit alike, and the record buffer is
p + 2T - 1 long, so a fold still lands every p committed tokens (p + 1
for plain decode, as before). The fold for every layer still runs in the
metadata builder, outside the captured graph.

Drop the speculative-decoding refusal.

The GPU tests run verify windows of 2 and 4 tokens, with random lengths
and random accepts, against an exact fp32 shadow across several flushes,
and check that each fold's boundary is the shadow's state up to one
quantisation; the T == 1 decode test now checks the latter as well.

Signed-off-by: Haoyang Li <lihaoyang0109@gmail.com>
A PAGE checkpoint image lives in KV pool units, and paged decode reads KV
bytes it then weighs by zero: a fresh block's rows past the context. Those
bytes were always finite before images shared the pool. A bf16 state over a
bf16 cache still is, but fp32 or int8 state bytes read as bf16 include NaN
and Inf patterns, and 0 * NaN is NaN.

So once the pool filled and images started trading places with KV, every
running request turned to noise at the same step. On Qwen3.5-9B with an
fp32 or LeapQuant state and prefix caching on, all 128 concurrent GPQA
requests degraded within 70 tokens of each other, at the step the pool ran
out of vacant blocks; GPQA fell from 61% to 2%. bf16 and ReplaySSM states,
prefix caching off, and a checkpoint interval of 0 were unaffected, and the
gluon decode kernel turns NaN in either place into a NaN output.

The other way an image reaches attention, the block a block-table row's
zeroed tail names, is physical block 0, which the pool already reserves
(`reserve_null_block`). This closes the first:

BlockPool marks the units an image releases, and reports a marked block
through `KVBlockPool.take_dirty`; the split UMBP pool asks its private part,
where PAGE units live, and a pool without raw units has none.
BlockManager._fresh_block sends a marked block to
StateMaintenanceOps.cleared_units, and the batch that first writes it
zeroes the whole unit before its stores, restores and block copies, since a
unit cleared there may be a copy's destination. The zeroing is a copy out of
a unit of zeros through the existing descriptor, kernel and fenced staging,
so every PAGE-copy backend gets it.

Signed-off-by: Haoyang Li <lihaoyang0109@gmail.com>
@haoyangli0109 haoyangli0109 changed the title [feature] add leapquant gdn [feature] LeapQuant for GDN: int8 recurrent state, with prefix caching and MTP Nov 27, 2026
@haoyangli0109
haoyangli0109 marked this pull request as ready for review November 27, 2026 11:54

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant