Repository navigation
Conversation
…he dtype The HiCache L2 write-back/load-back path only transfers the packed KV data buffers and never the FP4 block scale buffers, so reloaded pages silently lose their scales; the host pool also sizes tokens with a full-width dtype formula. Reject the combination at server args validation until full FP4 HiCache support lands.
|
Reviewer note from an sm_120 hybrid-model rig (2× RTX 5060 Ti 16 GB, Qwen3.8-27B: 16 full-attn + 48 GDN layers, nvfp4 KV, UnifiedRadixCache, SGLang 0.5.21 wheel). Two datapoints for this PR: 1) The fail-fast as drafted does not cover the hybrid assembly path. For our model the host pools are built in 2) A measurement that complicates "always corrupt": we ran cold → evict → host-hit tests with a secret code word spliced at 50% depth of a 185K-token document (2 rounds; hicache 20 GB, Adjacent and unrelated to host transfer, but same blind spot (nothing validates KV scale provenance): we separately found a load-path misuse where fp8-calibrated checkpoint Happy to run any variant you want on this box; logs/transcripts available. |
Motivation
Enabling the hierarchical cache (HiCache) together with an FP4 KV cache dtype (
--kv-cache-dtype nvfp4/fp4_mx_block16) currently passes server args validation but silently produces corrupted outputs after write-back/load-back. Two concrete gaps on current main:python/sglang/srt/mem_cache/pool_host/mha.pyoperate exclusively on the packed data buffers (k_data_ptrs/v_data_ptrs);k_scale_buffer/v_scale_bufferdo not appear in any host transfer set. After a page is written back and later reloaded, its FP4 block scales are lost, so attention consumes packed FP4 data with missing/garbage scales — silent corruption, no error anywhere.MHATokenToKVPoolHost.get_size_per_token()(pool_host/mha.py, thehead_dim * head_num * layer_num * dtype.itemsize * 2formula) does not account for FP4's half-width packed data plus the separate scale buffers, so the host pool size is also wrong for FP4.There is no existing guard rejecting this combination (checked on v0.5.17, v0.5.18, and main).
Modifications
Add a minimal fail-fast guard in
ServerArgs._handle_hicache()(python/sglang/srt/server_args.py): when any of the paths that build a hierarchical-cache host pool is active (--enable-hierarchical-cache, decode KV-cache offload, or decodehost_poolretraction backup) and--kv-cache-dtypeisnvfp4orfp4_mx_block16, raise aValueErrorexplaining that the L2 write-back/load-back path does not transfer FP4 scale buffers and that the host pool sizes tokens with a full-width formula, directing users to pick either HiCache or an FP4 KV dtype.Also add a unit test (
TestHiCacheArgs.test_hicache_rejects_fp4_kv_cache_dtype) covering both FP4 dtypes.Why fail-fast instead of a fix
Full FP4 HiCache support requires host-side scale-buffer transfer in every write-back/load-back path, an FP4-aware host-pool capacity formula, and dedicated correctness validation — each of which is meaningful follow-up work on top of the FP4 KV cache roadmap (#29913). Until then, rejecting the combination at startup is the safe behavior; this mirrors the fail-fast precedent for unsupported NVFP4 KV cache platforms in vLLM (vLLM PR #43669). Related area: #36010.
Verification
python -m py_compileon both changed files.pytest test/registered/unit/server_args/test_server_args.py: 150 passed; the 2 failures present (TestFa4PageSizeAutoForce::test_explicit_prefill_fa4_forces_page_size_128,TestGrpcServerArgs::test_start_server_call_site_matches_native_signature) also fail on unmodified upstreammainin this CPU-only environment, i.e. pre-existing and unrelated.TestHiCacheArgstests: all pass.F401,F821,UP037), black, and isort clean on the changed files.CI States
Latest PR Test (Base): ❌ Run #32680970506
Latest PR Test (Extra): ❌ Run #32680970320
Latest PR Test (AMD ROCm 7.2): ❌ Run #32680970426