Repository navigation
[rl] Send each trainer DP replica only its column of the grid - #5301
Closed
felipemello1 wants to merge 1 commit into
Closed
felipemello1 wants to merge 1 commit into
felipemello1 wants to merge 1 commit into
Conversation
The controller called forward_backward on the whole trainer mesh with the step's [num_microbatches][dp_degree] grid, so every rank received every DP column and kept one. It now splits the trainer mesh into DP replicas (the trainer orders ranks as (dp, cp, tp)) and calls each replica with only its column; a startup check confirms each replica's ranks report its DP rank. Trainer.forward_backward takes that column. This cuts the by-value message and unpickle per rank to 1/dp, and works with or without the RDMA fast path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TLDR: Every trainer rank received the whole step's
[num_microbatches][dp_degree]microbatch grid and kept only its column. Now each DP replica receives only its column, so each rank receives1/dp_degreeof the bytes. CPU Monarch, 4 ranks, a 2.6 GB step: 5.3 -> 2.1 s at dp 4 and 5.0 -> 3.0 s at dp 2 x tp 2, and peak memory per rank 7.6 -> 1.9 GB / 3.8 GB. Stacked on the PR that adds the opt-in RDMA fast path; works with it on or off.Problem
[num_microbatches][dp_degree]grid ofTrainingMicrobatch.trainer.forward_backwardon the whole trainer mesh with the whole grid.1/dp_degreeof it, and needs ~3x the message in fresh memory while it unpickles.Solution
(dp, cp, tp), and RL rejects PP. So each DP replica iscp * tpconsecutive ranks.Controller.setup_asyncuses Monarch'ssplitto cut the trainer mesh into one sub-mesh per DP replica, once.get_dp_rankendpoint, and setup raises if a replica's ranks don't all match.Controller._trainer_loopsends one call per replica, each with its column, then awaits them together. It reads rank 0's metrics as before.Trainer.forward_backwardtakes that column,microbatches: [num_microbatches], instead of the grid.Results
CPU Monarch, one host, 4 rank processes, real
TrainingMicrobatches, 131,072-token microbatches at 614 B/token (routed expert ids and top-32 logprobs inmodel_kwargs), RDMA fast path off. Time from the call to every rank holding its column:GPU, Qwen3-0.6B, H100, batch invariant, lockstep, trainer DP 2 (3 GPUs), one TP 1 generator, Monarch 0.7, 5 steps:
loss/meanis bitwise equal to main's DP 2 run at every step with the RDMA fast path on, at this PR's head. On top of the whole stack (the same final code), it is also bitwise equal with the fast path off and on.CPU mesh check (the controller's actual setup and
_trainer_loopcode against real Monarch actor meshes, a fake trainer with the real DP-rank lines and a collective that spans replicas; run when this PR sat on top of the batcher-process PR):You may ask:
1/dp_degree.cp * tptimes on the controller's event loop.NOTE:
cp * tpranks of a replica still each receive the same column (the "read once per replica" TODO).Test plan
pytest tests/rl/unit_tests/cpu(from the repo root, Monarch 0.7): 435 passed, 5 skipped; the 2 failures (test_verifiers_terminal_bench.py, a config mismatch) fail on main too.test_trainer.py:forward_backwardtrains a column by value, and reads a column ofRDMAMicrobatches before training it.