[KV-events] block token_offset + sequence numbers + replay#1316
Open
bongwoobak wants to merge 1 commit into
Open
[KV-events] block token_offset + sequence numbers + replay#1316bongwoobak wants to merge 1 commit into
bongwoobak wants to merge 1 commit into
Conversation
Build on ROCm#869 so external KV-event consumers can align and trust the stream: - BlockStored.token_offset: sequence position of the run's first block, so a consumer maps block i to [token_offset + i*block_size, ...). - ZmqEventPublisher tags each batch with a monotonic sequence number and sends [topic, seq, payload]; subscribers can detect dropped batches as seq gaps. - Optional replay ROUTER socket + ring buffer: a subscriber requests missed batches by start sequence number (ATOM_KV_EVENTS_REPLAY_ENDPOINT). Wire change: PUB frames go from single-frame to [topic, seq, payload]; consumers must use recv_multipart(). Validated on MI300 (Qwen3-0.6B).
Contributor
There was a problem hiding this comment.
Pull request overview
Adds reliability and positioning metadata to KV-cache event publishing so external subscribers can detect missed batches, map blocks into token sequence space, and optionally recover gaps via replay.
Changes:
- Extend
BlockStoredwithtoken_offsetand plumb it throughBlockManagerand scheduler remote-store paths. - Change ZMQ PUB wire format to multipart
[topic, seq, payload]with a monotonic per-batch sequence number. - Add optional replay support via a ROUTER socket + in-memory ring buffer, configured by
ATOM_KV_EVENTS_REPLAY_ENDPOINT.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
atom/distributed/kv_events.py |
Adds token_offset field, multipart [topic, seq, payload] publishing, and replay socket/buffer support. |
atom/model_engine/block_manager.py |
Computes/emits token_offset for newly-stored runs and forwards it for remote-store events. |
atom/model_engine/scheduler.py |
Wires replay_endpoint into publisher construction and sets token_offset for remote-store emission. |
atom/utils/envs.py |
Adds ATOM_KV_EVENTS_REPLAY_ENDPOINT env var accessor. |
atom/config.py |
Extends KVEventsConfig with replay_endpoint and loads it from env. |
tests/test_kv_events.py |
Adds unit coverage for token_offset, multipart seq framing, and replay behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+295
to
+297
| seq = next(self._seq_gen) | ||
| seq_bytes = seq.to_bytes(8, "big") | ||
| self._socket.send_multipart([self._topic_bytes, seq_bytes, item]) |
Comment on lines
+404
to
+406
| sub.setsockopt(zmq.SUBSCRIBE, b"") | ||
| sub.connect(endpoint) | ||
| seqs: list[int] = [] |
Comment on lines
+430
to
+432
| sub.setsockopt(zmq.SUBSCRIBE, b"") | ||
| sub.connect(pub_ep) | ||
| for i in range(3): |
Comment on lines
+470
to
+472
| sub.setsockopt(zmq.SUBSCRIBE, b"") | ||
| sub.connect(pub_ep) | ||
| for i in range(4): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
#869 added KV-cache event publishing. To make the stream consumable by KV-aware
routers / caches, a consumer needs to (1) trust it didn't miss events and
(2) know where each block sits in the sequence.
What this adds
BlockStored.token_offset— sequence position of the run's first block, soa consumer maps block
ito[token_offset + i*block_size, ...).[topic, seq, payload]so subscribers can detect dropped batches as seq gaps.ATOM_KV_EVENTS_REPLAY_ENDPOINT): a ROUTER socket + ringbuffer lets a subscriber request missed batches by start sequence number.
Note
Wire change: PUB frames go from single-frame to
[topic, seq, payload];consumers must use
recv_multipart().token_offsetis a trailing field, sostrict vLLM
array_likeconsumers ignore it.Verification
tests/test_kv_events.py(token_offset, monotonic seq, replay-by-start_seq).token_offset=32on ashared-prefix extension, replay over TCP recovers
[0..3]and[2..3].