Which CPU data-plane actors should share code? The two the controller owns, not the prefix writer

NVIDIA-NeMo/RL #5176, part 11 of 11 in the partial-checkpointing stack. A design proposal from the review, not part of the PR. "Before" links pin 981376a; "after" links pin the draft's a73b857.

Before
Two CPU Ray actors on main, AdvantageActor and RolloutReassemblerActor, each build a TQ client and repeat the same start-up, cleanup and checkpoint hooks.
This PR
Adds a third, PrefixWriterActor. It looks similar but differs in owner, count, placement and how data reaches it.
Status
Proposed, as draft PR #5256, not blocking #5176. The two controller-owned actors share one small base and one start helper; the prefix writer stays as it is.

Four pages on this PR. This one: which of the three CPU data-plane actors should share code, before and after.

Background. All three actors exist because some work on TQ is too slow, or too big, to do in the process that needs it, so it moves to a CPU-only Ray actor with its own TQ client. A shared base is worth it only where the base does most of the work and each actor adds a little; where the actors differ in what matters, a base just gets in the way. Dotted words have a short explanation: hover or tap them.

What the three have in common, and what they don't

Today: three CPU actors, each with its own TQ client and its own copy of the setup vLLM worker → ray.get(put.remote(...)) rows: byte columns PrefixWriterActor new in #5176 × 1 per vLLM engine · pinned to its node own TQ client start · wait ready · kill on fail no checkpoint hooks put / clear rows (W) controller: queue of free actors request: metadata only AdvantageActor × N · spread, off the head node own TQ client start · wait ready · kill on fail checkpoint hooks read → compute → write (R/W) controller: queue of free actors request: metadata only RolloutReassemblerActor × N · own Python env own TQ client start · wait ready · kill on fail checkpoint hooks read staging → write rows (R/W) TransferQueue (TQ) storage Orange: the same plumbing written in each actor. Red: missing here. Green: the one part that differs (the job). Dashed: one OS process. Proposed (#5256): the two controller-owned actors share a small base; the writer stays DataPlaneDelegate (base class) builds the client · __repr__ names it in Ray logs mooncake_checkpoint · get_data_plane_snapshot start_cpu_actors() · spread_off_head() create N · wait until ready · kill all if one fails CPU_ACTOR_OPTIONS written once PrefixWriterActor: unchanged owned by a vLLM worker, 1 per engine, pinned, rows through Ray, no storage AdvantageActor(DataPlaneDelegate) keeps run(request) pool of N, spread off the head RolloutReassemblerActor(DataPlaneDelegate) keeps finalize, check_dependencies pool of K, own Python env
AdvantageActor and RolloutReassemblerActorPrefixWriterActor (#5176)
OwnerThe controller (L459-L464)Each vLLM worker
CountA pool of NExactly 1 per engine
PlacementAnywhere: spread off the head node, or its own Python envPinned to its engine's node, hard (L390)
Data inMetadata only; it reads TQ itself (assert_metadata_only both ways)Rows sent through Ray
StorageLends Mooncake memory, so it has the checkpoint hooksHolds no rows (segment_size=0)
CallsMany at once, from a queue of free actorsOne at a time, in order (max_concurrency=1)
Caller seesThe actor handleA wrapper that looks like a TQ client (put_samples)

Same in the left column, different in the right: so the first two share a base, and the writer stays its own class. An earlier version of this page put all three behind one base and one pool; on real code that added a process() rename nobody called generically, a pool of one for the writer, and +128 lines.

The two shared actors, before and after (draft PR #5256, not merged)

Nothing below is merged. #5256 has the real diff and the tests. Red struck lines go, green lines arrive, plain lines stay. How they are called does not change: setup calls the same two start functions and gets the same list of handles; the controller still calls run and finalize from its own queues of free actors.

AdvantageActor

# AdvantageActor process (1 CPU) x n
@ray.remote(num_cpus=1, num_gpus=0, max_restarts=0, max_task_retries=0)
class AdvantageActor:
@ray.remote(**CPU_ACTOR_OPTIONS)                                               # same four options, written once
class AdvantageActor(DataPlaneDelegate):
    def __init__(self, dp_config, config, estimator, *, label):
        self._dp_client = build_data_plane_client(dp_config, bootstrap=False)
        super().__init__(dp_config, label=label)                               # client, log name, hooks
        self._computer = AdvantageComputer(self.dp_client, ..., shard_id=label)
    def mooncake_checkpoint(self, body): ...                                   # now in the base
    def get_data_plane_snapshot(self): ...                                     # now in the base
    async def run(self, request) -> AdvantageOutcome                           # unchanged; the job

# driver, setup: same call, same list of handles back
def create_advantage_actors(dp_config, config, estimator, *, num_workers):
    node_ids = _placement_node_ids()                                           # ≈ 20 lines
    actors = [AdvantageActor.options(spread or soft pin).remote(...) for i in range(n)]
    try: ray.get([a.__ray_ready__.remote() ...]) except: ray.kill each; raise  # ≈ 15 lines
    placement = spread_off_head()
    return start_cpu_actors(
        lambda i: AdvantageActor.options(scheduling_strategy=placement(i))
                                .remote(dp_config, config, estimator, label=str(i)),
        n=num_workers)                                                         # waits for each; kills all if one fails

RolloutReassemblerActor (the finalizers)

# RolloutReassemblerActor process (1 CPU, own Python env) x k
@ray.remote(num_cpus=1, num_gpus=0, max_restarts=0, max_task_retries=0)
class RolloutReassemblerActor:
@ray.remote(**CPU_ACTOR_OPTIONS)
class RolloutReassemblerActor(DataPlaneDelegate):
    def __init__(self, dp_config, config, *, label):
        self._dp_client = build_data_plane_client(dp_config, bootstrap=False)
        super().__init__(dp_config, label=label)
        self._finalizer = RolloutReassembler(self.dp_client, ...)
    def mooncake_checkpoint(self, body): ...                                        # now in the base
    def get_data_plane_snapshot(self): ...                                          # now in the base
    def check_dependencies(self)                                                    # unchanged
    def finalize(self, request) -> FinalizedGroup                                   # unchanged; the job

# driver, setup: same call, same list of handles back
def create_rollout_reassembler_actors(dp_config, config, *, num_workers):
    runtime_env = (the Gym env if it matches, else its own)                         # unchanged
    actors = [RolloutReassemblerActor.options(runtime_env=env).remote(...) ...]
    try: ray.get([a.check_dependencies.remote() ...]) except: ray.kill each; raise  # ≈ 15 lines
    return start_cpu_actors(
        lambda i: RolloutReassemblerActor.options(runtime_env=runtime_env)
                                         .remote(dp_config, config, label=str(i)),
        n=num_workers, ready='check_dependencies')

The shared piece

# new in #5256: nemo_rl/data_plane/delegate.py (119 lines)
CPU_ACTOR_OPTIONS = dict(num_cpus=1, num_gpus=0, max_restarts=0, max_task_retries=0)
class DataPlaneDelegate:                                                       # base for the two controller-owned actors
    __init__(dp_config, *, label)                                              # builds the client
    __repr__()                                                                 # 'AdvantageActor[2]' in Ray's log prefix
    mooncake_checkpoint(body); get_data_plane_snapshot()                       # the copies, written once
def spread_off_head() -> placement(index)                                      # moved from advantage_actor.py
def start_cpu_actors(make_actor, *, n, ready='__ray_ready__', timeout_s=None)  # create, wait, kill all on failure

PrefixWriterActor

No change: it stays as in #5176. Using start_cpu_actors would need an async twin (≈ 22 lines) to save ≈ 8 lines in the writer.

Change in #5256 (source only)Lines
New data_plane/delegate.py: base, start helper, placement, options+119
advantage_actor.py: client, hooks, placement, start, cleanup−61
rollout_reassembler_actor.py: client, hooks, start, cleanup−21
Net+37

Measured on the draft. Thirteen of the new lines are the license header; the rest roughly breaks even with what the two actors drop.

So what. Sharing pays for the two actors the controller owns: they are the same thing with a different job, so the base does the plumbing and each keeps only its job and its placement. The prefix writer only looks similar; forcing it in added a rename, a pool of one and more lines than it removed. #5256 changes nothing in #5176's own code, so it is an FYI for this review, not a request.