DeviceMesh is a PyTorch abstraction for arranging devices into a communication mesh. It defines named dimensions and creates process groups for coordinating different kinds of parallel work, such as replicated models and partitioned layers. section 16.6 section 16.12
A two-dimensional mesh
A 2 × 4 mesh can represent two model replicas, each split across four devices: from torch.distributed.device_mesh import init_device_mesh mesh_2d = init_device_mesh( "cpu", (2, 4), mesh_dim_names=("replicate", "model_parallel") ) The named dimensions expose separate communication groups. The replicate dimension can synchronize model parameters, while the model_parallel dimension can coordinate a partitioned forward pass. section 16.6
A DeviceMesh helps organize:
- Higher-dimensional parallelism that combines data, model, pipeline, tensor, or context parallelism. section 16.12 section 16.6
Figure 16.9 Visualization of a 2 × 4 device mesh, where the rows represent model replicas and the columns represent model partitions. The dashed arrows represent how each device is communicating.
Visualize how rows represent model replicas, columns represent model partitions, and dashed links show communication between devices. section 16.6
