Where a checkpoint cut's rows get built: in the engine, or in K writer actors next to it

PR #5469 ยท follows #5267 (its explainer) ยท permalinks pinned to head 27cd87fc and base dfe2dcd7

Before
At a cut, the vLLM engine process built every saved row's Gym records itself, on one thread, under the same Python lock that streams tokens. One CPU writer actor only did the final store write.
This PR
The engine only freezes each call and hands over its raw tokens. rollout_recovery.prefix_writers writer actors (default 1) build, encode and store the rows, splitting each write by row size.
Status
Speed-up, under review. Rows, digests and restores come out the same. The review asks for 3 test gaps closed, the real CPU count in the startup error, and docs that say the count is per HTTP frontend (links at the end).
Background. During an RL checkpoint, Gym asks each vLLM worker to save the tokens generated so far for every call still running: a generation-prefix cut. Each saved call becomes one TQ row. Building that row means making Gym's records, which is plain Python and grows with the call's whole prompt plus generated tokens. Dotted words have a short explanation: hover or tap them.
Why it should be faster. The slow part, building Gym's records, leaves the engine process and runs in K actors at once. Per call (16k prompt tokens, 4k generated), the PR measures: build records 4.8 ms (3.3 ms of it only to get the digest), encode 0.13 ms, and a new cost, sending the inputs to the actor, 0.7 ms. What does not change: freezing, sealing, the TQ write itself, and Gym's own checkpoint pause. When it is slower: at K = 1 one actor builds every row in turn, plus the hop, so small cuts get slower (median 0.388 s โ†’ 0.505 s); it pays off from K = 2 or on big cuts:
Benchmark (from the PR, one run each)BeforeK = 1K = 2K = 4
Long prompts, median cut, H1000.388 s0.505 s0.284 s0.181 s
Large MoE cuts, Dynamo, 2nd cut47.61 s15.85 sโ€”8.16 s
More writers is not always better: with 4 native frontends, K = 4 nearly doubled the first cut (7.15 s โ†’ 13.71 s).

The same 3 calls, before and after

Gym cuts 3 running calls. Their size (prompt plus generated tokens) is c1 = 40, c2 = 25, c3 = 20. On the right, prefix_writers = 2.

legend: new in this PR builds Gym's records (the slow part) one OS process Before (main) Gym: cut [c1, c2, c3] vLLM engine process (Ray actor, GPU) โ€” also streams tokens โ‘  cut thread: freeze + build records c1 โ†’ record(40 tok) + digest c2 โ†’ record(25 tok) + digest c3 โ†’ record(20 tok) + digest all 85 tokens' work on one engine thread โ‘ก writer thread: encode the batch 3 rows โ†’ byte columns + offsets (also in the engine process) โ‘ฃ seal each call, ack to Gym c1 โœ“ key k1, digest d1 c2 โœ“ key k2, digest d2 c3 โœ“ key k3, digest d3 PUT: keys, byte columns, tags writer actor (1 CPU, same node) โ‘ข put_samples โ†’ TQ stores only; builds nothing TQ W: k1, k2, k3 This PR, prefix_writers = 2 Gym: cut [c1, c2, c3] vLLM engine process (Ray actor, GPU) โ€” also streams tokens โ‘  cut thread: freeze โ†’ GenerationCutRow (no records built) c1, c2, c3 โ†’ raw ids + logprobs (+ route/top-k tensors) a call with no new tokens still builds its digest here โ‘ก writer thread: split by size, biggest first, to the less-loaded c1 (40) โ†’ w0 load w0 = 40 c2 (25) โ†’ w1 load w1 = 25 c3 (20) โ†’ w1 load w1 = 45 start both shares, then wait for both โ‘ฃ seal each call, ack to Gym (as before) c1 โœ“ k1, d1 (from w0) c2 โœ“ k2, d2 c3 โœ“ k3, d3 (from w1) results go back in the calls' order rows: ids, logprobs, tensors as NumPy bytes back: (key, digest) per row writer actor w0 (1 CPU, same node) โ‘ข build records, encode, PUT c1 โ†’ k1, d1 40 tokens of work writer actor w1 (1 CPU, same node) โ‘ข build records, encode, PUT c2, c3 โ†’ k2, d2, k3, d3 45 tokens of work, in parallel TQ W: k1 (w0); k2, k3 (w1)
QuestionAnswer
Who starts the writers, and where?Each engine's setup_token_capture starts K, pinned to its own node, each needing 1 free CPU. On native vLLM every HTTP frontend starts its own K, so N frontends use N ร— K CPUs.
What crosses to the actor?Each frozen call: its Gym call object, prompt and generated ids, logprobs, the new chunk, and route / top-k tensors as NumPy bytes (submit_generation_cut_rows). Back: each row's key and its call's digest.
What if a share fails?The pool waits for every started share, then the engine's own client clears all the batch's keys and retries each row alone. A dead writer fails the whole cut loudly, as before.
Local data plane?No actor: the worker's writer thread builds the rows itself, through the same functions. Setup rejects prefix_writers > 1 there.

