Shampoo steers each training step with two small matrices instead of one huge one. In the paper it halves the steps a Transformer needs, and fewer steps mean fewer syncs between islands.
Tangle the inputs with the slider, then pick a method. Watch how many steps each one needs to cut the loss to 1% of where it started. Then we build, piece by piece, the idea, the maths, the numerical care and the machine room that make it work.
You need the idea of a gradient (the direction that makes the loss grow fastest) and what a matrix is. We build the rest from zero.
Paper: Rohan Anil, Vineet Gupta, Tomer Koren, Kevin Regan and Yoram Singer, Scalable Second Order Optimization for Deep Learning (arXiv 2002.09018, 2020; v2 March 2021). Why it matters here: the Core Automation post The Hitchhiker’s Guide to Training on Compute Islands (Rohan Anil, 2 November 2026) says each site ran a variant of Distributed Shampoo as its local optimizer. The background on optimizers is in Optimizers and Momentum. We re-teach every idea in our own words and devices.
Toy problem, computed live in your browser: a 4 by 4 matrix of weights fits a target by minimising the loss ½ tr(A Δ S Δᵀ), where Δ is the weights minus the target, and A and S are 4 by 4 matrices whose entries are ρ|i−j|. Tangle is ρ: how strongly neighbouring rows and columns pull together. Every method gets its own best learning rate from a sweep of 17 values (10−3 to 101), full-batch gradients, 400 steps. AdaGrad here is the usual diagonal kind; Shampoo is the update L−1/4 G R−1/4 of Chapter 3, with the roots taken exactly. The paper’s own results are on real models (Chapter 7).
Chapter 0
See why a smarter training step is worth a lot when the link between your machines is slow
Picture two warehouses in different countries. Each one holds thousands of chips that train the same language model. Inside a warehouse the chips talk over fast cables. Between the warehouses there is one thin line, about 25 Gbps in the experiment that sparked this lesson. A Gbps is a gigabit per second: 25 Gbps moves about 3 gigabytes each second. That sounds like a lot, until you try to ship a whole model through it.
The Core Automation post calls such a warehouse a compute island: a block of chips with a fast network inside and a slow network outside. Its author, Rohan Anil, writes that the islands “exchanged updates on a 50-step schedule” and that “each site used a variant of Distributed Shampoo” as its local optimizer. Anil is also the first author of the paper we study here. Most of the post is about how islands trade updates. This lesson is about the line we just quoted: what the local optimizer is, and why it was worth building.
Training a model means changing its numbers, called weights, until its mistakes get small. The measure of the mistakes is the loss. One round of change is a training step. In each step the machine does four things. It shows the model some examples. It measures the loss. It computes the gradient, which is the direction in weight space that makes the loss grow fastest. Then it moves the weights a little the other way.
The last move is the job of the optimizer: the rule that turns a gradient into a change of weights. The simplest rule is “subtract the gradient times a small number”. That small number is the learning rate. Chapter 1 builds this rule from a picture, and the lesson Optimizers and Momentum teaches the background in more depth.
A large run takes hundreds of thousands of steps. The paper makes an observation about that. Common optimizers are already cheap per step, and nobody can make them much cheaper. So “the only way to train faster is by drastically reducing the number of steps”. If each step were smarter, the run would need fewer of them.
Smarter usually means second-order: the optimizer looks at how the loss curves, not just at which way it slopes. Methods of this kind are old and strong in theory. They are rare in deep learning, because they cost too much memory, time and communication. This paper shows how to make one of them, called Shampoo, cheap enough to win on real models. On the Transformer it needs 1.95 times fewer steps than the best tuned baseline, while each step costs about 16% more.
Shampoo itself came from an earlier paper by Gupta, Koren and Singer. This paper is about making it work at scale. Its authors list four contributions. They build a pipelined version of the optimizer that uses the CPUs attached to the accelerators. They extend Shampoo to very large layers, such as embedding tables. They replace the slow matrix decompositions with a stable iterative method. And they write down what hardware and software would need to change to help. Chapters 3 to 6 take these one at a time.
On an island, steps are cheap, and chips are plentiful. The scarce thing is the slow line between islands. Each exchange across that line costs real time. If a smarter local step cuts the steps a run needs, a run that exchanges every 50 steps makes fewer exchanges. The post does not spell out this argument, so treat it as our reading, not as a claim from the post. Try it below, with the paper’s 1.95 and the post’s 50.
The grey bar is a run with the baseline optimizer. The warm bar is the same run with an optimizer that needs 1.95 times fewer steps. Each tick is one exchange between islands. Drag the schedule and watch the ticks.
Illustrative: a baseline run of 100,000 steps and one exchange every k steps. The 1.95 is the paper’s step ratio for the Transformer on WMT’14 (Figure 3); the 50-step schedule is the post’s. We assume the exchange schedule stays the same. The post does not compare optimizers, and the paper has no islands.
Two cautions keep us honest. First, fewer steps is not the same as less compute: each Shampoo step costs more, and Chapters 5 to 7 show how the paper hides most of that cost. Second, the paper trains on one machine room with fast links. It never meets a slow line. What it gives us is the local engine. How the engines are linked is the job of the other lessons in this series, such as Local SGD and Model Averaging and Training on Compute Islands.
We build the method in eight more chapters. Each chapter has one idea, one toy to play with, and one quiz. The toy at the top of the page is a small cousin of the paper’s method; by Chapter 3 you will know every part of it.
Chapter 1
Roll a ball down a long narrow valley and see why the learning rate has to be tiny
You stand blindfolded in a long, narrow canyon. You want the lowest point. You can feel only the slope under your feet. Which way do you step, and how far?
This is training. Your position is the list of weights. Your height is the loss. The slope under your feet is the gradient, and it points uphill, so you step the other way. With two weights the canyon is a drawing you can look at. With 93.3 million weights, the size of the paper’s smaller Transformer, it is the same canyon in 93.3 million directions.
Call the weights w and the gradient g. The plain rule is one line.
In a real network the weights live in matrices, one per layer. A layer with m outputs and n inputs has a weight matrix W of shape m × n, and its gradient G has the same shape. The optimizer takes G in and gives a change of W out. Everything in this lesson is a different rule for that one map.
Take the simplest canyon: two weights, and the loss f = ½(x2 + 30 y2). Across the canyon (the y direction) the wall is steep: the slope grows 30 times faster than along the floor. The curvature of a direction is how quickly the slope changes as you move that way. Here the curvatures are 1 and 30. Their ratio, 30, is the condition number. A large condition number means a long narrow canyon.
Start at x = 3, y = 0.5, where f = 8.25, and use η = 0.05. The gradient is (3, 15). One step gives x = 3 − 0.05 × 3 = 2.85 and y = 0.5 − 0.05 × 15 = −0.25. The y number overshot the floor: it jumped from 0.5 to −0.25. The next gradient is (2.85, −7.5), and y becomes −0.25 + 0.375 = 0.125. So y flips sign and shrinks by half each step, while x shrinks by only 5% each step. You zigzag across the canyon and creep along it.
Why not a bigger η? Along y, each step multiplies y by (1 − 30η). When 30η passes 2, that factor is below −1 and y grows each step. The loss explodes. The stability limit is η < 2 divided by the largest curvature. Here that is 2/30 = 0.0667. Along x, the factor is (1 − η), so at the limit x shrinks by only 6.7% per step. The steep wall sets the speed limit; the gentle floor pays for it.
The rings are level lines of the loss. The dots are your steps from the start, up to 300. Drag the learning rate. Then switch momentum on and drag it again.
Toy canyon f = ½(x2 + 30y2), start (3, 0.5), computed live. A run counts as done when the loss falls to 0.1% of its start. Momentum is the heavy-ball rule: v ← 0.9 v + g, then w ← w − η v.
Look at what momentum does. It keeps a running sum of past gradients. The back-and-forth parts cancel, and the steady part along the floor adds up. The rule is a small patch, and it helps a lot in the toy: at η = 0.03 plain steps need 104 steps and momentum needs 29. But the patch has a limit. It cannot change the shape of the canyon, and the canyon is the problem. Adam and AdaGrad, which the next chapter explains, change the shape a little. The paper changes it a lot.
Where does the gradient come from? A batch of examples enters the network. The forward pass turns it into predictions, and the loss turns the errors into one number. Backpropagation then walks the network backward. It hands back, for each layer, a gradient G with the same shape as that layer’s weight matrix W. (Optimization and backpropagation builds this from zero.) The optimizer takes the list of G matrices, updates its own memory, and returns new W matrices.
That memory is the optimizer state. Plain descent has none. Momentum keeps one extra number per weight, and Adam keeps two. Shampoo, as Chapter 3 shows, keeps two small matrices per layer. Every optimizer buys its cleverness with state, and every byte of state must live in chip memory.
Here is momentum on the canyon, with η = 0.03. After four steps y has gone 0.5, 0.05, −0.40, −0.445, −0.085. It overshoots, but each overshoot is smaller than the last. Meanwhile x has gone 3, 2.91, 2.74, 2.51, 2.22. Plain steps would have left x at 2.66 after four steps. The steady push along the floor adds up while the zigzag cancels itself.
The symptom is a loss curve that wobbles, or one that climbs and ends in a number that is not a number. The measurement is the curvature: if the largest curvature is λmax and your η is above 2/λmax, plain steps must diverge. The usual fix is to lower η. That cures the blow-up and makes the floor crawl. The better fix is to reshape the canyon so that the steep and gentle directions look alike. Chapter 2 does exactly that.
Chapter 2
Stretch and turn the gradient so a long narrow canyon looks round, and see why that costs so much memory
Suppose you could redraw the canyon map so that the canyon looked like a round bowl. In a round bowl, the slope points straight at the bottom. One step of the right length would land you there. The map change you need is a preconditioner: a matrix P that you multiply the gradient by before you step.
Which P makes the bowl round? The Hessian H is the matrix of curvatures: entry (i, j) says how the slope in direction i changes as you move in direction j. For a quadratic canyon, P = H−1 is perfect. Check it on Chapter 1’s canyon. There H is the diagonal matrix with 1 and 30, and the gradient at the start is (3, 15). Multiply by H−1 and you get (3, 0.5). Subtract that from (3, 0.5) and you land on (0, 0). One step, with η = 1.
That is the promise of second-order methods. The price is steep. A d × d matrix needs d2 numbers, and inverting it takes about d3 operations. For a network, d is millions or billions. So practical methods use a cheaper P. The next two sections look at the cheapest one and then at the one the paper wants.
AdaGrad and Adam keep P diagonal: a separate number for each weight, zero everywhere else. AdaGrad adds up the squares of each weight’s past gradients, and it divides the weight’s step by the square root of that sum. A weight with big gradients gets small steps. A weight with small gradients gets large steps. Memory is d numbers, the same as the weights.
This fixes a canyon whose walls line up with the weight axes: the scale of each axis gets evened out. In the toy of Chapter 1, an ideal diagonal fix works in one step. But rotate the canyon by 45 degrees, so that it runs diagonally across the weight axes, and the diagonal fix does nothing. Now H is [15.5, −14.5; −14.5, 15.5]. Its two diagonal entries are equal, so dividing each axis by its own number rescales both the same way. The condition number stays near 30. A diagonal P can scale. It cannot turn.
Here is AdaGrad on Chapter 1’s canyon, one step. The first gradient is (3, 15). The sums of squares are (9, 225), with square roots (3, 15). Divide each gradient entry by its root and you get (1, 1). The two weights now move by the same amount, although their gradients differed five times over. That is the whole trick of a diagonal method: it evens out the scale of each axis.
The rings are the same canyon, turned by the angle you pick. Three walkers start at the same point. Blue takes plain steps, purple takes diagonal steps, warm takes full-matrix steps. Drag the angle from 0 to 45 and compare.
Toy canyon with curvatures 1 and 30 turned by the angle, computed live. Each walker uses its best fixed learning rate, 2/(λmin + λmax) of the preconditioned problem. The diagonal walker uses the exact diagonal of the Hessian, which is more generous than AdaGrad’s estimate from gradients. Done means 0.1% of the starting loss, within 300 steps.
Slide the angle between 0 and 45. At 0 degrees the diagonal walker is as good as the full one. As the canyon turns, it loses, and at 45 degrees it is no better than plain steps. The full-matrix walker does not care about the angle. It scales and rotates, so it always takes one step.
Real networks do not hand you the Hessian. Full-matrix AdaGrad builds a stand-in from what you do have. At each step it adds the outer product of the gradient with itself, g gT, to a running matrix Ht. This Ht is the second-moment matrix, close kin to a covariance matrix. Directions in which gradients have been large end up with large entries. The preconditioner is Ht−1/2. The square root brings squared slopes back to the units of slopes.
The paper says it simply: such methods “can exploit statistical correlations between (gradients of) different parameters; geometrically, they can scale and rotate gradients whereas first order methods only scale gradients.”
Now count the cost. A layer with weight matrix W of shape m × n has d = mn weights. Full-matrix AdaGrad stores a d × d matrix, which is m2n2 numbers, and its update costs about m3n3 operations. The paper notes that m and n “can be as large as 104”. Then d is 108, and d2 is 1016 numbers. At 4 bytes each that is 40 petabytes, for one layer. This is why everyone settled for diagonals. The rest of the paper is about getting most of the benefit of the strong method at the price of the cheap one.
Why not a classic quasi-Newton method such as L-BFGS? The paper answers in its introduction. Such methods still need memory “equivalent to storing several copies of the model”, and they work best with very large batches and careful line searches, which makes each iteration slow. The newer methods K-FAC, K-BFGS and Shampoo instead use the structure of a network, which is a set of tensors, and approximate each layer’s matrix by a factored form. That is the road we take in Chapter 3.
Chapter 3
Build the Shampoo update from a row matrix and a column matrix, and check it by hand on a two-by-two gradient
Look at the gradient of one layer. It is not a long list. It is a table with m rows and n columns, one number per weight, and it has the same shape as the weight matrix. Full-matrix AdaGrad throws that shape away. It lays the table out in one long line of d = mn numbers and then relates every number to every other.
Shampoo keeps the table. It asks two smaller questions. First: how do the rows of the gradient move together? Second: how do the columns move together? Each question has a small answer, and the two answers together stand in for the huge one.
Call the gradient at step s by Gs, a matrix of shape m × n. Multiply it by its own transpose in the two possible orders and add the results over time.
The Shampoo update then uses a fourth root of each statistic.
The quarter is not a trick. It falls out of two facts. A Kronecker product A ⊗ B of an m × m matrix and an n × n matrix is the mn × mn matrix made by multiplying every entry of A by the whole of B. It obeys two rules, and the paper uses both: (A ⊗ B)α = Aα ⊗ Bα, and (A ⊗ B) vec(C) = vec(A C BT). Here vec(C) means laying the table C out as one long column.
Full-matrix AdaGrad steps by Ht−1/2 g. Shampoo guesses that Ht is close to (Lt ⊗ Rt)1/2. Then Ht−1/2 becomes (Lt ⊗ Rt)−1/4, because the two exponents multiply: −½ times ½ is −¼. The first rule splits this into Lt−1/4 ⊗ Rt−1/4. The second rule turns that product acting on vec(G) into the table Lt−1/4 G Rt−1/4. No mn × mn matrix is ever built.
Is the guess sound? The paper’s Lemma 1 says yes, in a precise sense. If every gradient has rank at most r, then the true Ht is bounded above by r times (Lt ⊗ Rt)1/2. The paper uses this bound to prove a regret guarantee for its extended Shampoo (Theorem 3). We state it; we do not re-prove it.
Let the first gradient be G = [2, 0; 0, 1]. Then G GT is the diagonal matrix with 4 and 1, and so is GT G. Ignore ε. The inverse fourth root of 4 is 4−1/4 = 0.7071, and of 1 is 1. So L−1/4 = R−1/4 = diag(0.7071, 1). The update is diag(0.7071, 1) times G times diag(0.7071, 1). Entry (1,1): 0.7071 × 2 × 0.7071 = 1. Entry (2,2): 1 × 1 × 1 = 1. The update is the identity matrix.
The first step ignores that the raw gradient had a 2 and a 1: both directions move by the same amount. As more gradients arrive, L and R remember which directions are always large, and shrink those steps.
Each press adds one 3 by 2 gradient G (blue). The row statistic L and column statistic R (warm) collect G GT and GT G. The last box is the Shampoo step. Press the button a few times.
Toy gradients, seeded and rounded to one decimal: a steady pattern plus noise, so you can follow the arithmetic. L and R use ε = 10−6, and the roots are exact (computed with an eigendecomposition). The paper’s layers are far larger.
The saving is the point. For a 3 by 2 layer, full-matrix AdaGrad would hold a 6 by 6 matrix, 36 numbers. Shampoo holds a 3 by 3 and a 2 by 2, 13 numbers. For a 1024 by 1024 layer the gap is 1.1 × 1012 numbers against 2.1 million.
Real Shampoo adds momentum to the preconditioned step. It also borrows its step length from diagonal AdaGrad, layer by layer: the final step is scaled so that its size matches the size of the AdaGrad-style momentum step. Shampoo chooses the direction; AdaGrad sets how far. This lets the paper reuse well-tuned AdaGrad learning rates, and it reports that with the same settings Shampoo gives a modest gain, and then tolerates larger rates. The failure to watch for is numerical. Lt gets large condition numbers, up to the 107 to 109 range for one Transformer layer (Figure 7), and a fourth root of such a matrix is hard to compute. That is Chapter 4.
Chapter 4
Compute a matrix fourth root with plain multiplications, and see why 32-bit numbers can not hold it
Chapter 3 ended on a demand: for every layer, find the matrix X with X4 L = I. This is the inverse fourth root. For a single number a, it is a−1/4, easy. For a matrix it is a real job, and the paper says it is the slow part: “as much as 100 times the step time in some cases”.
A symmetric matrix can be split as L = U D UT. Here D holds the eigenvalues (the matrix’s stretch factors) on its diagonal, and U holds the matching directions. Any power of L is then U Dα UT. You raise each eigenvalue to the power and rebuild. The paper calls the splitting a singular value decomposition, SVD, and it is exact. It is also slow: Figure 7 of the paper shows it far behind the iteration below as the matrix grows.
The alternative is an iteration built only from matrix multiplications. Matrix products are the one thing accelerators do best. The paper uses the coupled Newton iteration of Guo and Higham (2006) and Iannazzo (2006).
Begin with a single positive number a and the root p = 4. We want x = a−1/4. Keep a second number m = x4 a. If x is right, m = 1. So the goal is to drive m to 1 while x moves to the answer. Each round has two lines.
Try a = 16, p = 4. The right answer is 16−1/4 = 0.5. The paper starts from z = (1 + p)/(2 × size of A) = 5/32 = 0.156, with X0 = z1/4 = 0.629 and M0 = z a = 2.5. M is too big, so the factor (5 − 2.5)/4 = 0.625 shrinks X to 0.393 and M falls to 0.382. Now M is too small, so the factor is (5 − 0.382)/4 = 1.155 and X rises to 0.454, with M at 0.678. The next rounds give X = 0.490, 0.4995, 0.5000, and M = 0.924, 0.996, 1.000. Five rounds, no square roots, no eigenvalues.
Why does this work for a whole matrix? Every matrix in the loop is a function of A, so they all share A’s eigen-directions and commute. The matrix iteration is the number iteration, run once on each eigenvalue at the same time. All the eigenvalues of M walk toward 1 together. The loop stops when the biggest entry of M − I is below a small threshold.
The true cost is hidden in the eigenvalues. The condition number of L is its biggest eigenvalue over its smallest. The paper’s Figure 7 shows that for one Transformer layer this number sits in the 107 to 109 range during training. Taking a p-th root of such a matrix loses about log2(κ/p) bits of precision, where κ is the condition number. Take κ = 108 and p = 4: that is log2(2.5 × 107), about 24.6 bits. A 32-bit float keeps 24 bits of detail. Nothing is left over. A 64-bit float keeps 53 bits, which is enough.
This is the awkward fact behind the paper’s hardware story. Accelerators prefer low precision, and the roots need double precision. That is why the paper runs the roots on the CPUs attached to the accelerators (Chapter 6). One exception: for ResNet-50 it used emulated single precision and cut each layer into blocks of 128, which keeps the matrices small and well conditioned.
The line shows how far M is from the identity after each round, on a log scale. Pick the number type and drag the condition number. The warm line starts from the root of the matrix one step earlier.
Toy 4 by 4 symmetric matrix with eigenvalues spread evenly in log from 1 down to 1/κ, plus a small update g gT with g = (0.1, 0.02, 0, 0) for the warm start. Algorithm I of the paper’s Appendix D with p = 4, stopping when the largest entry of M − I is below 10−6; 32-bit is simulated by rounding every multiplication and addition to 32 bits. The error is the size of the root’s mistake relative to the size of the root, against an exact eigendecomposition in 64-bit. Warm start gains depend on how much the matrix changed; the paper reports up to 4 times fewer rounds.
The paper adds three habits to the bare iteration. Scaled damping: add ε times the largest eigenvalue, found by a quick power iteration, times I to the matrix before rooting. The extra amount then matches the matrix’s own scale. Warm start: statistics change a little each time, so begin from the previous root, not from a blind guess. The iteration needs X and M to commute, which is only approximate after a warm start, so the code watches the commutator XM − MX and falls back to a cold start if it grows. Stopping rule: quit when M is close to I.
The failure shows up as an update that spikes in a few directions. Measure it: compare the root to an exact one on a small layer, or watch M − I stall above the threshold. The fixes are the ones just listed, plus more bits.
Chapter 5
Handle a layer with millions of rows by using one side, cutting it into blocks, and refreshing late
Now meet the layers that break the method. A language model begins with an embedding table: one row of numbers per word piece, so a vocabulary of 32,768 pieces and 512 numbers each gives a table of shape 32,768 × 512. A recommendation model such as DLRM, trained on the Criteo ad-click logs, has an embedding with about 186 million rows. The paper says the largest layer in its Transformer models can have up to 65,536 units in one dimension.
Shampoo’s row statistic L has one row and one column for every row of the layer. For 186 million rows, L would have 186 million squared entries. It will not fit anywhere. The paper answers with three tools, one for each kind of trouble.
The paper’s Lemma 1 says the choice of the quarter-and-quarter split is not forced. For any p and q greater than 0 with 1/p + 1/q = 1, the full matrix is still bounded by r times L1/p ⊗ R1/q. The step that follows is L−1/(2p) G R−1/(2q). Choose p = q = 2 and you get the update of Chapter 3. Choose (p, q) = (∞, 1) and the left factor disappears, because 1/p is zero and anything to the power zero is the identity. What remains is G R−1/2. Choose (1, ∞) and the right factor disappears instead, and you get L−1/2 G. (The paper lists the two limits in the opposite order. Working the exponents out, as above, gives this pairing.)
So for an embedding table you precondition only the short side, 512 wide, and leave the long side alone. The statistic is then 512 × 512, a small matrix, no matter how many rows the table has. The paper also uses the fact that embedding inputs are sparse, so most rows have a zero gradient at each step (its Appendix C). The measured price is small: Figure 3b shows step time up by only 6%, and Figure 4a shows about 20% fewer steps to converge.
For a big dense layer, the paper cuts the weight matrix into square blocks of size b × b and treats each block as its own small layer, with its own L and R. Lemma 2 says the block-diagonal matrix bounds the true one up to a factor equal to the number of blocks per side. The stored statistics shrink from m2 + n2 to about 2mn in total, and the work per step falls from about m2n + mn2 to about 2mnb (the paper’s Table 2 gives the orders: O(mnb) work, O(mn) memory). The cost is that weights in different blocks no longer share statistics. The paper tested a 512 × 2048 feed-forward layer cut into two blocks of 512 × 1024 and into four of 512 × 512. Quality did not drop, and run time fell by under 3% (Figure 4b).
The roots of Chapter 4 are the costly part, and the statistics change slowly. So the paper does not recompute the roots every step. It recomputes them every τ1 steps and reuses the old ones in between. Figure 4c tries intervals from 100 to 2,000 steps on the Transformer. The text says one can recompute “once every few hundred steps without a significant effect on the accuracy”. The rule it follows is to pick the smallest interval that does not hurt, namely the number of steps that fit in the time needed to compute the largest root. The statistics themselves are still added up every step, or every τ2 steps (default 1; BERT and DLRM use 10).
A worked example. Take the 32,768 × 512 table. Full-matrix AdaGrad would store (32,768 × 512)2 = 2.8 × 1014 numbers. Two-sided Shampoo stores 32,7682 + 5122 = 1.07 × 109, which is 4.3 GB at 4 bytes each, still heavy. One-sided Shampoo stores 5122 = 262,144 numbers, a megabyte. Blocks of 512 (the table is only 512 wide) store 2 × 5122 for each of 64 blocks, 3.4 × 107 numbers, 134 MB. Move the sliders to see other shapes.
Pick the layer’s rows and columns. The bars use a log scale, so each gridline is ten times the one before. Switch between what must be stored and what must be multiplied each step.
Orders of magnitude from the paper’s Table 2, with constants filled in by us. Full matrix: (mn)2 numbers, (mn)2 multiply-adds. Two-sided: m2 + n2 numbers, m2n + mn2. One-sided on the shorter side s with longer side l: s2 numbers, s2l. Blocks of 1,024 (or smaller if the layer is smaller): 2b2 numbers and 2b3 multiply-adds per block. The roots, done every τ1 steps, are extra. Bytes assume 4 bytes a number. The paper does not state which side it picks for each layer, so the shorter side is our reading of the O(n2) memory in Table 2.
The symptom of asking too much is simple: the job runs out of memory, or each step is dominated by the optimizer. The measurement is a step-time breakdown like the paper’s Figure 3b, with a bar for the statistics and a bar for the preconditioned gradient. The fix is the tool that matches the bar: one side for a huge dimension, blocks for a dense layer, a longer τ1 for slow roots.
Chapter 6
Keep the accelerators busy by sending the slow matrix roots to the idle CPUs next to them
Think of a kitchen. The head chef cooks without a pause: one dish after another. A sous-chef in the next room does a slow, careful prep job. Every few hundred dishes, a tray arrives with fresh prep. The chef swaps it in and never stops. The prep is a little old by the time it arrives, and nobody minds.
This is how the paper makes Shampoo cheap in time. The chef is the accelerator, a TPU or a GPU. The sous-chef is the CPU on the same machine. The prep is the matrix root of Chapter 4.
First recall data parallelism, covered in Data Parallel and All-Reduce. Every accelerator core holds a full copy of the weights. Each core takes a slice of the batch, called a sub-batch, and computes its own gradient. An all-reduce then averages those gradients across all cores, so that every core ends up with the same average gradient, and every core applies the same update. The paper’s Figure 3b shows that all-reduce and the weight update together are under 5% of step time on its Transformer.
With Shampoo, each core does six things per step. The paper’s appendix G.5 lists them: forward pass, gradient, all-reduce, preconditioner statistics (L += G GT and R += GT G), the preconditioned gradient (L−1/4 G R−1/4), and the parameter update. The two Shampoo steps are matrix products, and accelerators are good at those. The roots are the odd one out.
Figure 1 of the paper draws a timeline, and Algorithm II writes it as code. At every τ1-th step three things happen together.
The CPUs take the layers, split them across all available cores, and run the coupled Newton iteration in double precision. This is the paper’s design choice: CPUs offer 64-bit arithmetic cheaply, and they were mostly idle already. The paper reports that “the most expensive step in Shampoo adds almost nothing to the overall training time”. The transfer takes about 100 ms, which is spread over hundreds of steps.
Look at the step times in Figure 3. With diagonal AdaGrad a step takes 134 ms. With Shampoo on all layers except the embedding and softmax layers it takes 145 ms. With Shampoo on every layer it takes 155 ms, which is 16% more than AdaGrad. There is one more property worth noting. The cost of the preconditioned gradient does not depend on batch size, so a larger batch dilutes it. On the larger Transformer the paper measures the overhead falling from 40% to 19% when the batch grows (Figure 5b).
If τ1 is too short, the CPUs cannot finish a round before the next handoff. The accelerator then keeps using a root that is older and older. If τ1 is longer than needed, the root is staler than it must be. The paper’s rule is the smallest τ1 that does not hurt training, which is the number of steps that fit in the time the CPUs need for the largest layer. Its runs used τ1 of 1,000 for the Transformers, 999 for DLRM and 400 for BERT-Large.
Top lane: the accelerator. Middle lane: the CPU hosts computing roots. Bottom lane: how old the statistics inside the root in use are. Change the interval, the work and the number of CPU hosts. Then flip the switch to compute the roots on the accelerator instead.
Illustrative model, ours, not the paper’s system. “Root work” is the total time to take every layer’s roots, counted in training-step times (the paper says a single large root can cost up to 100 step times). We split the work evenly over the CPU hosts and add one step for the transfer. Roots used at a handoff come from statistics sent one interval earlier, so the statistics inside them are between one and two intervals old (Algorithm II).
Count the cost of the alternative. If the roots ran on the accelerators in the step loop, then every refresh would stall all of them for the whole root job. The device shows the average step growing by the work divided by the interval. That is the price the CPU pipeline avoids, and it is why the paper changed the training loop instead of calling a library routine.
The same design helps small jobs too. On CIFAR-10 with a ResNet-50 (batch 2,048), the largest root took under a millisecond on a CPU, and 8 CPU cores were enough. Training time fell 42%, from 1,428 to 827 seconds, and the baseline’s 93.45% accuracy came after 143 epochs instead of 300. The pipeline is cheap to run when the roots are small, and it scales when they are not.
One weakness remains. In the paper’s implementation every core computes the statistics and the preconditioned gradient for every layer. The BERT appendix counts over a hundred 1024 by 1024 matrix products repeated on each core, and the authors estimate that sharding this work across cores would remove at least half of the step overhead. They did not have compiler support to do it.
The paper is open about what this cost it. Frameworks such as TensorFlow offer optimizer hooks for first-order methods, but the pipeline needs the training loop itself to gather statistics at regular intervals and to hand work to the CPUs without blocking the TPUs. It had to change the framework. It lists hardware wishes too: types for symmetric matrices, which would save up to about half the storage and arithmetic; update sharding for Shampoo; mixed precision for the roots; more on-chip memory; and hardware 64-bit support.
Chapter 7
Read each table and figure of the paper as a product of fewer steps and costlier steps, and see where it stops paying
You open the results section. Every claim has the same shape: Shampoo reached the baseline’s accuracy in fewer steps. A careful reader asks the next question at once. Fewer steps, but how long does each step take? The answer is one line of arithmetic, and it explains every number in the paper.
For the Transformer: 0.51 × 1.16 = 0.59. The paper says the target is reached with about 40% less wall time. The arithmetic matches.
Autoencoders (Figure 2). On three small autoencoder tasks (MNIST, FACES, CURVES) Shampoo, K-FAC and K-BFGS all land in the same place, far ahead of RMSprop and Adam. The authors tuned Shampoo by hand and used the other methods’ published settings. The point of the figure is modest: with tuning, all these second-order methods work. It is not a scaling result.
Transformer on WMT’14 English to French (Figure 3). The model has 93.3 million weights, 6 encoder and 6 decoder layers, 512 model width, 2,048 hidden width and 8 heads, with a 32K word-piece vocabulary. It trains on 36.3 million sentence pairs on 32 cores of a Cloud TPU v3 Pod at batch size 1,536. Figure 3a plots test log-perplexity against steps, where higher is better. Read it sideways: pick a height and compare where each curve reaches it. Shampoo gets there 1.95 times sooner than AdaGrad or Adam. Figure 3b is the step-time breakdown from Chapter 6.
Transformer-Big (Figure 5). It has 375.4 million weights. The step count falls by about half again, but at the smaller batch the step overhead is 40%, so the wall gain is only 30%. At a larger batch the overhead is 19% and the wall gain 41%. The optimizer’s extra cost does not depend on batch size, so a bigger batch spreads it thinner.
DLRM on Criteo (Figure 6a). This click-prediction model uses a batch of 65,536. The baseline needs 64,000 steps. Shampoo reaches the target AUC of 80.25% in 30.97 thousand steps and goes on to a new best, 80.56%, about 0.3% higher; the paper notes that 0.1% counts as significant on this task. Preconditioning the embeddings is part of the win: without it the target takes 39.96 thousand steps.
BERT-Large (Figure 6b). It has 340 million weights. Shampoo needs about 16% fewer steps and ends about 1% higher in masked-word accuracy than the LAMB baseline. But each step costs 14% more, so the wall time falls by only about 4% (3.8 to 3.65 hours in the introduction; 228 to 219 minutes in the appendix table). The authors explain that they reused LAMB’s hyperparameters with grafting, did no tuning for Shampoo, and did not yet optimise the system.
ResNet-50 on ImageNet (Table 1). At batch size 32,768, Nesterov momentum and LARS both need 64 epochs and 2,512 steps to reach the 75.9% MLPerf target. Shampoo needs 44 epochs and 1,729 steps, with emulated higher precision and blocks of 128. That is 31.2% fewer steps by our arithmetic (the paper writes 31.7%), and 13% less wall time.
| Task | Steps, Shampoo vs baseline | Wall time, baseline to Shampoo |
|---|---|---|
| Transformer, WMT’14 | about 1/1.95 of the baseline | about 12 h to 6.5 h (6.7 h in the introduction) |
| Transformer-Big | about half | about 47 h to 29.5 h |
| DLRM, Criteo | 30.97K vs 64K | 13 min to 8.2 min |
| BERT-Large | about 16% fewer | 228 min to 219 min |
| ResNet-50, ImageNet | 1,729 vs 2,512 | 13% less |
The horizontal axis is Shampoo’s share of the baseline’s steps. The vertical axis is its share of the baseline’s wall time. Below the dashed line Shampoo wins on the clock. Pick one of the paper’s runs, or drag the two sliders yourself.
Step shares come from the paper’s step counts (Figures 3a, 5a, 6, Table 1). Extra time per step is reported for the Transformer (134 to 155 ms), Big (40% and 19%) and BERT-Large (14%); for DLRM and ResNet-50 we derived it as wall share divided by step share, so it is ours. The dots are plotted at the reported wall share. Table 4 lists two batch sizes for Transformer-Big, 384 and 1,536, and the captions of Figure 5 do not say which belongs to which, so we write small and large.
Four ablations carry the design. One-sided preconditioning of the embedding and softmax layers costs 6% in step time and saves about 20% of the steps (Figures 3b, 4a). Cutting a feed-forward layer into blocks keeps quality and saves under 3% of time (Figure 4b). Recomputing the roots less often, from every 100 to every 2,000 steps, costs little accuracy (Figure 4c). Preconditioning DLRM’s embeddings moves the target from 39.96 thousand to 30.97 thousand steps.
The authors say the gains are largest when the optimizer’s overhead can be spread out, and that data-limited settings, where the transfer to the CPUs is hard to hide, are harder. The BERT run shows the bad case: steps fell 16%, step time rose 14%, and the clock barely moved. Our own cautions. The comparison with K-FAC and K-BFGS is on small autoencoders only. The baselines are strong, but they are first-order methods tuned by the authors. And the system needs host CPUs with enough cores, 64-bit arithmetic and changes to the training framework.
Chapter 8
Review the method on one page, with its numbers, a checklist, the core code and the way back to islands
You can now rebuild the paper from memory. The aim, in the authors’ words, was a “scalable implementation of a second-order preconditioned method”. This chapter is for looking things up. Nothing in it is new.
Plain gradient descent is slow in a narrow canyon, because the steep wall caps the learning rate. A preconditioner reshapes the canyon. Diagonal ones (AdaGrad, Adam) only scale; full-matrix AdaGrad also rotates, but needs (mn)2 numbers for an m by n layer. Shampoo keeps the layer as a table and tracks a row statistic L (m by m) and a column statistic R (n by n), then steps by L−1/4 G R−1/4. The paper makes this fast with a stable coupled Newton root in 64-bit, one-sided and blocked preconditioners for big layers, roots refreshed every few hundred steps, and a pipeline that computes the roots on idle host CPUs. On a Transformer it needs 1.95 times fewer steps and about 40% less wall time.
| What | Number | Why it matters |
|---|---|---|
| Shampoo update | W ← W − η L−1/4 G R−1/4 | Two small matrices, no mn by mn matrix |
| Statistics, 104 by 104 layer | 2 × 108 vs 1016 numbers | Shampoo vs full-matrix AdaGrad |
| One root, worst case | up to 100 step-times | Why the roots leave the accelerator |
| Precision lost in a root | about log2(κ/p) bits; κ 107 to 109 | 32-bit is not enough |
| Transformer step time | 134 ms AdaGrad; 145 ms; 155 ms | 8% and 16% more per step |
| Transformer result | 1.95 times fewer steps; 40% less wall time | Step ratio times step-time ratio |
| Transformer-Big overhead | 40% falling to 19% with a larger batch | Batch size dilutes the cost |
| DLRM on Criteo | 30.97K vs 64K steps; AUC 80.56% | Embedding preconditioning pays |
| BERT-Large | 16% fewer steps; 14% slower steps; about 4% less time | The case where the gain nearly vanishes |
| ResNet-50, ImageNet | 1,729 vs 2,512 steps; 44 vs 64 epochs; 13% less time | Works outside language too |
| Refresh interval τ1 | 1,000 (Transformers), 999 (DLRM), 400 (BERT) | Roots are reused for hundreds of steps |
| Block size | 128 (ResNet-50), 1,024 (BERT) | Smaller blocks, cheaper roots |
import numpy as np
def inv_root(A, p=4, eps=1e-6, X=None, max_iter=100):
"""A^(-1/p) for a symmetric PSD matrix: the coupled Newton iteration (paper, Appendix D).
Runs in float64. Pass the previous root as X for a warm start."""
n = A.shape[0]
lam = np.linalg.eigvalsh(A)[-1] # the paper uses a power iteration here
A = A + eps * lam * np.eye(n) # scaled damping
I = np.eye(n)
if X is not None: # warm start: begin from the previous root
M = np.linalg.matrix_power(X, p) @ A # M starts near the identity if A changed little
if np.abs(M - I).max() >= 1: # the paper watches a commutator; we watch M
X = None # too far from the identity: start cold
if X is None:
z = (1 + p) / (2 * np.linalg.norm(A)) # Frobenius norm
X, M = z ** (1 / p) * I, z * A
alpha = -1.0 / p
for _ in range(max_iter):
if np.abs(M - np.eye(n)).max() < 1e-6:
break
M1 = (1 - alpha) * np.eye(n) + alpha * M
X = X @ M1
M = np.linalg.matrix_power(M1, p) @ M
return X
class Shampoo:
"""One weight matrix W of shape (m, n). Follows Algorithm II of the paper."""
def __init__(self, shape, lr=0.1, beta1=0.9, tau1=100, eps=1e-6):
m, n = shape
self.lr, self.b1, self.tau1, self.t = lr, beta1, tau1, 0
self.L, self.R = eps * np.eye(m), eps * np.eye(n) # row and column statistics
self.D = np.zeros(shape) # diagonal AdaGrad (sets the step length)
self.M = np.zeros(shape); self.Pm = np.zeros(shape) # two momentum buffers
self.Linv = np.eye(m); self.Rinv = np.eye(n) # roots in use (start as identity)
def step(self, W, G):
self.t += 1
self.L += G @ G.T # L_t = L_(t-1) + G G^T
self.R += G.T @ G # R_t = R_(t-1) + G^T G
self.D += G * G
self.M = self.b1 * self.M + (1 - self.b1) * G / (np.sqrt(self.D) + 1e-12)
if self.t % self.tau1 == 0: # in the paper this runs on CPUs, one round late
self.Linv = inv_root(self.L, 4, X=self.Linv if self.t > self.tau1 else None)
self.Rinv = inv_root(self.R, 4, X=self.Rinv if self.t > self.tau1 else None)
self.Pm = self.b1 * self.Pm + (1 - self.b1) * (self.Linv @ G @ self.Rinv) # L^-1/4 G R^-1/4
# graft: Shampoo's direction, AdaGrad-style length
scale = np.linalg.norm(self.M) / (np.linalg.norm(self.Pm) + 1e-12)
return W - self.lr * scale * self.Pm
Read it line by line and find the chapter behind each choice. The two statistics are Chapter 3. The root, with its damping and warm start, is Chapter 4. The delayed refresh is Chapter 5, and the comment on CPUs is Chapter 6. We ran it on the toy problem from the top of this page at tangle 0.8, learning rate 0.1, momentum 0.9 and a refresh every step, and it cut the loss to 0.5% of its start in 200 steps. This is a teaching sketch for one matrix. It is not the paper’s system, which shards the layers across hundreds of CPU cores.
K-FAC and K-BFGS also approximate a full preconditioner by factors that follow the network’s layers. The paper compares against both on small autoencoders and finds all three about equal there, then goes on to scale Shampoo. GGT approximates the AdaGrad matrix by keeping hundreds of copies of the gradient, which the authors call too expensive even for mid-sized models.
Shampoo has had a second life. Distributed Shampoo, by Shi and colleagues at Meta (arXiv 2309.06497), is a PyTorch implementation in the same family: a block-diagonal preconditioner whose blocks are Kronecker approximations. Our lesson on Polar Express (Muon) covers a newer optimizer that also treats weights as matrices.
The Core Automation post says that for its two-site run “each site used a variant of Distributed Shampoo”. Among the ingredients of the recipe it also lists “a stronger optimization method derived from Distributed Shampoo, building on existing work such as DiLoCo”. The post does not say what its variant changes, so we can not tell you. What this paper gives you is the engine inside each site: a step that does more work per training step, paid for with CPU time that the site already owns. How the sites combine their results is the subject of DiLoCo and Low-Communication Pretraining and Training on Compute Islands.
Credit. Scalable Second Order Optimization for Deep Learning is by Rohan Anil, Vineet Gupta, Tomer Koren, Kevin Regan and Yoram Singer (Google Research, Google Inc., Tel Aviv University, Princeton University), arXiv 2002.09018. The Shampoo algorithm itself is from Gupta, Koren and Singer (ICML 2018). The context here is the Core Automation post, The Hitchhiker’s Guide to Training on Compute Islands, by Rohan Anil, 2 November 2026. Every idea is re-taught in our words and devices.
Now press Present or Teach and explain Shampoo from memory: what L and R are, where the one-quarter comes from, why 32-bit fails, and what the CPUs do. Then go back to the race at the top, set the tangle to 0.95, and say why only one method gets there.