Skip to content

[rl] Add ModelStateDictTransport over torch.distributed._transport - #5996

Merged
d4l3k merged 10 commits into
mainfrom
gh/d4l3k/6/head
Nov 13, 2026
Merged

d4l3k merged 10 commits into
mainfrom
gh/d4l3k/6/head

Conversation

@d4l3k

@d4l3k d4l3k commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Stack from ghstack (oldest at bottom):

Summary (human-written)

Why

RL syncs the trainer's model state dict to the generators through TorchStore, which adds a store, controller and extra copies around the transfer. With 14B on one 8xB200 host (trainer FSDP 4, generator TP 2, NIXL) a TorchStore pull takes 10-13 s (2.3-3.0 GB/s); with this transport the same pull takes 0.6-0.9 s (RDMA read at ~60 GB/s per generator rank). torch.distributed._transport now provides one-sided RDMA reads over Mooncake/NIXL, so the generators can read the trainer's shards directly.

What changed

  • torchtitan/rl/model_state_dict_transport.py (new):
    • shard_layout / _staged_pieces: each trainer rank stages, per generator rank, the intersection of its FSDP box with the generator rank's box, cast to the generator dtype and 16 B aligned, in one registered pinned CPU buffer (pinned with cudaHostRegister, since pin_memory=True rounds up to a power of two). Generator ranks that need the same piece (e.g. a TP-replicated tensor) share one staged copy, so the buffer is about the trainer shard size at the transfer dtype.
    • _staged_placements: where a trainer shard cuts a generator shard on a dim after the first sharded dim, the trainer stages that DTensor with its later-dim shards moved to the first sharded dim, via one redistribute (an all-to-all within its mesh) in stage; e.g. a row-parallel weight (FSDP Shard(0), TP Shard(1)) read by a generator split on dim 0 is staged as (Shard(0), Shard(0)): one read per piece instead of one per row. A generator TP on dim 1 matching the trainer's needs no restage. The decision uses every trainer rank's box, so all trainer ranks agree (the redistribute is a collective).
    • _plan_reads: each generator rank plans reads from every trainer rank straight into its prefetch buffers, one contiguous read per piece per index of the dims before its sharded dim (1 for a 2-D weight, 2 for a stacked [2, F, D] w13 sharded on F). HSDP replicas are spread round-robin across generator ranks. Raises if the trainer does not cover a shard exactly, and on Partial or uneven _StridedShard placements.
    • shared_rank_layouts: checks every generator reports the same per-rank layout.
    • ModelStateDictTransport: register_trainer_source + stage (trainer; a collective when restaging), connect_generator + read (generator). read fails after Config.read_timeout_s (default 600 s) instead of hanging on a stuck transfer; the job must then restart.
    • Every generator key must be fully covered by the trainer, or init raises (TorchStore loads with strict=False). Trainer keys no generator has (e.g. ones the generator drops) are not staged.
    • Config.backend selects the torch.distributed._transport backend: "mooncake" (default) or "nixl".
  • Unused until the next PR wires it in behind a config flag.
  • Mooncake needs a PyTorch nightly from 2026-11-10 or later (Mooncake transport [Transport] Add Mooncake distributed transport  pytorch#202780, multi-peer [transport] Allow connecting an endpoint to multiple peers pytorch#202536 and [Transport] [Mooncake] Add slicing and multi-peer support to Mooncake transport pytorch#203461, poller fix [Transport] [Mooncake] Don't drop a reused batch id when settling a transfer pytorch#203623).

The staging buffer is laid out per staged piece, so a later delta sync can stage and read a subset of pieces without changing the plan.

Alternatives considered

  • Keep TorchStore: its extra hop and copies are the bottleneck measured above.
  • Read directly from trainer GPU memory: a pull would then race the next optimizer step, and dtype casts would still need a staging copy.
  • Monarch RDMA (as rdma_microbatch.py uses for microbatches): ties the trainer and generator cores to Monarch and offers no Mooncake backend; torch.distributed._transport is PyTorch-native and backend-selectable.

Related drafts

Size

Implementation +544, tests +451.

Testing

  • pytest tests/rl/unit_tests/cpu/test_model_state_dict_transport.py (19 pass): checks Config.backend reaches new_transport, and runs register_trainer_source/stage/connect_generator/read over an in-process fake transport and checks every element lands in the right place and every read targets a connected trainer rank, with a bf16 cast, for HSDP 3x4 -> TP 1/2 on either dim (replica assignment across two generators), a stacked [2, F, D] weight sharded on F -> TP 1/2 on F or D (multi-run reads), mixed dtypes with preserve_dtype_keys and an odd-sized key (alignment), generator ranks sharing a replicated piece (one staged copy), a generator rank with an empty shard, incomplete or overlapping coverage and dtype mismatches (raise), mismatched generator layouts, and rejecting Partial/uneven _StridedShard. A 4-rank gloo test stages real FSDP 2 x TP 2 DTensors (row-parallel (Shard(0), Shard(1)), colwise FSDP over TP (_StridedShard(0), Shard(0)), stacked w13 (_StridedShard(1), Shard(1)), and a small (Shard(0), Shard(1)) key on which 2 ranks have no pieces but must still join the restage) and reads them into generator TP 2 shards on two layouts, asserting the restage decision per layout (none when generator TP matches trainer TP on dim 1; (Shard(0), Shard(0)) for row-parallel and the small key when the generator splits dim 0). This catches layout/offset bugs that would otherwise silently corrupt weights.
  • End-to-end numbers are in the next PR.

AI-assisted (Claude).

d4l3k added 2 commits November 9, 2026 17:48
[ghstack-poisoned]
[ghstack-poisoned]
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 10, 2026

@kapilsh kapilsh left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@d4l3k
d4l3k marked this pull request as ready for review November 11, 2026 20:13
@pytorch-bot pytorch-bot Bot added the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Nov 11, 2026
@github-actions
github-actions Bot requested a review from pzhan9 November 11, 2026 20:13
return
works = await asyncio.to_thread(
lambda: [
self._transport.read(local, remote, async_op=True)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this creates trasfer handles e.g. for nixl calls initialize_xfer every request? Is the throughput close to line rate because caching the handles got us close to line rate in torchstore. Maybe something we want to put in torch.transport.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding a batch API would be the better long term option. We could cache the transfer handles but doesn't seem to be a significant problem for real model sizes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit surprised because batching and caching in my PR improved the perf in ts. Maybe it's because we do read instead of write. Maybe it shows up with bigger models.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's dependent on the number of reads so doing contiguous reads likely cuts this significantly. Will become more important with a large number of shards

We should add a batch API to torch transport and then revisit this cc @brandondfeng

return tuple(offset), tuple(shape)


def _staged_placements(tensor: DTensor) -> tuple[Placement, ...]:

@tushar00jain tushar00jain Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure we want to change the placement of the dtensor on the trainer? Because this adds an additional hop for staging. This will also double the memory usage on the trainer?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm running the numbers on perf for staging, it simplifies things so much I'm inclined to keep it if there's negligible cost. Memory shouldn't be significantly different as we only persist the new placement

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it slows down the transfer by adding another hop. memory is twice which seems significant. so we should avoid if we can - we didn't need this in ts so think we should be able to do the same thing

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This happens at stage time not transfer time. Looking at the benchmarks this is still way faster

stage time 0.39-0.41 s -> 0.12 s

I've added it so we only redistribute when required rather than always

@tushar00jain tushar00jain Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let @tianyu-l also confirm because iiuc gpu memory is sparse and we should avoid using more gpu memory. on the speed, this is only nvl domain and small model size. so stage time could go up if model size is larger and not all trainer shards using slower links or if the network is congested from generators pulling

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also this is assuming a particular sharding for generator to make the transfer easier? what if generator is not sharded in the same way we are redistributing?

we already are creating storage in terms of generator format so to get it to stage from trainer format to generator format, instead of the redistribute, maybe these approaches could also work

  1. Is it actually needed because IIUC copy_ can just do the translation including type conversion
  2. Use NIXL to transfer from trainer gpu to cpu but probably creates more handles depending on sharding

order.

Raises:
ValueError: if the generators' layouts differ.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to allow generators to have different layouts?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we aiming to support hardware heterogeneity for the generators? I'm not sure we want to add it until we actually need it given the significant memory or perf hit

@tushar00jain tushar00jain Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let @tianyu-l confirm the requirement but should be easy to change the layout code? so i'm ok if we want to add this later

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's worry about "different generators getting different layouts" later. It sounds an interesting problem though.

@felipemello1

Copy link
Copy Markdown
Contributor

from claude to felipe: a TLDR image of this PR, drawn from its diff at 97a921f09.

Each trainer rank copies the piece of its shard that each generator rank needs into one pinned CPU buffer, and each generator rank reads its pieces from there directly instead of through TorchStore; the next PR measures a 14B pull of 0.6-0.9 s instead of 10-13 s.

@tianyu-l

Copy link
Copy Markdown
Contributor

@claude review

@claude

claude Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @tianyu-l's task in 3m 57s —— View job


Approve, with small fixes needed before merging: fill in the human-written summary, restore the private-API TODOs with issue links, and reply to @tushar00jain's two open comments. Review

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Approve -- please address the items below before merging. The read planning and staging logic is correct for every layout I traced, the need is measured (10-13 s -> 0.6-0.9 s per pull), and #5997 already has a TODO to delete the TorchStore path. What remains are small fixes: the description, the TODOs, and two unanswered review comments.

What this PR does. Each trainer rank stages a cast, 16 B-aligned copy of exactly the parts of its shards that each generator rank needs, in one registered pinned CPU buffer. Each generator rank plans one-sided reads from every trainer rank straight into its prefetch buffers, over torch.distributed._transport (Mooncake or NIXL). Before staging, the trainer redistributes multi-dim-sharded DTensors onto their first sharded dim, so each piece is a single contiguous read.

Example. w is [8, 6], trainer FSDP 4 on dim 0, generator TP 2 on dim 1:

trainer rank r stages w[2r:2r+2, 0:3] (for g0) and w[2r:2r+2, 3:6] (for g1)
g0 issues 4 reads (one per trainer rank), each 2x3 elements, into its local rows 2r..2r+1
HSDP 3x4: same pieces on 3 replicas; generator rank k reads replica k % 3

Must fix

  1. PR description: "Summary (human-written)" is empty. The author needs to fill it in.
  2. torchtitan/rl/model_state_dict_transport.py:21 -- private-API TODOs were deleted in d0ce0d2; restore them with upstream issue links (inline).
  3. Unanswered review comments from @tushar00jain:
    • Line 99 (restage hop/memory): see my inline at :379. The memory cost is transient and per key. The restage is redundant when the generator shards a tensor on the same dim as the trainer's TP, so it could be done only when needed.
    • Line 488 (per-read transfer handle creation vs. cached handles): please reply with whether read creates a NIXL xfer handle per request and whether the ~60 GB/s figure already includes that cost. If not, say whether caching belongs in torch.distributed._transport.

Should consider

  • torchtitan/rl/model_state_dict_transport.py:460 -- connect only to the trainer ranks this generator rank actually reads from (inline, with a suggestion).
  • torchtitan/rl/model_state_dict_transport.py:387 -- registration handle lifetime (inline, unverified).
  • torchtitan/rl/model_state_dict_transport.py:58 -- each TrainerSource carries pieces for all G generator ranks, and #5997 sends all T sources to every generator rank. That is T x G x K StagedPieces per generator rank at init: fine on one host, large at 64+ trainer ranks with ~1k keys. Sending each generator rank only pieces[rank] would cut it by G.
Details
  • Coverage check: _check_disjoint + "all pieces inside the shard" + numel == prod(shard.shape) together guarantee an exact cover. Run planning: the piece spans the shard on every dim after dim, so each of the prod(piece.shape[:dim]) runs is contiguous both in the staging buffer (row-major over piece.shape) and in the generator's local tensor. (*index, 0) zipped against strides correctly stops summing at dim.
  • Collectives: _staging_plan keeps restaged keys even with no pieces, and its key set and order depend only on the shared rank_layouts and per-tensor placements, so every rank in a DTensor's mesh issues the same redistributes in the same order. PP is fine because each stage's meshes exclude the PP axis.
  • Async D2H copies from per-key temporaries are safe: the caching allocator reuses freed blocks in stream order.
  • Overlap with in-flight TorchStore PRs (#5751, #5872, #5778, #5484, #5844, #5846) is acknowledged. #5997 adds TODO: delete the TorchStore path once this one covers gpu_fetch, which fits "one way to do each thing".
  • Tests: 444 lines for 492 of logic, but they guard silent weight corruption (layout and offset bugs) that nothing else catches, and the gloo test exercises real _StridedShard boxes and restage participation.

Not verified: actual torch.distributed._transport semantics (handle lifetime, per-read handle cost). The installed torch could not be inspected in this environment.

order.

Raises:
ValueError: if the generators' layouts differ.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's worry about "different generators getting different layouts" later. It sounds an interesting problem though.

# a pageable temporary and casts on the CPU.
tensor = model_state_dict[key].to(dtype)
if placements is not None:
tensor = tensor.redistribute(placements=placements)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried that this per-tensor call won't be efficient, when we scale trainer beyond NVLink domain.

FSDP2 does bucketed communication -- should we at least group communication according to layouts and collective type?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel the concern on scalability is real.

Besides the per-tensor call (without bucketing), there could be another concern:
From #5183 I learned that NCCL memory allocation is depending on the collectives called, and all-to-all (used here!) would use Omega(world_size) memory per CTA because of p2p transfer, instead of O(1) for ring-based collectives (only talking to neighbors). See more comments https://github.com/pytorch/torchtitan/blob/main/torchtitan/components/optim/optimizer.py#L224

I don't know how torchstore work under the hood, but to replace it we really need to test at scales. It's fine to land this PR as is, but could you create an issue under TorchTitan Development "[RL] Weight sync" section and link it here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The redistribute is only applied on TP dimension and when EP dimension is higher than number of experts. For TP this should be very performant since it should always be limited to nvlink domain. I'll stack a PR to use an intermediate buffer on the generator side as a third option

# Generator: (local view, remote buffer) per read, or None until connected.
self._reads: list[tuple[Any, Any]] | None = None

def register_trainer_source(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's have at most one positional arg

@tianyu-l tianyu-l left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see inline comment.

# a pageable temporary and casts on the CPU.
tensor = model_state_dict[key].to(dtype)
if placements is not None:
tensor = tensor.redistribute(placements=placements)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel the concern on scalability is real.

Besides the per-tensor call (without bucketing), there could be another concern:
From #5183 I learned that NCCL memory allocation is depending on the collectives called, and all-to-all (used here!) would use Omega(world_size) memory per CTA because of p2p transfer, instead of O(1) for ring-based collectives (only talking to neighbors). See more comments https://github.com/pytorch/torchtitan/blob/main/torchtitan/components/optim/optimizer.py#L224

I don't know how torchstore work under the hood, but to replace it we really need to test at scales. It's fine to land this PR as is, but could you create an issue under TorchTitan Development "[RL] Weight sync" section and link it here?

[ghstack-poisoned]
@d4l3k
d4l3k changed the base branch from gh/d4l3k/6/base to main November 13, 2026 23:54
@d4l3k
d4l3k merged commit b7a90b3 into main Nov 13, 2026
d4l3k added a commit that referenced this pull request Nov 13, 2026
d4l3k added a commit that referenced this pull request Nov 17, 2026
…6097)

Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.18.0)
(oldest at bottom):
* __->__ #6097
* #5997


## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the
problem, why
     this approach, and what you checked yourself. -->

## Why
#5997 restages each DTensor on
the trainer (a redistribute collective per tensor) whenever a staged
piece would not be a contiguous run of the generator shard, e.g. a
row-parallel weight read by generator ranks split on dim 0. Scalability
concern:
#5996 (comment)
(tracked in #6096). This is
the third option from
#5996 (comment):
an intermediate buffer on the generator side.

## What changed
- `_plan_reads`: each piece is one read into the key's prefetch buffer,
at consecutive offsets in piece offset order. A key stays in place iff
every piece is one contiguous run of the generator shard; otherwise it
is packed.
- New `copy_prefetched_` (called by
`Generator._copy_prefetched_model_state_dict`): plain keys copy as
before; packed keys copy each piece into place (async H2D, one stream
sync per call before the next read can reuse the buffers).
- Trainer: `stage()` only casts and copies local shards;
`_staged_placements` and the redistribute are removed, so staging has no
collectives.
- Doc updated.

No extra bytes are read: each piece is still read exactly once. The cost
moves to a strided copy per packed piece at load.

Lines: implementation +137/-168, tests +32/-37.

Test plan:
- `pytest tests/rl/unit_tests/cpu/test_model_state_dict_transport.py
tests/rl/unit_tests/cpu/test_trainer.py`: 35 passed. `_transfer` now
loads through `copy_prefetched_`; `TestStageDTensors.test_fsdp_tp_to_tp`
checks which keys are packed for two generator layouts.
- Disabling the packed branch fails `test_stacked_pieces` (3 cases) and
`test_fsdp_tp_to_tp`.
- Random fuzz (400 1-4D shapes, random trainer/generator grid
partitions) through `_plan_reads`/`read`/`copy_prefetched_`: values
match; packed classification matches a brute-force contiguity check.
- GB200: packed `[2, 4096, 2048]` bf16 key in 4 pieces loads in ~0.18 ms
(vs 0.11 ms unpacked); overwriting the prefetch buffer right after
`copy_prefetched_` leaves the result intact (fails without the sync).
- Full RL CPU suite: same failures as the parent PR (env: vllm/monarch).
- Memory/perf bench (`ModelStateDictTransport` only, no RL loop;
Llama3-8B shapes, 32 layers, fp32 trainer DTensors with the torchtitan
FSDP+TP plan, bf16 generator, NIXL, median of 5 iterations, max over
ranks, 0 mismatched keys everywhere). Reads are single-host UCX loopback
(`UCX_TLS=rc,sm,self,cuda_copy`) on shared GPUs, so read times are not
representative of cross-host RDMA. 8x B200, trainer FSDP 4 x TP 2:

| generator | embed/output | version | reads | stage ms | stage GPU peak
| read ms | load ms | load GPU peak |
|---|---|---|---|---|---|---|---|---|
| 8 x TP1 | yes | #5997 | 2068 | 66 | 136 MB | 2430 | 519 | 0 |
| 8 x TP1 | yes | this PR | 2068 | 82 | 136 MB | 2470 | 367 | 15 MB |
| 8 x TP1 | no | #5997 | 2052 | 59 | 59 MB | 2230 | 446 | 0 |
| 8 x TP1 | no | this PR | 2052 | 59 | 29 MB | 2120 | 466 | 15 MB |
| 1 x 8 ranks, dim 0 | yes | #5997 | 291 | 58 | 136 MB | 203 | 79 | 0 |
| 1 x 8 ranks, dim 0 | yes | this PR | 355 | 65 | 146 MB | 270 | 82 | 7
MB |
| 1 x 8 ranks, dim 0 | no | #5997 | 289 | 70 | 59 MB | 226 | 82 | 0 |
| 1 x 8 ranks, dim 0 | no | this PR | 353 | 47 | 29 MB | 166 | 51 | 7 MB
|

- Trainer: the restage temp is gone (stage peak 59 -> 29 MB without
embeddings); with embeddings both are bound by the embedding/output
cast. Staging buffer size is unchanged.
- Generator: load adds a GPU temp of the largest packed piece (7-15 MB
here, 29-59 MB on 2x GB200 TP 2). No extra CPU memory.
- Reads: same count for TP1 generators; +22% (291 -> 355) for dim-0
generators, since pieces of row-parallel weights are no longer merged by
the restage. Bytes read are unchanged.
- Times: differences are within run-to-run noise (2x GB200 dim-0 stage
repeated 75-234 ms on #5997). 2x GB200 TP 2 showed the same pattern.
tianyu-l added a commit that referenced this pull request Nov 26, 2026
…er override; agent self-review; rl/transport (#6407)

## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the
problem, why
     this approach, and what you checked yourself. -->

## Why

Since #5667, `@claude review` has reviewed 459 PRs. Of the 380 PRs it
approved,
30 then got a formal "request changes" from a maintainer, and about 20
more got
substantive inline asks. In nearly all of them the bot either saw the
problem
and approved anyway, or never asked the questions maintainers ask most
("does
the repo already do this?", "who should own this?"). The opposite
failure, the
bot blocking something a maintainer was fine with, is rare: in the PRs
we
sampled, 2 of its 81 must-fix items were wrong and about a third were
minor
(the empty human-written summary was the biggest source).

**Example** (#6112, controller sizes the rollout worker pool):

```
before: bot approved 10 times; tianyu-l then blocked: "the controller reads
        rollouter.rollouts_per_worker to compute a count it hands back to the
        Rollouter -- violates encapsulation"
after:  same commit, new skill -> Request changes, must-fix #1:
        "controller.py:589 -- wrong owner for the worker count ..."
```

There was also no way for a code owner to overrule the bot except
dismissing
its review in the GitHub UI, and a later `@claude review again` would
block
again.

## What changed

**Review skill** (`.claude/skills/pr-review/`, `review-checklist.md`):
- Verdict rules: Approve only when every remaining item is an edit the
bot
could write itself. Anything the author still owes (a design change, an
unexplained golden change, evidence the PR rests on) is Request changes;
anything only a maintainer can decide is Needs discussion. A hedge like
"a
  maintainer should decide" can't come with Approve.
- Always must-fix: a violated written rule, a silent wrong result, a
second
  definition of an existing concept, a gate finding.
- Design gate: new questions for the existing counterpart, in-repo
ownership,
and the design behind a bug; "ban only what doesn't work on main"; read
the
numbers behind a claim. The overlapping-PR search is mandatory and
reported.
- Re-review covers every commit since the last full review, including
code
taken from the bot's own suggestions. A scoped question gets a
`COMMENT`, not
  a whole-PR verdict.
- The bot fact-checks its own proposed fixes, and cites a source for
claims
  about external tools or marks them unverified (never must-fix).
- An empty "Summary (human-written)" is a one-line "Before merge" note
that
  never affects the verdict.
- Checklist: config ownership direction, general shared wrappers, dead
code the
PR creates, model variants as flavors, a mechanical pass over every new
or
  changed function.

**Code owner override** (`SKILL.md`, `claude-code.yml`,
`CONTRIBUTING.md`): a
code owner comments `@claude override` (optionally `@claude override
2,3:
<reason>`); the bot approves if nothing else is open and doesn't
re-raise the
overridden items. A code owner's GitHub approval or "LGTM" is not an
override,
so a teammate can approve without the bot dropping its findings.
Dismissing the
bot's review still unblocks the PR, but isn't an override: the bot can't
tell
who dismissed it.

**Agent self-review** (`CLAUDE.md`, `pr-description`): an agent
preparing a PR
runs `pr-review` in branch mode first and records unaddressed items in
an
optional "Self-review" section. PRs written without an agent are
unaffected; a
missing section is never a finding.

Where each new rule comes from (maintainer asks the bot missed):

| Change | PRs |
| --- | --- |
| No Approve with open design/evidence items or a "maintainer should
decide" hedge | #6007, #5837, #5997, #5712, #5511, #5996 |
| Author waiver can't clear a must-fix | #6201, #6202, #6203 |
| Existing counterpart; one source of truth | #5228, #6169, #5881,
#5823, #5824, #6059, #5812 |
| Responsibility owner; config ownership direction | #6112, #6332,
#5802, #5803, #6325 |
| Fix the design behind the bug; a TODO doesn't justify a workaround |
#5572, #5689, #5657 |
| Fact-check the bot's own suggested fixes | #5740, #5802, #5511, #4819,
#5543 |
| Re-review covers all new commits; scoped asks don't approve | #5824,
#5842 |
| Mandatory overlap search | #5885, #6248 |
| Ban only what doesn't work on main | #5543 |
| Summary placeholder no longer a must-fix | #6119, #6174, #6112, #5868
|

**Rules**: `design.md` gets the one-general-wrapper rule (moved from
`models.md`, whose glob skipped `torchtitan/rl`), thin adapters, and the
consumer owning its values; `config.md` gets ownership direction and "a
Config
doesn't read runtime state"; `direction.md` calls all-to-all the MoE
reference
implementation, so a new vendor-specific dispatch path (e.g. #6242)
needs a
reason the existing backends can't serve.

**Area reviewers**: `.ci/` -> huydhn, wwwjn; `torchtitan/rl/transport/`
-> d4l3k.

**Mechanical, skim**: `torchtitan/rl/transport/` holds data movement
between RL
actors.
- `rl/model_state_dict_transport.py` ->
`rl/transport/model_state_dict.py`
- `rl/MODEL_STATE_DICT_TRANSPORT.md` ->
`rl/transport/MODEL_STATE_DICT_TRANSPORT.md`
- `rl/trainer/rdma_microbatch.py` -> `rl/transport/rdma_microbatch.py`
- tests:
`tests/rl/unit_tests/cpu/test_{model_state_dict_transport,rdma_microbatch}.py`
->
`tests/rl/unit_tests/cpu/transport/test_{model_state_dict,rdma_microbatch}.py`
- imports, READMEs and `scripts/install_rl_env.sh` updated; no code
changes.

## User-facing changes

| Before | After |
| --- | --- |
| Overrule the bot: dismiss its review in the UI, and it blocks again on
the next run | `@claude override [items]: <reason>`; the bot approves
and doesn't re-raise them |
| Empty human-written summary: bot must-fix | One "Before merge" line,
no effect on the verdict |
| `from torchtitan.rl.model_state_dict_transport import ...` | `from
torchtitan.rl.transport.model_state_dict import ...` |
| `from torchtitan.rl.trainer.rdma_microbatch import ...` | `from
torchtitan.rl.transport.rdma_microbatch import ...` |

## Testing

Backtest: the new skill run locally (nothing posted) on each PR at the
commit
and thread state the bot originally saw.

| PR | Bot then | New skill | What the maintainer asked |
| --- | --- | --- | --- |
| #6112 | Approve | Request changes | worker-count ownership (caught) |
| #5837 | Approve | Request changes | apply to `dp_shard` too (caught) |
| #5572 | Approve | Request changes | delete the injection design
(caught) |
| #6201 | Approve after author waived pins | Request changes, waiver
ignored | pins broke GPU tests after merge (caught) |
| #6007 | Approve | Request changes | fold K3.1 into K3 (caught) |
| #5543 | Request changes: "ban it" | Request changes: keep main's path
| don't break gpt-oss + DeepEP (fixed) |
| #6144, #5905 (controls) | Approve | Approve | -- |
| #6137 (control) | Approve | Needs discussion | -- (merge gate on an
upstream API) |

Code owner override, simulated on #6201: override by a code owner lifts
the
named item; `@claude override` from the author changes nothing; a code
owner's
"LGTM" approval followed by "review again" keeps Request changes.

Transport move: 83 RL CPU unit tests pass locally
(`transport/test_model_state_dict.py`, `test_trainer.py`,
`test_engine_loop.py`). `transport/test_rdma_microbatch.py`,
`test_generator.py` and
`test_batcher_actor.py` fail to collect in my env on `origin/main` too
(stale
attention-gym / Monarch), so CI is the check for those.

## Known issues / follow-ups
- Open PRs that edit the moved files rebase cleanly (git follows the
renames),
but new imports of the old module paths will break: #6309 (adds a delta
transport that should live in `rl/transport/`), #6237, #6176, #6177,
#5862,
  and drafts #6127, #6393, #6163, #5764.
- The Actions bot can't read dependency source (e.g. SGLang); follow-up
for the
  workflow.

## Self-review
pr-review (branch mode) at ad905a5: Needs discussion. Fixed: branch
mode diffs
against `origin/main` and skips description findings before a
description
exists; the "Config doesn't read runtime state" rule no longer
contradicts
hardware validation; dismissal dropped as an override form (the bot
can't tell
who dismissed); `test_rdma_microbatch.py` added to the transport area.
Not
addressed:
- One concern per PR -- the five changes ship together at the
maintainer's
  request.
- Open PRs touching the moved files -- listed above; the maintainer will
  coordinate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants