Skip to content

fix(perf): hybrid prefix caching + 2026-09-11 headroom findings - #1

Open
mmizutani wants to merge 2 commits into
mainfrom
headroom-2026-09-11
Open

mmizutani wants to merge 2 commits into
mainfrom
headroom-2026-09-11

Conversation

@mmizutani

@mmizutani mmizutani commented Sep 11, 2026 •

Copy link
Copy Markdown
Owner

Summary

Live 2× GB10 headroom investigation of this kit, the prefix-cache fix that came
out of it, and a measured merge of upstream PR MiaAI-Lab#130. Every number below was
measured on this 2× DGX Spark pair; raw receipts are under
logs/headroom-20260911/ and the full write-up is docs/headroom-2026-09-11.md.

The headline finding: the production 8.7 % prefix-cache hit rate was a
server-side cliff, not a client, capacity, or config problem. Replaying the
exact deep-swe agent payloads on an idle engine hit where the live run missed;
a sequential probe showed 1–2 long sessions retain prefixes while 3+ lost them
entirely, independent of the 918 k-token pool. Root cause: the
mamba_cache_mode=align + speculative-decoding bug family already tracked in
this repo (MiaAI-Lab#83, MiaAI-Lab#84, MiaAI-Lab#106) and upstream (vLLM #45238, #54094, #54163, #54076,
#55601).

What ships

Prefix caching (fixes the cliff)

Decode / launch (2026-09-11 re-measure)

  • GLM53_ADAPTIVE_K=ema is the .env.example default; start.sh auto-adds
    the required union capture list when the knob is on (the stock list missed the
    3- and 5-token graphs). Measured +10.3 % hash-map prose, structured neutral.
  • GLM53_SPINWAIT_MS=16 default.
  • Dense FP8 documented as opt-in with the measured KLD/decode numbers; enabled
    in this kit's .env (provisional numerics).

Boot warmup

  • scripts/boot-shape-warmup.sh: long-prefill rungs
    (3584/7168/14336/65536) so BuildPrefillChunkMetadataKernel does not JIT on a
    real request, payload staging through a file (long prompts exceeded ARG_MAX),
    tally ignores staged payloads.

Other included work

  • Dual-HCA GID preflight (start.sh) + tests/test_nccl_multi_hca.py.
  • Portable host-side jinja2 fallback for the new chat-template validation
    (linuxbrew python3 lacks jinja2; the launcher now probes the caller's
    interpreter, then system interpreters; GLM53_VALIDATE_PYTHON overrides).

Merge reconciliation with origin/main (PR MiaAI-Lab#130)

origin/main advanced to 9348755 ("per-KV-cache-group APC retention with
DFlash SWA replay"), synced into this fork's main, which conflicted with this
branch. The merge was resolved by measurement, not by text. Five same-probe
boots on this kit:

Boot Stack 1×30k 3×30k 4×30k 2×60k 3×5k
B3 MiaAI-Lab#83 per-group + pre-MiaAI-Lab#130 hybrid + fine-grained + block-drop 1.000 1.000 1.000 0.999 0.992
B4 MiaAI-Lab#130 unset/unset + fine-grained + block-drop 0.716 0.000 0.000 0.000 0.000
B5 MiaAI-Lab#130 explicit 0/0 + fine-grained + block-drop 0.000 0.000 0.000 0.955 0.000
B6 MiaAI-Lab#130 explicit 0/0 + fine-grained, block-drop removed 0.000 0.000 0.000 0.955 0.000
B7 merged launcher + restored MiaAI-Lab#83 overlays 1.000 1.000 1.000 0.999 0.992

The metric is the global prefix_cache_hits_total / queries_total delta over a
fill-then-repeat probe; wall time is ~0.4 s per 30 k repeat when it hits and
~17–20 s when it misses.

B6 isolates the cause from this branch's DFlash block-drop cherry-pick: the
difference is the reworked retention/replay overlays themselves. Upstream's own
qualification doc frames MiaAI-Lab#130 as "a draft contribution for maintainer
discussion", measured on 128 k append/edit/branch cases rather than repeat
growth. Resolution: this branch ships the MiaAI-Lab#83 overlay implementations
(live-validated) and adopts PR MiaAI-Lab#130's launcher machinery, artifact gate,
GLM53_OVERLAY_ORDER, retention knob validation, numeric-config changes, docs
and non-overlay tests. The two overlay files (and their matching host tests)
are the only functional divergence; it is recorded in
docs/headroom-2026-09-11.md §12.3 and .env.example.

Verification

  • Host suites all pass (12): test_launcher_rank_parity, test_numeric_config,
    test_apc_per_group_retention, test_hybrid_prefix_hit,
    test_apc_fine_grained_hits, test_dflash_block_drop_patch,
    test_spinwait_patch, test_indexer_workspace, test_kpool_tail_slotmap,
    test_xgrammar_termination, test_start_overrides, test_nccl_multi_hca.
  • B7 live, merged launcher: 1×/3×/4× 30 k repeats 1.000 at 0.3–0.4 s,
    2×60 k 0.999, 3×5 k 0.992; 4-agent × 60 k bench turns 1–3
    0.886–0.928 with per-turn wall 17.7–23.6 s (B3: 0.916–0.928 / 17.7–18.9 s;
    before the fix: 0.000 / 150–196 s). Hash-map prose 33.5–34.5 tok/s,
    coherence pass.

Remaining upstream items (not blocking)

…ndings

Live 2x GB10 investigation (docs/headroom-2026-09-11.md, logs/headroom-20260911/).
Config and correctness now ship together so a fresh checkout gets the measured best.

Decode / launch:
- adaptive-k (GLM53_ADAPTIVE_K=ema) is the .env.example default; start.sh
  auto-adds the required union capture list when the knob is ema/on/1 (the
  stock list missed the 3- and 5-token graphs). Measured +10.3% hash-map
  prose, structured neutral (A/B/A, median of 5).
- GLM53_SPINWAIT_MS=16 default (frozen sweep winner; re-checked at MNBT 7168).
- dense FP8 documented as opt-in with 2026-09-11 KLD/decode numbers and enabled
  in this kit's .env (provisional numerics).

Warmup:
- boot-shape-warmup.sh: long-prefill rungs (3584/7168/14336/65536) so
  BuildPrefillChunkMetadataKernel does not JIT on a real request, payload
  staging through a file (long prompts exceeded ARG_MAX), and the outcome
  tally ignores the staged payload files.

Prefix caching (the production 8.7% hit-rate cliff):
- adopt PR MiaAI-Lab#83 overlay/patch_apc_per_group_retention.py: per-group retention;
  the EAGLE-exempt DFlash2 drafter no longer spends 33 of the 38 block ids a
  cached 3584-token segment costs and stops evicting the MLA/mamba blocks that
  carry the hit (GLM53_APC_RETENTION_INTERVAL_SWA, default auto).
- adopt PR MiaAI-Lab#84 overlay/patch_apc_fine_grained_hits.py: exclude the KpoolTail
  scratch from the fine-grained veto, restoring 64-token hit alignment
  (GLM53_FINEGRAINED_APC=1).
- cherry-pick vLLM #54163 as overlay/patch_dflash_block_drop.py: DFlash/DSpark
  must not take the EAGLE trailing-block back-off (use_eagle_block_drop);
  otherwise the Mamba state never materializes and every reply recomputes.
- launcher hardening from the PRs: validate_overlay_artifacts fail-closed gate
  before restart stops anything, GLM53_OVERLAY_ORDER emitted identically to
  both rank containers, retention/bool knob validation, Dockerfile COPY/RUN.

Live A/B boot B3 (same probes): 3-4 x 30k repeats 17.2s/0.000 hits -> 0.4s/1.000;
2 x 60k 34s/0.000 -> 0.4s/0.999; 4-agent x 60k turns 1-3 0.000 / wall 150-196s ->
0.916-0.928 / wall 18s; hash-map prose 34.50 tok/s and coherence unchanged.

Host tests pass: test_launcher_rank_parity, test_apc_per_group_retention,
test_apc_fine_grained_hits, test_dflash_block_drop_patch, test_hybrid_prefix_hit,
test_spinwait_patch, test_indexer_workspace, test_kpool_tail_slotmap,
test_xgrammar_termination, test_start_overrides, test_nccl_multi_hca.
Resolved by measurement, not by text:

- Adopt upstream's launcher machinery as-is: overlay artifact gate,
  GLM53_OVERLAY_ORDER, retention knob validation/forwarding, tests, docs,
  start-tp4.sh, numeric-config changes.
- Keep the MiaAI-Lab#83 per-group retention and the pre-MiaAI-Lab#130 hybrid APC overlays.
  The MiaAI-Lab#130 rework measured worse on this kit's agent probe (3x30k repeats
  0.000 vs 1.000 hits; 2x60k 0.955 vs 0.999) across B4/B5 and was isolated
  from our DFlash block-drop patch by B6. Receipts:
  docs/headroom-2026-09-11.md section 12.3.
- Keep our additions: fine-grained 64-token hits (PR MiaAI-Lab#84),
  vLLM #54163 block-drop cherry-pick, adaptive-k default + auto capture
  list, spinwait 16, dual-HCA GID preflight, portable jinja2 host check
  for the new chat-template validation (linuxbrew python3 lacks jinja2),
  long-prefill boot warmup rungs.

Verification: all 12 host suites pass; B7 live re-validation on the merged
launcher reproduces B3 (1x/3x/4x 30k repeats 1.000 at 0.3-0.4s, 2x60k
0.999, 3x5k 0.992; 4-agent x 60k turns 1-3 0.886-0.928, wall 17.7-23.6s).

Merged upstream: origin/main @ 9348755 (PR MiaAI-Lab#130).
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