Repository navigation
PT distributed, all collectives on the sync device - #2086
Merged
Merged
Conversation
The train loop control sync (has data, complete_frac) runs on the device the level syncs on: the train device, or the CPU with sync_on_cpu. Some collectives were still fixed to the CPU, independent of sync_on_cpu: the max of the counts in the state sync (train step, optimizer step tensors, integer buffers), the broadcast of the optimizer state values which are no tensors, the eval control broadcast, and the broadcast of the eval scores. Now they all run on that same device, so one backend (e.g. NCCL) does all of it. Counts which live on the CPU are moved there as one flat buffer per dtype. The flat reduce gets the device as an argument (sync_device, before: sync_on_cpu). No change in results.
…-distributed-sync-device # Conflicts: # returnn/torch/distributed.py
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.
The train loop control sync (has data,
complete_frac) runs on the device the level syncs on:the train device, or the CPU with
sync_on_cpu.Some collectives were still fixed to the CPU, independent of
sync_on_cpu:_sync_state(the train step, thesteptensors of the optimizer state, integer buffers),has_datafrom rank 0),eval_model.Now they all run on that same device, so one backend (e.g. NCCL) does all of it.
Counts which live on the CPU (the train step, the
steptensors of a non-capturable torch optimizer)are moved there as one flat buffer per dtype.
For that, the flat reduce gets the device as an argument,
_all_reduce_flat(..., sync_device=...)(before:sync_on_cpu).No change in results.
What stays on the CPU:
the hostname gather at init (on purpose, before the device is selected),
and the seed which the torch
DataLoadershares per iterator (inside torch, a CPU scalar).So a backend for CPU tensors is still needed.
Tests: the epoch-end sync test records the device of every
all_reduceandbroadcast(the counts of three dtypes, the Python values, the eval control broadcast, the eval scores; it gets a dev dataset for that)
and checks that all are on the train device.
New CUDA variant
test_torch_engine_distributed_param_sync_at_epoch_end_cuda(two gloo ranks on one GPU),which fails on master (the counts and all broadcasts on the CPU) and passes with this PR.
On the CPU the check holds trivially, so the CPU tests pass on master as well.
Run with torch 2.12:
tests/test_torch_engine.pypasses (62 passed, 35 skipped, the skipped ones need CUDA).Not measured: the timing. Not run: NCCL over several GPUs or hosts (the CUDA tests use gloo, with both ranks on one GPU).
Master is merged in after #2085 (the same line of the object broadcast); both runs above were repeated on the merge result for the distributed tests.