vllm.distributed.kv_events
¶
Classes:
-
BlockRemoved– -
BlockStored– -
EventPublisher–Lightweight publisher for EventBatch batches with data parallelism
-
EventPublisherFactory– -
KVCacheEvent–Base class for all KV cache-related events.
-
KVConnectorKVEvents–Abstract base class for KV events.
-
KVEventAggregator–Aggregates KV events across multiple workers.
-
NullEventPublisher–No-op implementation (default when disabled).
-
ZmqEventPublisher–Reliable PUB/ROUTER publisher with an in-memory replay buffer.
BlockRemoved
¶
Bases: KVCacheEvent
Attributes:
BlockStored
¶
Bases: KVCacheEvent
Attributes:
-
block_size(int) –Deprecated: use
lora_namefor KV block key hash. -
extra_keys(list[tuple[Any, ...] | None] | None) –Store events carry cache-spec metadata so consumers can classify and
-
kv_cache_spec_sliding_window(int | None) –LOCAL or REMOTE relative to the publisher; None means unspecified.
-
locality(str | None) –Secondary offloading tier identifier, if generated by one.
-
lora_name(str | None) –Extra keys used in block hash computation, one entry per block in
-
ownership(str | None) –Session that triggered this store or reuse report.
-
session_id(str | None) –Tokens beyond each block used in its hash, one list per block_hashes entry.
block_size
instance-attribute
¶
Deprecated: use lora_name for KV block key hash.
Retained for backward compatibility.
extra_keys = None
class-attribute
instance-attribute
¶
Store events carry cache-spec metadata so consumers can classify and filter groups as they are learned. Remove events only need group_idx+hash.
kv_cache_spec_sliding_window = None
class-attribute
instance-attribute
¶
LOCAL or REMOTE relative to the publisher; None means unspecified.
locality = None
class-attribute
instance-attribute
¶
Secondary offloading tier identifier, if generated by one.
lora_name
instance-attribute
¶
Extra keys used in block hash computation, one entry per block in
block_hashes. Each entry contains, in order, the LoRA name (if
lora_name is set), (mm_identifier, offset) pairs, the cache_salt
string and prompt embedding digests for that specific block. These are
published untagged; the block hash itself uses each value tagged with
its source, e.g. ("lora", name) or ("mm", mm_identifier, offset).
ownership = None
class-attribute
instance-attribute
¶
Session that triggered this store or reuse report.
This identifies the request context that emitted the event, not exclusive ownership of the underlying block, which may be shared across sessions.
session_id = None
class-attribute
instance-attribute
¶
Tokens beyond each block used in its hash, one list per block_hashes entry. None when lookahead hashing is disabled.
EventPublisher
¶
Bases: ABC
Lightweight publisher for EventBatch batches with data parallelism support.
In data parallel setups, each DP rank runs its own EventPublisher instance to avoid duplicate events and ensure proper event attribution:
- Each DP rank creates a separate publisher
- Publishers automatically annotate events with their data_parallel_rank
- This allows consumers to distinguish events from different DP ranks
The publisher is responsible for adding DP metadata since the scheduler operates independently of DP topology and shouldn't need DP awareness.
Methods:
-
get_publisher_config–Return the publisher's resolved runtime configuration.
-
publish–Emit events in order.
-
shutdown–Shutdown the publisher.
EventPublisherFactory
¶
KVCacheEvent
¶
Bases: Struct
Base class for all KV cache-related events.
KVConnectorKVEvents
¶
KVEventAggregator
¶
Aggregates KV events across multiple workers. Tracks how many times each event appears and returns only those that were emitted by all workers.
Methods:
-
add_events–Add events from a worker batch.
-
clear_events–Clear all tracked events.
-
get_all_events–Return all events for all workers.
-
get_common_events–Return events that appeared in all workers.
-
get_number_of_workers–Return the number of workers.
-
increment_workers–Increment the number of workers contributing events.
-
reset_workers–Reset the number of workers to 1.
add_events(events)
¶
Add events from a worker batch.
Parameters:
-
(events¶list[KVCacheEvent]) –List of KVCacheEvent objects.
clear_events()
¶
Clear all tracked events.
get_all_events()
¶
get_common_events()
¶
Return events that appeared in all workers.
Returns:
-
list[KVCacheEvent]–List of events present in all workers.
increment_workers(count=1)
¶
reset_workers()
¶
Reset the number of workers to 1.
NullEventPublisher
¶
ZmqEventPublisher
¶
Bases: EventPublisher
Reliable PUB/ROUTER publisher with an in-memory replay buffer.
Spawns a separate thread to handle publishing from a queue.
Parameters:
-
(endpoint¶str, default:'tcp://*:5557') –PUB address. Use
tcp://*:5557to bind ortcp://host:5557to connect. -
(replay_endpoint¶str | None, default:None) –Optional ROUTER address for replay requests. When given, subscribers can request missed batches by sending the starting sequence number as an 8-byte big-endian integer.
-
(buffer_steps¶int, default:10000) –Number of past batches to keep for replay.
-
(hwm¶int, default:100000) –ZeroMQ high-water-mark for PUB socket.
-
(max_queue_size¶int, default:100000) –Maximum number of events to buffer in memory.
-
(topic¶str, default:'') –Topic to publish events to.
Methods:
-
offset_endpoint_port–Helper function to offset the port in an endpoint by
-
shutdown–Stop the publisher thread and clean up resources.
_bind(sock, endpoint)
staticmethod
¶
Bind; tcp://*:0 binds this node's IP and returns the bound endpoint.
_is_bind_endpoint(endpoint)
staticmethod
¶
Bind wildcard and ipc/inproc endpoints; connect to the rest.
_publisher_thread()
¶
Background thread that processes the event queue.
_service_replay()
¶
If a replay request is waiting, send buffered batches.
_socket_setup()
¶
Initialize sockets https://pyzmq.readthedocs.io/en/v19.0.0/morethanbindings.html#thread-safety
offset_endpoint_port(endpoint, data_parallel_rank)
staticmethod
¶
Helper function to offset the port in an endpoint by the data parallel rank.
Parameters:
-
(endpoint¶str | None) –The endpoint string (e.g., "tcp://*:5557" or "inproc://cache")
-
(data_parallel_rank¶int) –The data parallel rank to offset by
Returns:
-
str | None–The endpoint with the port offset by data_parallel_rank or suffix appended; a tcp port of 0 is left for the OS.
shutdown()
¶
Stop the publisher thread and clean up resources.