latest (dev)
Copy
Latest development documentation · Updated 2026-10-08
tensorplay.distributed.device_mesh
A device mesh is the execution context for
distributed tensors. It is an n-dimensional array
whose entries are global ranks: the value at coordinates
(i, j, ...) is the rank of the process holding that position of the mesh.
The mesh creates one process group per dimension, so collective operations
can run independently along each dimension — for example a 2D mesh
(2, 4) can do data parallelism along its first dimension and tensor
parallelism along the second.
This creates a DeviceMesh with an n-dimensional array layout, where n is the length of mesh_shape. |
|
The mesh is an n-d array whose values are global ranks. |
Creating a mesh
init_device_mesh() creates a
DeviceMesh from a device type and a tuple of mesh dimensions:
from tensorplay.distributed.device_mesh import init_device_mesh
# requires an initialized process group, e.g. via dist.init_process_group()
mesh = init_device_mesh("cuda", mesh_shape=(2, 4),
mesh_dim_names=("dp", "tp"))
Semantics follow the SPMD model: mesh_shape (and, when given,
mesh_dim_names) must be identical across all ranks, and the function blocks
until every rank has joined. Each mesh dimension can be given a name via
mesh_dim_names; the names are reflected in
mesh_dim_names and can
be used to address that dimension when sharding a
distributed tensor.
Querying the mesh
A DeviceMesh answers the usual questions about rank placement:
get_rank()— the global rank at a given coordinate (or the local rank of this process).get_local_rank()— the ordinal of this process within a mesh dimension.get_coordinate()— the coordinates of this process in the mesh.get_group()/get_all_groups()— the underlying process groups, per mesh dimension.
Where to go next
distributed tensors —
DTensorvalues that live on a mesh.tensor parallelism — sharding module weights across the mesh.
the distributed package — the process-group model and collectives the mesh is built on.
Help improve this page
Found an error, an unclear step, or a missing example?
tensorplay.distributed.checkpoint
tensorplay.distributed.checkpoint saves and restores the state of a distributed training job — one or more state_dict structures split across the ranks of a process group — and makes the checkpoint look like a single art
tensorplay.distributed.elastic
tensorplay.distributed.elastic runs a training job across a set of nodes that can change size while the job is live. The mental model has three moving parts:

