Skip to content

[rl] Read model state dict directly into generator GPU with gpu_fetch - #6127

Draft
d4l3k wants to merge 3 commits into
gh/d4l3k/10/basefrom
gh/d4l3k/10/head
Draft

d4l3k wants to merge 3 commits into
gh/d4l3k/10/basefrom
gh/d4l3k/10/head

Conversation

@d4l3k

@d4l3k d4l3k commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Stack from ghstack (oldest at bottom):

Summary (human-written)

Problem

ModelStateDictTransport (the default since #6125) only supports model_state_dict_load_mode="cpu_prefetch"; gpu_fetch (for hosts with little CPU memory, e.g. GB300) raises at config time and must fall back to TorchStore (#6070).

Change

With gpu_fetch, each generator rank registers one GPU fetch buffer sized to the largest FSDP load group. During the load, fetch_ reads each group's pieces from the trainer's pinned CPU staging buffers into it (one-sided RDMA, deadline read_timeout_s) and copies them into the sharded params, unpacking packed keys. Trainer GPU -> trainer pinned CPU -> generator GPU; no generator CPU copy.

  • ModelStateDictTransport.connect_fetching_generator / fetch_.
  • ModelStateDictLoader.load_groups (+ engine property) gives the per-group layouts.
  • Generator uses them for its layout and for the gpu_fetch load; TorchStore remains the None path.
  • Removes the cpu_prefetch-only ValueError.

Depends on #6097 (packed reads) and #6125.

Before After
gpu_fetch + transport ValueError RDMA reads into GPU

Lines: impl +223/-50 (incl. docs), tests +66/-6.

Numerics: unchanged; reads are exact copies (checked bitwise).

Benchmark

Muse Spark Open 816B-A42B DAPO-Math, 14 GB300 hosts (trainer 10 hosts FSDP5 TP4 CP2 EP8; 1 generator x 4 hosts), NIXL, 10 steps, 1 run each. Baseline: main + #6125, cpu_prefetch (tt-muse14-nx-0dbdcc). Change: this PR, gpu_fetch (tt-muse14-gfnx-4abd25). Median/max over ranks and steps; times in s, memory in GB.

Baseline (cpu_prefetch) Change (gpu_fetch)
Trainer push, n=1 / n>=2 0.34 / 0.34 (max 0.37) 0.33 / 0.33 (max 0.35)
Generator pull (prefetch), n=1 / n>=2 1.84 / 1.84 (max 2.22) -
Generator load, n=1 / n>=2 0.86 / 0.73 (max 1.48) 2.24 / 2.15 (max 2.55)
Generator pull + load, n>=2 2.57 2.15
gpu_fetch RDMA read per load (65 groups) - 2.02 (max 2.06)
Generator RSS 105.6 8.2
Trainer RSS steady / peak 47.7 / 47.8 47.3 / 48.6
Generator GPU peak alloc / reserved 245.3 / 246.4 246.8 / 247.9
Trainer GPU peak alloc / reserved 197.0 / 249.6 197.0 / 248.2
Full-step tok/s 670 744
Setup: trainer staging registered (after last generator init) 6.3 6.4
Setup: generator connected (after last generator init) 14.7 11.3
Setup: last generator init -> training loop start 18.2 14.3

Generator CPU memory drops by ~97 GB/rank, since the generator no longer keeps a CPU copy. Load replaces prefetch + load and is 0.4 s faster at the median. Weight sync is off the critical path in both runs: steps are rollout-bound (step_time_ratio/batch 0.98, blocking push/pull ~0). The tok/s difference is within single-run noise. Node MemAvailable drop is ~0 in both.

Test plan:

  • pytest tests/rl/unit_tests/cpu: 658 passed (4 pre-existing env failures). New test_gpu_fetch: 4 trainer -> 2 generator ranks, contiguous bf16, packed stacked and preserved-fp32 keys across two groups.
  • Real NIXL/Mooncake GB200 smoke (trainer pinned CPU -> generator GPU fetch buffer, packed + contiguous keys): bitwise match.
  • RL integration tests via ciflow/rl (regression only: no CI config runs gpu_fetch with the transport; the GB200 smoke above is the end-to-end check).
  • Muse14 GB300 benchmark above: 10 steps complete on both arms.

[ghstack-poisoned]
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 16, 2026
d4l3k added a commit that referenced this pull request Nov 17, 2026
## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why
     this approach, and what you checked yourself. -->

## Problem

`ModelStateDictTransport` (the default since #6125) only supports `model_state_dict_load_mode="cpu_prefetch"`; `gpu_fetch` (for hosts with little CPU memory, e.g. GB300) raises at config time and must fall back to TorchStore (#6070).

## Change

With `gpu_fetch`, each generator rank registers one GPU fetch buffer sized to the largest FSDP load group. During the load, `fetch_` reads each group's pieces from the trainer's pinned CPU staging buffers into it (one-sided RDMA, deadline `read_timeout_s`) and copies them into the sharded params, unpacking packed keys. Trainer GPU -> trainer pinned CPU -> generator GPU; no generator CPU copy.

- `ModelStateDictTransport.connect_fetching_generator` / `fetch_`.
- `ModelStateDictLoader.load_groups` (+ engine property) gives the per-group layouts.
- `Generator` uses them for its layout and for the gpu_fetch load; TorchStore remains the `None` path.
- Removes the cpu_prefetch-only `ValueError`.

Depends on #6097 (packed reads) and #6125.

| | Before | After |
|---|---|---|
| `gpu_fetch` + transport | `ValueError` | RDMA reads into GPU |

Lines: impl +223/-50 (incl. docs), tests +66/-6.

Numerics: unchanged; reads are exact copies (checked bitwise).

Test plan:
- `pytest tests/rl/unit_tests/cpu`: 658 passed (4 pre-existing env failures). New `test_gpu_fetch`: 4 trainer -> 2 generator ranks, contiguous bf16, packed stacked and preserved-fp32 keys across two groups.
- Real NIXL/Mooncake GB200 smoke (trainer pinned CPU -> generator GPU fetch buffer, packed + contiguous keys): bitwise match.
- RL integration tests via `ciflow/rl` (regression only: no CI config runs `gpu_fetch` with the transport; the GB200 smoke above is the end-to-end check).
ghstack-source-id: b0c51d2
Pull-Request: #6127
d4l3k added a commit that referenced this pull request Nov 17, 2026
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.18.0)
(oldest at bottom):
* #6127
* __->__ #6125

## 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
`ModelStateDictTransport` (one-sided `torch.distributed._transport`
reads) replaced TorchStore for `cpu_prefetch` but was opt-in. It beat
TorchStore on every measured axis in two GB300 runs.

GB300 Muse Spark 18 hosts (trainer 10 hosts, 2 generators x 4 hosts, 11
steps):

| | TorchStore (NIXL) | ModelStateDictTransport (Mooncake) |
ModelStateDictTransport (NIXL) |
|---|---|---|---|
| Trainer push n=1 (median/max) | 5.05/5.38 s | 0.33/0.33 s | 0.33/0.35
s |
| Trainer push n>=2 (median) | 0.39 s | 0.33 s | 0.33 s |
| Generator pull n=1 (median/max) | 30.4/37.7 s | 14.9/26.1 s |
1.89/1.97 s |
| Generator pull n>=2 (median/max) | 13.1/19.9 s | 11.4/21.0 s |
1.91/2.46 s |
| Full-step tok/s (median) | 630 | 725 | 743 |
| Trainer RSS steady/peak (median/max) | 89.2/89.7 GB | 48.0/48.8 GB |
47.3/48.5 GB |
| Trainer node MemAvailable drop, push n=1 | 168 GB | 0 | 0 |
| Generator RSS steady/peak (median/max) | 105.5/105.7 GB | 106.6/106.8
GB | 105.5/105.6 GB |
| Trainer GPU peak alloc/reserved | 197/248 GB | 197/248 GB | 197/248 GB
|
| Generator GPU peak alloc/reserved | 245/246 GB | 245/246 GB | 245/246
GB |
| Setup: trainer staging alloc + pin + register (24-42 GB/rank) | none
up front (lazy, inside push n=1) | 2.2 s | 7.0 s |
| Setup: generator connect to 40 trainer ranks + register prefetch
buffers | none up front (lazy, inside pull n=1) | 30.0 s | 8.7 s |
| Setup: last generator ready -> training loop start (incl. initial
push/pull) | 45.0 s | 60.0 s | 19.3 s |

Setup is measured from the last generator becoming ready (slowest rank).
Pinning is the same code for both backends, so the trainer gap (7.0 vs
2.2 s) is NIXL agent creation and UCX registration. Mooncake's generator
connect is the largest setup cost. Trainer registration includes the
generator layout RPC.

GB300 Qwen3.5 27B (separate, smaller run; pull is the slowest generator;
memory identical across arms; push not recorded):

| | TorchStore (NIXL) | ModelStateDictTransport (Mooncake) |
ModelStateDictTransport (NIXL) |
|---|---|---|---|
| Generator pull n=1 | 22.5 s | 4.56 s | 0.95 s |
| Generator pull n>=2 | 15.6-16.8 s | 2.2-2.8 s | 0.96-1.08 s |
| tok/s (mean) | 13.0k | 16.9k | 15.7k (one 3.2k outlier step) |

Memory is per rank, sampled every 50 ms during push/pull/load. On H100
32x8 Muse (trainer FSDP CPU offload, Mooncake): generator pull n=1 102
-> 8.3 s (median), generator RSS 54.1 -> 56.1 GB (max 54.3 -> 58.2),
trainer RSS 124 -> 109 GB, GPU identical. Pulled weights were checked
bitwise against the trainer across FSDP/TP/EP layouts (0 mismatches).

## What changed
| | Before | After |
|---|---|---|
| `Controller.Config.model_state_dict_transport` default | `None`
(TorchStore) | `ModelStateDictTransport.Config()` (NIXL) |
| `generator.model_state_dict_load_mode="gpu_fetch"` | works by default
| requires `model_state_dict_transport=None` (ValueError says so) |

- `ModelStateDictTransport.Config.backend` defaults to `"nixl"` instead
of `"mooncake"`. On a GB200 devserver, Mooncake's default RDMA path took
25-39 s per small read vs about 1 ms for NIXL, and RL CI (torch
2026-11-07) cannot load Mooncake (`transport 'mooncake' is not
supported`) and lacks the Mooncake fix
pytorch/pytorch#203623.
- Mooncake doc: set `MC_FORCE_TCP=1` on hosts without RDMA devices
(Mooncake's NVLink fallback cannot read pinned CPU memory).
- Run 2 of the `rl_grpo_checkpoint_resume` integration test sets
`model_state_dict_transport=None`, so CI keeps covering TorchStore until
it is deleted; run 1 covers `ModelStateDictTransport`.
- Docs and README updated.

Lines: implementation +20/-14 (controller +10/-6, transport +1/-1, docs
+9/-7), tests +8/-4.

Test plan:
- `pytest tests/rl/unit_tests/cpu
--ignore=tests/rl/unit_tests/cpu/test_vllm_wrapper.py`: 657 passed; 4
failures are a local env ImportError
(`torch_checkpointing.CallbackArgs`), unrelated.
- Audited in-repo `Controller.Config` users: no recipe or integration
test uses `gpu_fetch`; existing `gpu_fetch` tests build engines
directly.
- NIXL and Mooncake real-backend read smoke on GB200 (pinned CPU and GPU
buffers, packed and contiguous keys, bitwise compare): both pass.
- RL integration tests (NIXL in every entry except run 2 of
`rl_grpo_checkpoint_resume`, which uses TorchStore): via `ciflow/rl` CI.
d4l3k added a commit that referenced this pull request Nov 17, 2026
## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why
     this approach, and what you checked yourself. -->

## Problem

`ModelStateDictTransport` (the default since #6125) only supports `model_state_dict_load_mode="cpu_prefetch"`; `gpu_fetch` (for hosts with little CPU memory, e.g. GB300) raises at config time and must fall back to TorchStore (#6070).

## Change

With `gpu_fetch`, each generator rank registers one GPU fetch buffer sized to the largest FSDP load group. During the load, `fetch_` reads each group's pieces from the trainer's pinned CPU staging buffers into it (one-sided RDMA, deadline `read_timeout_s`) and copies them into the sharded params, unpacking packed keys. Trainer GPU -> trainer pinned CPU -> generator GPU; no generator CPU copy.

- `ModelStateDictTransport.connect_fetching_generator` / `fetch_`.
- `ModelStateDictLoader.load_groups` (+ engine property) gives the per-group layouts.
- `Generator` uses them for its layout and for the gpu_fetch load; TorchStore remains the `None` path.
- Removes the cpu_prefetch-only `ValueError`.

Depends on #6097 (packed reads) and #6125.

| | Before | After |
|---|---|---|
| `gpu_fetch` + transport | `ValueError` | RDMA reads into GPU |

Lines: impl +223/-50 (incl. docs), tests +66/-6.

Numerics: unchanged; reads are exact copies (checked bitwise).

Test plan:
- `pytest tests/rl/unit_tests/cpu`: 658 passed (4 pre-existing env failures). New `test_gpu_fetch`: 4 trainer -> 2 generator ranks, contiguous bf16, packed stacked and preserved-fp32 keys across two groups.
- Real NIXL/Mooncake GB200 smoke (trainer pinned CPU -> generator GPU fetch buffer, packed + contiguous keys): bitwise match.
- RL integration tests via `ciflow/rl` (regression only: no CI config runs `gpu_fetch` with the transport; the GB200 smoke above is the end-to-end check).
ghstack-source-id: 3be2885
Pull-Request: #6127
@claude claude Bot mentioned this pull request Nov 25, 2026
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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

1 participant