IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).

Python class

DeviceMesh

DeviceMesh​

class max.experimental.sharding.DeviceMesh(devices, mesh_shape, axis_names)

source

Bases: object

An N-dimensional logical grid of devices.

Parameters:

axis_names​

axis_names: tuple[str, ...]

source

The human-readable name for each mesh axis.

axis_size()​

axis_size(axis)

source

Returns the size of a mesh axis by name or index.

Raises:

  • ValueError – If axis is a name not on the mesh.
  • IndexError – If axis is an integer outside [0, ndim).

Parameters:

axis (str | int)

Return type:

int

default()​

static default()

source

Returns a single-device mesh on the default device (CPU).

Return type:

DeviceMesh

device_coord()​

device_coord(device_idx, axis)

source

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.

Parameters:

  • device_idx (int) – The flat device index in row-major order.
  • axis (str | int) – The mesh axis to query, by name or integer index.

Returns:

The device’s coordinate along axis, in [0, axis_size).

Raises:

  • IndexError – If device_idx is out of range, or if axis is an integer outside [0, ndim).
  • ValueError – If axis is a name not present on the mesh.

Return type:

int

devices​

devices: tuple[Device, ...]

source

The devices in the mesh, in row-major order.

is_simulated​

property is_simulated: bool

source

Returns True if all mesh slots reference the same device.

A simulated mesh uses graph-level ops to emulate multi-device collectives on a single CPU or GPU.

is_single​

property is_single: bool

source

Returns True if this mesh contains exactly one device.

mesh_shape​

mesh_shape: tuple[int, ...]

source

The shape of the logical grid.

ndim​

property ndim: int

source

The number of mesh dimensions.

num_devices​

property num_devices: int

source

The total number of devices.

single()​

static single(device)

source

Creates a trivial single-device mesh.

Parameters:

device (Device)

Return type:

DeviceMesh