vllm.distributed.kv_events
AllBlocksCleared
¶
Bases: KVCacheEvent
BlockRemoved
¶
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: Optional[KVEventsConfig],
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
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
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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 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 |
|
_event_queue
instance-attribute
¶
_event_queue = Queue[Optional[EventBatch]](
maxsize=max_queue_size
)
_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: Optional[str] = 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
|
Optional[str]
|
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 |
---|---|
Optional[str]
|
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.