vllm.distributed.kv_events ¶
AllBlocksCleared ¶
Bases: KVCacheEvent
BlockRemoved ¶
Bases: KVCacheEvent
Source code in vllm/distributed/kv_events.py
BlockStored ¶
Bases: KVCacheEvent
Source code in vllm/distributed/kv_events.py
EventBatch ¶
Bases: Struct
Source code in vllm/distributed/kv_events.py
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.
Source code in vllm/distributed/kv_events.py
publish abstractmethod ¶
publish(events: EventBatch) -> None
Emit events in order.
Implementations should guarantee at-least-once delivery and monotonic ordering (e.g., via sequence numbers).
EventPublisherFactory ¶
Source code in vllm/distributed/kv_events.py
_registry class-attribute instance-attribute ¶
_registry: dict[str, Callable[..., EventPublisher]] = {
"null": NullEventPublisher,
"zmq": ZmqEventPublisher,
}
create classmethod ¶
create(
config: KVEventsConfig | None,
data_parallel_rank: int = 0,
) -> EventPublisher
Create publisher from a config mapping.
Source code in vllm/distributed/kv_events.py
register_publisher classmethod ¶
register_publisher(
name: str, ctor: Callable[..., EventPublisher]
) -> None
KVCacheEvent ¶
Bases: Struct
Base class for all KV cache-related events
KVConnectorKVEvents ¶
Bases: ABC
Abstract base class for KV events. Acts as a container for KV events from the connector.
Source code in vllm/distributed/kv_events.py
add_events abstractmethod ¶
add_events(events: list[KVCacheEvent]) -> None
aggregate abstractmethod ¶
aggregate() -> KVConnectorKVEvents
clear_events abstractmethod ¶
get_all_events abstractmethod ¶
get_all_events() -> list[KVCacheEvent]
KVEventAggregator ¶
Aggregates KV events across multiple workers. Tracks how many times each event appears and returns only those that were emitted by all workers.
Source code in vllm/distributed/kv_events.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
add_events ¶
add_events(events: list[KVCacheEvent]) -> None
Add events from a worker batch.
:param events: List of KVCacheEvent objects.
Source code in vllm/distributed/kv_events.py
clear_events ¶
get_all_events ¶
get_all_events() -> list[KVCacheEvent]
Return all events for all workers.
:return: List of events for all workers.
get_common_events ¶
get_common_events() -> list[KVCacheEvent]
Return events that appeared in all workers.
:return: List of events present in all workers.
Source code in vllm/distributed/kv_events.py
KVEventBatch ¶
NullEventPublisher ¶
Bases: EventPublisher
No-op implementation (default when disabled).
Source code in vllm/distributed/kv_events.py
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: PUB address. Use tcp://*:5557 to bind or tcp://host:5557 to connect. replay_endpoint: 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: Number of past batches to keep for replay. hwm: ZeroMQ high-water-mark for PUB socket. max_queue_size: Maximum number of events to buffer in memory. topic: Topic to publish events to.
Source code in vllm/distributed/kv_events.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 | |
_replay_endpoint instance-attribute ¶
_thread instance-attribute ¶
_thread = Thread(
target=_publisher_thread,
daemon=True,
name="zmq-publisher",
)
__init__ ¶
__init__(
data_parallel_rank: int,
endpoint: str = "tcp://*:5557",
replay_endpoint: str | None = None,
buffer_steps: int = 10000,
hwm: int = 100000,
max_queue_size: int = 100000,
topic: str = "",
) -> None
Source code in vllm/distributed/kv_events.py
_publisher_thread ¶
Background thread that processes the event queue.
Source code in vllm/distributed/kv_events.py
_service_replay ¶
If a replay request is waiting, send buffered batches.
Source code in vllm/distributed/kv_events.py
_socket_setup ¶
Initialize sockets https://pyzmq.readthedocs.io/en/v19.0.0/morethanbindings.html#thread-safety
Source code in vllm/distributed/kv_events.py
offset_endpoint_port staticmethod ¶
Helper function to offset the port in an endpoint by the data parallel rank.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint | str | None | The endpoint string (e.g., "tcp://*:5557" or "inproc://cache") | required |
data_parallel_rank | int | The data parallel rank to offset by | required |
Returns:
| Type | Description |
|---|---|
str | None | The endpoint with the port offset by data_parallel_rank or suffix appended |
Source code in vllm/distributed/kv_events.py
publish ¶
publish(events: EventBatch) -> None
shutdown ¶
Stop the publisher thread and clean up resources.