Files
84b94d72bf perf(gdn): index prefill state and reuse inline graphs (#4006)
## Summary

- Pass recurrent-state pages and their read and write indices directly
to the selected FlashInfer GDN prefill scan. The scan seeds fresh rows
from zero and writes live final state directly to the pool.
- Capture one inline graph per token bucket for indexed GDN. Default its
request capacity to rank-local `--max-num-seqs` and cap it at the
bucket's token count. An explicit list selects its largest capacity. Pad
unused slots with zero tokens and state indices of `-1`. Size the
startup probe arena for the widest candidate capture.
- Preserve in-forward checkpoints and cover full buckets, padding,
variable request counts and GPU memory release in regression tests.

## Performance

The A and B runs used Qwen3.8-Flash-Next-NVFP4 on one SM103 GPU (TP1),
BF16 recurrent state and 2048-token prefill chunks, with FlashInfer
0.7.6rc1. Timings were collected on the benchmark branch before
rebasing.

### Full-chunk replay with 63 requests

Both sides used indexed GDN state, `--max-num-seqs 64`,
`--prefill-graph-capture-batch-sizes 64` and a single `2048` token
bucket. Each wave starts one uncached prefill round. The full wave uses
32 prompts of 33 tokens and 31 of 32 tokens. TTFT is measured from the
scheduler release request and uses 64 waves per case per side (4,032
requests). Replay p50 is from 16 separate CUDA-event samples per case
per side.

| Tokens | Replay route before → after | TTFT p50 (ms) | TTFT p95 (ms) |
Replay p50 (ms) |
|---:|:---|---:|---:|---:|
| 2048 | ordinary → inline capacity 64 | 65.06 → 48.60 (−25.3%) | 69.23
→ 52.74 | 51.79 → 34.90 (−32.6%) |
| 2047 | inline capacity 64 → inline capacity 64 | 49.21 → 49.05 | 53.11
→ 53.19 | 35.27 → 35.09 |

### State indexing

At concurrency 1 with 128 samples per side, changing dense state to
indexed state reduced 2048-token ordinary-graph TTFT p50 from 51.13 to
49.73 ms (−2.7%). Inline TTFT p50 was 42.70 → 42.60 ms. The sum of GDN
scan and state-preparation GPU time across 36 layers fell from 2.80 to
2.39 ms on the ordinary route.

### AgentX trace replay

Both sides used indexed GDN state. Over 20 minutes of measured replay
(150 seconds per concurrency and variant), six token buckets and request
capacities `1,2,8,32` produced 24 → 6 inline captures. Warm recapture
went from 28.0–28.8 s to 15.2 s.

| Client concurrency | Completed requests per side | Output tokens per
second before → after | TTFT p50 (ms) | TTFT p95 (ms) |
|---:|---:|---:|---:|---:|
| 1 | 65 | 190.81 → 190.81 | 91.8 → 84.7 | 549.8 → 552.9 |
| 2 | 23 | 115.79 → 115.77 | 110.9 → 110.0 | 326.0 → 325.9 |
| 8 | 8 | 111.58 → 111.58 | 396.5 → 396.5 | 3506.9 → 3505.4 |
| 32 | 99 | 695.40 → 695.40 | 212.5 → 244.9 (+15.2%) | 4728.6 → 4729.4 |

At concurrency 32, the median per-request TTFT delta across the same 99
completed requests was +1.33 ms. The server reached 14 running requests
in both variants.

## Test Plan

- `pre-commit run --all-files` passed.
- On SM103 with the pinned FlashInfer 0.7.6, 55 kernel tests passed,
including BF16 and FP32 indexed-state CUDA graph replay with and without
checkpoints. The runtime regression run had 200 passed, 3 skipped, and
44 passed subtests.
- A freshly started Qwen3.8-Flash-Next-NVFP4 server on the PR branch
captured the 2048-token bucket, replayed one uncached wave of 63
requests through inline capacity 64, and returned one completion token
per request.
- The indexed GDN memory-release regression and the existing
managed-metadata release test both encountered
`CUDA_ERROR_INVALID_VALUE` from `cuMemFree_v2` on this host. Local
release and resume validation is pending.
- The default-capacity follow-up passed 126 focused runtime tests and 39
subtests. With the graph-memory probe enabled and `--max-num-seqs 64`, a
fresh server captured `(2048, 64)` using the default request capacity.
An uncached wave of 63 requests and 2048 tokens replayed through inline
capacity 64 with 63 successful completions.
- The review follow-up passed 59 kernel tests and 60 runtime tests on
SM103 with FlashInfer 0.7.6. CUDA Graph replay covered int32 and int64
state indices. The fused preparation tests covered mixed input dtypes
and verified that varying request counts reuses the warmed Triton
kernel.

---------

Signed-off-by: tuanzhangCS <26617745+tuanzhangCS@users.noreply.github.com>
Signed-off-by: lightseek-bot <243258330+lightseek-bot@users.noreply.github.com>
Co-authored-by: tuanzhangCS <26617745+tuanzhangCS@users.noreply.github.com>
Co-authored-by: lightseek-bot <243258330+lightseek-bot@users.noreply.github.com>
2026-12-02 16:49:23 +08:00
..