Skip to content

[Perf] mooncake: Group and parallelize direct linker layer-wise loads - #45106

Merged
hzh0425 merged 7 commits into
sgl-project:mainfrom
alphabetc1:perf/mooncake-linker-grouped-load
Nov 9, 2026
Merged

hzh0425 merged 7 commits into
sgl-project:mainfrom
alphabetc1:perf/mooncake-linker-grouped-load

Conversation

@alphabetc1

@alphabetc1 alphabetc1 commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

The Mooncake direct linker loads an L3 hit with one synchronous batch_get_into_multi_buffer_ranges call per layer per pool, on a single thread. Each ranged op costs roughly 3 us serialized, so a DSA page-layer (a 72 KB KV range plus an 8 KB indexer range) moves at about 12-14 GB/s per rank, well below the NIC line rate. With a short new suffix on a long cached prefix (the common multi-turn / agentic shape) the load cannot hide behind compute, so it is directly on TTFT.

A standalone Mooncake microbenchmark with the GLM-5.2 page geometry (64K tokens, 6.6 GB, one GPU and its PIX NIC) shows where the time goes:

read pattern time GB/s
one call per layer (current) 454 ms 14.5
one call per layer, keys split over 4 threads 188 ms 35.0
one call per page (all layers), 8 threads 137 ms 47.8

Concurrency is the main lever; reading several layers of a page per call adds more on top.

Modifications

  • load_layer_wise reads linker_load_layer_group layers per call (default 8) and splits each call's keys over linker_load_threads workers (default 4). All groups are submitted up front; layers are still published to LayerWiseLoadCounter in order, group by group, so the forward keeps overlapping with later groups.
  • On failure, reads not yet started are cancelled and in-flight reads are awaited before batch_get_session_end, since they still write into device rows.
  • Both knobs are read from --hicache-storage-backend-extra-config; {"linker_load_layer_group": 1, "linker_load_threads": 1} reproduces the previous request pattern.

The UMBP direct linker already groups layers per call (UMBP_LAYER_GROUP, default 8); this brings the Mooncake linker to the same shape.

Speed Tests

GLM-5.2-FP8, 8xH200, TP8, page 64, Mooncake RDMA store on the same node over 8 NICs. L3-hit TTFT (median of 3, ms), prefix flushed from device before each measurement, cached_tokens checked on every request. G = layers per call, T = threads; G1/T1 is the previous behavior.

Short suffix (prefix + 64 new tokens):

prefix device hit G1/T1 G1/T4 G4/T4 G8/T4 G78/T4
8K 43 97 90 72 65 84
32K 53 209 218 182 175 224
64K 66 384 427 318 315 414

Same, with --enable-linker-mla-dedup:

prefix device hit G1/T1 G1/T4 G4/T4 G8/T4 G78/T4
8K 43 101 107 90 84 94
32K 52 211 229 164 158 200
64K 67 395 440 303 263 352

Long suffix (prefix + 8192 new tokens), with dedup: 32K 257 -> 177 ms, 64K 431 -> 283 ms (G8/T4).

Without dedup, all 8 ranks read the same replicated MLA pages and the store's aggregate bandwidth becomes the limit, so the gain is smaller; with dedup a single reader benefits fully. Threads without grouping (G1/T4) are slower than the baseline at TP8, and loading the whole page in one call (G78) gives up the layer overlap, which is why G8/T4 is the default.

Accuracy Tests

  • test_unified_cache_linker_kl_inkling.py (bit-exact, threshold 1e-9), test_unified_cache_linker_kl_glm52.py and test_unified_cache_linker_kl_dsv4.py pass with the new defaults.
  • The GLM-5.2 and DSV4 KL tests do not notice a few misplaced distant prefix pages (a page-rotation mutation still passes them), so they were rerun with the destination rows filled with 0xA5 before each load:
model poisoned, this PR poisoned, last layer group skipped
GLM-5.2-FP8 pass (avg KL 0.0094) fail (avg KL 0.206 > 0.03)
DeepSeek-V4-Flash-FP8 pass (avg KL 0.0032 / 0.0054 / 0.0021) fail (avg KL 8.56 > 0.01)
  • New unit test test_mooncake_direct_linker_load.py covers range merging per key, in-order layer publication when later groups finish first, and session end after in-flight reads on failure; each test fails under a matching mutation of the implementation.

End-to-end: agentic trace replay (measured together with #46168)

Arms: main 985837b6ff vs main + #46168 032273dcdc + #45106 3f21e6c619 (the combination builds new rows in _group_range_meta instead of extending the shared size/offset rows). The two PRs were measured together, so the gain below is not split between them.

Setup: 4 x TP4 aggregated servers on GB300 behind a cache-aware router, Mooncake RDMA store on every node, Mooncake direct linker in layer_wise mode, --max-total-tokens 2097152 per server so most prefix hits come back from L3, DSPARK with a fixed acceptance length, InferenceX AgentX trace replay at 64 concurrent conversations for 900 s. One run per arm; across separate jobs TTFT p90 varies by about 8%.

MiniMax-M3.1-Flash (TP4/EP4, 600 GB of L3 per node; no Mooncake put failures or evictions, so both arms reach the same hit rate):

main main + #46168 + #45106
output tok/s/GPU 23,994 24,891
TTFT p50 / p90 0.460 / 2.299 s 0.396 / 1.193 s
prefix hit rate 96.8% 96.8%

L3 reload of a 480K-token prefix on an idle single TP4 server (load_layer_wise instrumented, 3 rounds):

main main + #46168 + #45106
request latency 2.90-3.03 s 1.89-1.95 s
load_layer_wise wall time 1.37-1.49 s 0.41-0.42 s
range metadata build 0.33-0.36 s 0.15 s
range gets 125 calls in series, 1.31-1.39 s from first to last 68 calls on 4 threads, 0.34-0.35 s from first to last
bytes read per rank 7.44 GB 7.44 GB

The remaining ~1.5 s of the request is outside the linker and is the same in both arms.

DeepSeek-V4.1-Flash, same setup: throughput and TTFT stay within run-to-run noise (25,865 vs 25,462 tok/s/GPU, TTFT p90 2.66 vs 2.84 s, both at 96.7% hit rate). Its compressed/sparse KV makes a 529K-token reload only 0.87 GB per rank, so main's load already takes just 0.12 s of a 1.2 s request. The gain grows with the bytes read per rank; dense-KV models such as MiniMax-M3.1 (60 layers of full GQA KV) are where the serial per-layer path dominates TTFT.

Checklist

Related: #38639 (page-wise Mooncake loads behind an object-count threshold, plus ReadPlan and metrics).


CI States

Latest PR Test (Base): ✅ Run #42359402217
Latest PR Test (Extra): ❌ Run #42359402202
Latest PR Test (AMD ROCm 10): ✅ Run #42359402206

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

@alphabetc1 alphabetc1 added the run-ci CI: run the baseline test suite on this PR label Oct 31, 2026

@hzh0425 hzh0425 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.

awesome

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

Labels

hicache Hierarchical Caching for SGLang mooncake 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