Skip to content

[Fix] hicache: Prevent incorrect outputs from cross-layout L3 cache reuse - #44732

Open
lhzds wants to merge 2 commits into
sgl-project:mainfrom
lhzds:fix/hicache-storage-page-format
Open

lhzds wants to merge 2 commits into
sgl-project:mainfrom
lhzds:fix/hicache-storage-page-format

Conversation

@lhzds

@lhzds lhzds commented Oct 16, 2026 •

Copy link
Copy Markdown

Motivation

Reusing persisted HiCache pages after changing the host memory layout can silently produce incorrect model outputs. Dense MHA and MLA host pools share L3 storage keys across layouts with different page byte orders, even with the logical dtype tagging from #38362. The file backend accepts these incompatible pages because their byte counts are identical, so the restored KV values are interpreted using the wrong layout.

This occurs when pages written with layer_first are reused after restarting with page_first, while keeping the same model, rank configuration, page size, and storage directory.

Reproduced on the original PR revision (68c917c75d) using an NVIDIA L20 with Qwen3-0.6B: all three requests reported 240-token L3 hits but produced different token sequences from the cold-cache control. With this fix, all three miss the incompatible entries and match the cold-cache outputs token for token. GPU page round-trips also reproduced incorrect KV values for both MHA and MLA.

Modifications

Add layout-specific storage_format_tag values to the dense MHA and MLA host pools through the existing storage model-name tagging mechanism, so incompatible cached pages miss.

  • Keep layer_first and page_first_direct in the same namespace because their flattened page byte order is identical.
  • Compose the layout tag with the resolved logical KV dtype introduced by [Fix] hicache: Include logical KV dtype in storage keys #38362.
  • Test all MHA/MLA layout pairs across FP16 and BF16, including MHA page_head, using the current host-pool constructors.
  • Reject legacy entries with no layout tag, including entries that already carry a dtype tag.

Compatibility: Existing MHA/MLA L3 entries without a layout tag will miss and require cache warmup under the new keys, even if the host layout is unchanged. Existing entries are not deleted or migrated.

Accuracy Tests

CPU validation after merging main at d9ec74eb72:

Validation Result
Storage format and dtype regressions 8 tests and 118 subtests passed, including 100 layout/dtype combinations. The registered test entry point also passed.
Regression control on unmodified main (8d3185e367) The same tests produce 30 failing subtests, confirming cross-layout false hits and reuse of entries without a layout tag.
Related host-pool, file/LRU, DCP, unified-key, and pool-assembler tests 193 tests and 269 subtests passed. Two Linux-only cases fail identically on the unmodified base: SHM allocation (memfd_create / /dev/shm) and the native hash extension.
Scheduler attach/detach and L3 object-layout tests 29 tests and 32 subtests passed.
Pre-commit All applicable hooks passed, including formatting, lint, and registered-test checks.

These CPU tests ran on macOS with real tensors and file I/O. A local test adapter uses native anonymous mmap without the Linux-only MAP_POPULATE flag; the regression control uses the same adapter.

GPU validation on the original PR revision (68c917c75d):

Validation Result
MHA / MLA GPU page round-trips All four incompatible-layout cases miss. All four same-layout cases restore every element exactly.
Qwen3 cross-layout reuse All three requests miss the incompatible entries and match the cold-cache outputs token for token.
Qwen3 same-layout reuse Each request hits 240 tokens and matches the unmodified same-layout warm-cache control token for token.

Model validation used one NVIDIA L20, Qwen3-0.6B, and the file backend: TP=1, Triton attention, CUDA graphs disabled, buffer_only, write_through, and page size 16. The three prompts each contained 253 tokens and generated 16 tokens. GPU page tests exercised device-to-host and host-to-device transfers for MHA and MLA with layer_first and page_first.

Speed Tests and Profiling

This change is limited to storage-key namespacing.

Checklist

  • Format code with pre-commit.
  • Add focused, registered unit tests.
  • Follow the SGLang code style guidance.
  • I have performed a self-review of my own code.

CI States

Latest PR Test (Base): ❌ Run #43706125222
Latest PR Test (Extra): ❌ Run #43706125026
Latest PR Test (AMD ROCm 10): ❌ Run #43706125127

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

@github-actions github-actions Bot added the hicache Hierarchical Caching for SGLang label Oct 16, 2026
detain added a commit to detain/sglang that referenced this pull request Oct 29, 2026
…mily + S-EXT1 + riders + S-RACE + LLGUARD/ENVREG), S-EXT1 and S-RACE items CLOSED, entry-256's raw-env deviation and LL-vs-PCIe-IPC collision warning both marked CLOSED with the BOOT_DELTA (h') needle in landing terms, sgl-project#35617 left as the sole FAM-A7 survivor, sgl-project#44732 re-pointed to the operator's merge-sgl-project#5 answer, and the KV-ROUTE DECISION RECORD added (HOLD NVFP4-KV until armed PCIe-IPC is measured post-merge; preferred-if-ever sequence merge -> sgl-project#43356-delta -> sgl-project#46452 NOT sgl-project#43240 -> optional sgl-project#43471 -> fork BUILD-A QSA FP4 reads (template sgl-project#38724) -> BUILD-B L3 scale sidecar -> one GPU window; sgl-project#46141 template, sgl-project#44462 NEXT, MXFP4 declined, entry-247 re-sync watch-string modelopt_e4m3_k32)
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.
@lhzds lhzds changed the title [Fix] hicache: Separate storage keys for incompatible host layouts [Fix] hicache: Prevent incorrect outputs from cross-layout L3 cache reuse Nov 15, 2026
Merge upstream main and retain logical KV dtype isolation. Adapt host-pool construction and cover layout/dtype pairs plus legacy keys.

Signed-off-by: lhzds <[email protected]>

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

hicache Hierarchical Caching for SGLang

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant