Skip to content

vllm.v1.kv_offload.tiering.p2p.manager

P2PSecondaryTierManager: Secondary tier for P2P KV cache sharing.

Owns transports and a single bidirectional P2PSession per remote peer.

Classes:

  • P2PDestInfo –

    Producer side: a remote fetches this request's blocks from us.

  • P2PSecondaryTierManager –

    Secondary tier for P2P KV cache sharing.

  • P2PSourceInfo –

    Consumer side: this request fetches from a remote (prefiller or peer).

P2PDestInfo dataclass

Producer side: a remote fetches this request's blocks from us.

kv_request_id is None when the remote_decoder block is present but malformed (no id); the block's presence still marks the request as remote-decode, so submit_store must fail rather than store locally.

P2PSecondaryTierManager

Bases: SecondaryTierManager

Secondary tier for P2P KV cache sharing.

A single P2PSession per remote peer handles both client-role (loading blocks from the peer) and server-role (serving blocks to the peer) over the same control connection.

Never entered concurrently: every public method runs under the tiering manager's lock, held either by the scheduler thread for the length of a step or by the tier-poll thread for the length of one round. Peers are not driven by the engine, so this tier sets tolerates_off_thread_polling to be serviced from that thread too; without it a peer's lookup or fetch waits for a step boundary, which on a saturated rank can be seconds.

has_pending_work() reports peer-originated work, not idle polling, so a peer-only engine can pause and shut down. The tiering manager keeps the engine ticking when the tier-poll thread is off or another secondary tier exists.

Methods:

  • __init__ –

    Initialize the P2P secondary tier manager.

  • drain_jobs –

    Block until every submitted load/store job has completed or failed.

  • on_new_request –

    Parse kv_transfer_params once and open the outbound session.

  • on_request_finished –

    Cancels pending loads and prunes session-scoped state.

  • serve_external_requests –

    Serve inbound peer lookups against the tiering manager.

__init__(offloading_spec, primary_kv_view, tier_type='p2p', host=None, port=None, backends=None, num_threads=4, unbound_store_timeout_s=_UNBOUND_STORE_TIMEOUT_S, access_mode=OffloadAccessMode.READWRITE, **kwargs)

Initialize the P2P secondary tier manager.

All keyword arguments after primary_kv_view come from the secondary_tiers entry in kv_connector_extra_config. See docs/features/kv_offloading_usage.md for the user-facing configuration reference.

