Skip to content

[Refactor] memory-pool: Build KV host pools from buffer info - #40917

Merged
ispobock merged 6 commits into
mainfrom
hicache-decl-e
Oct 18, 2026
Merged

ispobock merged 6 commits into
mainfrom
hicache-decl-e

Conversation

@ispobock

@ispobock ispobock commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

The MHA and MLA HiCache host pools took the device pool object and read its private fields (k_buffer, v_buffer, kv_buffer, data_ptrs, layer bounds, draft pools) to rebuild the buffer list, layer mapping and packed draft offsets that the device side already knows. Every new pool layout had to be taught to each host consumer separately.

Each KV device pool now exports a typed MHABufferInfo or MLABufferInfo through get_device_pool_infos(), and the host pools are built from that info plus explicit capacity and layer bounds. GPU host pools no longer hold a device pool reference. Packed MTP drafts are passed as their own buffer infos and checked against the target row geometry at construction. Physical layout, host capacity, transfer kernels and the L3 page format are unchanged.

This replaces the earlier declaration based approach of this PR.

Three behavior changes come with it:

  • An MHA host now rejects KV scale layouts other than MXFP8 at construction. On main an FP4 KV pool gets a host that saves the packed payload without its scales, so a load back restores wrong values silently.
  • Aibrix storage takes the dtype from the host pool instead of the device pool. With FP8 KV on main, an L1 write and read back through the Aibrix SDK corrupted 416 of 6656 bytes per block, while this PR returns every byte unchanged.
  • Packed MTP draft layers under prefill CP layer split now map to the host row after this rank's target layers. On main the first write-through on a GLM-5.2 PD prefill worker with --enable-dsa-cache-layer-split and EAGLE fails with index 78 is out of bounds for dimension 0 with size 40.

Modifications

  • device_pool_info.py: MHABufferInfo, MLABufferInfo, MLAHostAllocation, and providers on the MHA, MLA, SWA, unified and hybrid pools.
  • pool_host/mha.py, mha_mxfp8.py, mla.py: construct from buffer info, drop device pool reads, validate packed drafts.
  • hybrid_pool_assembler.py, hisparse_coordinator.py: pass buffer info and capacity instead of the pool.
  • Aibrix and TensorCast storage read the host dtype instead of the device pool.
  • test_hicache_staged_write_back_dispatch.py: set the host fields the new constructors own on the __new__ built MLA host.

Accuracy

Each row compares this PR with main on the same launch config. Cache hits are forced to come back from host (small device pool plus eviction) and checked through cached_tokens_details. KL is decode logprob vs prefill replay on the same server.

model / path                          host hits (prefill, decode)   KL prefill hit      KL decode hit
                                      main / PR                     main / PR           main / PR
Qwen3-0.6B MHA, layer_first, draft    4/8 8/8 / same                3.548e-4 / same     2.488e-4 / same
Qwen3-0.6B MHA, write_back            7/8 8/8 / same                3.349e-4 / same     2.456e-4 / same
Qwen3-0.6B MHA, page_first_direct     4/8 8/8 / same                2.991e-4 / same     2.456e-4 / same
gpt-oss-20b SWA                       5/8 8/8 / same                2.777e-2 / same     2.690e-2 / same
gpt-oss-20b SWA, unified memory       5/8 8/8 / same                2.777e-2 / same     2.690e-2 / same
DeepSeek-V2-Lite MLA                  4/8 8/8 / same                9.51e-4 / 1.04e-3   3.049e-4 / same
GLM-5.2 tp4 DSA + EAGLE               6/8 8/8 / same                3.343e-2 / 3.347e-2 4.622e-2 / same
Qwen3.8-27B FULL+Mamba, NEXTN draft   5/8 8/8 / same                2.596e-4 / same     1.115e-4 / same

The assembled host pools and the host to device transfer sequence are identical to main on every row above.

test_unified_radix_cache_kl_hybrid_bitexact.py (Inkling, deterministic), HiCache and L3 buffer_only classes:

                         main     this PR
avg_kl_div (L2 host)     0.0      0.0
avg_kl_div (L3 storage)  0.0      0.0

GSM8K, Inkling tp4, sgl-eval, all 1319 questions:

main:     0.9606
this PR:  0.9606  (every output identical to main)

CI States

Latest PR Test (Base): ✅ Run #39113648668
Latest PR Test (Extra): ✅ Run #39113648559
Latest PR Test (AMD ROCm 10): ❌ Run #39113648632

@ispobock
ispobock changed the base branch from hicache-decl-d to main October 1, 2026 13:35
@ispobock ispobock added run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci) bypass-fail-fast CI: a failing job no longer aborts its siblings (lint still gates) labels Oct 1, 2026
@ispobock
ispobock requested a review from whybeyoung as a code owner October 18, 2026 06:52
@ispobock ispobock changed the title Assemble plain KV from declarations and drop old paths [Refactor] memory-pool: Build KV host pools from buffer info Oct 18, 2026
# Conflicts:
#	test/registered/kernels/ops/kvcache/test_hicache_strided_device_rows.py
#	test/registered/unit/mem_cache/test_mem_pool_host.py
@ispobock

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

