advanced27 min studyLesson 558 in Engineering

Device meshes: multiply ranks without multiplying sharding claims

Compose tensor, data, context, and pipeline dimensions while accounting separately for parameter replicas and activation shards.

On this page

What you’ll understand

  • Identify tensor-parallel and data-parallel groups on a small mesh.
  • Compute local weight payload without dividing by replica dimensions.
  • Explain why each parallel axis has its own communication and ownership contract.

A multidimensional device mesh organizes ranks into groups that cooperate in different ways. One axis may split a layer’s parameters, while another repeats that logical model shard for different data. A third may partition token context while retaining parameter replicas, and pipeline stages may own different layers. Multiplying axis sizes counts ranks; it does not mean every tensor is divided by their product. Account for each tensor’s placement on each axis.

A mesh axis defines a group, not one universal tensor split

Consider a2×2 mesh whose first axis is data parallel and second is tensor parallel. With ranks arranged[[0,1],[2,3]], tensor-parallel groups are{0,1} and{2,3}, while data-parallel counterpart groups are{0,2} and{1,3}. Each TP group computes one logical model replica on a data shard. Corresponding parameter shards across DP groups need matching initialization and the defined gradient synchronization. Merely creating the mesh does not make a model’s current tensors obey those placements.

Process-group and collective ordering must be consistent across participants. A rank selecting the wrong mesh slice can hang or combine unrelated values. Physical topology also matters for performance: a communication-intensive TP axis can benefit from a stronger interconnect, while the DP axis may have a different traffic pattern. These are placement decisions based on the selected algorithm and hardware, not universal claims that one axis must always be intra-node or that all meshes have equal cost.

Nranks=PDPPTPPCPPPPN_{\rm ranks}=P_{\rm DP}P_{\rm TP}P_{\rm CP}P_{\rm PP}
This product counts ranks when the four axes are independent dimensions of one complete rectangular mesh. It does not specify a tensor’s local size, and omitted axes have degree 1. Pipeline stages and context groups still need an actual model/data assignment.↔ Scroll wide equations horizontally.

Replicated dimensions do not reduce local parameter payload

For a layer whose weights are evenly tensor-sharded over TP and otherwise replicated in DP, local parameter elements equal that layer’s count divided by TP, not by TP×DP. DP increases the number of copies of each shard. Context parallelism commonly partitions sequence activations while retaining parameter copies across the relevant context ranks; its gradient groups must combine those token contributions. Pipeline parallelism assigns layers to stages, so its parameter accounting depends on which layers a stage actually owns, not a blanket division of every individual layer.

Optimizer-state sharding is another independent placement choice. Adding a sharded optimizer can change local optimizer memory without changing which weight shard a rank needs during the forward pass. Tied parameters across pipeline boundaries need explicit treatment. Distinguish unique logical parameter elements, resident per-rank bytes, and aggregate bytes across the cluster. A chart that divides every category by the total device count can look balanced while badly understating memory needed on each rank.

Mweights,local=NlayersPTP,Mweights,aggregate=PDPNlayersM_{\rm weights,local}=\frac{N_{\rm layer}s}{P_{\rm TP}},\qquad M_{\rm weights,aggregate}=P_{\rm DP}N_{\rm layer}s
This counts the entire two-axis DP×TP mesh: one layer is evenly TP-sharded and DP-replicated, and every other replication or sharding dimension has degree 1. A separate replicated CP axis would multiply the cluster aggregate by its degree. s is bytes per stored element. These are weight payloads only, excluding gradients, optimizer states, padding, buffers, and pipeline-specific ownership changes.↔ Scroll wide equations horizontally.

Compose the objective as carefully as the topology

DP ranks often process different data, whereas TP ranks cooperate on the same logical examples. Averaging a loss across both indiscriminately can introduce extra factors. Sequence/context owners may hold unequal valid-token counts, so global mean scaling needs a valid-count denominator and the framework’s actual sum or average reductions. Track where gradients have already been combined to avoid reducing them twice. A correct mesh is a map of identities and algebraic responsibilities, not just a convenient reshape of rank numbers.

The reliability lab counts available replicas only. Reset, set n=4 and k=0, predict four up with majority threshold 3, then Step. This does not build a device mesh or establish TP/DP membership, and majority has no role in the parameter formulas. It supplies a simple reminder that four available devices are a capacity count, not evidence that every tensor has four distinct shards. The mesh and weight example below carries the actual ownership argument.

Four devices but only two distinct weight shards

Use the mesh[[0,1],[2,3]] with DP=2 and TP=2. One layer has 16 parameter elements, each stored in two bytes, evenly split by TP and replicated by DP.

  1. Each TP group holds two eight-element shards that together represent the 16-element layer. Rank 0 and rank 2 own corresponding copies of one shard; rank 1 and rank 3 copy the other.

  2. Local weight payload is 8×2=16 bytes per rank. Dividing 16 elements by all four devices would incorrectly predict only four elements per rank.

  3. Aggregate payload is 4×16=64 bytes, equal to two DP copies of the 32-byte logical layer. This count says nothing about additional gradients, optimizer memory, communication buffers, or activation layout.

The result

TP splits the selected layer, while DP repeats its shards. Counting devices and counting unique parameter pieces are different operations.

Explore the model

Interactive lab

Interactive lab · reliability

Count devices without inventing tensor shards

Reset, set n=4 and k=0, predict four available replicas, then Step. This availability model does not create a device mesh, TP/DP groups, gradient synchronization, or parameter sharding; its majority threshold is unrelated.

Count devices without inventing tensor shardsA replica count and a majority threshold, without a consensus protocol. Playback highlights fixed replica states. Having a majority alone does not establish linearizability, durability or failure independence. Current readings: Available replicas: 4 of 5; Majority needed: 3; Majority available?: Yes. All parameters are adjustable with the labeled controls below.Majority available · need 3 of 5Playback highlights fixed statesR1 · upR2 · upR3 · upR4 · upR5 · downCyan mark: majority threshold
AvailableUnavailableMajority threshold
Available replicas
4 of 5
Majority needed
3
Majority available?
Yes
t = 0 s

A replica count and a majority threshold, without a consensus protocol. Playback highlights fixed replica states. Having a majority alone does not establish linearizability, durability or failure independence. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forA device count alone cannot determine which logical values are distinct or replicated.

Check your understanding

A layer is TP-sharded over 4 ranks and replicated over DP=2. With no other weight sharding, what fraction of its elements does one rank store?

Try it yourself

A layer has 1,024 elements at two bytes each, TP=4 and DP=2. Compute local and aggregate weight payload under the same assumptions.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Use TP for each local shard and DP for the count of complete logical copies.

Compare with the solution

Each rank stores 1,024/4=256 elements, or 512 bytes. Eight ranks total 4,096 bytes, equal to two copies of the 2,048-byte logical layer. This excludes all non-weight state and assumes even supported partitioning.

Take it with you

  • Mesh axis sizes count participants, while tensor placements define ownership.
  • Replication axes do not automatically divide local parameter storage.
  • Gradient groups and loss normalization must match the composed parallel objective.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.