Skip to content

vllm.v1.kv_offload.tiering.p2p.data

Modules:

  • base –

    Abstract base class for the P2P data-plane transport.

  • nixl –

    NixlTransport: Data-plane transport for RDMA-based KV block transfers via NIXL.

Classes:

  • DataTransport –

    Abstract data-plane transport for RDMA-style block transfers.

  • NixlTransport –

    Manages a NIXL agent, memory registration, and block transfers.

  • PollResult –

    Result of polling inflight transfers.

DataTransport

Bases: ABC

Abstract data-plane transport for RDMA-style block transfers.

Owns the local KV block memory region and manages transfers to/from registered remote peers.

Construction

view: A 2D memoryview (num_blocks × block_len bytes) over the local KV cache block storage. config_fields: Dict of model config values used to compute the compatibility fingerprint. None → empty fingerprint (compatible with any peer).

Methods:

  • add_remote_peer –

    Register a remote peer for block transfers.

  • add_remote_peer_async –

    Register a remote peer without blocking the caller.

  • cancel –

    Cancel inflight transfers by their IDs.

  • close –

    Release all resources (registrations, handles, memory).

  • force_release_retired –

    Release retired transfers that have not stopped.

  • get_agent_metadata –

    Return opaque metadata needed by remote peers to connect.

  • poll –

    Poll inflight transfers for completion.

  • poll_retired –

    Release retired transfers that have stopped; return their ids.

  • remove_remote_peer –

    Unregister a remote peer and release associated resources.

  • write_blocks –

    Submit a WRITE transfer: local blocks → remote peer's blocks.

Attributes:

base_addr property

Base address of the local block memory region.

block_len property

Size of each block in bytes.

config_fingerprint property

Content-hash of the model configuration (hex string).

Peers must have matching fingerprints to exchange blocks. Empty string means no fingerprint (always compatible).

num_blocks property

Number of blocks in the local region.

add_remote_peer(peer_id, agent_metadata, base_addr, num_blocks, block_len) abstractmethod

Register a remote peer for block transfers.

Must be called before write_blocks() to this peer.

Parameters:

  • peer_id

    (str) –

    Unique identifier for the remote peer.

  • agent_metadata

    (bytes) –

    Opaque bytes from the peer's get_agent_metadata().

  • base_addr

    (int) –

    Base address of the peer's block memory region.

  • num_blocks

    (int) –

    Number of blocks in the peer's region.

  • block_len

    (int) –

    Size of each block (must match local block_len).

add_remote_peer_async(peer_id, agent_metadata, base_addr, num_blocks, block_len)

Register a remote peer without blocking the caller.

Registration is O(num_blocks) and can take seconds for a large secondary tier, so the session starts it here and sends ConnectAckMsg only once the returned future resolves. The acknowledgement is therefore the peer's guarantee that this side is ready to serve, and no write_blocks can arrive before it.

The default implementation runs add_remote_peer inline and returns an already-resolved future; transports whose registration is cheap need not override it.

Parameters:

  • peer_id

    (str) –

    Unique identifier for the remote peer.

  • agent_metadata

    (bytes) –

    Opaque bytes from the peer's get_agent_metadata().

  • base_addr

    (int) –

    Base address of the peer's block memory region.

  • num_blocks

    (int) –

    Number of blocks in the peer's region.

  • block_len

    (int) –

    Size of each block (must match local block_len).

Returns:

  • Future[None] –

    A future resolving to None on success. A failed future means

  • Future[None] –

    the peer must be rejected rather than acknowledged.

cancel(transfer_ids, mode='immediate') abstractmethod

Cancel inflight transfers by their IDs.

Best-effort: transfers that already completed are ignored.

Parameters:

  • transfer_ids

    (Iterable[int]) –

    IDs to cancel. Unknown IDs are ignored.

  • mode

    (CancelMode, default: 'immediate' ) –

    "immediate" (default): pop and release each handle and return []. Matches the legacy fire-and-forget behavior — the caller does not wait for the underlying transfer to drain. "wait": release only transfers that have stopped. A transfer still PROC/PEND (or whose release fails) stays in the inflight set and its id is included in the returned list. The caller is expected to keep calling poll() until every returned id surfaces in done/failed.

Returns:

  • list[int] –

    For mode="wait", the subset of transfer_ids still

  • list[int] –

    tracked as inflight after the cancel attempt. For

  • list[int] –

    mode="immediate", always [].

close() abstractmethod

Release all resources (registrations, handles, memory).

Cancels any remaining inflight transfers. Idempotent. After close(), no other methods may be called.

force_release_retired(transfer_ids)

Release retired transfers that have not stopped.

Unsafe while one may still be writing; for a bounded hold only.

get_agent_metadata() abstractmethod

Return opaque metadata needed by remote peers to connect.

The returned bytes are sent during the control-plane handshake and passed to the remote peer's add_remote_peer().

poll(peer_id=None) abstractmethod

Poll inflight transfers for completion.

Parameters:

  • peer_id

    (str | None, default: None ) –

    If given, only poll (and drain) transfers submitted for this peer_id — the value passed to write_blocks. This is required when a single transport is shared across multiple peer sessions: poll() pops completed handles, so an unscoped poll by one session would consume and discard the completions of its siblings, starving them. None polls every peer's transfers (used only for the shutdown drain).

