For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).
Python class
DeviceMesh
DeviceMesh
class max.experimental.sharding.DeviceMesh(devices, mesh_shape, axis_names)
Bases: object
An N-dimensional logical grid of devices.
axis_names
The human-readable name for each mesh axis.
axis_size()
axis_size(axis)
Returns the size of a mesh axis by name or index.
For several axes, returns the number of devices they span together,
which is the product of their sizes. On a (2, 3) mesh,
mesh.axis_size((0, 1)) == 6.
-
Parameters:
-
axis (str | int | Sequence[str | int]) – The mesh axis or axes, by name or integer index.
-
Returns:
-
The number of devices along
axis. -
Raises:
-
- ValueError – If
axisis a name not on the mesh. - IndexError – If
axisis an integer outside[0, ndim).
- ValueError – If
-
Return type:
device_coord()
device_coord(device_idx, axis)
Returns device_idx’s coordinate along the given mesh axis.
For a mesh shaped (2, 3) with row-major device ordering, the
device at flat index 4 has coords (1, 1) — so
mesh.device_coord(4, 0) == 1 and
mesh.device_coord(4, 1) == 1.
For several axes, returns the device’s index among the devices they
span, counted in row-major order over the axes as given, so
mesh.device_coord(4, (0, 1)) == 4.
-
Parameters:
-
Returns:
-
The device’s coordinate along axis, in
[0, axis_size(axis)). -
Raises:
-
- IndexError – If
device_idxis out of range, or ifaxisis an integer outside[0, ndim). - ValueError – If
axisis a name not present on the mesh.
- IndexError – If
-
Return type:
devices
The devices in the mesh, in row-major order.
mesh_shape
The shape of the logical grid.
ndim
property ndim: int
The number of mesh dimensions.
num_devices
property num_devices: int
The total number of devices.
single()
static single(device)
Creates a trivial single-device mesh.
-
Parameters:
-
device (Device)
-
Return type: