Skip to content

[Feat] hicache: opt-in exclusive L2->L3 tiering, dedup cache-mode L3 writes through the existence cache - #39845

Closed
YAMY1234 wants to merge 9 commits into
sgl-project:mainfrom
YAMY1234:pr/c-standalone
Closed

YAMY1234 wants to merge 9 commits into
sgl-project:mainfrom
YAMY1234:pr/c-standalone

Conversation

@YAMY1234

@YAMY1234 YAMY1234 commented Sep 16, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

With --hicache-storage-backend in cache mode, storage (L3) is written at L2 admission: every page that enters the host pool is also written to storage. L3 therefore always holds a superset of L2 and adds no reusable capacity. A prefix that is evicted from host is only in L3 if its write happened to complete, and a prefix that is still in host is fetched from host anyway. On a Mooncake store shared by several prefill workers this showed up as a store that turns over constantly (every L2 admission is a put) while the hit rate does not move.

This PR adds an opt-in mode where L3 is written from the coldest host pages ahead of their eviction instead. The two tiers then hold different pages and L3 becomes an overflow layer for L2. Measured on Qwen3.5-397B-A17B-NVFP4, GB300, 3P:2D PD-disaggregated, AgentX closed-loop trace at concurrency 1000: 142.2K total TPS/GPU without a store, 152.2K with the store in this mode (+7%); host hit rate held at 93.1%. At concurrency 850, where the host pool alone already covers the working set, the extra write traffic costs about 1.5%, which is why the mode is opt-in.

The second commit fixes write-side dedup in cache mode. A recompute after L2 eviction re-creates a node with backuped=False, so the node flag alone re-writes content that L3 already holds. write_backup_storage now skips spans the StorageExistenceCache covers, and beliefs are recorded on the storage ack from the full hash chain (not the completed_tokens-truncated one) so ranks cannot diverge in the write/skip decision. The cost of that choice is that a failed write still records the pages as stored until a prefetch miss invalidates the belief; test_hicache_l3_failed_write_still_records_belief pins this behavior down.

Modifications

Commit 1, SGLANG_HICACHE_L3_WRITE_ON_HOST_EVICT (default off):

  • unified_cache/components/full.py: the host-eviction heap walk is one generator (_host_eviction_walk) shared by drive_host_eviction and the new read-only peek_host_eviction_candidates(num_tokens), which returns host leaves in eviction order until num_tokens are covered. _is_host_leaf gains ignore_children so the simulation reuses the same predicate. The Rust adapter raises NotImplementedError; the mode requires the Python tree core.
  • unified_radix_cache.py: when the mode is on, the L2-admission storage write is skipped and _write_behind_host_tail runs on the check_hicache_events path (every 4th call, rank-replicated inputs only). It keeps SGLANG_HICACHE_L3_EVICT_WRITE_RESERVE_FRACTION (default 0.05) of the host pool either free, in flight, or already in storage. Candidates the existence cache already covers count as covered until host eviction consumes them, so a steady state with a fully tiered tail does not re-walk the heap; reset() clears both the in-flight map and that clean-tail count. Counters: wb_walks, wb_issued_tokens, wb_clean_tokens, wb_unbacked_tokens via prefetch_outcome_stats_snapshot.
  • Enabling the mode with --hicache-host-memory-mode buffer_only or the Rust tree core raises ValueError at init.
  • write_backup_storage returns the operation id.

Commit 2, existence-cache dedup in cache mode:

  • write_backup_storage skips spans covered by storage_existence_cache.
  • The prefetch-cut belief invalidation runs in both host memory modes (was buffer_only-only).
  • Beliefs are added on the storage ack from operation.hash_value unconditionally.
  • New unit test test_hicache_l3_failed_write_still_records_belief.

Accuracy Tests

Not applicable (cache placement only; no change to model forward).

Speed Tests and Profiling

Qwen3.5-397B-A17B-NVFP4, GB300 (4 GPU/node), 3 prefill nodes (PP4) + 2 decode nodes (TP4/DP4/EP4), Mooncake store on the decode nodes, AgentX 3600 s closed-loop trace, total TPS / total GPU:

concurrency no L3 store store, default (write at L2 admission) store, this PR
1000 142.2K no gain (superset) 152.2K (+7%), host hit 93.1%
850 151.8K 149.5K (-1.5%; host pool already covers the working set)

