Repository navigation
fix: preserve QSA indexer state through HiCache - #39893
Merged
Merged
Conversation
alphabetc1
requested review from
Ying1123,
hanming-lu,
hnyls2002,
huangtingwei9988,
hzh0425,
ispobock,
merrymercy,
xiezhq-hermann and
yizhang2077
as code owners
September 17, 2026 04:16
detain
pushed a commit
to detain/sglang
that referenced
this pull request
Sep 17, 2026
(cherry picked from commit c0a51b7) Upstream-PR: sgl-project#39893
detain
added a commit
to detain/sglang
that referenced
this pull request
Sep 17, 2026
test_qsa_indexer.py published its minimal ServerArgs at module import. pytest imports every selected module before running any test, so when the qsa directory runs in one process that publish happens during collection and is then dropped by test_qsa_hicache.py's reset_context() teardown -- which PR sgl-project#39893 added, and which is the documented idiom for a test that publishes outside a scoped override. The four tests that construct an MRotaryEmbedding then failed with "config namespace 'exec' not published". CI runs these files per-file, so it never saw it; a local run of the directory did. An autouse fixture republishes per test (last-publish-wins), which keeps the file correct under either arrangement. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
detain
added a commit
to detain/sglang
that referenced
this pull request
Sep 17, 2026
…revise HiCache caveat
Adds a single-line `STACK:` identifier near the top -- main plus each PR
and each local change in build order:
main+pr36787+pr37275+pr38144+pr38209+pr36644+local_sm120_integration
+pr39807+pr39862+pr39809+mambapoolhost_newinit_fix+pr39893
+qsa_test_context_isolation
sgl-project#39893 fixes the QSA-indexer half of issue sgl-project#39830; sgl-project#39862 already in the
stack fixes the PLE half. The caveat no longer says "do not enable
HiCache" but states what is and is not established: both PRs are needed,
each was measured with the other applied, the numbers are the author's on
1x B200, and nothing has been run end-to-end with HiCache on this host.
Commits that touch only stack.txt are excluded from the numbered list, so
regenerating the manifest does not keep adding entries to it.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
detain
added a commit
to detain/sglang
that referenced
this pull request
Sep 17, 2026
…eads alive The sgl-project#39862/sgl-project#39893 author's closing caveat on sgl-project#39830 was that a page which exists but cannot be (de)serialized -- e.g. a storage directory written by a build with the old, shorter page layout -- raised from inside the daemon storage threads, which only catch queue.Empty. One corrupt page therefore killed the prefetch or backup thread silently, disabling that tier for the rest of the serve and leaking the operation's host allocation. - HiCacheFile.get: OSError (short read included) now returns None like a missing file, keeping the tensor-or-None contract. - _read_page/_write_page: the flat-page deserialize/serialize legs (set_from_flat_data_page raises ValueError on incompatible layouts by design, per sgl-project#39862) are wrapped per page and reported as misses; _batch_io_v2 routes every page through _safe_page_op so a bad page truncates the prefix instead of skipping the rest of the batch. Warnings are rate-limited (_BAD_PAGE_WARN_BUDGET) -- a stale directory can hold thousands of such pages. - prefetch_io_aux / prefetch_thread / prefetch_thread_func hit-query / backup_thread loops (base and hybrid controller): per-operation Exception guards that follow the existing failure signaling (batch miss, zero sidecar hits, partial progress) and ALWAYS emit the same acks -- the prefetch sync thread MIN-reduces PrefetchAcks pairwise across ranks, so ack-count parity is load-bearing; the hit-count all_reduce is kept outside the guard so a locally failed query still participates with a zero rather than desyncing collectives. Tests: +7 cases in test_hicache_file_lru_unit.py (truncated page, raising set_from_flat_data_page, mixed good/bad batch, write-side). CPU-only; 41 pass. py_compile clean; formatters not installed in this venv, formatting deferred to CI. Refs: sgl-project#39830
This was referenced Sep 19, 2026
Refefer
pushed a commit
to Mad-Labs-HQ/sglang
that referenced
this pull request
Oct 2, 2026
HiCache backed up and restored only KV + MAMBA for QSA models, so a prefix reloaded from host (L2) or NIXL (L3) kept whatever compressed index keys the device slots last held. The indexer then picked its top-k blocks from stale keys and Flash-Next lost sight of most of its own context on every host/storage hit longer than the 2048-token indexer budget. Adds a QSA indexer host pool (one packed byte row per full-KV page, target and packed MTP draft layers) as an INDEXER sidecar of the KV pool, sizes it out of --hicache-size, and fences indexer reads on the layer transfer counter. The new test lands in test/registered/kernels/ops/qsa/, where this tree keeps the QSA kernel tests. (cherry picked from commit 89f2167)
5 tasks done
detain
added a commit
to detain/sglang
that referenced
this pull request
Oct 10, 2026
Brings in 699 upstream commits up to 87845cd (sgl-project#43301, 2026-10-09). Conflict resolutions (67 files): - multimodal_gen quality tiers: adopt upstream exact/lossless/high migration (old lossless=bit-exact -> new "exact"; fusion moves into "lossless", which is now the DEFAULT). Migrated the stack's teacache guard (minimax_h3) to the "exact" tier and ltx_2 mask-skip to quality_allows(q, "lossless"). - video saving: take upstream's one-pass _save_video_ffmpeg (plugin-free), superseding the stack's PyAV/ffmpeg-pipe two-pass path (c16d89e/1b66dcb374); video_api generate_audio re-expressed over their request_extra_value. - teacache: union API -- keep our get_thresh/get_skip_boundaries/is_step_boundary alongside their get_skip_step_range (wanvideo/longcat/minimax + tests use all). - orchestrator.py: kept OURS wholesale (their refactor targets classic dispatchers our DAG sgl-project#139 removed); glm_distributed NotImplementedError lives in scheduler_mixin. - schedule_batch: retained our grammar_needs_sync field. - pool_host / mamba naming: took theirs. - unified_radix_cache: took their prefix-hit API, re-porting our bounded-evict logic into allocate_storage_hit. - hybrid_cache_controller: kept sgl-project#39830 degrade-to-miss guard over their changes. - hybrid_pool_assembler: took theirs (sgl-project#39893 absorbed our earlier patch). - qwen4_exp: rebuilt stage-boundary logic + re-applied PLE deltas. - qsa_sparse_attn_backend: integrated upstream CP / breakable-graphs / verify-fusion over our SM120 triton-decode and FP8-descale paths. - sgl-project#38480 + sgl-project#39862 arrived via upstream (stack dupes dropped). - tests: upstream deleted test_scheduler_decision_batch_params; ported that coverage to test_scheduler_grammar_mixed_tail_sync.py. - quantization import test (merge fallout): upstream renamed kitchen_int8 -> convrot_int8 and dropped the package-level config-class __getattr__ shim, so test_quantization_imports now asserts get_quantization_config dispatch against the concrete modules (canonical convrot names) plus an explicit kitchen_int8->convrot alias check. Deferred: GPU end-to-end verification owed (all 4 GPUs are running production servers; this battery was CPU-forced). Stack fixes land live only after the next diffusion/AR server restarts. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
lovedheart
added a commit
to lovedheart/sglang
that referenced
this pull request
Oct 16, 2026
Upstream 89f2167 (sgl-project#39893) landed QSAIndexerPoolHost: the same compressed-K page mirror over the same KV-derived indexing, plus MTP draft-pool coverage. Keep its INDEXER sidecar as the single backup path and retire the branch-local QSA_COMPRESSED_K sidecar, which would have backed up the same bytes a second time. The strategy-level fail-loud guards (buffer_only, page % ratio) stay, now keyed on the indexer pool, and the CPU contract test covers the upstream registration algebra. Co-authored-by: Copilot App <[email protected]>
jpezzulli
pushed a commit
to jpezzulli/sglang-rtxpro6000
that referenced
this pull request
Oct 21, 2026
HiCache restores QSA compressed index keys layerwise on the H->D stream, alongside K/V (pool_host/qsa.py, 7b5cfb7). get_key_buffer() and the other restored-state accessors wait on the layer transfer counter, but get_qsa_compressed_k_buffer() did not. The QSA indexer reads these keys to choose which KV blocks to attend, so after a host-tier hit it could select blocks from keys that had not finished loading: reworded or wrong answers on host hits only, while device hits stayed exact. This is the consumer fence from upstream sgl-project/sglang#39893, which Penny's own QSA host pool predates and never picked up. Measured on 1x RTX PRO 6000, Flash-Next NVFP4, 64 mamba slots, 48 GB host tier, hicache-repeat (~207K-token prefix restored from host): v3.0.2: 12/18 needle, 3/18 replies identical to cold v3.0.2 + this change: 9/9 needle, 9/9 identical to cold Host-hit latency is unchanged (0.64-0.67 s). Fixes #74. Co-Authored-By: Claude Opus 5.5 <[email protected]>
lovedheart
added a commit
to lovedheart/sglang
that referenced
this pull request
Oct 24, 2026
Upstream 89f2167 (sgl-project#39893) landed QSAIndexerPoolHost: the same compressed-K page mirror over the same KV-derived indexing, plus MTP draft-pool coverage. Keep its INDEXER sidecar as the single backup path and retire the branch-local QSA_COMPRESSED_K sidecar, which would have backed up the same bytes a second time. The strategy-level fail-loud guards (buffer_only, page % ratio) stay, now keyed on the indexer pool, and the CPU contract test covers the upstream registration algebra. Co-authored-by: Copilot App <[email protected]>
2 tasks done
jdjohndoe13
pushed a commit
to jdjohndoe13/sglang-flashnext-sm120
that referenced
this pull request
Nov 2, 2026
…- the root cause of S13 S14 in hallucination-investigation.md: the S13 A/B failure is explained. The QSA compressed index keys live in qsa_compressed_k_buffer_pool - OUTSIDE full_kv_pool - and the hybrid-mamba HiCache stack (build_hybrid_ mamba_stack) mirrored only KV + MAMBA to the host tier. A restored prefix therefore got its KV and mamba state back but re-used another request's indexer keys: the QSA indexer selected the wrong attention blocks and the model confabulated over mismatched attention - exactly the "content born in the response" class. The 0012/0013 fences were necessary but not sufficient because they fence the mamba state, which was already restored correctly. Port of upstream sgl-project/sglang#39893 (open, tested on this exact model on B200) to the fork's API: - new mem_cache/pool_host/qsa.py: QSAIndexerPoolHost page-row host mirror (fork DeepSeekV4PagedHostPool base; no page_aligned_only kwarg in the fork - QSA transfers are always whole-KV-page) - build_hybrid_mamba_stack: optional qsa_pool -> KV host-size shrink + PoolName.INDEXER entry with its own (pre-extension) layer mapping - _MambaStrategy.build: detect QSATokenToKVPool, register SidecarPoolSpec(INDEXER, KV) - the fork's UnifiedRadixCache sidecar machinery is generic and needed no changes; pools_desc becomes "KV + MAMBA + INDEXER" - get_qsa_compressed_k_buffer: consumer fence _wait_for_layer Validated on the live box alongside the running server (scripts/test_qsa_indexer_hicache.py): D2H -> poison -> H2D round-trip bit-exact; with the fence, reads are correct while the H2D stream is busy; WITHOUT the fence the race reproduces (stale data) - the test detects the bug class and the fence is what fixes it. size-parity with the KV anchor holds. Live tree: patch applied (git apply; inert on the current HICACHE=0 boot), changed files compile + import in the deployment venv. serve_best_kv_offload.sh: expected boot log now requires "pools=KV + MAMBA + INDEXER". A/B gate: 60-min bench + watcher on HICACHE=1. Until it passes, HICACHE=0 remains the only safe profile.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
QSA compressed index keys live outside
full_kv_pool, so the hybrid HiCache stack restores KV and Mamba state without restoring the indexer state used to select attention blocks. After device eviction, a prefix hit can therefore read valid KV through stale QSA block selections and produce incorrect output.Related to #39830. The independent PLE slot-state fix in #39862 is not included; it is applied only to both builds in the full-model validation environment to isolate the QSA failure.
Modifications
Accuracy Tests
Six real B200 GPU tests pass, covering reordered physical pages, four transfer/layout combinations, File L3 reader recreation and missing sidecars, and packed target/draft indexer restoration. Removing the consumer fence makes the delayed-copy regression fail with 93.8% mismatched elements.
Full-model validation: Qwen3.8-Flash-Next-NVFP4, 1x B200, TP=1, ~12.5K-token prompts, three independent documents with five random codes each. Both builds include the same validation-only PLE patch from #39862. Every host/storage leg restores 12,480 tokens from the asserted tier.
NEXTN uses 3 speculative steps, top-k 1, and 4 draft tokens. The validation-only E2E reproduction script is preserved in commit history, not included in this PR's final diff. It requires #39862 and a fresh output directory.
Speed Tests and Profiling
No standalone speed benchmark. The fix adds the missing indexer transfer bytes and uses existing per-layer completion events without adding a device-wide synchronization.
Checklist
CI States
Latest PR Test (Base): ❌ Run #36856850529
Latest PR Test (Extra): ✅ Run #36856850491
Latest PR Test (AMD ROCm 10): ❌ Run #36856850608