Skip to content

[TPU/Raiden/StagingHostRam] Add num_staging_layers constructor parameter to PyTorch KVCacheManager, replacing TPU_RAIDEN_NUM_STAGING_LAYERS - #1402

Merged
copybara-service[bot] merged 1 commit into
mainfrom
test_1008676768
Oct 29, 2026
Merged

copybara-service[bot] merged 1 commit into
mainfrom
test_1008676768

Conversation

@copybara-service

Copy link
Copy Markdown

[TPU/Raiden/StagingHostRam] Add num_staging_layers constructor parameter 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.
# 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.

…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
copybara-service Bot merged commit 9f5270b into main Oct 29, 2026
2 checks passed
@copybara-service
copybara-service Bot deleted the test_1008676768 branch October 29, 2026 20:07
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant