Megatron-LM
Megatron-LM copied to clipboard
Incorrect world_size logic in run_simple_mcore_train_loop.py causes deadlock
Describe the bug
In run_simple_mcore_train_loop.py, the script derives world_size from torch.cuda.device_count(). When launching with fewer processes than available GPUs, this results in a mismatch between world_size and WORLD_SIZE provided by torchrun, causing init_process_group to deadlock.
Example: running with --nproc_per_node=2 on an 8-GPU machine hangs during initialization.
Steps/Code to reproduce bug
-
Use a machine with more GPUs than the number of processes to launch.
-
Run:
torchrun --nproc_per_node=2 examples/run_simple_mcore_train_loop.py
- The script hangs at:
torch.distributed.init_process_group(world_size=world_size, rank=rank)
Expected behavior
The example should initialize without deadlock.
Using:
world_size = int(os.environ["WORLD_SIZE"])
avoids the mismatch.
Additional context
This may be related to issue #881.