Repository navigation
Train in several processes with DDP (#17) - #68
Merged
Merged
Conversation
Part of exea-labs#17. Not used yet; the next commit calls them. - dist_setup joins the process group when torchrun started the run (WORLD_SIZE, RANK, LOCAL_RANK): NCCL with one GPU per process, gloo on the CPU. A plain run gets rank 0 of 1 and nothing changes. - sync_from_rank0 runs after a search round on process 0. A replaced slot gets fresh random weights and cleared Adam rows on that process only, so the others take its circuits, weights, buffers and optimizer state. It stops with an error if the optimizer state no longer has the same layout on every process. - broadcast_ copies one tensor from process 0, through the device for tensors that live off it (Adam's step).
Part of exea-labs#17. torchrun --nproc_per_node N -m exealm.train.pretrain ... now trains in N processes; a plain run is unchanged (same weights, same search choices and the same log, checked on a 60-step run with search rounds and retrieval on). - Data: --batch is the total over processes. Every process draws the same batch from the same generator and keeps its own rows. The total must split into whole swarms per process, so a swarm never spans two. - Loss: each process's loss is weighted by its share of the targets, so the update is the one a single process would take on the whole batch, even when masked seam targets make the shares unequal. The logged train loss is the whole batch's. - Search: process 0 runs each round; then every process copies its circuits, weights and optimizer state. - Retrieval: process 0's datastore keys go to every process after each refresh. - Process 0 evaluates, logs, talks to W&B and writes checkpoints, so --resume auto works as before. The start record notes the number of processes. - find_unused_parameters, since RG slots read nothing without a library.
Part of exea-labs#17. tests/test_ddp.py starts two gloo processes on the CPU the way torchrun does, on the tiny preset with search rounds every 4 steps and retrieval on: - both processes end with identical parameters, through every replacement and update (switching the sync off makes this fail); - the search makes the same choices as one process on the same total batch, and validation stays within 0.01 bits per token; - a two-process run stopped at step 6 and resumed ends with exactly the weights of one that ran straight through; - a total batch that cannot split into whole swarms is refused.
Closes exea-labs#17. pretrain.py's docstring and docs/training.md say how to start a run with torchrun and what each process does. Measured on the tiny preset, 300 steps on a CPU: two processes match one process on the same total batch to within 0.0003 bits per token (two seeds differ by 0.033), and a two-process run resumes exactly. FSDP and a sharded datastore search stay on the to-do list. The README ticks DDP and swarm-aware multi-GPU training.
This was referenced Nov 20, 2026
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.
Closes #17.
What changed
torchrun --nproc_per_node N -m exealm.train.pretrain ...now trains in N processes (DDP: NCCL with one GPU per process, gloo on a CPU). A plain run is unchanged: same weights, same search choices and the same log on a 60-step run with search rounds and retrieval on.The issue's three points:
--batchis the total over processes. Every process draws the same batch and keeps its own rows, whole swarms only (a total that can't split into whole swarms per process is refused with a clear error). So N processes train on exactly the data one process would.--resume autoworks as before.Two more things it needed to stay one model:
sync_from_rank0). Without this the processes drift apart after the first replacement.Process 0 also evaluates, logs and talks to W&B.
Result (the issue's "done when")
tiny, synthetic data, 300 steps on a CPU, final validation bits per token:1 vs 2 processes differ by 0.0002 and 0.0003; seed 0 vs seed 1 by 0.033. With search rounds and retrieval on (60 steps), both make the same choices in all 10 search rounds. The Llama baseline gives the same numbers to 4 decimals.
The small remaining difference: each process updates its slots' running output size (the unit scale) from its own rows, and DDP copies process 0's buffers before each forward.
Not in this PR
FSDP, and a sharded datastore search (every process holds the whole datastore). Both stay on the to-do list.
Tests
tests/test_ddp.py(3 tests, about 90 s): two gloo processes started like torchrun, on the tiny preset with search rounds every 4 steps and retrieval on.Full suite: 229 passed, 2 skipped (226 on main plus these 3), and every commit passes on its own.