vllm.v1.kv_offload.tiering.p2p.session.protocol ¶
P2P KV cache sharing protocol constants and documentation.
Protocol Overview¶
Two session types communicate over a bidirectional message channel: - P2PClientSession (requests blocks from a server) - P2PServerSession (serves blocks to a client)
Connection Lifecycle¶
- Client opens a connection and sends ConnectMsg with its identity, RDMA metadata, memory layout, and config fingerprint.
- Server validates block_len and config_fingerprint, registers the RDMA peer, and replies with ConnectAckMsg.
- Client receives ConnectAckMsg and transitions to ready state (flushes any queued messages).
- Either side may send DisconnectMsg to gracefully close.
Block Transfer Flow (happy path)¶
- Client sends FetchMsg with a kv_request_id and lists of block keys + remote indexes where it wants the data written.
- Server matches requested blocks against locally stored blocks:
- Blocks already available are transferred immediately via RDMA.
- Blocks not yet available are recorded as "demanded" and transferred when the server later stores them.
- When all blocks for a kv_request_id are transferred, the server sends TransferDoneMsg (success=True) to the client.
- Client reports the load job as complete.
Abort Flow (timeout path)¶
- If the client times out waiting for TransferDoneMsg, it sends AbortFetchMsg to cancel the request.
- Server cancels inflight transfers for that kv_request_id and replies with AbortAckMsg.
- Client receives AbortAckMsg and reports the load job as failed.
- If AbortAckMsg itself times out, the client fails the job anyway.
Message Format¶
All messages are dicts serialized with msgpack. Every message has a TYPE_KEY key identifying its type. Additional fields depend on the message type (see per-message class docstrings below).
Security¶
Sessions wrap all incoming message handling in try/except to guard against malformed messages from adversarial or buggy peers. Invalid messages are logged and dropped without crashing the session.
The config_fingerprint field in ConnectMsg ensures peers have compatible model configurations (model, dtype, block sizes). Mismatches are rejected during the handshake.
Classes:
-
AbortAckMsg–Server → Client: acknowledge cancellation.
-
AbortFetchMsg–Client → Server: cancel a pending request.
-
ConnectAckMsg–Server → Client: handshake acknowledgement.
-
ConnectMsg–Client → Server: initial handshake request.
-
DisconnectMsg–Either → Either: graceful connection close.
-
FetchMsg–Client → Server: request blocks by key.
-
TransferDoneMsg–Server → Client: all blocks transferred for a request.
AbortAckMsg ¶
Server → Client: acknowledge cancellation.
Fields
KV_REQUEST_ID: The request that was cancelled.
Methods:
-
validate–Raise ValueError if any field has an invalid type or value.
Source code in vllm/v1/kv_offload/tiering/p2p/session/protocol.py
validate(msg) staticmethod ¶
AbortFetchMsg ¶
Client → Server: cancel a pending request.
Fields
KV_REQUEST_ID: The request to cancel.
Methods:
-
validate–Raise ValueError if any field has an invalid type or value.
Source code in vllm/v1/kv_offload/tiering/p2p/session/protocol.py
validate(msg) staticmethod ¶
Raise ValueError if any field has an invalid type or value.
ConnectAckMsg ¶
Server → Client: handshake acknowledgement.
Fields
PEER_ID: Server's peer identity string.
Methods:
-
validate–Raise ValueError if any field has an invalid type or value.
Source code in vllm/v1/kv_offload/tiering/p2p/session/protocol.py
validate(msg) staticmethod ¶
ConnectMsg ¶
Client → Server: initial handshake request.
Fields
PEER_ID: Local peer identity string. AGENT_METADATA: RDMA agent metadata (opaque bytes). BASE_ADDR: Base memory address of the KV block region. NUM_BLOCKS: Number of blocks in the KV block region. BLOCK_LEN: Size in bytes of each block (must match between peers). CONFIG_FINGERPRINT: SHA-256 prefix of the model configuration. Peers with different fingerprints are incompatible.
Methods:
-
validate–Raise ValueError if any field has an invalid type or value.
Source code in vllm/v1/kv_offload/tiering/p2p/session/protocol.py
validate(msg) staticmethod ¶
Raise ValueError if any field has an invalid type or value.
Source code in vllm/v1/kv_offload/tiering/p2p/session/protocol.py
DisconnectMsg ¶
Either → Either: graceful connection close.
No additional fields beyond TYPE_KEY.
Source code in vllm/v1/kv_offload/tiering/p2p/session/protocol.py
FetchMsg ¶
Client → Server: request blocks by key.
Fields
KV_REQUEST_ID: Identifies this block transfer request. BLOCK_HASHES: List of block keys (OffloadKey bytes). BLOCK_INDEXES: List of remote block indexes (same length as BLOCK_HASHES).
Methods:
-
validate–Raise ValueError if any field has an invalid type or value.
Source code in vllm/v1/kv_offload/tiering/p2p/session/protocol.py
validate(msg) staticmethod ¶
Raise ValueError if any field has an invalid type or value.
Source code in vllm/v1/kv_offload/tiering/p2p/session/protocol.py
TransferDoneMsg ¶
Server → Client: all blocks transferred for a request.
Fields
KV_REQUEST_ID: The request that completed. SUCCESS: Whether the transfer completed successfully.
Methods:
-
validate–Raise ValueError if any field has an invalid type or value.
Source code in vllm/v1/kv_offload/tiering/p2p/session/protocol.py
validate(msg) staticmethod ¶
Raise ValueError if any field has an invalid type or value.
_require(msg, key, typ, *, name='') ¶
Raise ValueError if msg[key] is missing or not isinstance(typ).
Source code in vllm/v1/kv_offload/tiering/p2p/session/protocol.py
_require_list(msg, key, *, name='') ¶
Raise ValueError if msg[key] is not a list.
Source code in vllm/v1/kv_offload/tiering/p2p/session/protocol.py
_require_non_neg_int(msg, key, *, name='') ¶
Raise ValueError if msg[key] is not a non-negative int.
Source code in vllm/v1/kv_offload/tiering/p2p/session/protocol.py
_require_pos_int(msg, key, *, name='') ¶
Raise ValueError if msg[key] is not a positive int.