Megatron-LM icon indicating copy to clipboard operation
Megatron-LM copied to clipboard

Incorrect world_size logic in run_simple_mcore_train_loop.py causes deadlock

Open vineash opened this issue 1 year ago • 0 comments

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

  1. Use a machine with more GPUs than the number of processes to launch.

  2. Run:

torchrun --nproc_per_node=2 examples/run_simple_mcore_train_loop.py
  1. 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.

vineash avatar Dec 02 '25 16:12 vineash