@ispobock

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/hicache/test_dsa_host_release.py test/registered/hicache/test_k_only_host_release.py test/registered/kernels/ops/attention/qsa/test_qsa_hicache.py test/registered/kernels/ops/kvcache/test_hicache.py test/registered/kernels/ops/kvcache/test_hicache_page_first_write_back.py test/registered/kernels/ops/kvcache/test_hicache_strided_device_rows.py test/registered/kernels/ops/kvcache/test_mxfp8_host_allocation.py test/registered/unit/mem_cache/pool_host/test_kvcacheio_asymmetric.py test/registered/unit/mem_cache/test_asymmetric_mha_pool_host_unit.py test/registered/unit/mem_cache/test_dsa_pool_host_unit.py test/registered/unit/mem_cache/test_hicache_auto_size.py test/registered/unit/mem_cache/test_hicache_dcp_host_pool.py test/registered/unit/mem_cache/test_hicache_seaweedfs_storage.py test/registered/unit/mem_cache/test_hicache_staged_write_back_dispatch.py test/registered/unit/mem_cache/test_hybrid_pool_assembler.py test/registered/unit/mem_cache/test_mem_pool_host.py test/registered/unit/mem_cache/test_minimax_sparse_pool_host_unit.py test/registered/unit/mem_cache/test_minimax_sparse_pool_pd_unit.py test/registered/unit/mem_cache/test_mla_host_dedup_primitives.py test/registered/unit/mem_cache/test_mxfp8_mha_pool_host_unit.py

@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

🚀 1-gpu-5090 (5 tests): ✅ View workflow run

cd test/ && python3 registered/hicache/test_dsa_host_release.py
cd test/ && python3 registered/hicache/test_k_only_host_release.py
cd test/ && python3 registered/kernels/ops/kvcache/test_mxfp8_host_allocation.py
cd test/ && python3 registered/unit/mem_cache/test_dsa_pool_host_unit.py
cd test/ && python3 registered/unit/mem_cache/test_minimax_sparse_pool_host_unit.py

🚀 4-gpu-b200 (1 test): ✅ View workflow run

cd test/ && python3 registered/kernels/ops/attention/qsa/test_qsa_hicache.py

🚀 1-gpu-h100 (4 tests): ✅ View workflow run

cd test/ && python3 registered/kernels/ops/kvcache/test_hicache.py
cd test/ && python3 registered/kernels/ops/kvcache/test_hicache_page_first_write_back.py
cd test/ && python3 registered/kernels/ops/kvcache/test_hicache_strided_device_rows.py
cd test/ && python3 registered/unit/mem_cache/pool_host/test_kvcacheio_asymmetric.py

🚀 ubuntu-latest (10 tests): ✅ View workflow run

cd test/ && python3 registered/unit/mem_cache/test_asymmetric_mha_pool_host_unit.py
cd test/ && python3 registered/unit/mem_cache/test_hicache_auto_size.py
cd test/ && python3 registered/unit/mem_cache/test_hicache_dcp_host_pool.py
cd test/ && python3 registered/unit/mem_cache/test_hicache_seaweedfs_storage.py
cd test/ && python3 registered/unit/mem_cache/test_hicache_staged_write_back_dispatch.py
cd test/ && python3 registered/unit/mem_cache/test_hybrid_pool_assembler.py
cd test/ && python3 registered/unit/mem_cache/test_mem_pool_host.py
cd test/ && python3 registered/unit/mem_cache/test_minimax_sparse_pool_pd_unit.py
cd test/ && python3 registered/unit/mem_cache/test_mla_host_dedup_primitives.py
cd test/ && python3 registered/unit/mem_cache/test_mxfp8_mha_pool_host_unit.py

@ispobock
ispobock merged commit 4ec19ca into main Oct 18, 2026
270 of 288 checks passed
@ispobock
ispobock deleted the hicache-decl-e branch October 18, 2026 15:21
nbommi19 added a commit to nbommi19/sglang that referenced this pull request Oct 24, 2026
Re-apply MLA host dedup onto the buffer-info MLA host pool (sgl-project#40917): the
pool keeps the owned target layers by filtering its MLABufferInfo, so the
existing per-layer slot maps, owned-layer load skip and all-layer backup
carry the rotation. Append the flag's positional slot after main's fields
(sgl-project#44991), and keep the dedup storage-attach guard next to the DCP L3 checks
(sgl-project#41187).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Nozom1ff added a commit to Infrawaves/sglang that referenced this pull request Nov 7, 2026
v0.5.23 (sgl-project#40917) removed MLATokenToKVPoolHost's is_dummy argument and
selects the allocator-only pool by its input type. The per-node MLA host
copy, written against v0.5.22, still passed is_dummy=True through
build_kv_host_pool's kwargs, so every follower rank of
--enable-mla-hicache-per-node failed with a TypeError at startup.

Followers now pass an MLAHostAllocation sized like this rank's real MLA
host pool (row width x target + draft layers, plus the indexer rows under
page_first_kv_split), so their share matches the leader's per-rank share.

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bypass-fail-fast CI: a failing job no longer aborts its siblings (lint still gates) bypass-fastfail hicache Hierarchical Caching for SGLang memory-pool npu run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants