# tensorplay.distributed.device_mesh.init_device_mesh

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

# tensorplay.distributed.device_mesh.init_device_mesh

tensorplay.distributed.device_mesh.init_device_mesh(device_type: [str](https://docs.python.org/3/library/stdtypes.html#str), mesh_shape: [tuple](https://docs.python.org/3/library/stdtypes.html#tuple)[[int](https://docs.python.org/3/library/functions.html#int), ...], *, mesh_dim_names: [tuple](https://docs.python.org/3/library/stdtypes.html#tuple)[[str](https://docs.python.org/3/library/stdtypes.html#str), ...] | [None](https://docs.python.org/3/library/constants.html#None) = None, backend_override=None) &#x2192; [DeviceMesh](tensorplay.distributed.device_mesh.DeviceMesh.html#tensorplay.distributed.device_mesh.DeviceMesh)[[source]](../_modules/tensorplay/distributed/device_mesh.html#init_device_mesh)

Initializes a DeviceMesh based on device_type and mesh_shape (torch parity).

This creates a DeviceMesh with an n-dimensional array layout, where n
is the length of mesh_shape. If mesh_dim_names is provided, each
dimension is labeled as mesh_dim_names[i].

Note

Follows SPMD: ensure mesh_shape is identical across all ranks.

Example:

```
>>> mesh_1d = init_device_mesh("cuda", mesh_shape=(8,))
>>> mesh_2d = init_device_mesh("cuda", mesh_shape=(2, 8),
...                             mesh_dim_names=("dp", "tp"))
```