Unit tests: test/registered/unit/mem_cache/{test_unified_radix_cache_unittest,test_storage_prefetch_lifecycle,test_hicache_staged_write_back_dispatch}.py on the Python tree-core backend, 1293 passed / 0 failed in the 2026-09-13 nightly container.

Checklist


CI States

Latest PR Test (Base): ✅ Run #42430426545
Latest PR Test (Extra): ❌ Run #42430426558
Latest PR Test (AMD ROCm 10): ✅ Run #42430426601

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

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

[by Claude Code] Review comments are inline.

@YAMY1234

YAMY1234 commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Oct 6, 2026
@nvpohanh

Copy link
Copy Markdown
Collaborator

@hzh0425 Could you help to review this? Thanks!

@hzh0425 hzh0425 self-assigned this Oct 12, 2026
@YAMY1234 YAMY1234 changed the title feat(hicache): opt-in exclusive L2->L3 tiering, dedup cache-mode L3 writes through the existence cache [Feat] hicache: opt-in exclusive L2->L3 tiering, dedup cache-mode L3 writes through the existence cache Oct 14, 2026
@alphabetc1 alphabetc1 self-assigned this Oct 15, 2026
…TE_ON_HOST_EVICT)

Cache mode wrote L3 at L2 admission (_finish_write_through_ack), so L3
was a superset of L2 and added no capacity: every L2 miss was also an
L3 miss unless L3 retention exceeded L2's.

With SGLANG_HICACHE_L3_WRITE_ON_HOST_EVICT=1, L3 is instead written
from the coldest L2 pages ahead of their eviction: a reserve fraction of
the host pool (SGLANG_HICACHE_L3_EVICT_WRITE_RESERVE_FRACTION, default
0.05) at the LRU tail is kept either free or already in storage.
peek_host_eviction_candidates walks evictable host leaves in the order
drive_host_eviction takes them (leaf cascade to parent, honouring the
same host/segment lock tests) and _write_behind_host_tail issues
write_backup_storage for the uncovered ones, refilling the reserve in
quarter quanta (once every 4th check_hicache_events call) so a slow ack
does not re-issue deeper into the tail. In-flight write-behind ops count
as covered until acked. L2-admission writes are skipped while the flag
is on, so L2 and L3 hold different pages and their capacities add. All
inputs (pool state, tree, in-flight set, step counter) are
rank-replicated, so issue order stays identical across ranks.

Off by default; Python tree core only (the Rust adapter raises).
Write-behind tier counters join the prefetch outcome stats snapshot.

Measured on Qwen3.5-397B AgentX 3P:2D at C1000: no store 142.2K vs
store 152.2K total-TPS/GPU (+7%); at C850 the write traffic costs
~1.5%.

(cherry picked from commit f2790e9)
…and record beliefs TP-deterministically

In cache mode a recompute after L2 eviction re-creates the node with
backuped=False, so the node flag alone re-writes content L3 already
holds. write_backup_storage now skips spans the StorageExistenceCache
covers, and the prefetch-cut belief invalidation runs in both host
memory modes (it was buffer_only-only) so stale positives at the usable
cut heal the same way.

Beliefs are added unconditionally on the storage ack (full hash chain,
not completed_tokens-truncated): completed_tokens can diverge across
ranks under backend failure, and a divergent belief desyncs the
write/skip decision, which then hangs the rank collectives. A stale
positive is advisory and heals via the prefetch hit-query shortfall.

(cherry picked from commit 300f201)
@github-actions

This comment has been minimized.

detain added a commit to detain/sglang that referenced this pull request Oct 30, 2026
… C closure -- the post-merge port queue is now decided

