Repository navigation
perf(checkpoint): pipeline packed prefix writes through a TQ actor - #5176
Conversation
|
/ok to test 981376a |
macandro96
left a comment
There was a problem hiding this comment.
The core design is sound, and several choices are worth keeping as they are:
- One cut generator drives both the synchronous and the pipelined modes, so there is no second copy of the cut loop (the problem the #4508 review removed).
- No receipt is sent before the rows are durable, and keys that no receipt advertised are cleared on interruption.
- The writer client has the same
put_samples/clear_samplesinterface as the data-plane client, so the sink does not need to know about actors. - The direct encoder writes exactly the same rows as the general one, and 3,600 contended stress runs of the pipeline tests showed no flaky failures.
Must fix before merge
- (C1) CI Lint is red: one pyrefly error and import order in 3 test files.
- (C2) The 78 new tests run in no CI lane, because they lack the
nemo_gymmark.
How to organize this PR and remove the clutter
- (C3) Move the new keys into one block under
rollout_recovery, next to their siblings. This removes the 2 copied limits, the hand-written bool check, and the 6 YAML hunks. - (C6) Check each setup rule in one place instead of up to four (about 70 lines become about 25).
- (C7) Remove the benchmark timing code (about 110 lines) and keep prefix PUTs in the existing data-plane metrics.
- (C8) Move the writer actor into a stacked PR, so the encoder and pipeline can land first.
Together these remove about 200 lines and give each rule one home.
Other comments
- Behavior: (C4) resume fails when the new keys change before the first trainer checkpoint; (C5) the pipeline holds calls frozen for longer; (C10) a dead writer actor is never replaced; (C24) with the pipeline on, a call whose row goes over the byte limit is never checkpointed again.
- Smaller cleanups: (C9) writer startup timeout and error message, (C11) encoder split in the sink, (C12) copied key prefix, (C13) repeated column code, (C14) byte-estimate constants, (C15) module location.
- Comments and docs: (C16) and (C17) restore deleted explanations; (C18) name the required keys in the docs.
- Tests: (C19) expired prepared batch, (C20) byte limit and admission limit, (C21) encoder parity, (C22) writer startup failure, (C23) end-to-end coverage.
PR description
- Write "Part of #3594" under Issues (not "Closes"; the stack is not complete).
- Note that #4843 changes the same cut and route code on an older base, so whichever PR lands second needs to be ported onto the new generator.
Visual explainer: https://macandro96.github.io/gh-pages-poc/amahishi/pr-5176-prefix-writes.html
Generated by Claude Code
…ctors The class-per-everything version cost more than it saved: the prefix writer differs in owner, count, placement, transport and concurrency, and a pool and a common process() method had no generic caller. Keep only what the advantage actor and the rollout reassembler really share: - DataPlaneDelegate: owns the storage-lending client, names the actor in Ray logs, and holds the checkpoint and metrics hooks once. - start_cpu_actors: create, wait for a ready method, kill all on failure. - spread_off_head: the advantage actor's placement, now reusable. run/finalize keep their names, the controller keeps its queues, and the prefix writer is as in NVIDIA-NeMo#5176. Signed-off-by: Terry Kong <[email protected]>
981376a to
d42cf30
Compare
terrykong
left a comment
There was a problem hiding this comment.
Review of #5176 — pipelined prefix writes and the TQ writer actor
Two parts of the design work well: the generator protocol in _checkpoint_steps lets one code path serve both the sync cut and the pipeline, and the service/actor split lets the write order be unit-tested without Ray.
Before merge
- Two asks are for when the stack moves onto #4979: C14 (
run_cutdeadline) and the Dynamo half of C10. - CI has not run yet (copy-pr-bot vetting is pending), and the new path has no GPU run.
Scope. Written on 981376a3, then re-checked on the rebased head d42cf304 (+2,298/−60 on top of #4508's 46c9ea6c); inline links pin 981376a3. The rebase already fixed the ruff import-order failures.
Size. Together, the asks below remove about 560 lines (≈ 385 source, config and docs, ≈ 175 test), which brings the PR to about +1,720 and keeps every measured win. C17 could remove ≈ 290 more, depending on one measurement. If it is still too big, it splits cleanly: (A) direct encoder + pipeline, the bigger measured win (52 → 32 s, 108 → 81 s), then (B) the writer actor (32 → 25 s, 81 → 72 s).
Inline comments
- (C1) CI runs none of the 78 new data-plane tests; add the
nemo_gymmarker to both files. - (C2) Keep the NumPy byte views but shrink them to two helpers; replace
RayPrefixWriterClientwith a small wrapper. ≈ −130 source, −75 test. - (C3) Drop the timing fields, per-PUT logs and stats counters that only logs and tests read. ≈ −110 source, −20 test.
- (C8) Delete
_validate_keys, which can never fire. - (C9) Share one dense-or-jagged helper in
direct_prefix_batch.py. - (C10) Make the L1 prefix-recovery run fail if the writer actor never started; same for the Dynamo run after #4979.
- (C11) Put back the docstring paragraph that explains
deadline. - (C14) Let
run_cuttake the caller'sdeadlinein both branches, ready for #4979. - (C15) Drop the three settings and pick the new path automatically; keep the old path only for media and non-
simpleTQ backends. ≈ −120 source, config and docs, −65 test. - (C16) Rename
_checkpoint_steps/CutSteps/BatchReleasedfor what they hold. - (C17) Measure the direct encoder on its own; delete it if it does not pay for itself (≈ −290 more), otherwise make it the only text encoder.
- (C18) FYI only: the writer stays its own class; #5256 shares code between the two CPU actors already on main.
- (C19) With the actor always on, drop the pipeline's writer thread: send with
.remote()and use Ray's future.
Notes
- The benchmark rows are single runs.
timing/rollout_checkpoint/total_save_secondsover 3 or more runs per row would make the table firmer. - Cross-inventory merging and the 10 ms coalescing window have no number of their own. With 39 inventories per engine in the benchmark they may matter; could you share a with/without number? If they show no gain, dropping them removes ≈ 45 source + 30 test lines.
- Not from this PR: a stuck TQ PUT still has no timeout, as before. With the pipeline, more calls stay frozen while it waits.
Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-5176-who-calls-what.html
Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-5176-write-paths.html
Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-5176-what-can-shrink.html
Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-5176-one-actor-pattern.html
Generated by Claude Code
a56b00c to
6e59987
Compare
|
/ok to test 6e59987 |
Pull Request is not mergeable
Signed-off-by: Anish Mahishi <[email protected]>
The second round of prefix batched I/O review dropped `fail_multi_row` from the shared `_BatchPrefixSink` fake, but the write-pipeline test still sets it to force a batch failure and a one-row-at-a-time retry. The flag was silently ignored and `[batch]` failed on `len(sink.batches) > 1`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
- Move the prefix-write settings from policy.generation.vllm_cfg to rollout_recovery.prefix_writes (pipeline, writer_actor and the pipeline bounds), passed to setup_token_capture as a required argument. The pipeline now implies direct column encoding and takes its row and token limits from prefix_write_max_rows/prefix_write_max_tokens. - Check each setup rule once: buffer bound on the config model, token capture/prefix target/async vLLM and TQ simple in the SC validator, text-only capture in SC setup. Exclude the block from the bootstrap fingerprint. - Prepare at most one write ahead of the write in flight, so cut calls stay frozen for about two writes rather than the whole queue. - Write a row above max_batch_payload_bytes alone instead of refusing it, matching the non-pipeline path's handling of an oversized row. - Report the writer actor's data-plane counters with the worker's, and the pipeline's write counts under generation_prefix/pipeline_*; drop the timing-only fields and per-PUT log lines. - Fail a cut loudly when the writer actor dies, discarding its partial write through the local client; name the writer startup timeout and its cause. - Split the sink's prefix encoders, move the capture-mode codes and the generation-cut key prefix to schema.py, and make direct columns a TQTokenSink constructor argument. - Move the pipeline to prefix_recovery/write_pipeline.py. - Fix the pyrefly bad-return and mark the pipeline and writer tests nemo_gym so the Nemo_Gym lane runs them. - Add tests for expired, oversized, byte-split, admission-limit, mixed-group parity, dead-writer and writer-startup-failure paths, and a functional variant of the prefix-recovery parity test with the pipeline and writer actor on. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
…r actor Address the second round of review on the generation-prefix write path: - The write pipeline is the only path for generation-prefix cuts; its bounds are fixed module constants (PREFIX_WRITE_LIMITS) and the rollout_recovery.prefix_writes config is removed. - Prefix PUTs go through the CPU writer actor whenever the data plane is TransferQueue, on any backend; a local data plane writes in-process. The actor's client owns no shared-memory segment (segment_size=0). - Remove the direct column encoder; the sink keeps one prefix encoder. - Lift the text-only restriction: media capture cuts go through the pipeline and writer actor, with a row-parity test. - A failed batch write falls back to writing each row alone exactly once; a dead writer re-raises PrefixWriterDiedError. Signed-off-by: Anish Mahishi <[email protected]>
…n and its snapshot test Shutdown can run on a worker whose token-capture state was never built, as it already does for _prefix_recovery. The frontend-snapshot test's fake worker now carries _prefix_writer like a real one. Signed-off-by: Anish Mahishi <[email protected]>
6e59987 to
9d9d34e
Compare
|
/ok to test 9d9d34e |
…kind-advantages Brings in 8 commits, including the BaseModel environment configs (#5234), the BaseModel EvalConfig (#4909), the pipelined prefix writer (#5176) and the self-review status check (#5348). No conflicts. The two GRPO configs pick up main's new math verifier_type key next to this PR's masked_reward_policy comments. Main's ledger schema is still 8, so failure_kind stays in schema 9. The Gym pin is the same on both sides (9e2e5d0ad0). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Yi-Fu Wu <[email protected]>
What and why
Problem. At a rollout checkpoint, each vLLM engine cuts every unfinished model call it holds: it freezes the call, encodes its new tokens as a row, writes the rows to TransferQueue (TQ), and seals the call once the write is confirmed. Since #4508 this runs on one thread, one inventory at a time: prepare a batch, write it, wait, seal, then prepare the next. Preparation and writing never overlap, and every cut writes separately.
Change. Every generation-prefix cut now goes through a write pipeline, and on TQ the writes run in a separate CPU writer process.
write_pipeline.py). One prepare thread steps each inventory's cut, which keeps every call's freeze/seal on that thread. One write thread does one write at a time. Prepared batches from different inventories of the same checkpoint are merged into one write, withinrollout_recovery.prefix_write_max_rows/prefix_write_max_tokensand a byte bound. At most one write is prepared ahead of the write in flight, so only about two batches of calls are frozen at once. A row larger than the byte bound is written alone instead of being dropped.prefix_writer_actor.py). Withdata_plane.impl: transfer_queue(any backend), prefix PUTs run in a 1-CPU actor pinned to the engine's node. It needs one free Ray CPU there. A local data plane keeps writing in-process. Terminal writes and restore reads keep the worker's own client.PrefixWriterDiedError. Duplicate in-flight inventories share one result; inventories that share calls never prepare at the same time. Router-replay routes and media capture are supported.There is no new config. The pipeline's bounds are fixed in
PREFIX_WRITE_LIMITS: 128 pending inventories, 512 MiB buffered, 128 MiB per merged write, and a 10 ms window for merging. They are documented insingle-controller-rollout-checkpointing.md.Issues
Follow-up to #4508. Part of #3594.
Convergence / perf / functionality proof
Perf (single runs, earlier revision of this PR). 4 nodes: two TP4 generation engines, one TQ node, one driver node; router replay on,
max_num_seqs=512, 630 outstanding calls and 39 inventories per engine. Prefix cut + TQ save time only, not full rollout-checkpoint latency.These were measured before the direct column encoder was removed and the pipeline became the only path, so no row matches the code as it ships. The shipped path (pipeline + writer actor, one encoder) has not been re-benchmarked.
Functionality.
test_prefix_write_pipeline.py,test_prefix_writer_actor.py,test_vllm_token_capture_hosting.py.9d9d34e: 366 passed (default lane) and 320 passed (Gym lane) across those files,test_tq_token_sink.pyandtest_setup.py. pyrefly 1.4.0: 0 errors over main's baseline.9d9d34e: in progress.Needs upstream changes
None.
PR commands and CI
CI:Lfast: the default for most PRs. Runs a fast test subset.CI:L1: dependency or container changes (pyproject.toml,uv.lock,Dockerfile) or broad core changes. Builds a new image and runs unit and functional tests.CI:docs: docs-only changes. Runs doc tests only./ok to test <full-commit-sha>: start CI for that commit. Post again after each push./review: automated review comments. Addmode=strictfor a stricter review,reset=truefor a fresh full review./resolve-conflict: Autobot mergesmaininto this PR and resolves the conflicts. PRs from forks must allow edits by maintainers./review-pr-team <pr-number>for a team review before you ask for human review.🤖 Generated with Claude Code