The write path as pseudocode

Before (main)

# cut thread, engine process, one per worker
for call in inventory:
    row = next(cut_transaction(call))   # freeze; the call stays frozen
      #   inside: record = gym.build_prefix_record(...)  โ† slow, on this thread
    batch.add(row)                       # hand batch to the writer thread
# writer thread, engine process
keys = sink.stage_batch(records)       # encode here, then one PUT via the actor
for tx, key in zip(batch, keys):
    tx.send(key)                         # seal + ack (back on the cut thread)

After (this PR)

# cut thread, engine process
for call in inventory:
    row = next(cut_transaction(call))   # freeze only
      #   inside: record = gym.build_prefix_record(...)
      #   inside: row = GenerationCutRow(ids, logprobs, tensors)
    batch.add(row)
# writer thread, engine process
shares = split_by_size(batch, K)          # biggest first, to the less-loaded writer
refs = [w.submit(s) for w, s in shares]  # all K start at once
staged = [w.result(r) for ...]           # wait for every share, even after a failure
for tx, (key, digest) in zip(batch, staged):
    tx.send((key, digest))                # seal + ack, same as before
# each writer actor, its own process, 1 CPU
records = [gym.build_prefix_record(r) for r in share]   # the slow part, now here
keys = sink.stage_batch(records)         # encode + PUT
return [(key, prefix_digest) ...]

Real code: _cut_transaction, PrefixWritePipeline._write, PrefixWriterPool.stage_generation_cut_rows, stage_generation_cut_rows.

What the review asks

The design holds up: one build path for the local plane, the actor and the engine's digest, and a pool even at K = 1, so there is no separate one-writer path. The asks are about proving and explaining the new setting:

AskWhy
Test a writer that is already dead (fails at submit) (C1)Every pool test fails later, at result(); the "wait for every started share" promise has no test on the submit path.
Test that prefix_writers reaches the pool (C2)No test passes a value other than 1; the two new prefix_writers=2 L1 runs also pass with one writer.
Test the local-data-plane half of the setup check, and print what tripped it (C3)Only the "prefix cuts off" half is tested.
Name the setting and the real CPU count in the startup error (C4)It still says "needs 1 free CPU" when K writers start.
Say "per HTTP frontend" and when to raise K in the docs (C5)N frontends use N ร— K CPUs; K = 1 makes small cuts slower.

C1 โ€” test_prefix_writer_actor.py:671C2 โ€” test_prefix_writer_actor.py:445C3 โ€” setup.py:1580C4 โ€” prefix_writer_actor.py:390C5 โ€” single-controller-rollout-checkpointing.md:99

So what. Moving the record build out of the engine is a real win on big cuts, and it frees the thread that streams tokens. Keep prefix_writers = 1 unless cuts are large or generation_prefix/pipeline_write_us dominates the cut, and budget one CPU per writer per HTTP frontend.