ARRIVAL SCAN (git log 12dc623..2a6c204 --grep) + LIVE gh STATE +
head-sha comparison for EVERY deferred item. Verdicts:
  RELEASED-BY-MERGE: sgl-project#42689 (@ 7a632cf in-range -- the SECTION-B
    cherry is now redundant; behavior note rides the restart).
  CLOSED (C-items whose PRs arrived and whose integration this stack
    performed): C1 (the dedicated merge week WAS merge sgl-project#5; all eight
    precursor PRs in-range), C2 (sgl-project#44993/sgl-project#44994 -- B5), C3 (sgl-project#45232/
    sgl-project#45236/sgl-project#45334 -- B2), C4 (sgl-project#45238/sgl-project#45241/sgl-project#45242 -- B3), C5 (sgl-project#44912/
    sgl-project#44913 -- arrived; entry-230 canary re-planted as its guard),
    C9 (sgl-project#39727 -- verified OPT-IN, no purge; BOOT_DELTA anti-needle),
    C0a (arrival shas already recorded at entry 310 -- Section C now
    carries NO open code-integration items: C6/C10 retain only their
    explicitly-named docs/boot-measurement remainders, re-stated).
  STILL-OPEN: sgl-project#44342 (head unchanged; auto-merge comfort LOST to
    #46970x), sgl-project#46153/sgl-project#37106/sgl-project#32479/sgl-project#45391 (gh CONFLICTING -- stale
    bases, rebase before any port), sgl-project#41624/sgl-project#42525/sgl-project#42660/sgl-project#44462/sgl-project#35617
    (open, heads unchanged), sgl-project#46191/sgl-project#39845-class (watch-list, none in
    range).
  HOLD STANDS (operator decision, binding): sgl-project#43356/sgl-project#46452/sgl-project#43240/
    sgl-project#43471 KV route -- step-1 'MERGE sgl-project#5 lands first' is NOW MET; the
    sequence may be re-visited ONLY with the post-merge PCIe-IPC
    measurement at an operator sitting. sgl-project#44732: the 'one purge if done
    WITH the merge' premise LAPSED when merge sgl-project#5 completed without it
    -- later execution costs the SAME single purge once; no penalty,
    no haste. Recorded for the operator, not decided by B6.
detain added a commit to detain/sglang that referenced this pull request Oct 30, 2026
…gl-project#44462(317)/sgl-project#44342-trunk(318) in both the FAM-A3b block and the B6 re-triage verdicts; 10 dated corrections (mergeable flips: sgl-project#46191 REAL -> WATCH-HIGH with the re-derive-vs-QSA_RING_GROUPS=2 instruction, sgl-project#39845 DISPUTED as UNKNOWN-not-true plus the general 'UNKNOWN is no signal' rule; sgl-project#44344 -> SECTION R DOA with the entry-268 unconditional-clear subsumption citation and the mergeable-is-a-trap note; sgl-project#42525 target path moved fla->linear; sgl-project#45520 STILL OPEN -> re-apply rule ARMED FOR MERGE sgl-project#6; b12x-package archived claim DISPUTED with the frozen cutlass-dsl==4.8.0 pin risk standing; sgl-project#46153+sgl-project#41624 gated as ONE QAD bundle; sgl-project#37106 PARKED on eroded motivation with named revive conditions; sgl-project#32479 gated behind the PCIe-IPC measurement and DE-COUPLED from sgl-project#45391; sgl-project#44462's NEXT note spent); NEW S-item S-B12XDENSE filed
@NorthmanPKU

Copy link
Copy Markdown
Contributor

Sorry I approved this PR by mistake. I accidentally switched tabs while trying to approve a PR in my personal project. Could a maintainer please dismiss my approval? Thanks!

@github-actions

This comment has been minimized.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
YAMY1234 added a commit to YAMY1234/sglang that referenced this pull request Nov 12, 2026
…behind engagement logs

Port the read-only FULL host-tail peek (sgl-project#39845's peek_host_eviction_candidates)
to the Rust TreeCore so SGLANG_HICACHE_L3_WRITE_ON_HOST_EVICT runs on it:

- FullComponent::peek_host_eviction_candidates walks the same coldest-first
  heap as drive_host_eviction (HostEvictionWalk), simulating the child-count
  cascade with is_evictable_host_leaf_ignoring_children_; nothing in the tree
  changes and hashes are copied.
- Binding + HOST_EVICTION_PEEK_SCHEMA_VERSION = 1; the adapter reports
  supports_host_eviction_peek and init_hicache refuses a Rust build without it.
- Startup log names the write-back mode, the TreeCore backend and class, and
  the loaded native extension's path and sha256; a once-a-minute log line
  carries the cumulative write-behind counters, now including settled ops,
  settled and failed tokens.
- Tests: six Rust peek tests (read-only, budgets, parity with the real cascade
  under every eviction policy, parent predicates); the DSV4 sidecar case and a
  new peek-is-the-eviction-order case run on both cores.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@YAMY1234

Copy link
Copy Markdown
Collaborator Author

Closing in favor of #52682, which implements the same idea (L3 written from host-eviction victims, opt-in) on current main with hybrid-model chain close and rank-agreed engagement. This branch is 1,200+ commits behind main. Tracking issue with the data from this PR and the planned follow-ups: #52694.

@YAMY1234 YAMY1234 closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci CI: run the baseline test suite on this PR unified-radix-cache

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants