Repository navigation
Conversation
130ab06 to
fb3ffbd
Compare
fb3ffbd to
5e6da90
Compare
5e6da90 to
884df47
Compare
|
from claude: Rebased onto #6301's new head 6e2d4ba, where each rollout worker records its own groups ( |
There was a problem hiding this comment.
Verdict: Request changes -- the knob adds ~810 lines of transport code plus ~720 lines of tests, but the measurements show no benefit yet: 30 ms saved in a 238 s step, slower for small groups, the cross-host case unmeasured, and no in-repo workload that needs it. It also duplicates the torch-transport pool that #6163 is building.
What this PR does. With BaseRolloutWorker.Config.rdma_min_group_bytes set, a rollout worker serializes each group above the threshold once into a NIXL-registered pooled buffer. The group's ref becomes an RDMARolloutGroupRef (buffer descriptor plus per-rollout byte regions with tags). Each trainer DP replica leader reads only its rollouts' regions one-sided, checks the tags and rebuilds the rollouts. At setup every leader reads a probe from every worker. With the knob off, the get_rollouts fetch path from #6303 is unchanged.
Example.
4K score centering, 16-rollout group = 17 MB, leader's column = 277 MB/step
before (#6303): leader --get_rollouts--> worker pickles 277 MB --reply--> leader unpickles 0.27 s
after: worker copies the group into a pooled buffer at keep time; the ref carries
handle + regions; leader reads its regions by RDMA, checks tags, rebuilds 0.24 s
step time: 238 s either way (one host). T1 alphabet sort, all groups by RDMA: 71 -> 116 ms.
Must fix
- Value not shown (gate). The PR's own numbers point the wrong way or sit inside noise: -30 ms of a 238 s step at 4K, +45 ms per step at T1, and the column send is slower (94 -> 139 ms) because each ref carries a NIXL descriptor. The case the knob is for (MB-size groups read across hosts) is "not measured on this head". The workloads that would produce such groups are still open PRs (score centering #6378, router replay #6459), and no recipe sets the knob. Under
CONTRIBUTING.md#proof-of-valueandrules/config.md("expose only options a verified recipe uses"), a justification that depends on unlanded features doesn't count. Fix: hold this PR until one of those workloads lands, then show a cross-host end-to-end step-time win on it. If the read turns out not to be on the critical path, drop the PR; #6324's read-ahead already hides it in trainer-bound runs. torch_transport_rdma.py:84-- a second grow-only registered torch-transport pool for the same NIXL stale-key problem as #6163 (different upstream issue cited). Coordinate on one pool inrl/transport/(details inline).
Should consider
torch_transport_rdma.py:335-- probes are read sequentially, each with a 30 s NIXL timeout, against a fixed 60 s controller timeout. With two or more hung workers, the per-host diagnostic is lost.rdma_rollout_group.py:123-- every group under the threshold is pickled just to measure its size. Gate on array and image bytes before pickling.rollout_group_store.py:103-- two parameters plus an assert for one optional feature.trainer.py:509--trainer/rdma_read_bytes/maxis logged every step on the default path, where it is always 0, and it widens the broadcast tuple. Consider emitting it only when the knob is set.test_trainer.py:288-- this test only checks thatto_threadruns on a thread. Delete it.
Questions
- Every rollout worker process now runs a NIXL progress thread that spins one core. How many workers did the 4K run have, and did rollout throughput change? This cost is on the controller host's CPU pool, which also runs the envs.
- The
_RDMA_PROBE_TIMEOUT_Scomment says "~2 s on one host": is that per probe or for the whole check? If per probe, about 30 workers already exceed 60 s on a healthy fabric.
Details
Overlap search. Searched open PRs for "rdma rollout", "torch transport" and "rollout_group_store". Found #6163 (TransportRDMAMicrobatch, grow-only owner pool, nixl#1267), #6334 (images onto this PR's pool), #6378 (score centering), #6459 (router replay) and the rest of this stack (#5862, #6301-#6303, #6324). direction.md has no RL transport entry, so whether the RL data plane standardizes on Monarch RDMAObject or on torch transport is a maintainer call. With #5862 on Monarch and #6163 plus this PR on torch transport, the stack currently goes both ways.
Smallest alternative. None needed today: #6303's fetch path plus #6324's read-ahead. If a cross-host number later justifies the path, it could be smaller: size gate before pickling, one shared pool with #6163, and probes read in one call.
Correctness checked. The release order holds: groups are released after the pull, after every leader's forward_backward returns, and the next step's reads under read-ahead touch different groups. Region and tag offsets, _merged_ranges, _buffer_size_class (multiples 5..8, at most 25% over the request), the staging-buffer handling after a failed read, and select (images trimmed to the kept rollouts) all check out.
Not verified: any multi-host behavior, and whether Monarch's call_one sends at call time (the read_rollout_groups comment "Each call is sent here" relies on it to overlap fetches with the RDMA reads).
Before merge: fill in the human-written summary.
| # owner unregisters them (https://github.com/pytorch/pytorch/issues/206300). Today it does not | ||
| # (module docstring), so freeing a buffer a reader has read can make a later buffer at the same | ||
| # addresses unreadable; that is why this pool never unregisters, and why its memory never shrinks. | ||
| class RegisteredBufferPool: |
There was a problem hiding this comment.
This is the second registered pool over torch.distributed._transport built for the same NIXL stale-registration problem. #6163 (open, updated today) adds a grow-only owner pool in rl/transport/rdma_microbatch.py for batcher microbatches. That pool also never unregisters and also has a free list, but it cites nixl#1267 where this one cites pytorch#206300. #6334 then moves prompt images onto this pool too. Two pools mean two copies of the reuse invariant, two upstream TODOs, and two NIXL progress threads in any process that ends up with both.
Fix: agree with #6163 on one owner pool in rl/transport/ that microbatches, rollout groups and images all use, plus one TODO that links both upstream issues. Also, after #6303 the leaders pack, so it needs deciding whether the batcher's RDMA microbatch path that #6163 migrates still exists in this stack at all.
There was a problem hiding this comment.
from claude: Not changed here: whether the RL data plane keeps this pool or the other torch transport pool PR's (and whether the batcher's RDMA microbatch path still exists after #6303) is for the maintainers and that PR's author to settle. The PR body lists it as open.
| instead of mid-step, naming each owner host and this reader's host. | ||
| """ | ||
| failures = [] | ||
| for probe in probes: |
There was a problem hiding this comment.
The probes are read one at a time, and per the read docstring each read can take up to NIXL's 30 s timeout. The controller gives the whole loop 60 s (controller.py:341). So if two or more workers hang, the controller's generic timeout fires first and you lose this function's per-host message, which is the diagnostic the probe is for. A healthy setup also gets slower linearly with the worker count while the 60 s budget stays fixed.
Fix: submit every probe in one buffers.read call, since the reads can be in flight together. Then derive the controller timeout from the transport's timeout (one read plus connection setup) instead of hardcoding 60 s.
There was a problem hiding this comment.
from claude: Every probe is now read in one buffers.read call, so hung reads fail within one NIXL read timeout (30 s), inside the controller's 60 s; a failed read names every worker host. The controller comment now says this instead of the ~2 s estimate. test_a_probe_read_that_fails_raises_at_setup checks one call for two probes. a034714
| pickled_turns.append(pickled_turn) | ||
| rollout_layout.append(tuple(turn_layout)) | ||
| rollout_arrays.append(arrays) | ||
| pickled = pickle.dumps( |
There was a problem hiding this comment.
Every rollout gets pickled before allocate decides whether the group crosses the threshold. A group under rdma_min_group_bytes is therefore pickled once on the worker's event loop just to measure it, then pickled again in the get_rollouts reply. That is the serialize_group timing the description adds for every group.
The size is dominated by array.nbytes and the image data lengths, both known without pickling. Fix: check sum(array.nbytes) + sum(len(image.data)) against min_bytes first, and pickle only groups that go into a buffer. Small groups then pay nothing with the knob on, and the always-on serialize_group metric can go.
There was a problem hiding this comment.
from claude: keep_in_registered_buffer now compares the turn arrays' and distinct image files' bytes with min_bytes before pickling, so a small group is neither pickled nor allocated, and serialize_group is logged only for kept groups. The knob docstring says what it counts. a034714
| asyncio.run(run()) | ||
|
|
||
|
|
||
| def test_check_rdma_probes_reads_off_the_event_loop(monkeypatch) -> None: |
There was a problem hiding this comment.
This test monkeypatches both collaborators and checks that asyncio.to_thread runs on a thread. That is one line of implementation, and the test doesn't guard an invariant that could break silently (rules/tests.md). Suggest deleting it. test_a_probe_read_that_hangs_fails_setup_naming_the_leader_and_hosts already covers the user-visible behavior.
| rdma_byte_buffers: RDMAByteBuffers | None, | ||
| rdma_min_group_bytes: int | None, | ||
| ) -> None: | ||
| assert (rdma_byte_buffers is None) == (rdma_min_group_bytes is None) |
There was a problem hiding this comment.
One optional feature is split across two parameters, plus an assert that keeps them in sync. The _keep path asserts it again. Pass one optional value instead, e.g. rdma: tuple[RDMAByteBuffers, int] | None, or a small frozen dataclass if it reads better. Then "off" has a single representation and both asserts go away.
There was a problem hiding this comment.
from claude: Kept as two: #6334 gives the store a pool with no group threshold (prompt image files alone, rdma_min_image_bytes), where the pool metrics still need the buffers, so one optional pair here would split again one PR later.
884df47 to
ab295d3
Compare
ab295d3 to
a034714
Compare
|
from claude: @claude review This round (a034714): the size check before pickling, all probes in one read, the |
There was a problem hiding this comment.
Verdict: Request changes -- the line-level fixes landed, but the gate finding stands: the new 4K numbers show no end-to-end win (step 238.2 -> 238.1 s), the cross-host case is still unmeasured, and no in-repo workload produces the groups the knob is for.
What this PR does. With BaseRolloutWorker.Config.rdma_min_group_bytes set, a rollout worker serializes each group whose turn arrays and distinct images reach the threshold into a pooled NIXL-registered buffer. The ref it hands the controller is an RDMARolloutGroupRef (buffer descriptor plus tagged per-rollout and per-image regions). Each trainer DP replica leader reads only its regions one-sided, checks the (group_id, generation) tags and rebuilds the rollouts. At setup, every leader reads every worker's probe. With the knob off, #6303's get_rollouts fetch is unchanged.
Example.
4K score centering, 8 workers, 17 MB groups, 277 MB per leader per step (one host, medians)
fetch (#6303) this PR
read_rollout_groups 0.29 s 0.24 s
first microbatch wait 393 ms 334 ms (-59 ms, 0.02% of the step)
column send 14 ms 21 ms (refs carry NIXL descriptors)
controller plan wait 109.9 s 112.1 s
step 238.2 s 238.1 s
T1 alphabet sort (small groups, all by RDMA): read 71 -> 116 ms
Resolved since the last review
- Size check before pickling:
keep_in_registered_buffergates on_num_array_and_image_bytes, so small groups are neither pickled nor allocated. - Probes: all read in one
buffers.readcall. - The
to_threadtest is deleted. - Two store parameters plus an assert: the reply holds. #6334 uses the buffers without a group threshold, so one optional pair would have to split again.
- New: alignment padding is zeroed (
rdma_rollout_group.py:212-215). I checked the written ranges. Header, arrays, and both tags of every region are covered, and everything else up to the last tag is zeroed. A stale region that straddles the new group's end fails its head-tag check. A stale region entirely past the end still holds its old, unchanged bytes.
Must fix (still open)
- Value not shown (gate). The new numbers replace the old ones but point the same way. The read saves 50 ms, of which the slower column send gives back 7 ms. The step does not move, and the controller's plan wait grows by 2.2 s (unexplained, possibly noise). Small groups are still slower. The target case (MB-size groups read across hosts) is not measured on this head. Its workloads (#6378 score centering, #6459 router replay) are still open, and no recipe sets the knob. Under
CONTRIBUTING.md#proof-of-valueandrules/config.md("expose only options a verified recipe uses"), the PR has to wait until one of those lands and a cross-host run shows a step-time win. If the read turns out to be off the critical path there, drop the PR. torch_transport_rdma.py:84-- a second grow-only torch-transport pool, alongside #6163's (still open). The author defers this to the maintainers. It still needs that decision before merge: one pool inrl/transport/, and whether #6163's batcher microbatch path survives #6303.
Should consider (still open)
trainer.py:509--trainer/rdma_read_bytes/maxis added to every step's metrics and to the broadcast tuple on the default path, where it is always 0. Consider emitting it only when the knob is set.
Questions
- The knob docstring says the NIXL progress thread spins a core "seen with the 1.5.2 wheel; not checked with the pinned 1.5.0". Does the pinned wheel spin too? With 8 workers, is the +2.2 s controller plan wait at 4K that cost on the env/rollout CPU pool?
Details
Overlap search. "torch transport" and "rdma rollout" found the same PRs as last round: #6163 (open, torch-transport microbatch pool), #6334 (images onto this pool), #6378 and #6459 (the workloads, both open), and this stack (#5862, #6301-#6303, #6324). direction.md still has no RL transport entry. The stack uses both Monarch RDMAObject (#5862) and torch transport (#6163, this PR).
Smallest alternative. None needed today: #6303's fetch plus #6324's read-ahead.
Re-checked at HEAD. Release order (after the weight pull, after every leader's forward_backward), tag placement in tagged, _merged_ranges, the staging-buffer handling after a failed read, the probe ranges (0, 4096) and (1024, 1024) against _PROBE_BYTES, and select trimming images to the kept rollouts.
Not verified: multi-host behavior. Also unverified: whether Monarch's call_one sends at call time. read_rollout_groups relies on that ("Each call is sent here") to overlap the endpoint fetches with the blocking RDMA read.
Before merge: fill in the human-written summary.
a034714 to
fd7b0f3
Compare
|
from claude: @claude review Answers to the open questions (fd7b0f3):
|
There was a problem hiding this comment.
Verdict: Request changes -- the open questions are answered, but the gate is still open. The new noise data makes it clearer that the knob has no measurable end-to-end effect on one host, and the cross-host case it exists for is still unmeasured.
What this PR does. With BaseRolloutWorker.Config.rdma_min_group_bytes set, a rollout worker serializes each group whose turn arrays and distinct image files reach the threshold into a pooled NIXL-registered buffer. It hands the controller an RDMARolloutGroupRef instead of a WorkerRolloutGroupRef. Each trainer DP replica leader reads only its rollouts' tagged regions one-sided and rebuilds them. With the knob off, #6303's get_rollouts fetch is unchanged.
Example.
4K score centering, 8 workers, 17 MB groups, 277 MB per leader per step (one host)
fetch (#6303) knob on
read_rollout_groups 0.29 s 0.24 s
first microbatch wait 393 ms 334 ms
step, run pair 1 238.2 s 238.1 s
step, run pair 2 238.1 s 239.1 s (the author's earlier pair)
T1 alphabet sort, every group by RDMA: read 71 -> 116 ms
Resolved since the last review
- NIXL progress thread: measured at 0.99 idle cores per process with both the pinned 1.5.0 and 1.5.2, and the knob docstring now says so (
rollouter.py,rdma_min_group_bytes). The 4K run used 8 of 168 cores. - +2.2 s controller plan wait: noise. The earlier pair moved the other way.
trainer/rdma_read_bytes/maxon the default path: I accept the reply. Non-leader ranks don't know the knob, and the loss-mesh reduction needs the same keys on every rank. One scalar per step doesn't justify plumbing the knob to every rank.
Must fix (still open)
- Value not shown (gate). The two run pairs put the step-time difference at -0.1 s and +1.0 s, which is inside run-to-run noise. The ~59 ms first-microbatch saving doesn't reach the step, and small groups are slower. The case the knob is for (MB-size groups read across hosts) is not measured on this head. Its workloads are still open: #6378 (score centering) and #6459 (router replay). No recipe sets the knob. Under
CONTRIBUTING.md#proof-of-valueandrules/config.md("expose only options a verified recipe uses"), this needs a cross-host end-to-end step-time win on one of those workloads once it lands. If the read turns out to be off the critical path there, drop the PR. #6303's fetch plus #6324's read-ahead already covers today's workloads. torch_transport_rdma.py:84-- this is a second grow-only torch-transport pool alongside #6163's (still open, last updated 2026-12-01). The author defers this to the maintainers. Before merge it needs that decision: one pool inrl/transport/, and whether #6163's batcher microbatch path survives #6303.
Details
Overlap search. "torch transport", "score centering" and "router replay" found the same PRs as last round: #6163 (open), #6334 (images onto this pool), #6378 / #6380 / #6384 / #6385 (score centering, all open), #6459 / #5255 (router replay, open), and the rest of this stack (#5862, #6301-#6303, #6324). direction.md still has no RL transport entry.
Re-checked at HEAD. keep_in_registered_buffer gates on _num_array_and_image_bytes before allocating or pickling. check_rdma_probes reads every probe in one buffers.read call. The pool, release order and tag layout are unchanged since the last review.
Not verified: multi-host behavior; whether Monarch's call_one sends at call time (read_rollout_groups relies on that to overlap fetches with the RDMA read).
Before merge: fill in the human-written summary.
Human note: TODO (Jiani)
TLDR: Opt-in
BaseRolloutWorker.Config.rdma_min_group_bytes: a training group of at least that many serialized bytes stays in its rollout worker in one registered torch transport (NIXL) buffer, and each trainer DP replica leader reads only its rollouts' byte ranges by RDMA instead of fetching them with aget_rolloutscall. Off by default. On one host it saves little for MB-size groups (4K score centering on this head: the read drops 0.29 -> 0.24 s and the first microbatch wait 393 -> 334 ms per step, 277 MB per leader; the 238 s step is unchanged) and costs time for small ones (alphabet sort: 71 -> 116 ms); it targets MB-size groups read across hosts, which is not measured on this head.Merge bottom-up. This path was in #6303 until review split it out: #6303's endpoint fetch stands alone, and this PR carries the RDMA path's own measurements.
Problem
get_rolloutscall per rollout worker: the worker pickles them into the reply and the leader unpickles them.Solution
rdma_min_group_bytesbytes (checked before anything is pickled) is serialized once, when its worker keeps it (keep_in_registered_buffer, newtransport/rdma_rollout_group.py): one region per rollout (its pickled fields, then each turn's arrays, 64-byte aligned) and one per distinct image file, each with a(group_id, generation)tag on both sides. Alignment padding is written as zeros, so a buffer reused from a larger group keeps none of that group's tags.RDMARolloutGroupRef(the buffer handle and each region's place);RolloutGroupRef = WorkerRolloutGroupRef | RDMARolloutGroupRef. A leader reads only the regions its column names, all reads in flight together, checks the tags and rebuilds the rollouts (read_rdma_rollout_groups).RegisteredBufferPool(newtransport/torch_transport_rdma.py, used throughRDMAByteBuffers). A released buffer is reused, never unregistered: a NIXL reader keeps the metadata of a buffer it has read, and the owner's unregister never reaches it (pytorch#206300).Trainer.check_rdma_probes), so a broken fabric fails setup within one read timeout, not step 1. Each worker's probe stays allocated for the run (one 64 KiB pool buffer). A read that fails or times out leaves its staging buffer registered and unused, since the transfer may still write into it.BaseRolloutWorkerowns the buffers and the store; the actor's endpoints only forward.trainer/rdma_read_bytes/maxon the trainer (0 when every group is fetched). With the knob, on the workers:timing/rollout_worker/serialize_groupandrollout_worker/pool_{bytes,bytes_in_use,registrations}on the groups kept in registered memory.Results
NOTE:
torch.distributed._transportis a private upstream API (a TODO, as inmodel_state_dict.py).RDMABufferis not used here: it reads a buffer whole, and a leader reads byte ranges of a group (its rollouts).RDMARolloutGroupRefcarries its NIXL buffer descriptor: 256 refs of 4-rollout groups pickle to 166 KiB instead of 6 KiB (5.6 vs 0.9 ms to pickle, 5.1 vs 0.7 ms to unpickle, one CPU process). That is part of the slower column send at T1 (94 -> 139 ms).Test plan
pytest tests/rl/unit_tests/cpu: 828 passed, 8 skipped, 4 failed, with nixl ([WIP] [rl] Read the next step's rollout groups during the optimizer step #6324: 807 passed). The 4 also fail on main076f2e88b: recipe tests whosetorch_checkpointing.storage.fsspec_storageimport fails locally.transport/test_rdma_rollout_group.py(new): a kept group reads back whole from its ref alone; a read of a reused buffer raises naming both tags; a torn region raises;test_a_group_that_fails_to_serialize_returns_its_buffer_to_the_poolfails without the release on error;test_a_kept_group_writes_the_same_bytes_whatever_its_buffer_heldfails without the zeroed padding.test_torch_transport_rdma.py(new): the pool reuses the smallest free buffer that fits and keeps released buffers registered; every probe is read in one call and a failed read raises at setup naming the worker hosts; with real NIXL, a reused buffer reads back its new bytes without a new registration;test_a_read_after_a_failed_read_uses_a_new_staging_bufferfails without setting the failed read's staging buffer aside.test_rollout_group_store.py: large groups go by RDMA and small ones are fetched, read in ref order in one call.