# DeviceMesh

Source: https://www.tensorplay.cn/docs/generated/tensorplay.distributed.device_mesh.DeviceMesh.html

# DeviceMesh

class tensorplay.distributed.device_mesh.DeviceMesh(device_type: [str](https://docs.python.org/3/library/stdtypes.html#str), mesh=None, *, mesh_dim_names=None, _dim_group_names=None, _rank_map=None, _sizes=None, _strides=None, _root_mesh=None)[[source]](../_modules/tensorplay/distributed/device_mesh.html#DeviceMesh)

DeviceMesh represents a mesh of devices (torch parity).

The mesh is an n-d array whose values are global ranks. Process groups
are created per mesh dimension so collectives can run on each dimension
independently.

Example:

```
>>> from tensorplay.distributed.device_mesh import init_device_mesh
>>> mesh = init_device_mesh("cuda", mesh_shape=(2, 4),
...                         mesh_dim_names=("dp", "tp"))
```

classmethod from_group(group, device_type=None, mesh=None, mesh_dim_names=None) &#x2192; [DeviceMesh](#tensorplay.distributed.device_mesh.DeviceMesh)[[source]](../_modules/tensorplay/distributed/device_mesh.html#DeviceMesh.from_group)

Construct a 1-D DeviceMesh from an existing ProcessGroup.

get_coordinate() &#x2192; [tuple](https://docs.python.org/3/library/stdtypes.html#tuple)[[int](https://docs.python.org/3/library/functions.html#int), ...] | [None](https://docs.python.org/3/library/constants.html#None)[[source]](../_modules/tensorplay/distributed/device_mesh.html#DeviceMesh.get_coordinate)

Returns this rank’s coordinate in the mesh, or None if absent.

get_group(mesh_dim=None)[[source]](../_modules/tensorplay/distributed/device_mesh.html#DeviceMesh.get_group)

Returns the process group along mesh_dim (torch parity).

get_local_rank(mesh_dim=None) &#x2192; [int](https://docs.python.org/3/library/functions.html#int)[[source]](../_modules/tensorplay/distributed/device_mesh.html#DeviceMesh.get_local_rank)

Returns local rank along mesh_dim (torch parity).
