About 560 of #5176's 2,281 added lines can go without losing a measured speedup

NVIDIA-NeMo/RL #5176, part 11 of 11 in the partial-checkpointing stack. Counts are the PR's own commit 788133a..981376a (+2,281 / โˆ’49). Permalinks pin 981376a. The review is pending; its comment links work once it is published.

Before
#4508 writes generation-prefix rows in batches from one thread, with the worker's own TransferQueue client.
This PR
Adds a column encoder, a prepare/write pipeline and a writer actor: 1,390 source lines and 880 test lines, behind three settings that are off by default.
Status
Proposed in the review, not done: the cuts below. Each one keeps the behavior the benchmark measured.

Four pages on this PR. This one: which lines can go, and why each cut is safe.

Two asks do most of the work. C15 drops the PR's three settings (prefix_writer_actor, prefix_write_pipeline.enabled, direct_column_encoding), which today allow six ways to write a cut, and picks the new path whenever the run can use it: text-only capture on TransferQueue simple. The old path stays only for media capture and other TQ backends, which the new one does not support (L851-L856). C2 keeps the NumPy byte views, because Ray 2.58 copies torch tensors (and so a TensorDict) through torch's own pickle but hands NumPy arrays to the actor in place (โ‰ˆ 45 + 14 ms against โ‰ˆ 2 + 0 ms for a 128 MiB batch). It shrinks them to two helpers and replaces the 94-line RayPrefixWriterClient with a thin wrapper.

stays review asks to remove (comment IDs in brackets) tests (3 files) +882 โ†’ โˆ’175 (C2 C3 C8 C15) prefix_pipeline.py +441 โ†’ โˆ’30 (C3 C15) prefix_writer_actor.py +404 โ†’ โˆ’235 (C2 C3 C8) direct_prefix_batch.py +214 โ†’ โˆ’5 (C9) recovery.py +112 โ†’ โˆ’3 (C15) tq_token_sink.py +71 โ†’ โˆ’8 (C15) vllm_worker_async.py +66 โ†’ โˆ’30 (C2 C15) vllm/config.py +36 โ†’ โˆ’34 (C15) docs + 6 YAML +52 โ†’ โˆ’38 (C15) Total: about 558 of 2,281 โ†’ about +1,723. Estimates; exact counts depend on how each ask is written.

Each cut, and why the behavior stays

IDWhat goesWhy nothing measured is lostLines
C2G_DTYPES, PackedColumn, PrefixPut, the bf16 branch, RayPrefixWriterClientTwo helpers do the same no-copy byte views for every dtype; the actor options already keep writes ordered and failures loud.โ‰ˆ 205
C3Timing fields, per-write INFO logs, snapshot(), stats()Only log lines and tests read them.โ‰ˆ 130
C8_validate_keys in the actorIts only caller sends generation-cut keys for the same partition, so it never fires.โ‰ˆ 26
C9Copied dense-or-jagged tail in the encoderOne helper, same output.โ‰ˆ 5
C15The three settings, their checks in two places, 6 YAML blocks, the doc table, the config testsThe run already says which path can work; the new path won every measured row, and the old one stays where it is needed.โ‰ˆ 185

๐Ÿ”ด Review comments: C2 ยท prefix_writer_actor.py:95C3 ยท prefix_writer_actor.py:86C8 ยท prefix_writer_actor.py:202C9 ยท direct_prefix_batch.py:70C15 ยท vllm/config.py:119

The two biggest cuts, as pseudocode (proposed, not run)

Nothing below is implemented.

Where it lands: RL only. No TQ or Ray change.

C2 ยท the hop to the writer actor

# writer thread in the vLLM worker (proposed: two small helpers, a thin wrapper)
cols = encode_prefix_groups(rows)                                                        # one TensorDict
ref = ray.put(PrefixPut(pack_columns(cols)))                                             # ~100 lines: dtype table, bf16 branch, checks
RayPrefixWriterClient.put_samples(...)                                                   # ~95 lines: locks, timings, reply checks
columns = {name: to_bytes(t) for name, t in cols.items()}                                # NumPy uint8 views, no copy
ray.get(actor.put_samples.remote(columns=columns, ...))                                  # Ray copies once into shared memory

# PrefixWriterActor process (CPU only, same node)
def put(batch): fields = unpack_columns(batch.columns)
def put_samples(columns, ...): fields = {k: from_bytes(*v) for k, v in columns.items()}  # reads shared memory in place
    own_tq_client.put_samples(sample_ids, fields, tags)

Real code today: pack_columns, unpack_columns, RayPrefixWriterClient.

C15 ยท choosing the write path

# vLLM worker, setup_token_capture (proposed: no settings)
writer_on   = cfg.prefix_writer_actor                                                       # 3 settings, 6 combinations
pipeline_on = cfg.prefix_write_pipeline.enabled
encoder_on  = cfg.prefix_write_pipeline.direct_column_encoding
fast = prefix_cuts and not capture_media and tq_backend == 'simple'                         # decided once, from what the run is
if fast:
    pipeline = PrefixWritePipeline(encoder=direct, limits=parts.generation_prefix_batch_*)  # existing limits
    writer   = create_prefix_writer()                                                       # fails clearly if no free CPU
else:
    keep today's path                                                                       # media capture, other TQ backends

Real code today: setup_token_capture checks, validate_vllm_async_actor_settings, PrefixWritePipelineConfig.

So what. The three speedups the PR measured all survive: the column encoder, the prepare/write overlap and the separate writer process, and they become the default. What goes is a no-copy bridge written longer than it needs to be, metrics nothing reads, and settings that let a run pick a slower path for no reason. The PR would then be about +1,723 lines. A further option is to split it: encoder + pipeline first (the bigger win), then the writer actor.