Repository navigation
pd: stream RNGD prefill KV layers into Torch and ATOM decode (opt-in) (#265) - #287
Merged
Merged
Conversation
…#265) Port the library and test parts of #266 onto optimus-rm: - layer_progress.LayerProgress: validated, non-overlapping per-layer token coverage of a reserved slab; finish() requires complete coverage. - PagedKV.write_layer_span: import a model-layer subset into reserved pages without publishing length/prefix/state. - SubprocessPrefillWorker(stream_layers=True): requires producer capability kv_progress=1, accepts {id, kv_span} messages, exposes future.kv_progress. - PDBatcher and AtomBatcher import published spans while the producer runs and admit only after completion and full coverage. - prefill_server: stream_result() writes validated spans into the slab before notifying; _RngdFull.prefill_stream; --engine factory loader. - serve_batched.py --pd-prefill-stream-layers (off by default). From #266 commits 42f59c3, 8e0d271, 952f491, 171e8c4 (prefill_server.py and test_prefill_factory.py only), 33d6cb0, 69180aa. The #254 chunk-copy code (_ChunkCopy, --pd-prefill-copy-overlap and its test) is stripped; streaming_factories.py, STREAMING.md evidence and scripts are not taken. Refs #265 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Layer streaming carries attention KV only, not linear-attention state, so PDBatcher imported nothing until the first span and then raised. Reject the combination when it is configured instead: PDBatcher with a stream_layers worker over a recurrent cache, SubprocessPrefillWorker(stream_layers=True, recurrent_state=True) before it allocates the slab or spawns, and serve_batched.py --pd-prefill-stream-layers for a recurrent model before the producer starts. The import-time check stays as a guard for other producers. Refs #265 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…st (#265) Add a short STREAMING.md design note: protocol, decode-side invariants, and the measured attribution. The notification-delay control kept most of the completion-time gain (22.7/19.6/2.8/21.3%) while early sending added only 4.6/3.0/0.4/1.7%, so the gain comes from the research factories' slower whole-result export, not overlap. State in --engine-factory help and the factory_engine docstring that it is a trusted research flag that imports arbitrary module:callable code and loads the checkpoint as fp32 on the host. Refs #265 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Background
PD with a subprocess prefill producer (RNGD through
prefill_server) transfers the whole prompt KV after prefill finishes. #265 / #266 add an opt-in path: the producer exports KV one layer or layer group at a time into the shared-memory slab, and the Torch or ATOM decoder imports each finished span. The decoder publishes cache length and prefix state only after full coverage.This PR lands the library and test part of #266 on current
optimus-rm, plus three review fixes.Changes
Commit 1 (port). From #266 (branch
perf/265-rngd-stream), path-limited and resolved againstoptimus-rm:pd/layer_progress.py(LayerProgress);PagedKV.write_layer_spaninpaged.py;tests/test_pd_layer_progress.pypd_batching.py:_KVProgress,SubprocessPrefillWorker(stream_layers=)(capabilitykv_progress: 1,kv_spanmessages), PDBatcher partial import and wake-up event;layer_progress.pypending/finished;tests/test_pd_stream_admission.py,tests/test_subprocess_layer_progress.pyprefill_server.py:_RngdFull.prefill_stream,_last_logits,stream_result, ready capability,stream_layersrequest handling;serve_batched.py --pd-prefill-stream-layers;tests/test_prefill_source_progress.py; layer-stream tests intests/test_serving_prefill_cache.pyprefill_server.py(factory_engine,--engine factory,--engine-factory,prefill(list(tokens))) andtests/test_prefill_factory.pyatom/batching.py: streamed import through the ATOM owner (reserved lane, B1 prefetch waits for the lane, hybrid/multi-lane deferral);serve_batched.pyallows--backend atom;tests/test_atom_stream_progress.py;test_serving_prefill_cache.pyparametrizationtests/test_atom_stream_progress.py(partial-prefetch faults)Not taken:
optimus-rm: 8903b73 (= fix: map dense subprocess KV into hybrid GPU cache groups #258 / pd: import dense subprocess KV into hybrid GPU cache groups (#258) #283) and 2e69570 (= Prefill one queued request during single-lane ATOM decode #255 / atom: prefill one queued request during B1 remote-only decode (#253) #285)._ChunkCopy,TorchPrefillEngine(copy_overlap=),--pd-prefill-copy-overlap,test_copy_overlap_rejects_unsupported_route_before_model_load, and theThreadPoolExecutorimport. These were stripped while resolving conflicts.examples/pd/streaming_factories.pyandtests/test_streaming_factories.py. They import theserving_matrix/qwen3_rngdexample modules, which are not onoptimus-rm.http_matrix/evidence, experiment records, evidence scripts and the docs-only commits.Commit 2 (review: recurrent models fail early). Layer streaming carries attention KV only. Before this commit, a recurrent (linear-attention) model failed at the first span import. It is now rejected at setup:
PDBatcher.__init__rejects astream_layersworker over a cache withrstate.SubprocessPrefillWorker(stream_layers=True, recurrent_state=True)raises before it allocates the slab or spawns.serve_batched.pyprefill_workerrejects--pd-prefill-stream-layerswhendescribe_model(config).recurrentis set, before the producer starts.kv_progresswithoutstream_layers.tests/test_pd_stream_recurrent.py.Commit 3 (review: docs).
--engine-factoryhelp text and thefactory_enginedocstring now say it is a trusted research flag (it imports and calls anymodule:callablefromPYTHONPATH), and that it loads the whole checkpoint into host memory as fp32 first (4 bytes per parameter, about 32 GB for 8B).examples/pd/STREAMING.mdis cut down to a short design note: protocol, decode-side invariants, and the measurement attribution below.Verification
Targeted files only. CUDA cases run on one GPU; full suite: CI.
qwen3_5), 3 failed. The failures are the CUDA cases oftest_pd_stream_admission.py, with an InductorNoValidChoicesErrorin flex-attention. A plain whole-KV CUDA Gemma3PDBatcheron unmodified code fails the same way under that torch, so the cause is the environment, not this change.test_pd_stream_recurrent.pyfail (no raise, unknownrecurrent_statekeyword, producer started). After it, they pass.optimus-rmcode (pd: import dense subprocess KV into hybrid GPU cache groups (#258) #283 dense-hybrid import,ProcessPrefillWorker.ready, subprocess close order).Compatibility and limits
--pd-prefill-stream-layers/stream_layers=True, the whole-KV path is unchanged.kv_progress: 1(in-tree:--engine rngd-full, or a trusted--engine factorycallable) and a Torch or ATOM decoder. Same-host shared memory only; no cross-host streaming.Related Issue
Refs #265
Refs #47
Supersedes #266 (library part)
🤖 Generated with Claude Code