Repository navigation
[TPU/Raiden/StagingHostRam] Add num_staging_layers constructor parameter to PyTorch KVCacheManager, replacing TPU_RAIDEN_NUM_STAGING_LAYERS - #1402
Merged
Conversation
…meter to PyTorch `KVCacheManager`, replacing `TPU_RAIDEN_NUM_STAGING_LAYERS`
**Why**
- `TPU_RAIDEN_NUM_STAGING_LAYERS` was process-global, shrinking host layer buffers across all `KVCacheManagerBase` instances and breaking coexisting full-mirror managers.
- Exposing `num_staging_layers` as a constructor parameter allows per-manager configuration and eliminates hidden global environment state.
```python
# Before (process-global env var affecting all managers):
os.environ["TPU_RAIDEN_NUM_STAGING_LAYERS"] = "2"
manager = KVCacheManager(kv_caches, local_control_port=..., max_blocks=..., num_slots=...)
# After (explicit per-manager constructor parameter):
manager = KVCacheManager(
kv_caches,
local_control_port=...,
max_blocks=...,
num_slots=...,
num_staging_layers=2,
)
```
**What**
- Replace `TPU_RAIDEN_NUM_STAGING_LAYERS` with an optional `num_staging_layers` constructor parameter (validated in `[1, num_layers]`).
- Plumb `num_staging_layers` from Python `KVCacheManager` through the PyTorch C++ bindings to `KVCacheManagerBase`.
PiperOrigin-RevId: 1009904595
copybara-service
Bot
force-pushed
the
test_1008676768
branch
from
October 29, 2026 20:07
fc210ff to
9f5270b
Compare
jcc-google
added a commit
to sgl-project/sglang-torchtpu
that referenced
this pull request
Nov 5, 2026
…gression (#1970) tpu-sync-torch 0.0.1.dev20261029204745 includes google/tpu-sync#1391, which leases a staging slot per pool on pool-reshard receives even with full host mirrors. Incoming pushes are then addressed into the leased buffer but bounds-checked against the pool's own buffer, so every PP->TP Raiden pipeline transfer fails with 'Chunk out of bounds' followed by 'explicit-destination push ... has no registered plan on this pool-mode worker'. The fix is google/tpu-sync#1489. Until a nightly with that fix exists, pin 0.0.1.dev20261029081917, the newest nightly before #1391. That wheel predates num_staging_layers (google/tpu-sync#1402), so RaidenKVManager now passes num_staging_layers only when the installed KVCacheManager accepts it and otherwise keeps full host mirrors (as with SGLANG_TPU_RAIDEN_STAGING_LAYERS=0). Signed-off-by: Jincheng Chen <chenjincheng@google.com>
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.
[TPU/Raiden/StagingHostRam] Add
num_staging_layersconstructor parameter to PyTorchKVCacheManager, replacingTPU_RAIDEN_NUM_STAGING_LAYERSWhy
TPU_RAIDEN_NUM_STAGING_LAYERSwas process-global, shrinking host layer buffers across allKVCacheManagerBaseinstances and breaking coexisting full-mirror managers.num_staging_layersas a constructor parameter allows per-manager configuration and eliminates hidden global environment state.What
TPU_RAIDEN_NUM_STAGING_LAYERSwith an optionalnum_staging_layersconstructor parameter (validated in[1, num_layers]).num_staging_layersfrom PythonKVCacheManagerthrough the PyTorch C++ bindings toKVCacheManagerBase.