A distributed training entry point must receive the process identity assigned by its launcher before it can join a process group. torchrun supplies that identity to every Python worker, so a two-process CPU probe can check the launch contract before model or GPU code is added.
For a single host, --standalone creates a local rendezvous and --nproc-per-node=2 starts two worker processes. Each process receives LOCAL_RANK, while the initialized process group reports RANK and WORLD_SIZE.
The probe uses the Gloo backend so it can run without GPUs. PyTorch must already be installed, and the two rank lines may appear in either order because separate workers write to the terminal independently.
Related: How to install PyTorch with pip
Related: How to run distributed training in PyTorch
Related: How to run a training loop in PyTorch
import os import torch.distributed as dist dist.init_process_group("gloo")
rank = dist.get_rank() world_size = dist.get_world_size() local_rank = int(os.environ["LOCAL_RANK"])
print(f"rank={rank} local_rank={local_rank} world_size={world_size}")
dist.destroy_process_group()
$ export OMP_NUM_THREADS=1
The setting limits CPU thread contention during this local smoke run and lasts only for the current shell.
$ torchrun --standalone --nproc-per-node=2 rank_probe.py rank=1 local_rank=1 world_size=2 rank=0 local_rank=0 world_size=2
The line order may vary. Distinct ranks with world_size=2 show that both workers joined the same launch.