the xla path · 0/15
start the path

the xla path · Collectives · lesson 01 of 1

Six shardings, one matmul

The same (512,256) by (256,512) matmul, six ways of sharding it across eight devices, and the collectives XLAThe compiler: brilliant at fusing along dataflow edges, structurally unable to change your algorithm. That gap is why kernels exist.taught in /l/xla → actually inserted for each, captured on this repo.

the goal For any sharded matmul, predict whether resharding is needed at all, and read the inserted collectives as the partitioner's chosen plan rather than the only possible one.

mastery work · this chapter0/2
  1. go →
manual items are your word; auto items complete from your streaks, labs, and can-you ticks · stored in your browser only
§ 01

The table, from the capture

The corpus behind the collective picker instrument (EX·16 on the spmd chapter) holds six real cases: one matmul, shapes (512,256) x (256,512), on an eight-device mesh laid out (4 data, 2 model), jax 0.4.38. Each row names the two input shardings, the requested output sharding, and the collectives the compiled module actually contains. The table is worth reading before any theory, because two of its rows are silent and one of them is louder than you would guess.

a shardedb shardedout requestedcollectives inserted
rows over datareplicatedrows over datanone
rows over datareplicatedreplicatedall-gather
cols over modelrows over datareplicatedall-gather
replicatedcols over modelcols over modelnone
rows data, cols modelreplicatedrows over dataall-gather
cols over modelcols over modelreplicatedall-gather + collective-permute
verbatim from site/src/data/xla/sharding-corpus.json · mesh (4 data, 2 model), 8 devices, jax 0.4.38
§ 02

The silent rows

Rows one and four insert nothing, and they share a shape: the contraction axis arrives whole on every shard, and the local results already sit exactly as the requested output sharding wants them. Row one splits a by rows across data and leaves b replicated, so each shard computes its own rows of the answer; row four mirrors it on the other side, splitting b by columns. No resharding question is ever asked, so the partitioner has nothing to answer. Free is not a special case; it is what alignment looks like.

§ 03

The rows where the partitioner chose

Row three is the teaching row. Both inputs are split along the contraction axis, a over model and b over data, so no shard can finish its arithmetic alone; something has to move. A partial-sum analysis predicts a reduction. The capture shows an all-gather: the partitioner chose to reassemble an operand and compute locally rather than reduce partials, and the module records that choice without asking your opinion. Row six goes further, splitting both inputs over the same model axis, and pays with two collectives, an all-gather and a collective-permute, to reconcile the two different splits.

The lesson in those rows is not the specific plans; it is who decides. The partitioner picks among mathematically equal strategies with a cost model you do not see, and the only reliable account of the plan you got is the dump. The partitioner lesson under the spmd unit gives every collective its author; this table is where you watch the author make six different calls on one program. Step through the same six rows live in EX·16, then predict row five before revealing it.

before you move on

Check yourself

01 Two rows insert nothing. What makes a sharded matmul free?

The contraction axis arrives whole on every shard and the local results already match the requested output sharding, so no resharding question is ever asked. Alignment, not luck.

02 Row three gathers an operand where an analysis predicts a reduction of partial sums. What is the lesson in that?

The partitioner picks among mathematically equal plans with its own cost model, and the dump records the choice it made. Reading the inserted collectives is how you learn the plan you actually got, rather than the one you assumed.

assigned

Readings