Add DMA-mapped PyTorch KV cache offloader - #851
Open
enkidu-214 wants to merge 1 commit into
Open
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Add borrowed-shm whole-pool DMA registration, raw-page H2D/D2H copies, lifecycle coverage, and PyTorch packaging.
enkidu-214
force-pushed
the
dev/new_kvcache_offloader
branch
from
September 4, 2026 09:20
c65443d to
d069a36
Compare
enkidu-214
marked this pull request as ready for review
September 4, 2026 09:22
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.
Summary
KVCacheOffloaderfor bidirectional KV-cache page transfers.TpuClient::DmaMap, then reuse that registration for H2D and D2H transfers from smaller object-tensor views within the pool.DmaUnmap, and surface the API through the native Torch extension and Python wrapper.libtpu>=0.0.47, which provides the DmaMap behavior used by this path.Design
The caller owns the host-memory pool, its page locking, its process-local mapping lifetime, and the construction of mutually disjoint object-tensor views.
map_shared_memory(address, size)registers the whole pool once with the same PJRT client that owns the KV-cache device buffers. Subsequenth2dandd2hcalls operate on complete object-tensor views and issue raw page transfers without registering each object separately.unmap_shared_memory()first prevents new submissions, waits for all previously submitted copies, and then releases the pool registration throughTpuClient::DmaUnmap.Validation
bazel test //tpu_sync/frameworks/torch:kv_cache_offloader_testpython -m unittest -v tpu_sync.api.torch.kv_cache_offloader_test2,2,1,2: H2D, clear host buffers, D2H, byte comparison, and unmap all completed successfully.