Parameters:

  • offloading_spec

    (OffloadingSpec) –

    Owning OffloadingSpec (provides normalized model, parallel, and cache layout configuration).

  • primary_kv_view

    (memoryview) –

    Memoryview over the CPU primary tier; the NIXL agent registers this region for RDMA transfers.

  • tier_type

    (str, default: 'p2p' ) –

    Tier identifier (defaults to "p2p").

  • host

    (str | None, default: None ) –

    Address the ZMQ control socket binds to, used verbatim as both the bind address and the identity peers dial back (mirrors the NIXL connector's VLLM_NIXL_SIDE_CHANNEL_HOST; no auto-detection). Defaults to VLLM_P2P_SIDE_CHANNEL_HOST (localhost) when not set; must be set to the node's routable IP for cross-host P2P so remote peers can reach the socket.

  • port

    (int | None, default: None ) –

    Base port for the ZMQ control socket. Must be reachable from peers. Defaults to VLLM_P2P_SIDE_CHANNEL_PORT (5710) when not set. The bound port is base + data_parallel_index so each DP replica gets a distinct port (one socket per replica, like NIXL); for DP=1 the offset is 0.

  • backends

    (list[str] | None, default: None ) –

    NIXL transport backends (e.g. ["UCX"], ["MOONCAKE"], ["LIBFABRIC"]). Defaults to ["UCX"]. When any non-UCX backend is requested, the NIXL agent is initialized with backends=...; otherwise it falls back to a UCX-only agent with num_threads threads.

  • num_threads

    (int, default: 4 ) –

    NIXL agent worker threads for the UCX-only branch. Ignored when backends contains a non-UCX entry.

  • unbound_store_timeout_s

    (float, default: _UNBOUND_STORE_TIMEOUT_S ) –

    Seconds a producer holds stored blocks for a consumer that has not fetched them yet, before _reap_unbound_stores drops them. Raise it for deployments whose prefills outlast the default; the blocks keep primary-tier slots pinned for the whole window.

  • access_mode

    (OffloadAccessMode | str, default: READWRITE ) –

    Direction(s) in which this tier may transfer data. read fetches blocks from peers but never stages local blocks for them; write stages blocks for peers but never fetches. The tiering manager skips the directions the mode disables.

  • **kwargs

    (Any, default: {} ) –

    Reserved for future tier-specific options.

Raises:

  • ValueError –

    If unbound_store_timeout_s is not a positive number, or anything convertible to one.

_drain_inflight_for_shutdown()

Best-effort drain of inflight transfers before closing _data.

Collects inflight transfer_ids from each session, repeatedly calls _data.cancel(..., mode="wait") and _data.poll() so handles can surface as done/failed. Unlike session._drain_abort, which never force-releases, it falls back to mode="immediate" once _SHUTDOWN_DRAIN_TIMEOUT_S elapses: the engine is exiting, and a wedged peer must not hang shutdown.

_get_hash_seed()

The seed NONE_HASH was derived from, resolved on first session.

_get_or_create_session(peer_id)

Return the existing session for peer_id, or open one outbound.

Consumer-side helper for on_new_request: when remote_prefiller (PD) or remote_kv_source (symmetric P2P) is set, the consumer must reach the producer at peer_id. If we already have a session toward that peer (from a prior load or a peer-initiated inbound), reuse it; otherwise open an outbound ControlConnection and build a connected session.

Returns None if the session could not be created (capacity exceeded or transport error).

_poll_once(*, draining=False)

One sweep of the polling work.

Drains the control transport, polls every session, accumulates their results into _finished_jobs, and reaps any dead sessions. Runs under the tiering manager's lock, on the scheduler thread or on the tier-poll thread.

_poll_retained()

Unpin retained transfers once they stop, or at the hold cap.

A store job is failed only once no retained transfer reads it.

_reap_idle_sessions()

Evict idle sessions when remaining peer slots are scarce.

A session is idle when it has no pending work and its last activity timestamp exceeds VLLM_P2P_IDLE_TIMEOUT_S. Eviction runs only when len(_sessions) >= VLLM_P2P_MAX_PEERS - _IDLE_REAP_HEADROOM so a quiet but healthy mesh is not torn down. Uses the same teardown path as _reap_dead_sessions.

_reap_unbound_stores(*, force=False)

Time out submit_store batches that no peer has ever fetched.

Walks _unbound_stores for entries whose oldest batch is older than _unbound_store_timeout_s. Drops the kv_request_id, surfaces every batched job as failed, and records the id in _reaped_stores so a late inbound FetchMsg is rejected in one round trip and a late submit_store fails instead of re-parking under the reaped id.

Also expires _reaped_stores entries whose consumer can no longer be waiting, which is why this runs before the empty check below.

_retain(peer_id, retained)

Hold a reaped session's still-running transfers and their pins.

_retained_peer(peer_id)

Whether a reaped session of peer_id still has running transfers.

Its registration stays until they stop. A new session would load the peer's NIXL agent again under the same name: NIXL keeps the old UCX endpoints, possibly failed, and the old registration's release removes the agent under the new one. So the peer stays out until the transfers stop, at most _RETAINED_HOLD_CAP_S.

_schedule_reconnect_backoff(peer_id)

Record a data-plane fault for peer_id; return its reconnect wait.

The wait doubles (1 s up to the max) when the previous fault's wait expired less than the max ago, and is 0 otherwise. Only time is checked, not whether any transfer succeeded in between.

drain_jobs()

Block until every submitted load/store job has completed or failed.

Fail stores still waiting for a fetch, then poll until no session has outstanding inbound loads or in-flight outbound stores, and no reaped session's transfer is still retained (bounded by its hold cap). Mid-flight transfers are NOT cancelled — the caller (TieringOffloadingManager.reset_cache) needs the primary memoryview to be quiescent, not aborted. Results accumulate in _finished_jobs and are surfaced by the next get_finished_jobs() call.

Inbound loads are aborted up front rather than waited out: a peer that never writes would otherwise block the reset for the full load timeout. Each is failed at once with a deferred release and stays pending until its AbortAck, or until a missed AbortAck disconnects the session and the reap's close() sets the event, so every event is set on return.

on_new_request(req_context)

Parse kv_transfer_params once and open the outbound session.

Parses the P2P routing state onto req_context (cached for the later lookup/submit/finish calls). On the consumer side (remote_prefiller for PD or remote_kv_source for symmetric P2P), open a session toward the producer at remote_host:remote_port so submit_load can issue FetchMsg as soon as it fires. On the prefiller side, sessions are created when the consumer's inbound connection arrives in _accept_new_peers — submit_store no longer pre-creates anything.

Producer-leg requests (remote_decoder present) ask for REQUEST_LEVEL: the peer needs every block of the request, not just the ones this request computed.

Requests without a remote_decoder opt out of cascades of newly stored primary chunks, since there is no destination to receive them.

on_request_finished(req_context)

Cancels pending loads and prunes session-scoped state.

Consumer side (remote_prefiller for PD or remote_kv_source for symmetric-P2P): looks up the session by peer_id because the producer's address is what addresses the client-role load to cancel; also drops any pending symmetric-P2P lookup state via session.finish_request. Prefiller side (remote_decoder set): looks up via kv_request_id because peer_id is no longer carried on store-time kv_transfer_params; if a session has bound the id, finish it. If no session has bound the id yet, this is a no-op: parked batches in _unbound_stores are left in place and cleaned up only by _reap_unbound_stores after _unbound_store_timeout_s.

A PD prefiller request may carry both roles: remote_kv_source (pull cached blocks from a P2P source) and remote_decoder (serve the decoder). Each role is finished independently, on its own session. Both roles may share one session when the source and the decoder are the same node; that session is then finished once per distinct kv_request_id.

serve_external_requests(parent)

Serve inbound peer lookups against the tiering manager.

Called once per scheduler step (before this tier's on_schedule_end) with a parent handle valid only for the duration of the call — the sole window in which the P2P server role may query the tiering manager. First release bookkeeping for the failed serves left by a reaped session, then let every live session resolve its enqueued inbound LookupMsgs.

P2PSourceInfo dataclass

Consumer side: this request fetches from a remote (prefiller or peer).

_UnboundStoreBatch dataclass

A submit_store batch parked at the manager before any peer has fetched.

Indexed by kv_request_id only — the prefiller no longer learns the peer identity at store time. When a FetchMsg(kv_request_id) arrives on some session, the manager binds the kv_request_id to that session and replays every parked batch into ServerRole via session.add_stored_blocks.

_annotate_req_context(req_context)

Parse kv_transfer_params once and cache the P2P routing state.

Called from on_new_request; later calls for the same request read the cached P2PSourceInfo/P2PDestInfo via get_state instead of re-parsing.

_parse_dest(kv_params)

Parse the producer remote_decoder sub-dict into a P2PDestInfo, or None if the block is absent (not a remote-decode request).

_parse_source(kv_params)

Parse the consumer sub-dict (PD remote_prefiller or symmetric remote_kv_source) into a P2PSourceInfo, or None if absent/incomplete.

_peer_id_from_params(role_params)

Build host:port peer_id from a role-scoped sub-dict, or None.

_remote_decoder_params(kv_params)

Return the remote_decoder sub-dict, or None if absent or null.

Set on prefiller requests to name the remote decoder they serve; carries kv_request_id. A present but non-dict value is treated as an empty dict so submit_store fails closed instead of storing locally.

_remote_kv_source_params(kv_params)

Return the remote_kv_source sub-dict, or None if absent.

Set on symmetric-P2P consumer requests to name the remote source they pull from; carries kv_request_id, remote_host, remote_port.

_remote_prefiller_params(kv_params)

Return the remote_prefiller sub-dict, or None if absent.

Set on decoder requests to name the remote prefiller they pull from; carries kv_request_id, remote_host, remote_port.