Repository navigation
Conversation
Two SGLang instances sharing one Mooncake store with the same model but different --kv-cache-dtype could reuse the wrong cache bytes. Compose the logical device dtype into Mooncake tenant_id instead of prefixing object keys, and require mooncake-transfer-engine>=0.3.12. Co-authored-by: Teng Ma <[email protected]>
2c7831e to
60d307e
Compare
Preserve per-rank SSD offload directories alongside the shared tenant-aware setup helper. Adapt the dtype regression fixture to the current storage host-pool format interface. Validation: all 42 Mooncake CPU unit tests and pre-commit checks on the six PR files passed. Live Mooncake and GPU integration tests were not run. Signed-off-by: Teng Ma <[email protected]>
Reuse the existing Mooncake setup and tenant compatibility paths instead of refactoring KV and embedding initialization. Keep the shared logical-dtype config field and a single tenant composition helper. Consolidate dtype regressions into the existing tenant test fixture and shorten the documentation. Validation: 38 Mooncake CPU unit tests and pre-commit on all five PR files passed. Live Mooncake and GPU tests were not run. Signed-off-by: Teng Ma <[email protected]>
| dp_rank=dp_rank, | ||
| extra_config=storage_backend_extra_config, | ||
| # Host buffers may store different FP8 formats as uint8 bytes. | ||
| kv_cache_dtype=str(self.mem_pool_device.dtype).removeprefix("torch."), |
There was a problem hiding this comment.
which data type should we refer exactly when we are talking about dtype? Isn't host memory type aligned with the storage exactly? Would using device type cause confusion?
There was a problem hiding this comment.
Here dtype means the logical KV-cache encoding. The host pool uses device_pool.store_dtype, which is uint8 for both E4M3 and E5M2. mem_pool_device.dtype preserves that distinction, and the bytes are copied unchanged to Mooncake. It represents the KV-cache format, not the model’s compute dtype.
There was a problem hiding this comment.
Fix it in the latest commit
| "Please upgrade Mooncake to use non-default " | ||
| "Mooncake tenants with SGLang." | ||
| "Upgrade with: pip install -U " | ||
| "'mooncake-transfer-engine>=0.3.12'." |
There was a problem hiding this comment.
Why we need mooncake-transfer-engine>=0.3.12
Resolve the host-pool import conflicts with the current host-memory preflight helper. Carry the mirrored K/V store and value dtypes on page-envelope layouts so tenant isolation still applies after host construction moved off the device pool. Co-authored-by: Teng Ma <[email protected]>
xiezhq-hermann
left a comment
There was a problem hiding this comment.
Thanks @stmatengss for keeping this up to date, and sorry for the slow design answer. The bug is real on current main. Take two instances with the same model name (and extra_backend_tag) but different persisted KV dtypes: bf16 vs fp16, or fp8 e4m3 vs e5m2 (both stored as uint8). They get the same Mooncake key and tenant. _batch_postprocess counts any positive read as a hit, so the second instance can load pages in the wrong format and nothing reports an error. Your host-side get_storage_dtype() / value_dtype plumbing is the right answer to "which dtype is actually persisted", and I'd like to keep it.
I don't think tenant_id is the right place for it, though:
- It doesn't isolate anything with a default master. Tenants only separate objects when the master runs with
--enable_multi_tenants=trueand a quota policy that registers every composed tenant. With multi-tenancy off, Mooncake ignores the request tenant and everything stays in thedefaultnamespace (see the note in the Mooncake README). So the most common setup still collides. - It breaks existing deployments. The default tenant becomes
dtype_<x>, so in embedded modesetup()now receivestenant_idfor every MHA/MLA host pool, and a client without that parameter fails at startup. I checked this on fd511a8 with a stub client whosesetup()rejectstenant_id: main starts, and this branch raises the new>=0.3.12RuntimeError. The AMD wheel still pinsmooncake-transfer-engine-non-cuda==0.3.8.post1. Existing multi-tenant quota policies would also have to register<tenant>_dtype_*. Standalonemooncake_clients would need a restart with the composed--tenant_id, and nothing checks that they match: the branch only logs a warning at startup. - It covers Mooncake only. File, HF3FS, NIXL, EIC and the other backends have the same gap. See the TODO in
HiCacheFile._init_config_suffixand the "KV format and host layout are not yet in the keys" note in the Mooncake README. - Existing objects go cold anyway (which is why #44844 exists), so keeping the object keys unchanged doesn't make migration any easier.
Could you move the persisted dtype into the backend-agnostic storage key instead? For example, storage_model_name() could append get_storage_dtype() next to storage_format_tag. That is the same path #44732 uses for host layouts, and the unified key scheme already carries the logical dtype in KVCacheNamespace. Then the tenant composition, the >=0.3.12 requirement (which also settles the open question in the review thread) and the README section can all go. Every backend that keys on the model name (Mooncake, File, NIXL, EIC, ...) would get the fix with no master configuration, at the cost of one cold-cache warmup, the same cost #44732 accepts. HF3FS doesn't key on the model name today, so it needs its own change either way. #36420 instead adds the dtype to each backend's keys directly (File, NIXL, EIC, HF3FS and Mooncake); please coordinate so that the dtype plumbing lands only once. Once the dtype is in the key, #44844 should no longer be needed.
Two more things on the current head:
base-a-test-cpuis red on fd511a8 because of this change. Test stubs built withobject.__new__/SimpleNamespacehave no.dtypeorget_storage_dtype(). Locally on fd511a8 these fail; all of them pass on main:test_hybrid_pool_assembler.py, 18 tests:'DSATokenToKVPool'/'MLATokenToKVPool'object has no attribute'dtype'.test_mem_pool_host.py::TestDSAIndexerPoolInfo, 4 tests: the same error.kv/test_declared_parts.py::test_file_cache_keeps_rank_local_draft_inside_mla_pages: the stub sets the classUnifiedPageEnvelopeHostPoolasstorage_host_pool, soget_storage_dtype()is called unbound.test_hicache_l3_object_layout.py::test_deepseek_v4_uses_rank_replicated_storage_config.
UnifiedPageEnvelopeHostPool.get_storage_dtype()falls back touint8when the layout doesn't carrystore_dtype/value_dtype, which puts e4m3 and e5m2 back in the same namespace. I'd rather a missing pair fail loudly; the same applies togetattr(storage_config, "kv_cache_dtype", None).
cc @alphabetc1 (#44844) @wuhangxian (#36420)
|
Thanks @xiezhq-hermann for the detailed review. Updated in 7f2efb2ccd.
Existing objects become cold under the new keys; there is no fallback to untyped objects. I also updated the PR title/body and documented the overlap with #36420: this PR supplies the shared host-dtype/model-key path, while HF3FS still needs its dedicated file/metadata-key change. The overlapping plumbing should be consolidated before merge. This version introduces no dtype-specific tenants for #44844's proposed tenant-migration fallback. Validation on this commit:
That is 245 tests passed, plus all applicable pre-commit checks. The new regressions were also run against pre-fix Local tests used Python 3.12 / PyTorch 2.14.1 on macOS, real CPU tensors/File IO, fake Mooncake clients, and a bounded host-memory budget with a portable CPU allocation adapter for the host-pool suites. They do not establish live distributed Mooncake or GPU model-accuracy validation. Hosted CI has now passed all 10 |
|
Thanks @stmatengss for the quick and thorough rework, and sorry: I'm going to walk back part of what I asked for on 11-09. Seeing the result, threading a per-pool Could you shrink it to this?
The Mooncake-side cleanup you already did (no tenant composition, no version requirement) can stay as it is. The end-to-end behaviour I verified on 7f2efb2 (instances with different dtypes sharing one File store don't hit each other's pages, and the same dtype still hits after a flush) is what the smaller version should keep. Sorry for the churn. |
|
@xiezhq-hermann Updated in 49d8432cdc following your latest suggestion.
Validation on this revision: 238 local CPU tests passed (54 storage-format/Mooncake tests + 184 related host-pool, DCP, unified-key, storage-identity and L3-layout tests), and all applicable pre-commit hooks passed. The focused File test verifies BF16/FP16 and E4M3/E5M2 isolation plus same-dtype persisted-byte readback through fresh readers. It reproduces collisions with the original main model-name implementation and passes with this revision. Plain/routed controller paths and missing/unresolved dtype errors are covered too. These are macOS CPU tests with real File IO, fake Mooncake clients, and a bounded portable allocation adapter for host-pool tests. I have not rerun the live server flush/GPU experiment you described; the local same-dtype check uses a fresh backend reader. New-head hosted CI is still in progress. The Extra/AMD Extra/MLU gate logs currently report missing opt-in labels ( |
|
Let me double-check all these changes |
|
/rerun-test -c |
|
🚀 |
Two servers sharing the same HiCache file backend directory can silently reuse each other's KV pages whenever the key does not distinguish the page layout. The original report (sgl-project#51045) covers one flavour: same model, same dtype, page layout differing. fp16 and bf16 pages are the same size, so nothing rejects the stale key, and the reader applies KV values written under a different layout -- returning clearly corrupt text with HTTP 200. The dtype half of the bug was fixed by sgl-project#38362 by folding the logical KV dtype into the storage namespace (via storage_model_name). The remaining gap is layout: HiCacheStorageConfig.is_page_first_layout describes the byte order within a page, and the file backend's config_suffix does not yet include it. hicache_storage.py's TODO already noted that "Other layout differences still need extra_backend_tag", and while simm / mooncake / umbp / npu_memcache honor that key, HiCacheFile does not. Fold the layout tag and the user-supplied extra_backend_tag into the per-rank file suffix, between the pp sharding markers and the CP sharding markers. The position keeps CP rank/size as the trailing portion of the suffix so existing endswith assertions stay valid. The tag format is intentionally short: `_page1st` for page-first layout, `_bkt<tag>` for the extra_backend_tag passthrough. The suffix is on the filename, not on the metadata channel, so the tag has to be grep-friendly and short. Tests cover the four namespaces produced by the (layout, extra_tag) matrix and assert they are pairwise disjoint. The lru_file_evictor only manages files under the current suffixes, so files written under a previous layout stay on disk; operators migrating a shared directory need to purge or rotate it instead of expecting the new key to overwrite the old one. This is documented in the comment above the suffix write. Fixes: sgl-project#51045
… level 2 follows upstream PR 52724. Qwen3.8-Flash-Next disk tier: the previous release said the serve script empties the host cache's disk tier once when the weights change. It did not. Since upstream sgl-project/sglang#38362 the page files carry the KV dtype in their names (_<served name>-dtype_<dtype>_<rank>_<tp>.bin), and the script's file pattern matched none of them. So after a switch to the QAD checkpoint, pages computed with the previous weights stayed, and an engine could load them when a prompt prefix matched. The pattern now matches both name forms, and the page epoch is 3: the first launch after this update removes this model's pages once, whatever wrote them, and recomputes them on demand. Hybrid cache level 2 (models with linear-attention layers: Qwen3.8-Flash-Next, GLM-5.3-Flash, SenseNova-Loop-9B): the prompt-end fix from the previous release is replaced by upstream sgl-project/sglang#52724 (Ruilin Gao), which covers both of its cases. One difference: a prompt whose last chunk is a single 64-token step (k x 4096 + 64 tokens) now resumes at the end of the previous chunk instead of being recomputed. Checked on Qwen3.8-Flash-Next with the same weights as the previous release: the other resume points, the 24-turn agent loop at 32K (23 of 23 turns resume at the previous prompt end), sibling sessions sharing a 6K preamble and the repeat check are unchanged. The state kept for such a prompt gives bit-identical greedy tokens and logprobs to a resume from an ordinary prompt end at the same depth. Upstream's slot-lease unit test expects no state from a complete prompt and fails on the PR; ours expects the prompt-end state. GLM-5.3-Flash docs: the first tool turn after a cold 190K-token prompt takes 0.82 s. Greedy decode (merge_sorted, tok/s): GLM-5.3-Flash 206.0 (205.9), SenseNova-Loop-9B 70.2 (70.2); the repeat check's output is unchanged on both.
Motivation
Two instances sharing a model name and storage backend can address the same cache objects even when their logical KV dtypes differ. BF16 versus FP16, or FP8 E4M3 versus E5M2, can therefore load incompatible bytes without reporting a miss.
Modifications
storage_model_name(), alongside the existingstorage_format_tag. The controller reads the existing token KV device view'sdtype, so E4M3 and E5M2 remain distinct even when both useuint8backing buffers. Plain and routed device pools use the same path.auto; device views already carry the resolved dtype.Existing untyped objects become cold and are repopulated under the new keys; there is no fallback to untyped objects. Other representation/layout differences still require distinct
extra_backend_tagvalues where they are not already encoded.Related work
This extends the shared model-namespace path used for host layouts in #44732. It overlaps #36420's model-keyed backend changes; the overlapping changes should be consolidated before merge. HF3FS does not use the model namespace and still needs its dedicated path/metadata-key change. This PR introduces no dtype-specific tenants for #44844's tenant-migration fallback.
Validation
On commit
49d8432cdc90ad60d32e14c0573bdbe894c4dbda, with Python 3.12 / PyTorch 2.14.1:test_mooncake*.pysuites.TestDSAIndexerPoolInfo, declared parts, DCP hosts, unified keys, storage identity, and the complete HiCache L3 object-layout suite.dfaca5681d, reproducing key collisions for both ordinary and page-envelope storage. It passes with this fix.238 tests passed locally. Tests ran on macOS with real CPU tensors and File IO, fake Mooncake clients, and a bounded host-memory budget/portable CPU allocation adapter for host-pool suites. The same-dtype File check uses a fresh backend reader; live server flush, distributed Mooncake, GPU inference, and model accuracy were not rerun locally. Hosted CI results must be checked against this new head; earlier-head results are not validation of this revision.
Speed Tests and Profiling
Not run. Dtype namespacing happens during storage configuration; the transfer path is unchanged.
Checklist
CI States
Latest PR Test (Base): ✅ Run #43162546242
Latest PR Test (Extra): ❌ Run #43162545981
Latest PR Test (AMD ROCm 10): ❌ Run #43162546053
Tip
Base CI only covers the core cases, and its workload may not exercise your change. Use
/rerun-testto run the tests your change touches, or copy this prompt for an agent: