Repository navigation
[Perf] KVShard: 0SM KV Cache Allgather for KV Cache Sharding - #44029
Merged
Merged
Conversation
The sharded pool's per-layer prefix allgather ran on NCCL ring/LL kernels that compete with attention and GEMMs for SMs and HBM while overlapped. With SGLANG_ENABLE_KV_SHARD_ZERO_SM_GATHER (default on) the gather communicator is created with NCCL_CTA_POLICY_ZERO and both scratch slots are carved, at 4 KiB-aligned offsets identical on every rank, out of one ncclMemAlloc buffer registered as a symmetric window, so NCCL runs the in-place allgather on copy engines. - _scratch_tensor_specs returns name -> (shape, dtype); the mixin allocates. - Torch allocation is kept when the env is off, under the memory saver or a custom mem pool, with NCCL < 2.28, or when the shard group spans nodes (NCCL would take its hierarchical inter-node RMA path there, unverified). A NULL window (NCCL cuMem off) logs one warning and the gather stays on SM kernels. - The buffer is deregistered and freed when the last tensor view dies. - The engine defaults NCCL_CUMEM_ENABLE=1 when the zero-SM gather applies on a single-node deployment. - Works around an NCCL 2.30 race: with NVLS, the multicast team is built lazily inside the first CE collective's sync without a barrier, so the first gather could hang; the pool builds it at registration and barriers. - The GPU test profiles a gather batch and asserts no NCCL kernel launches and peer copies do, so a comm that loses CTA_POLICY_ZERO fails it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Shunkangz
requested review from
CatherineSue,
JustinTong0323,
Ying1123,
alphabetc1,
ch-wan,
hanming-lu,
hnyls2002,
huangtingwei9988,
hzh0425,
ispobock,
merrymercy,
slin1237,
xiezhq-hermann and
yizhang2077
as code owners
October 13, 2026 09:12
Shunkangz
requested review from
sogalin,
wisclmy0611 and
zijiexia
as code owners
October 13, 2026 10:03
Contributor
Author
|
/tag-run-ci-label |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 of 6 tasks
This comment has been minimized.
This comment has been minimized.
Preserve the zero-SM symmetric buffer types alongside upstream NCCL registration diagnostics and updated DSA kernel APIs.
5 tasks done
6 of 8 tasks
Collaborator
|
Please post accuracy results (for verifying the correctness of 0sm kv cache all gather), and the performance improvement results (how much speed up it can get) |
Contributor
Author
For both of accuracy and performance speedup, we might need to wait for the #44447 merged. After that, we can directly reuse the E2E test for Qwen3.8 Flash Next to verify accuracy and performance. |
Fridge003
reviewed
Oct 22, 2026
Contributor
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
Require NCCL 2.31.2 for patched copy-engine synchronization and release symmetric allocations on initialization failures. Compare zero-SM gathers byte-for-byte with normal NCCL on two and four GPUs, including graph replay and profiler checks.
Shunkangz
force-pushed
the
kvshard/zero-sm-gather
branch
from
October 23, 2026 02:56
a1ce245 to
5e3feac
Compare
Preserve upstream DSA test relocation alongside zero-SM gather correctness and lifetime coverage. Check the actual pool device before enabling symmetric scratch so CPU pools on CUDA hosts retain ordinary allocation.
Fridge003
approved these changes
Oct 24, 2026
Preserve the upstream page-interleave module imports and MTP coverage. Move zero-SM gather and symmetric-buffer lifetime tests into the dedicated multi-GPU suite, retaining two- and four-GPU CI registrations.
Merged
6 of 7 tasks
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
Zero-SM KV-Shard Gather
The sharded pool's per-layer prefix allgather previously used NCCL ring/LL kernels. When overlapped with attention and GEMMs, these kernels competed for SMs and HBM bandwidth.
SGLANG_ENABLE_KV_SHARD_ZERO_SM_GATHERenables zero-SM gathering and is on by default. The gather communicator is created withNCCL_CTA_POLICY_ZERO, allowing NCCL to run the in-place allgather on copy engines instead of SM kernels.Memory Allocation
Both scratch slots are carved from a single
ncclMemAllocbuffer registered as a symmetric window. Each slot uses a 4 KiB-aligned offset that is identical across all ranks._scratch_tensor_specsreturns a mapping ofname -> (shape, dtype).Activation and Fallbacks
The engine defaults
NCCL_CUMEM_ENABLE=1when zero-SM gathering applies to a single-node deployment.The pool retains Torch allocation when any of the following applies:
SGLANG_ENABLE_KV_SHARD_ZERO_SM_GATHERis disabled.If window registration returns a
NULLwindow because NCCL cuMem is disabled, the pool logs one warning and gathering remains on SM kernels.NCCL 2.30 Race Workaround
With NVLS enabled, NCCL 2.30 lazily builds the multicast team during the first copy-engine collective's synchronization, without a barrier. This race can cause the first gather to hang.
The pool works around the race by building the multicast team during registration and issuing a barrier afterward.
GPU Test Coverage
The GPU test profiles a batch of gathers and verifies that:
A gather communicator that loses
NCCL_CTA_POLICY_ZEROtherefore fails the test.Modifications
Accuracy Tests
Speed Tests and Profiling
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciCI States
Latest PR Test (Base): ⏳ Run #40061210028
Latest PR Test (Extra): ❌ Run #40061209948
Latest PR Test (AMD ROCm 10): ⏳ Run #40061210004