[TransferEngine] Share one host KV segment across a TP group - #3252
Closed
ascend-direct-dev wants to merge 1 commit into
Closed
[TransferEngine] Share one host KV segment across a TP group#3252ascend-direct-dev wants to merge 1 commit into
ascend-direct-dev wants to merge 1 commit into
Conversation
ascend-direct-dev
requested review from
ShangmingCai,
alogfans,
chestnut-Q,
doujiang24 and
staryxchen
as code owners
August 3, 2026 11:05
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
ascend-direct-dev
marked this pull request as draft
August 4, 2026 01:05
ascend-direct-dev
force-pushed
the
feat/shared-host-segment
branch
3 times, most recently
from
August 4, 2026 12:04
8410fc9 to
3e2d76d
Compare
Add SharedSegment (VMM/mmap) with create_shared_segment()/tensors() as the Python surface, and resolve HostRegister-mapped host VAs to device pointers when Ascend Direct registers location=npu so ROCE D2rH works. For mmap segments, best-effort shmem THP: align and madvise when enabled, otherwise keep base-page allocation. Co-authored-by: Cursor <cursoragent@cursor.com>
ascend-direct-dev
force-pushed
the
feat/shared-host-segment
branch
from
August 4, 2026 12:24
3e2d76d to
72f02d2
Compare
Collaborator
Author
|
Superseded by #3285 (same branch tip |
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
MLA keeps the same KV cache in every rank of a tensor-parallel group. When those ranks offload KV to host memory during decode, each one allocates its own copy, so host usage grows with the TP size while every copy holds identical bytes.
This PR adds a shared segment: the owner rank allocates the pages once through the platform's virtual memory manager, and every other rank maps the very same physical memory. Host usage for offloaded MLA KV drops to 1/TP.
Design
C++ shares one contiguous host span. Tensor layout (which offset holds which layer's K/V) is computed in Python and folded into the segment name so peers that disagree still fail the fingerprint check.
Two-phase creation. The handle exchange belongs to the caller's process group:
SharedSegment::Createreserves address space (owner also allocates and exports) and returns a fixed-size blob.all_gathers the blob over its own group.segment->Complete(blobs)maps the owner's pages and verifies that every rank declared the same thing.Doing it this way avoids calling back into Python collectives from C++ under the GIL. Non-owner blobs are the same length as the owner's, so a plain fixed-size all-gather carries them.
Addresses are not forced to match. Ranks agree on the byte layout, not on virtual addresses, so each rank reserves
sizerather thansize * world_size.Backends. Compiled in per platform and both optional:
adxl::AdxlEngineaclrtMemFabricHandlecuMemCreate/cuMemMap)CUmemFabricHandle, CUDA 12.4+SharedSegment::Supported()reports whether the running system can actually share memory. Builds without either backend returnkNotImplementedrather than failing to link.Python API
Test plan
shared_segment_test: fingerprint, blob encode/decode, and the full two-phase protocol against a fake backend.-Wall -Wextraagainst the CUDA driver headers.