liveBook · Manning

Device mesh

As explained in Deep Learning with JAX

An arrangement of multiple devices in a grid used to assign different tensor shards to different devices for parallel computation.

A device mesh arranges devices as an n-dimensional grid so tensor axes can be partitioned across selected mesh axes. Its shape expresses how computation and data shards are distributed, while create_device_mesh() chooses an ordering suited to the hardware topology and collective communication. section 8.1.1

>>> mesh_utils.create_device_mesh((8, 1), devices=jax.devices("cpu"))

Create an eight-device, two-dimensional mesh for CPU emulation or another available device set. A shape of (8, 1) partitions a tensor's first axis; (1, 8) partitions its second. section 8.1.1

The mesh shape must align with the tensor rank and divide its dimensions evenly. For example, a (2, 4) mesh can partition a (4000, 10000) array into 2,000-vector groups and 2,500-feature chunks. Each device computes partial dot products, then the partial results are combined. section 8.1.1 section 8.1.3

JAX supports positional meshes, where array positions determine partitioning, and named meshes, where resource names such as batch and features make the mapping explicit through Mesh, NamedSharding, and PartitionSpec. None leaves an axis replicated. section 8.1.6

Mixing data and tensor parallelism

A (4, 2) mesh can shard training items across four device groups while splitting selected model weights across two groups. Small final-layer parameters can remain replicated across all devices. section 8.2.2

How Deep Learning with JAX covers it

How deep it goes
Explains topology-aware construction, shape constraints, positional and named mappings, and sharded computation, but defers broader parallelism details.
Examples
Demonstrates (8, 1), (1, 8), and (2, 4) meshes for tensor axes, vector dot products, and neural-network training.
What it assumes
Assumes basic JAX arrays and tensor sharding, while teaching mesh shapes, device placement, and named resource axes.
What you can do after
Operate/configure JAX meshes and sharding specifications for partitioned arrays and mixed-parallel training.
How it connects
Connects device meshes to tensor sharding, positional sharding, named sharding, data parallelism, tensor parallelism, and pipeline parallelism.

Also explained in

Compare how 3 books explain device mesh →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with JAX. The section links point to the parts of the book it draws on.