Returns:

  • PollResult –

    PollResult with lists of completed and failed transfer_ids.

  • PollResult –

    Completed/failed transfers are removed from the inflight set.

Must be called periodically to drive progress checking.

poll_retired()

Release retired transfers that have stopped; return their ids.

Must be called periodically while any transfer is retired. The default transport retires nothing.

remove_remote_peer(peer_id) abstractmethod

Unregister a remote peer and release associated resources.

Transfers to this peer still inflight are retired, not released (see "Failure model"); the peer's registration is released once they have stopped.

write_blocks(peer_id, local_idxs, remote_idxs) abstractmethod

Submit a WRITE transfer: local blocks → remote peer's blocks.

Parameters:

  • peer_id

    (str) –

    Target peer (must be registered via add_remote_peer).

  • local_idxs

    (list[int]) –

    Indexes of local blocks to read from.

  • remote_idxs

    (list[int]) –

    Indexes of remote blocks to write to. Must be same length as local_idxs.

Returns:

  • int | None –

    A unique transfer_id (int) to track this transfer, or

  • int | None –

    None if the peer is not registered or submission failed.

NixlTransport

Bases: DataTransport

Manages a NIXL agent, memory registration, and block transfers.

Wraps the NIXL C library behind a Python interface so the rest of the P2P tier code never touches NIXL types directly. Tracks inflight handles internally and returns completed/failed tags on poll.

Methods:

  • cancel –

    Cancel inflight transfers by their IDs.

  • force_release_retired –

    Release retired transfers that never stopped (bounded hold).

  • poll –

    Poll inflight transfers.

  • poll_retired –

    Release retired transfers that have stopped; return their ids.

  • write_blocks –

    Submit a WRITE transfer to peer_id.

_begin_registration(peer_id)

Claim the next registration generation for peer_id.

_build_peer_handles(peer_id, agent_metadata, base_addr, num_blocks, block_len)

The expensive half: agent wireup plus one descriptor per block.

Holding the peer lock across native registration would stall the scheduler thread for exactly as long as the registration it is meant to move off that thread.

_publish_peer(peer_id, gen, nixl_name, remote_dlist)

Install freshly built handles, unless gen is stale.

Returns False when the peer was removed or re-registered while the handles were being built; the handles are released here since nothing else ever saw them.

_record_failure(peer_id, exc)

Classify a NIXL exception: a peer fault, or one strike.

_record_state_check_failure(peer_id, exc)

Fault peer_id for a check_xfer_state that raised.

The bindings raise for every NIXL error status (only success and in-progress are returned), so a raise is a failure NIXL reported, not a flaky check. A peer whose transfer state can't be trusted is torn down rather than given strikes: with strikes, successes to the same peer could keep resetting them while the transfer stays inflight, holding its pins, for good.

_release_remote_handles(peer_id, dlist, nixl_name)

Release a peer's descriptor list and remote agent independently.

The two teardown operations are independent: NIXL may reject one after a transport failure, and a release_dlist_handle that raises must not skip remove_remote_agent. Skipping it would leave a stale remote registration behind after the peer is gone (peer removal) or after its registration was superseded.

cancel(transfer_ids, mode='immediate')

Cancel inflight transfers by their IDs.

See DataTransport.cancel for the contract. In "wait" mode, a transfer is released only once NIXL reports it terminal. Releasing a PROC/PEND handle does not stop the WRITE: the UCX backend frees the request without cancelling RMA, and the bytes keep landing. So PROC/PEND transfers, and those whose state check or release_xfer_handle raises, stay in self._inflight for a later poll() to observe. A state check that raises faults the peer; only a remote disconnect also counts as terminal (see _is_terminal_state_error).

force_release_retired(transfer_ids)

Release retired transfers that never stopped (bounded hold).

poll(peer_id=None)

Poll inflight transfers.

When peer_id is given, only transfers submitted for that peer_id are checked and drained — the transport is shared across peer sessions, so an unscoped poll by one session would consume and discard siblings' completions. peer_id None polls every peer (shutdown drain only).

Returns PollResult(done=..., failed=..., peer_fault=...) with transfer IDs. Completed handles are released automatically. peer_fault is set on a scoped poll once peer_id is faulted.

poll_retired()

Release retired transfers that have stopped; return their ids.

A transfer stopped once NIXL reports it terminal, by the same rule as cancel(mode="wait"), but without charging its peer: the peer is gone, and a reconnected one under the same id is not at fault. A removed peer's remote handles are released once none of its retired transfers remain.

write_blocks(peer_id, local_idxs, remote_idxs)

Submit a WRITE transfer to peer_id.

Returns a transfer ID, or None if the peer is not registered or submission fails. The ID is returned via poll() when the transfer completes or fails.

PollResult

Bases: NamedTuple

Result of polling inflight transfers.

Attributes:

  • done (Sequence[int]) –

    Transfer IDs that completed successfully.

  • failed (Sequence[int]) –

    Transfer IDs that failed (error, timeout, etc.).

  • peer_fault (str | None) –

    Set only on a peer-scoped poll() once the transport has judged the peer unusable (see "Failure model"); a short human-readable cause. None while the peer is healthy.