kempnerforge.distributed.setup¶
Distributed process group and DeviceMesh initialization.
Sets up torch.distributed, CUDA devices, and constructs a DeviceMesh with named parallelism dimensions based on DistributedConfig.
Functions
Clean up distributed process groups. |
|
Return (rank, local_rank, world_size) from environment variables. |
|
|
Initialize distributed training and build the DeviceMesh. |
Check if the current process is rank 0. |
- kempnerforge.distributed.setup.get_world_info()[source]¶
Return (rank, local_rank, world_size) from environment variables.
Works with both torchrun (RANK/LOCAL_RANK/WORLD_SIZE) and direct srun launch (SLURM_PROCID/SLURM_LOCALID/SLURM_NTASKS). When running under srun, also sets RANK/LOCAL_RANK/WORLD_SIZE so that PyTorch’s env:// rendezvous can find them.
- kempnerforge.distributed.setup.is_rank_zero()[source]¶
Check if the current process is rank 0.
- Return type:
- kempnerforge.distributed.setup.init_distributed(config, seed=42)[source]¶
Initialize distributed training and build the DeviceMesh.
config.nccl_timeout_secis the collective timeout of the default process group this creates and of every groupinit_device_meshcreates for the mesh, which would otherwise get PyTorch’s default.init_device_meshcreates a group for each dimension smaller than the world, and for one as wide as the world only with CUDA and Gloo alone; otherwise that dimension uses the default group, which keeps the timeout it was created with. The options name the default group’s backend, so with the mixed backend a group is made withnew_groupeven when the default group is bound to a device, where torch 2.12 and 2.13 would split it and leave Gloo at its default. A bound default group of NCCL alone is split with these options. One of Gloo alone is split too, and Gloo keeps its default timeout there: naming it otherwise sends it tonew_group, which fails on the ranks a subgroup leaves out.- Parameters:
config (DistributedConfig) – Distributed configuration with parallelism dimensions.
seed (int) – Random seed for reproducibility.
- Returns:
DeviceMesh if world_size > 1, None for single-GPU.
- Return type:
DeviceMesh | None