Who calls what in #5176: a new CPU actor next to each vLLM worker does the prefix TQ writes

NVIDIA-NeMo/RL #5176, part 11 of 11 in the partial-checkpointing stack. Own commit only: 788133a..981376a (also on a mirror PR that shows just this diff). Permalinks pin 981376a; "before" links pin 788133a.

Before
The vLLM worker process cuts the calls, encodes the rows and writes them to TQ itself, with its own in-process TQ client, on one control thread.
This PR
Adds a prepare thread and a writer thread inside the worker, and an optional CPU-only Ray actor on the same node that does only the prefix writes.
Status
New, off by default. Review open: the shape is sound; the review asks to make it the default with no settings (C15) and to shrink the hop to the actor (C2).

Four pages on this PR. This one: which process and which class does each step, and what crosses each boundary.

Background. At a checkpoint, Gym sends each vLLM worker an inventory. The worker freezes each call, builds one row of tokens per call, writes the rows to TQ, and only after TQ confirms does it seal the rows and answer Gym. Dashed boxes are OS processes; solid boxes inside are the classes that run each numbered step. Dotted words have a short explanation: hover or tap them.

Processes and classes, before and after

Before (#4508) one control thread does everything Gym process sends the inventory: 5 calls (example), POST generation cut vLLM worker process (Ray actor, GPU) × N PrefixRecovery.run_cut ① hands the inventory to the single control thread control thread: checkpoint_cut → _cut_batched ② freeze each call (holds its lock), build 5 rows ⑤ after the write: seal 5 rows, receipt back to Gym TQTokenSink.stage_generation_prefix_batch ③ _encode_record per row → stack into one TensorDict ④ TQStagingStore.put_many → this process's TQ client PrefixReadBatcher (restore reads) + terminal writes same TQ client, same process TQDataPlaneClient (in-process object, one per worker) built by build_data_plane_client in setup_token_capture TQ: controller + SimpleStorage unit actors units are spread over the nodes; clients reach them directly W: prefix rows, terminal rows, both from the worker R: restore R / W, all from the worker This PR (pipeline + writer actor on) prepare and write overlap; the TQ write leaves the worker Gym process same inventory, same 5 calls vLLM worker process (Ray actor, GPU) × N PrefixRecovery.run_cut → PrefixWritePipeline.submit ① queue the inventory; a repeated inventory shares one result prepare thread: _advance → _checkpoint_steps (generator) ② freeze calls, build 5 rows, pause at yield PrefixWrite ⑤ _complete: keys go back in, seal, receipt to Gym writer thread: _write → TQTokenSink.stage_generation_prefix_batch ③ merge rows of several inventories; encode_prefix_groups RayPrefixWriterClient.put_samples: pack_columns, ray.put then ray.get: this thread waits for the actor's reply PrefixReadBatcher (restore reads) + terminal writes unchanged: still the worker's own TQ client TQDataPlaneClient (worker's own) no longer used for prefix PUTs when the actor is on setup_token_capture → create_prefix_writer: starts the actor once PrefixWriterActor process (Ray actor, 1 CPU, 0 GPU) pinned to the worker's node: NodeAffinity, soft=False PrefixWriterService.put → unpack_columns ④ its OWN TQDataPlaneClient.put_samples (a second client) one call at a time (max_concurrency=1), no retries PrefixPut via Ray's object store: keys, NumPy byte columns + offsets, tags reply: PrefixWriteReply (keys + timings) TQ: controller + SimpleStorage unit actors W: prefix rows (from the actor) + terminal rows (worker) R: restore, still from the worker W prefix rows existing class new in this PR OS process

Your questions, answered from the code

QuestionAnswer
Who starts the writer actor?The vLLM worker itself, once, in setup_token_capture, and only on the worker that owns the model, when prefix_writer_actor: true. It is not a detached actor, so the worker that made it owns it; the worker kills it at shutdown.
Isn't there already a TQ client actor on every node?No. TQ's own actors are the controller and the storage units. A TQ client is a plain object inside each process that uses TQ: the worker builds one with build_data_plane_client. The writer actor builds a second client in its own process (L272).
What crosses the boundary?A PrefixPut: the row keys, the partition name, every column as a flat NumPy byte buffer (plus dtype, shape, and row offsets for ragged columns), and the per-row tags. For the 5-row example: token_ids_delta = all 5 rows' new token ids end to end, as int64 bytes, with 6 offsets marking where each row starts; route columns are [tokens, layers, top-k] int16. It goes through ray.put then actor.put.remote. The reply is the same keys plus timings.
Can it land on another node?No. It is created with NodeAffinitySchedulingStrategy(node_id, soft=False), so Ray only places it on the worker's node. If that node has no free CPU, it stays pending, and setup gives up after 180 s and fails loudly. A node check after start is a second guard.
Does it do TQ reads?No. Only prefix PUTs and the cleanup of a failed PUT. Restore reads (PrefixReadBatcher) and the final write when a call finishes keep the worker's own client.
Why a separate process at all?Encoding and sending the bytes costs CPU and holds Python's lock. Moving the send out of the vLLM worker keeps it free to serve requests. Measured with the actor and the packing added: 31.7 s → 25.2 s for the first snapshot (one run).

The classes this PR adds

Class / functionRuns inMade byJob
PrefixWritePipelineworker: 2 threadsPrefixRecovery.__init__Prepare thread runs the cut generators; writer thread runs one merged write at a time.
PrefixWrite, BatchReleasedworkerthe cut generatorWhat the generator hands out: "write these rows", then "their locks are released".
encode_prefix_groupsworker, writer threadcalled by the sinkBuilds whole columns at once, same bytes as _encode_record.
RayPrefixWriterClientworkercreate_prefix_writerLooks like a TQ client to the sink; packs columns and calls the actor. (C2: a 10-line wrapper is enough)
PrefixWriterActor ⊂ PrefixWriterServiceits own CPU processcreate_prefix_writerThe actor only builds its TQ client; the service unpacks and calls put_samples, so it is testable without Ray.
PrefixPut, PackedColumn, PrefixWriteReplyboth sidesthe clientWhat crosses the boundary. (C2: keep the NumPy byte views, they are what make the hop cheap; drop the rest)

🔴 Review comments: C2 · shrink the hopC15 · no settingsC3 · timing-only fieldsC8 · key check never fires

So what. The writer actor is a second TQ client in a CPU process pinned to the worker's node; it only writes prefix rows, and the worker still does every read. The worker hands it ready-made columns and waits for TQ's confirmation before sealing anything, so nothing is acknowledged early. The packing into NumPy bytes and the client class around the actor are the parts the review asks to remove: Ray can carry the TensorDict, and the sink's _call_dp already calls actor handles.