Repository navigation
Conversation
MLA latent KV is identical on every TP rank, but each rank kept its own HiCache host copy and read it from L3 on its own, so a 4-GPU node held and fetched 4 copies of the same data. With --enable-mla-hicache-per-node, only the first rank on each node (leader) keeps a real MLA host pool and loads from L3; the other local ranks use the allocator-only host pool from sgl-project#36800. During the forward, the per-layer HiCache wait hook (as in sgl-project#42009) broadcasts each loaded MLA layer from the leader to the local GPUs over NCCL/NVLink, so the broadcast overlaps with compute. KDA/Mamba state, L3 keys and L3 layout are unchanged, so existing L3 data stays valid. The leader's host pool and budget are sized for the whole node; all ranks size the allocator the same so the radix tree stays consistent. PD decode, DCP, FP4 MLA and single-rank nodes fall back to per-rank copies with a warning. The flag is off by default. Co-Authored-By: Claude <[email protected]>
Three bugs in the --enable-mla-hicache-per-node path. 1. Chunked-prefix prefill read prefix KV before the leader's broadcast A follower's device KV comes only from the leader's broadcast, and that broadcast is sent from the layer-wait hook (LayerDoneCounter.wait_until). The trtllm_mla eager prefill takes MHA_CHUNKED_KV and reads prefix KV through HybridLinearKVPool.get_mla_kv_buffer, which, unlike the other reads on that pool, did not wait. The inner MLA pool does not wait either: the hybrid pool clears its counter to None. So a follower read stale rows for that layer and gave wrong output with no error. get_mla_kv_buffer now waits on the model layer id before swapping in the compact id, as get_key_buffer does. This also fixes the same missing wait on H2D for the non-dedup path. 2. Explicit --hicache-ratio/--hicache-size could pin past host memory Followers build an allocator-only MLA pool with no memory check and go straight on to the Mamba host pool, whose check reads live free memory while the leader is still pinning. With an explicit size there is no budget snapshot, so an oversized config could fail while pinning (or be killed) instead of with "Not enough host memory available". Every rank now waits on a gloo barrier over the TP CPU group before the Mamba pool is built. Followers block until all leaders have pinned, so the check sees real free memory. Gloo, not NCCL, since pinning can outlast the NCCL watchdog. No new process group. 3. GB200/GB300: the leader's pool was sized for two Graces A tray has two Graces, each its own NUMA node, and the scheduler is membind-ed to its GPU's node. The leader's budget is the whole tray's free memory, but it can only pin from one Grace, so the default auto-sized pool asked for about twice what that node can give. auto_size_hicache halves the per-rank budget when the flag is on and is_mnnvl_fabric_device() is true; the MIN all-reduce keeps every rank's ratio equal. Limits: Mamba host capacity is halved too, and an explicit ratio/size is not covered. Not run: no GPU available, only checked with py_compile. Co-Authored-By: Claude <[email protected]>
The previous commit fixed GB200/GB300 by halving the auto-size budget. That was wrong in two ways: - auto_size_hicache overrides the global hicache_ratio, and the Mamba host pool reads the same value (MambaPoolHost in build_hybrid_mamba_stack), so Mamba host capacity was halved too. - An explicit --hicache-ratio/--hicache-size never reaches auto_size_hicache, so the leader still pinned the whole tray's share on one Grace. The real constraint is per NUMA node, not per host. With the same ratio, the tray's total is unchanged by this feature; what changed is that the leader, membind-ed to its GPU's node, pins every follower's share there. A GB300 tray has two Graces, each its own node, so the leader's node took twice its share. Spread the leader's MLA host pool over the nodes its ranks are bound to instead: - build_for_node all-gathers each rank's NUMA node and cpuset-allowed nodes over the TP CPU group. The node comes from get_numa_node_if_available, the same query the launcher binds with. - leader_host_shares derives the multiplier from that layout, not a constant. If the group spans several nodes, every rank is bound and the leader may allocate on all of them, the pool is interleaved over them and the multiplier is (fewest ranks on a node) x (node count): 2 x 2 = 4 on a GB300 tray. Even interleave puts the same amount on every node, so this keeps each node at or below its own ranks' share. A group on one node, or with NUMA binding off, keeps the group size and is not interleaved. If the leader cannot reach every node, or binding is mixed, it falls back to the ranks on its own node. The minimum over all groups is used so every rank sizes its allocator the same. - numa_utils.interleave_memory sets MPOL_INTERLEAVE on the calling thread for the leader's pool build only, then restores the previous policy, mode flags included. It must wrap the allocation: the HiCache mmap is pre-faulted, so mbind afterwards would not move the pages. It raises if the policy cannot be set, since the pool was sized for it. - leader_budget_scope uses the same multiplier and enters the interleave scope. With the same ratio, no NUMA node holds more host memory than without the flag. Mamba is unchanged, explicit ratio/size and auto-sizing are both covered, and KV cache capacity stays 4x on GB300. L3 reads stay at one per tray. Trade-off: the leader's H2D now reads half its pages from the other node (Grace-Grace link on GB300, the socket link on dual-socket x86). Dual-socket x86 hosts with binding on are interleaved too, with the multiplier going from 4 to 8. Neither link's bandwidth was measured. Not checked: whether the Mooncake/UMBP host allocators fault pages in this process, which the policy needs. The halving in hicache_auto_size.py is reverted. Not run: no GPU available, only checked with py_compile; the multiplier and nodemask logic were checked on GB300, single-NUMA, dual-socket, uneven and restricted-cpuset layouts in isolation. Co-Authored-By: Claude <[email protected]>
--enable-mla-hicache-per-node keeps one MLA KV HiCache host copy per node. SGLANG_MLA_HICACHE_PER_NODE_MODE now selects how followers get the KV: - broadcast (default): unchanged #72 behaviour. Followers keep an allocator-only host pool and the leader broadcasts each loaded layer over NCCL from the layer-wait hook. - shm: the leader allocates the MLA host pool in a memfd (interleaved over the node's NUMA nodes by the existing leader_budget_scope) and sends the fd to same-host followers over an abstract Unix socket (SCM_RIGHTS). Every rank maps and pins the same pages and does its own H2D, so the forward path is the same as without the flag. In both modes only the leader writes the shared copy: followers skip the anchor D2H, use a page-get stub for L3 prefetch (the leader's count wins through the existing all_reduce(MIN)), and do not register the buffer with Mooncake. shm rejects --hicache-write-policy write_back at startup and on attach-storage: write-back eviction syncs locally, so a follower could load shared pages before the leader's D2H into them lands. Also adds benchmark/hicache/bench_h2d_numa.py, which compares HiCache-style page-gather H2D from one interleaved shared buffer against per-GPU private local buffers, one process per GPU. Not run: no GPU here; checked with py_compile, ruff and isort only.
Reject pipeline parallelism for per-node MLA HiCache and check mode agreement on the WORLD CPU group before entering mode-specific collectives. Close shared-buffer descriptors and bootstrap sockets on success and failure. Derive the controller's follower role from the MLA host pool, skip unused follower D2H staging, and avoid follower MLA existence queries while retaining rank-sharded Mamba checks. Add focused regression coverage, including cold/preloaded module identity handling in the Mooncake fixtures. Validation: Python compilation, formatting/import-order checks, no new Ruff diagnostics, and isolated before/after source probes. Registered tests could not collect because torch/msgspec are unavailable; GPU/distributed/Mooncake integration remains untested.
Three gaps in the per-node MLA HiCache startup path: - A follower waited for the leader's shared host buffer with no timeout, so a stuck leader hung it forever. The wait now uses --dist-timeout, or 120 minutes (the gloo group default) when it is unset, and raises a RuntimeError that points at the leader's log. - NodeSharedHostTensorAllocator closes its sockets after the first exchange, so a second allocate() raised IndexError on a follower and returned an unshared buffer on the leader. It now rejects a second call explicitly. - In broadcast mode, the one-rank-per-node early return leaked the NCCL group it had just created. Every rank takes that return together, so each now destroys its own handle before returning. Adds unit tests for all three. Not run: torch is unavailable locally; checked with py_compile only. Co-Authored-By: Claude <[email protected]>
luke396
force-pushed
the
hicache-mla-kv-remove-redundant-copies-one-per-node
branch
from
October 20, 2026 07:06
8d9126e to
b9391c9
Compare
luke396
changed the base branch from
infrawaves/v0.5.21
to
infrawaves/dev/v0.5.21
October 20, 2026 07:11
Share one initialization path between broadcast and shm, replace the socket
handoff, fix L3 configuration at startup, and trim the feature to its
contracts.
- Both modes: the leader sizes a memfd without prefaulting it, followers
reopen it via /proc/<pid>/fd/<fd>, each rank prefaults a contiguous
page-aligned share with MADV_POPULATE_WRITE, and no rank registers before
every share is populated. Broadcast followers then drop the mapping and
keep dummy slot metadata. The leader's FD stays open until that fence;
open and mapped-size failures abort every rank.
- Leave NUMA placement to deployment: remove the leader interleave, the NUMA
benchmark and their helpers.
- With the flag on, reject runtime L3 attach/detach and policy updates.
Reject at startup Mooncake standalone_storage, PD decode, DCP, stacks
other than hybrid MLA + Mamba/KDA, and non-CUDA or FP4 MLA pools.
- Replace SGLANG_MLA_HICACHE_PER_NODE_MODE with
--mla-hicache-per-node-mode {broadcast,shm}; drop the WORLD mode agreement.
- NodeSharedHostTensorAllocator takes this node's ranks and the cache group
and derives its index, size and leader.
- Make host-pool parameters explicit and keep allocation fences in the
assembler.
- Cover the hybrid MLA read waiting on its layer load.
- Trim tests to contract-level guards and comments to unstated contracts.
luke396
force-pushed
the
hicache-mla-kv-remove-redundant-copies-one-per-node
branch
from
October 23, 2026 06:26
35adf0d to
2dc9858
Compare
Nozom1ff
pushed a commit
that referenced
this pull request
Oct 29, 2026
--enable-mla-hicache-per-node keeps one MLA KV HiCache host copy per node. SGLANG_MLA_HICACHE_PER_NODE_MODE now selects how followers get the KV: - broadcast (default): unchanged #72 behaviour. Followers keep an allocator-only host pool and the leader broadcasts each loaded layer over NCCL from the layer-wait hook. - shm: the leader allocates the MLA host pool in a memfd (interleaved over the node's NUMA nodes by the existing leader_budget_scope) and sends the fd to same-host followers over an abstract Unix socket (SCM_RIGHTS). Every rank maps and pins the same pages and does its own H2D, so the forward path is the same as without the flag. In both modes only the leader writes the shared copy: followers skip the anchor D2H, use a page-get stub for L3 prefetch (the leader's count wins through the existing all_reduce(MIN)), and do not register the buffer with Mooncake. shm rejects --hicache-write-policy write_back at startup and on attach-storage: write-back eviction syncs locally, so a follower could load shared pages before the leader's D2H into them lands. Also adds benchmark/hicache/bench_h2d_numa.py, which compares HiCache-style page-gather H2D from one interleaved shared buffer against per-GPU private local buffers, one process per GPU. Not run: no GPU here; checked with py_compile, ruff and isort only.
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.
Why
MLA latent KV is identical on every rank of a TP group, yet HiCache pins a separate L2 (host DRAM) copy on each rank, and each rank reads it from L3 (Mooncake) on its own. On an N-GPU node, the same data is stored N times and read N times.
What
--enable-mla-hicache-per-node--mla-hicache-per-node-mode {broadcast,shm}broadcast/proc/<pid>/fd/<fd>. Each rank populates only its own share, and no rank pins before all shares are populated. Broadcast followers drop the mapping afterwards.all_reduce(MIN), so the leader's completion decides.write_back, Mooncakestandalone_storage, stacks other than hybrid MLA + Mamba/KDA, non-CUDA or FP4 MLA pools. With the flag on, runtime L3 attach/detach and policy updates are rejected.Results
Production traffic replay, starting from a cold L3.
Merge Danger
Door: two-way. The flag is off by default and the L3 format is unchanged, so turning it off restores the current behavior.
Blast Radius: prefill instances with the flag on. Known limitations: