Skip to content

v0.10.1.dev284

@hallerite hallerite tagged this 22 Nov 00:28
## Summary

Everything needed to run disaggregated P/D for multi-turn agentic
rollouts with **bidirectional KV transfer**.

In a multi-turn rollout each turn's prompt is the previous turn's prompt
and completion plus new messages (tool output, a user message). With
one-way NIXL transfer, prefill recomputes all of that every turn,
although decode still holds the KV. With bidirectional transfer (vLLM's
`bidirectional_kv_xfer`), decode keeps a finished turn's blocks and the
session's next prefill reads them back over NIXL, so prefill computes
only the new tokens.

```toml
[inference.deployment.bidirectional_kv_transfer]
decode_blocks_ttl_s = 480   # router_ttl_s defaults to 450
```

Full example: `configs/advanced/deepseek-v4-flash/inference_pd.toml` (1
prefill + 3 decode nodes, DP8 + EP per node).

## Changes

**Bidirectional transfer** (`deployment.bidirectional_kv_transfer`)
- Adds `bidirectional_kv_xfer` and `decoder_kv_blocks_ttl` to the NIXL
connector on both roles. The TTL is persisted into the per-role engine
configs (`pd_decode_blocks_ttl_s`), the same way as
`use_pd_kv_transfer`.
- Starts vllm-router with its bidirectional session mode
(`--pd-bidirectional-kv --pd-bidirectional-ttl-secs`). The router keeps
each session's decode handle and gives it to that session's next
prefill.
- **A handle is used at most once.** Decode frees the blocks after the
first read. A second read (a retried turn, a client retry after an
error) loads whatever KV has since been written there, and the model
continues from corrupted context. This is not hypothetical: a proxy that
kept handles across retries produced garbled turns in about half of all
episodes under load. The router drops the handle when a turn starts, and
a retried turn runs a plain prefill.
- Prefill gets `kv_load_failure_policy = "recompute"` on its top-level
kv_transfer_config (also under MultiConnector, where vLLM's scheduler
reads it). vLLM 0.34 defaults to `fail`, so a read that prefill declines
because decode's blocks are about to expire would fail the request
instead of prefilling locally. `inference.kv_load_failure_policy`
overrides it. Decode and one-way P/D keep vLLM's default.
- Validated: the router must be `vllm-router`, the router TTL must be
shorter than decode's, and HiSparse decode instances are rejected.
- **Speculative decoding:** with a drafter, a decode request finishes
with `num_computed_tokens` counting the drafted positions after its last
token, whose KV belongs to rejected drafts.
- Decode exported that count as the handle's coverage: 42 for 23 prompt
+ 16 output tokens with 3 drafts.
- The router drops handles that cover more tokens than it has seen, so
with a drafter no turn ever read decode's KV back.
- Decode now reports `num_tokens - 1` and trims each KV cache group's
blocks to it. The trim happens before vLLM clips sliding-window groups,
because prefill pairs block lists from their ends.

**Router turn retries** (`router.pd_turn_retries`, default 2)
- In P/D mode the router reruns a turn whose prefill or decode request
fails with a connection error (`--pd-turn-retries`).
- Before, the first error went to the client. A decode request sent on a
pooled connection that had died in the network ended the client's
episode with "Connection timed out".
- A retried turn runs a fresh prefill and then decode, without the
previous turn's decode KV.

**Weight-update pauses under P/D**
- The orchestrator pauses engines with `mode="keep"` to update weights.
A paused engine completes the pause once its scheduler has no requests,
and that count included finished requests whose blocks it held for the
other side:
- prefill's handoffs, kept alive by decode's lease heartbeats while they
wait in decode's queue;
  - decode's bidirectional turns, held for up to their TTL.
- Under load a pause took many minutes and could exceed the
orchestrator's admin timeout. While paused with `PAUSED_ALL`, those held
requests no longer count.
- NIXL send leases keep their remaining time across a `keep` pause.
While both engines are paused for a weight update, no lease heartbeats
are sent or processed. Without this, an update longer than a lease's
remaining time would free blocks that the paused reader still reads
after resume.
- The pause records, in the engine's workers, each unexpired lease's
remaining time (inside a MultiConnector too).
- Resume restores those leases from the resume time before the next
reap, keeping any later heartbeat deadline.
- Expired leases are not revived, and leases granted during the pause
are left alone.
  - Outside a `keep` pause, vLLM's wall-clock reaper is unchanged.

**NIXL NIC affinity** (`deployment.nixl_nic_affinity`, default on)
- Each single-GPU engine sends its NIXL traffic through the RDMA port
nearest its GPU in the PCIe tree, on one rail (`UCX_NET_DEVICES=<port>`,
`UCX_MAX_RMA_RAILS=1`).
- Before this, UCX spread GPUDirect RDMA over all 8 NICs, so part of the
traffic crossed CPU sockets. On B200 nodes, 7 of 7 sustained P/D load
tests lost a GPU (Xid 119 GSP timeout, then Xid 154 "GPU Reset
Required"), always GPU 5 or 6. With pinning: 0 in 2 h at the same load.
- It uses InfiniBand ports, or RoCE ports on nodes without InfiniBand.
When no port is found the rank log says so and NIXL keeps every port.
- The PCIe-distance lookup moves into `prime_rl.utils.rdma`. The NIXL
weight transport now uses it too, with unchanged behaviour.

**vLLM 0.34.0 patches** (vLLM general plugin). Besides the
speculative-decoding and pause patches above, two backports of open
upstream PRs:
- vllm-project/vllm#64860: after a failed or evicted D->P pull, a
bidirectional prefill request now prefills locally. Before, it waited in
`WAITING_FOR_REMOTE_KVS` forever, and under load the prefill instance
stalled.
- vllm-project/vllm#65584 (NIXL side): for sliding-window models,
prefill leaves the last prompt token to decode. Otherwise, whenever `N -
W + 1` is a multiple of the block size, the token decode recomputes
reads the null block in its window. This applies to DeepSeek V4, whose
compressor caches are `SlidingWindowMLASpec`.

**Launcher**
- The sbatch templates reinstall a source-built `deps/nixl_cu13-*.whl`
into the project environment (`UV_PROJECT_ENVIRONMENT`, else `.venv`)
after `uv sync`, then export `UV_NO_SYNC=1`. The docs require that build
for P/D, but the setup sync and every process's `uv run` sync replaced
it with the locked wheel. The node-local sync script runs with `set -e`,
so a failed sync still stops the job.

## Status

- [x] vllm-router 0.2.6 (PrimeIntellect-ai/router#76) is released and
pinned here. It provides `--pd-bidirectional-kv`,
`--pd-bidirectional-ttl-secs` and `--pd-turn-retries`.
- [x] End-to-end run through this launcher: 2 prefill + 2 decode nodes,
a 3-token drafter, multi-turn agentic load. Results are in the test plan
below.
- [x] Weight updates under load with the pause and lease patches: 27
consecutive updates under multi-turn load on a 28-node P/D deployment
with a drafter, each pause completing in 0.5–6.2 s (mean 2.4 s). The
lease freeze was not checked separately there; the fake-clock tests
below cover it.

## Test plan

- `pytest tests/unit/test_configs.py -k "pd_ or disagg or kv_cache"`
(new `test_pd_bidirectional_kv_transfer`)
- `pytest tests/unit/inference/test_nixl_bidirectional_scheduler.py`: a
declined D->P read runs through vLLM 0.34.0's scheduler with the prefill
config prime-rl builds. The request prefills locally, finishes, and
leaks no blocks. The test fails without the vllm#64860 backport, and
under the default `fail` policy.
- `pytest tests/unit/inference/test_nixl_patches.py`: both patches
against the vLLM 0.34.0 classes. The first lookup still offers decode's
blocks, a processed request prefills locally, the backoff is 1 only with
a sliding-window group, and both patches are idempotent.
- `inference @ configs/advanced/deepseek-v4-flash/inference_pd.toml
--dry-run`: the generated sbatch has the router flags, NIC affinity and
NIXL reinstall. The per-role engine configs carry the TTL.
- `python -m prime_rl.utils.rdma <gpu>` on a B200 node returns the
PCIe-local NIC for all 8 GPUs, matching `nvidia-smi topo -m`.
- `pytest tests/unit/test_router_launch.py`: the P/D router launch
passes `--pd-turn-retries`, and the regular router does not.
- `pytest tests/unit/inference/test_nixl_bidirectional_scheduler.py -k
keep_pause` and `test_nixl_patches.py -k "spec_decode or trim or lease
or freezes"`: covers three things.
  - The decode handle covers only valid KV under speculative decoding.
- A held prefill handoff stops counting as work while paused and counts
again after resume.
- On a fake clock, a 30 s lease expires after five 6 s steps with no
pause. A lease with 4 s left still has 4 s left after a two-minute
`keep` pause, then expires.
- The patched engine pause and resume reach the NIXL worker inside a
MultiConnector, through both `EngineCore` and `EngineCoreProc` (which
serves). An `abort` pause leaves leases alone.
  - The pause and lease tests fail without their patches.
- **End-to-end, 2P/2D with a drafter, through this launcher:**
- **Readback:** after the coverage fix, 71 of 71 follow-up turns read
decode's KV back (0 of 39 before). Over a multi-hour agentic load,
56,960 turns read back, against 1,358 without a handle and 8 with an
expired one.
- **Logprob parity** against a full prefill on a prefill engine, per
turn:

    | turn | readback mean \|Δ\| | control mean \|Δ\| |
    |---|---|---|
    | 1 | 0.026 | 0.026 |
    | 2 | 0.050 | 0.051 |
    | 3 | 0.054 | 0.052 |
    | 4 | 0.062 | 0.061 |

The control re-prefills every turn, so readback adds no error beyond
what the longer context does.
- **Reward:** on an agentic benchmark, mean reward with readback matched
runs without it over the same episode count per task (0.924 vs 0.935,
n=383 each).
- Idle logprob parity, run on the same vLLM 0.34 stack outside this
launcher: turns 2–3 read the previous turn's KV from decode (48 of 48),
and their |Δlogprob| against an aggregated reference engine matches the
reference's own run-to-run gap (mean 0.029–0.030 vs 0.024–0.033).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **High Risk**
> Touches core P/D KV transfer, router session semantics, and vLLM
scheduler patches; incorrect handle reuse or lease behavior could
corrupt multi-turn context or stall weight updates under load.
> 
> **Overview**
> Adds **bidirectional KV transfer** for disaggregated prefill/decode:
decode retains finished-turn KV blocks (configurable TTL), **vllm-router
0.2.6** tracks per-session handles and passes them to the next turn’s
prefill, which pulls from decode over NIXL instead of recomputing the
full conversation. New **`deployment.bidirectional_kv_transfer`** and
**`nixl_nic_affinity`** (default on) wire NIXL/UCX to the RDMA port
nearest each GPU; **`router.pd_turn_retries`** retries failed P/D turns
without stale decode KV.
> 
> Config and launch paths auto-enable `bidirectional_kv_xfer` on the
NIXL connector, default prefill **`kv_load_failure_policy =
"recompute"`**, and validate **`vllm-router` only** (no HiSparse
decode). SLURM templates pass router flags, NIC affinity env, reinstall
source-built NIXL after `uv sync`, and set **`UV_NO_SYNC=1`**.
> 
> Several **vLLM 0.34 backports/monkey patches** cover failed D→P reads
(single pull), sliding-window prefill backoff, speculative-decode handle
trimming, **`keep` pauses** that ignore held KV, and **frozen NIXL send
leases** during weight-update pauses. RDMA nearest-port logic moves to
**`prime_rl.utils.rdma`**, with docs and an example
**`configs/advanced/deepseek-v4-flash/inference_pd.toml`**.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
7321161df1b5a6c09d51d860c0255bad8b993d93. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Assets 2
Loading