Repository navigation
Conversation
With Generator.Config.receive_quantized_operands (default False), the trainer quantizes each parameter the generators hold quantized (MXFP8 Dist-MoE experts) with the generators' own format and sends the operand bytes. The generator copies them straight into the operand storage its forward reads: loads no longer reallocate, unshard or re-quantize those parameters, and the sync moves fp8 codes and scales instead of BF16 (61 -> 33 GB per sync for Qwen3-30B-A3B). The operands are bitwise the ones a BF16 load re-quantizes. - _ShardedFSDPTensor._packed_operands: optional format hook returning views of the operands with one row per row of the logical tensor's dim 0 (one per expert); MXFP8 Dist-MoE implements it. - torchtitan/rl/quantized_operands.py: the format a generator reports (class and __tensor_flatten__ context), the byte layout sharded on dim 0 like the parameter, and the trainer-side packing. - ModelStateDictLoader.receive_quantized_operands: swaps the prefetch buffers of quantized parameters for their packed rows; loads leave their FSDP parameter groups unsharded and copy the rows into the operands. - ActorSystem.initialize_quantized_operands hands generator rank 0's formats to the trainer before the model state dict transport initializes; the trainer packs them in _trainable_model_state_dict on the push stream, and _preserve_dtype_keys casts only parameters. Unsupported layouts raise: gpu_fetch, trainer shards that split an expert, generator FSDP groups that mix quantized and other parameters (EP 1), FSDP sharding of a quantized parameter on the generator. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Same behavior on every supported configuration; about half the diff of the previous commit: - ModelStateDictTransport keeps the dtype of non-floating-point tensors, as TorchStore's _wire_dtype does, instead of the trainer listing every non-parameter key as preserved; revert the _preserve_dtype_keys rewrite. - Inline operand_format; drop the "nothing quantized" ValueError and the post-fetch missing-keys check (cpu_prefetch fills every key); the FSDP-sharding check on the generator becomes an assert (full EP). - Shorter docs. - Tests: the 2-GPU check parametrizes the existing MXFP8 generator test; the CPU tests keep only the mixed-group ValueError and the uncast bytes in test_mixed_dtypes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With ModelStateDictTransport.Config.xor_delta_codec="zstd" (default None), each trainer rank sends every push after the first as the XOR of its staged bytes with the previous push's, compressed with nvCOMP zstd on its GPU per 256 MiB window. Generator ranks read only the compressed windows covering their pieces, decompress them on their GPU and XOR them into their prefetch buffers, which end up bitwise equal to a whole read. The first push, a missed push and a delta that does not fit its buffer fall back to whole reads. On Qwen3-30B-A3B (FP32 master, BF16 sent) a push shrinks 27-53x at lr 5e-6, from 15.3 GB to ~0.5 GB per generator rank. With one generator on InfiniBand the pull time is unchanged; with two generators it drops from 2.15 to 1.66 s, and over TCP from 6.26 to 1.66 s. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lace With receive_quantized_operands, a generator's quantized experts keep the previous push's operand bytes between loads. ModelStateDictTransport takes them as resident keys: their XOR deltas skip the CPU prefetch buffers, and copy_prefetched_ decompresses them on the GPU and XORs them into the live operand tensors. For MXFP8 Qwen3-30B-A3B, over sending the operands whole: pull 0.79 -> 0.33 s, load 0.36 -> 0.28 s, ~0.09 GB instead of 8.2 GB per rank per push. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
|
@claude review |
|
Claude finished @tianyu-l's task in 4m 40s —— View job Needs discussion -- review posted. The maintainers still need to decide RFC #6178 Q3 (XOR into live weights; should the BF16 weights get it too?), and #6152 and #6176 haven't been reviewed yet. Must fix: the empty human-written summary, and an unchecked read/load contract in |
There was a problem hiding this comment.
Verdict: Needs discussion -- This PR's own commit (3114fdc, +171/-36) is small and I found no correctness bug on the paths it exercises. But it writes deltas straight into the generator's live weights, which is RFC #6178 question 3, and no maintainer has answered that yet. It is also stacked on #6152 and #6176, which have no reviews. I reviewed only 3114fdc.
What this PR does. With receive_quantized_operands, the generator's MXFP8 expert operands stay on the GPU between loads. They are passed to connect_generator as resident_keys. On a delta read, read() XORs only the non-resident keys into the CPU prefetch buffers and keeps the resident keys' compressed windows in the receive buffer. At load time, copy_prefetched_ decompresses those windows on the GPU and XORs them into the operand tensors in place. A push read whole still loads through the prefetch buffers. Once a delta read happens, the resident keys' prefetch buffers are stale until the next whole read.
Example. One generator rank, expert key w13.weight.qdata:
push 0 (whole): read -> prefetch[qdata] = P0; load -> gpu[qdata] = P0
push 1 (delta): before: read XORs into prefetch (P1); load copies prefetch -> gpu (8.2 GB/rank over the wire)
after: read keeps compressed d1 = P0^P1 in the receive buffer, prefetch[qdata] stays P0
load: gpu[qdata] ^= decode(d1) -> P1 (~0.09 GB/rank over the wire)
push 2 (too big) read whole -> prefetch[qdata] = P2; load copies prefetch -> gpu, as before
Must fix
- The PR description's "Summary (human-written)" section is empty. CLAUDE.md requires the author to write it, and agents must not fill it in.
torchtitan/rl/model_state_dict_transport.py:956-- The "onecopy_prefetched_per read" contract is never checked. Two reads without a load in between, or two loads after one read, corrupt the expert weights with no error. About 6 lines would turn that into an assert (see the inline comment).
Questions
- RFC #6178 Q3 asks whether this should extend to the BF16 weights. That would be the shared version of this design. If every key were resident,
_apply_deltasand its CPU-side H2D/XOR/D2H pipeline could go, along with the per-key resident/non-resident split in_plan_deltas,readandcopy_prefetched_. The cost is that the generator reallocates FSDP-sharded storage on every load (_restore_sharded_params). Only the unsharded params persist, and they use a different layout from the prefetch buffers. Maintainers should decide whether only operands get the in-place path before this lands. If so,MODEL_STATE_DICT_TRANSPORT.mdshould say why. - The ~8.2 GB/rank of operand prefetch buffers are now only used for whole reads (first push, a missed push, an oversized delta). Is that pinned memory worth keeping, or should one of those cases fail clearly instead?
Details
- Checked and found fine:
- Byte offsets: a resident part's offset is
local_byte_offset + lo - byte_offsetinto a non-packed buffer. The destination (_packed_operandsfrompacked_operand_tensors) has the same rows and shape as its prefetch buffer, and the packed-keyValueErrorguarantees the two layouts match. - Receive capacity and
_plan_delta_readsnow count resident windows. - Whole/delta is decided across all of a rank's sources, so stale resident prefetch buffers are never mixed with fresh ones.
- Scratch buffers come from the caching allocator on the codec stream and are synchronized before they are freed.
wait_stream(caller)orders the XOR after queued forwards, ascopy_already does for hot swap.ModelStateDictLoader.loadfetches all of_packed_operandsin one call, so theresident.keys() == self._resident_keysassert holds.
- Byte offsets: a resident part's offset is
- Call order today:
InterGeneratorRouter.pull_model_state_dictawaits the prefetch, then the load. Engine-loop coalescing can merge load messages but not prefetches, so the invariant in must-fix 2 currently holds. - Tests: the parametrization changes from
[1, 2]to[(1, False), (2, True)]. That still covers HSDP with packed non-resident keys, and adds resident keys under HSDP, the whole-read fallback and the missed-push path. No coverage is lost. - Minor: a window that holds both resident and non-resident parts is decoded twice, once in
readand once in the load. That is boundary windows only, so the cost is negligible.
Not verified: that nothing in vLLM or SGLang (CUDA graph re-capture, sleep/wake) rewrites the operand tensors between loads; the PR's 154-push bitwise run is the only evidence. I also didn't verify the MXFP8 timing and memory numbers; this review ran no GPU jobs.
| transfers = self._reads if whole else [t for _, ts, _ in planned for t in ts] | ||
| await self._transfer(transfers) | ||
| read_s = time.perf_counter() - start_s | ||
| self._resident_deltas = [] |
There was a problem hiding this comment.
This line throws away the previous read's resident deltas without checking whether they were applied. Resident keys only work if each delta read is followed by exactly one copy_prefetched_ of the resident keys before the next read. The transport assumes that order but never checks it, and both ways of breaking it corrupt weights without any error:
- Two reads with no load in between: delta N is dropped here, so the destinations at N-1 get only delta N+1. Meanwhile the non-resident prefetch buffers apply both deltas and end up correct, which makes the corruption harder to spot.
- A second
copy_prefetched_after one delta read:_resident_deltasis already[], so the loop at L1086-1091 copies the resident keys from prefetch buffers left over from the last whole read. The experts silently go back to an old push.
Today's callers follow the order: InterGeneratorRouter.pull_model_state_dict always prefetches and then loads, and load failures are fatal. But nothing else enforces it. A failure here would look like slow policy drift, not a crash. Principle 8 says to validate contracts like this, whose failure would otherwise be silent. Roughly 6 lines would cover both cases:
# read(), before planning
assert not self._resident_deltas, "the last read's resident deltas were never loaded"
...
# after the transfer: a delta read leaves resident keys' prefetch buffers stale
if whole:
self._resident_prefetch_stale = False
elif any(plan.resident_windows for plan, _, _ in planned):
self._resident_prefetch_stale = True
# copy_prefetched_, before copying a resident key from its prefetch buffer
assert not self._resident_prefetch_stale, f"{key}: stale prefetch buffer; load once per read"…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.
Summary (human-written)
Stacked on #6152 (quantized operands) and #6176 (XOR delta pushes). Design discussion: RFC #6178.
Why
With
receive_quantized_operands(#6152), a generator's quantized experts (e.g. MXFP8) keep the previous push's operand bytes on the GPU between loads. So their XOR deltas (#6176) can be XORed straight into them, as humans& do (blog), instead of making a round trip through the CPU prefetch buffers (8.2 GB per rank for MXFP8 30B) and a copy at load. Operand deltas are also sparser: 82-169x with zstd, against 27-53x for BF16.What changed
connect_generator(..., resident_keys): keys whose load destination keeps what the last load wrote. RaisesValueErrorfor a resident key whose pieces arrive packed.read()XORs only non-resident keys into the prefetch buffers.copy_prefetched_decompresses the resident keys' windows on the GPU and XORs them into the destination tensors. A push read whole loads them as before.receive_quantized_operands' operand keys as resident keys.MODEL_STATE_DICT_TRANSPORT.mddocuments it.Testing
The resident XOR on the GPU takes ~0.06 s per load.
Notes
🤖 Generated with Claude Code