Case study: Muse Glimmer 30B training¶
Prerequisites: Sharding, meshes and collectives, FSDP and TorchTitan on TPU
TorchTPU ships a pure-PyTorch training loop for the full Muse Glimmer 30B model: one TPU VM host with four Ironwood (v7x) chips, FSDP written with PyTorch's functional collectives, torch.compile on each layer, activation checkpointing, and a chunked loss. Google reports 2,400 to 2,800 tokens per second per rank for it, and 38% MFU. This chapter takes that run apart the way you would take apart your own: write down the model and the hardware, estimate memory, FLOPs, communication and step time before looking at any measurement, then read what the case study did, compare its numbers with the estimates, and judge each choice by the evidence behind it. Every number below is either quoted from a source or derived with its arithmetic shown, and code/ch16_case_study/estimate.py reproduces all of them.
What this chapter covers¶
- A published training run broken down into its model shape, its mesh and the work each device does per step.
- Memory, FLOPs and collective time per device estimated from first principles, before reading any measurement.
- The measured step time and MFU set against those estimates, and the likely causes of the gap.
- The case study's implementation choices weighed against the evidence for each, and the next experiment to run.
- Published MFU figures reproduced and put on one FLOP convention before they are compared.
The model and the hardware¶
Start where the scaling book's applied training chapter starts with Llama 3: a table of the model's shape and of the run. For Muse Glimmer 30B both come from the example's Config in model_fsdp.py, which the case study quotes, and from its launcher:
| Quantity | Value | Source |
|---|---|---|
| Layers | 52; every 4th uses full causal attention, the other 39 a sliding window of 2,048 tokens | num_layers, swa_size; is_swa = (layer_idx % 4) != 3 |
| \(d_\text{model}\), \(d_\text{ff}\) | 6,656 and 19,968 (SwiGLU: up, gate, down) | dmodel, dff |
| Attention heads | 32 query heads and 2 KV heads of 128, plus a sigmoid output gate | num_q_heads, num_kv_heads, dhead, gate_proj |
| Vocabulary | 202,048; the LM head is a separate matrix inside the loss module | vocab_size, lm_head |
| Batch per rank | 8 sequences of 5,120 tokens: 40,960 tokens per device per step | batch_size, seq_len |
| Hardware | One host, topology 2x2x1: 4 v7x chips, 8 PyTorch devices | launcher.py, batchv1_job.yaml |
| Ranks | 8, one per TensorCore; one FSDP group over all of them | world_size = 8, group.WORLD |
| Precision | bf16 by default: torch.set_default_dtype(torch.bfloat16); layer norms in fp32 |
worker.py, DecoderBlock |
| Optimizer | torch.optim.AdamW, lr 1e-5 |
worker.py |
The launcher explains the 8: "Ironwood TPUs each have two TensorCores, each with their own HBM, they show up in PyTorch as 8 devices", which is chapter 1's point that a v7x chip is two devices of 96 GiB each, joined by a die-to-die link.
There is one mesh axis and it covers every device. A weight shard on one TensorCore reaches its neighbour on the same chip over D2D and the other three chips over ICI; nothing leaves the host.
Counting the parameters¶
Count from the shapes, as the scaling book does for Llama 3 70B. Per layer, with \(D = 6{,}656\):
| Weights | Shape | Parameters |
|---|---|---|
| q, attention gate, o | \(D \times 4{,}096\) each (32 heads of 128) | \(3 \times 27{,}262{,}976 = 81{,}788{,}928\) |
| k, v | \(D \times 256\) each (2 heads of 128) | \(2 \times 1{,}703{,}936 = 3{,}407{,}872\) |
| FFN up, gate, down | \(D \times 19{,}968\) each | \(3 \times 132{,}907{,}008 = 398{,}721{,}024\) |
| One layer | 483,917,824 | |
| 52 layers | 25,163,726,848 | |
| Embedding, LM head | \(202{,}048 \times D\) each | \(2 \times 1{,}344{,}831{,}488\) |
| RMSNorm weights | 4 per layer and a final one | 1,391,104 |
| Total | 27,854,780,928 |
The FFN is 82% of each layer, as the scaling book found for Llama. Two counts matter later. The active count for FLOPs drops the embedding table, since a lookup does no matmul: \(27{,}854{,}780{,}928 - 1{,}344{,}831{,}488 = 26{,}509{,}949{,}440\). The sharded count is what the example splits over the 8 ranks: only the eight projections of each layer, 25,163,726,848 parameters. The embedding, the LM head and the norms are replicated on every device; get_non_fsdp_params collects them, and their gradients are all-reduced after backward.
The case study says the bf16 weights take "about 60 GiB". The count gives \(27.85 \times 10^9 \times 2\) bytes \(= 55.7 \times 10^9\) bytes, 51.9 GiB. Sixty is what 30 billion parameters at 2 bytes would be in decimal gigabytes; read it as a round figure. Either way, the weights alone fit on one 96 GiB device, which is the case study's point: memory pressure in training comes from everything else.
Estimates before measurements¶
The scaling book's method is to estimate memory and time from the shapes, then check. All four estimates below are per device per step.
Memory per device¶
The example's dtypes decide the byte budget. With bf16 as the default dtype, each sharded parameter costs 2 bytes of weight, 2 of gradient, and 4 for AdamW's two moments, which torch.optim.AdamW allocates like the parameter: 8 bytes, against the 12 or 16 of chapter 14's budgets. The fp32 layer norms cost 16 bytes each, but there are only 1.4 million of them.
| Item | Arithmetic | GiB |
|---|---|---|
| Sharded layer state | \(25{,}163{,}726{,}848 \times 8 / 8\) bytes | 23.44 |
| Replicated embedding, LM head, norms | \((2 \times 1{,}344{,}831{,}488 + 6{,}656) \times 8 + 1{,}384{,}448 \times 16\) | 20.06 |
| Saved layer inputs (checkpoints) | \(52 \times 8 \times 5{,}120 \times 6{,}656 \times 2\) bytes | 26.41 |
| One gathered layer | \(483{,}917{,}824 \times 2\) bytes | 0.90 |
| One loss chunk of logits | \(4{,}096 \times 202{,}048 \times 2\) bytes | 1.54 |
| Total | 72.34 |
That leaves about 24 GiB of the 96 for what the table does not count: the intermediates of the one layer being recomputed in backward, attention scores, temporaries and allocator overhead. The case study does not report peak HBM, so this is a prediction for a memory profile to confirm, not a fact about the run. Two items stand out. The replicated embedding and head take 20 GiB, nearly as much as all 52 sharded layers. And the checkpointed activations take more than either, because 40,960 tokens per device is a large batch.
Without the chunked loss, the full logits would add \(8 \times 5{,}120 \times 202{,}048 \times 2 = 16.55 \times 10^9\) bytes, 15.42 GiB: the case study's "about 16 GiB". The total would then be 86.2 GiB, which still fits, but with under 10 GiB left for the recomputed layer.
FLOPs per step¶
With \(N = 26{,}509{,}949{,}440\) active parameters and \(T = 40{,}960\) tokens:
That is the model's work. The chip does more, because every decoder layer is checkpointed: its forward runs once in the forward pass and again inside backward, so each layer parameter costs \(2 + 2 + 4 = 8\) FLOPs per token instead of 6. The LM head runs forward and backward once per chunk, 6 FLOPs. The matmul work the chip executes is
1.316 times the model's. Attention adds little at this length. TorchTitan's count, \(6 \times 32 \times 256\) FLOPs per attended token per layer, with 5,120 attended tokens in the 13 global layers and 2,048 in the 39 windowed ones, is \(7.20 \times 10^9\) per token, about 4.5% of \(6N\).
Collectives per step¶
Each layer's forward all-gathers its eight projections, 967.8 MB in bf16. Backward gathers them again when the checkpointed layer is recomputed, and the autograd formula of all_gather_single reduce-scatters the bf16 gradients. Chapter 14's fsdp_comm_bytes_per_step(25_163_726_848, 8, 2, 2, 1) gives the bytes each rank sends: \(3 \times 25.16 \times 10^9 \times 2 \times 7/8 = 132.1\) GB per step. After backward the replicated gradients, 5.38 GB in bf16, are all-reduced.
Time them with chapter 13's ring model. A 2x2x1 host has no wraparound links (chapter 1), so use the one-way formula with 90 GB/s per link:
Two gathers and one reduce-scatter make 1.47 s, and the all-reduce of the replicated gradients (twice an all-gather's traffic) adds 0.105 s: 1.57 s per step. The two chiplets of a chip share its external ICI links, so a more pessimistic model halves the bandwidth: 3.15 s. Both models ignore the faster D2D hop inside each chip.
Expected step time¶
At the device's peak of \(2{,}307 / 2 = 1{,}153.5\) TFLOP/s:
| Term | Arithmetic | Seconds |
|---|---|---|
| Model FLOPs, \(6NT\) | \(6.515 \times 10^{15} / 1.1535 \times 10^{15}\) | 5.65 |
| Recompute of each layer's forward | \((8.576 - 6.515) \times 10^{15} / 1.1535 \times 10^{15}\) | 1.79 |
| Attention, with recompute | \(7.20 \times 10^9 \times 4/3 \times 40{,}960 / 1.1535 \times 10^{15}\) | 0.34 |
| AdamW, HBM-bound | 7 bf16 reads and writes per local parameter at 3,690 GB/s | 0.02 |
| Compute floor | 7.80 | |
| Collectives, one-way ring | (overlappable) | 1.57 to 3.15 |
The collectives need a fifth to two fifths of the compute floor, so FSDP should be compute-bound here with room to spare. Chapter 13's threshold says the same: a device's FLOP/s over its link bandwidth, \(1{,}153.5 \times 10^{12} / 90 \times 10^{9} \approx 12{,}800\) tokens on a one-way ring, or about 25,600 if the two chiplets share the links, against 40,960 tokens per device. The prediction is a step of at least 7.8 s, longer by whatever the matmuls lose to imperfect MXU use and by everything that is not a matmul. At 7.8 s, a device would process \(40{,}960 / 7.8 = 5{,}250\) tokens per second, and MFU would be \(5.65 / 7.80 = 72\%\): the ceiling that per-layer recompute alone imposes.
What the case study did, in order¶
The case study explains four implementation choices. Each answers a problem the estimates above make visible.
1. torch.compile on each layer. apply_torch_compile wraps the embedding norm, each of the 52 DecoderBlocks and the final norm in torch.compile(..., dynamic=False, backend="tpu"), rather than the whole model. The case study gives two reasons: whole-model compilation takes much longer, and for this model there is no performance benefit beyond the scope of one layer. TorchTPU caches compiled layers, and there are only two kinds here (full and sliding-window attention), so 52 layers cost two compilations. dynamic=False declares that every shape is static, which chapter 7 explains is what you want when you can guarantee it.
2. Activation checkpointing inside the compiled layer. DecoderBlock.forward calls torch.utils.checkpoint.checkpoint(self.forward_impl, ..., use_reentrant=False), and torch.compile wraps the block from outside. The order matters, and the case study is explicit: checkpointing inside the compiled region works, compiling the attention and FFN sub-layers separately inside a checkpointed block does not work as expected. With this order, the backward pass runs each layer as a small joint forward-and-backward program, which XLA compiles as one graph and can optimize, including the memory of the intermediates. This is where the 26.4 GiB of saved layer inputs and the 1.79 s of recompute come from.
3. "Naive" FSDP with functional collectives. Each projection is an nn.Linear created with 1 / world_size of its output rows. In forward, func_col.all_gather_single(self.q_proj.weight, gather_dim=0, group=self.pg) rebuilds the full weight and F.linear uses it. The functional collective is registered with autograd, so backward issues the matching reduce-scatter with no extra code. The sharded dimension is the first dimension of the stored weight because nn.Linear stores the matrix transposed and the collectives work on dimension 0. There is no prefetching of the next layer's weights. The case study's argument for why that is acceptable: the collectives sit inside the compiled layer, and XLA reorders them and offloads them to run asynchronously on the SparseCore, in forward and in the joint forward-backward, which "turns out to be enough to achieve nearly perfect communications / computation overlap". This is chapter 14's manual FSDP, at full scale.
4. A chunked, fused LM head and loss. The loss module takes the backbone's output detached, splits the \(40{,}960\) tokens into chunks of 4,096, and for each chunk runs a compiled function that applies the LM head, the soft-cap, the cross-entropy and loss.backward(), then keeps only the gradient with respect to the chunk's hidden states. The concatenated gradients are passed to h.backward(gradient=h_grad) for the backbone. The case study notes that in recent PyTorch versions .backward() inside a compiled function no longer causes a graph break, so the forward and backward of each chunk compile together. This is the 15.4 GiB the memory table did not have to spend. The loss is scaled by \(1/(\text{world size} \times \text{batch} \times \text{sequence})\), so that the summed gradients are those of the global mean, as chapter 14 requires for a sum reduction.
Follow the purple segment. FSDP shrinks the blue one eightfold and leaves the purple one alone, so after step 3 the replicated embedding and head cost almost as much as all 52 layers. The last two frames show what that means the day you switch to fp32 optimizer state.
What the case study lists as missing is as instructive as what it does: no data loading or tokenization, no checkpoint saving or loading, no health monitoring or convergence diagnostics, no fault tolerance. The worker also seeds every rank differently (torch.manual_seed(42 + rank)) and notes that this initializes the replicated weights differently on each rank, which is fine for a throughput demonstration and wrong for training. For a production setup the case study points to TorchTitan.
Measured results against the estimates¶
The case study reports 2,400 to 2,800 tokens per second per rank at sequence length 5,120, 19k to 22k for the 8 ranks together. The example's README prints a log: run 0 takes 51.4 s while compiling, and runs 1 to 4 take 17.04 to 17.20 s, 2,381 to 2,404 tokens per second per rank. Turn both into step times with the 40,960 tokens per rank: 2,800 tokens per second is a 14.63 s step, 2,400 is 17.07 s.
The estimate explains a little under half to a little over half of the measured step. The collective bars are drawn for scale only: if they were exposed, they would add to the step rather than sit beside it.
Three readings follow from the figure.
The collectives are not what limits the run. Even fully exposed under the pessimistic model they would be 3.15 s of a 14.6 to 17.1 s step, and the case study's account is that XLA overlaps them. The estimate agrees that this is possible: the compute they hide behind is at least 2.5 times longer. A trace is what would confirm it.
About 7 to 9 seconds per step are not matmuls at peak. The case study does not break the step down, so the candidates come from the code and from earlier chapters, not from a measurement: matmuls running below peak MXU efficiency (the k and v projections have only 256 output columns); vector-unit work, which chapter 1 showed runs at a small fraction of the MXU's rate (four fp32 RMSNorms per layer, the QK norms, RoPE, the sigmoid gate, SwiGLU); attention through plain F.scaled_dot_product_attention with a dense additive mask for the windowed layers; the ten loss chunks run one after another, each preceded by two copies; and host dispatch between the 52 compiled layers and the uncompiled parts of the step, which TorchTitan's optimization guide calls a structural MFU ceiling. Attention is not the main suspect even in the worst case: if the windowed layers computed every position instead of the 2,048-token window, attention would cost \(52 \times 6 \times 32 \times 256 \times 5{,}120 \times 4/3 \times 40{,}960 / 1.1535 \times 10^{15} = 0.62\) s instead of 0.34 s.
The published 38% is the top of the range. Reproduce it from the run's own numbers. MFU is the model's FLOPs per second over the peak; per rank,
and at 2,400 tokens per second per rank, 33.1%. The Introducing TorchTPU announcement post states "~5.6k TPS per TPU with 38% MFU": per chip, \(2 \times 2{,}800\). The two figures agree within their rounding if the throughput was between 5,550 and about 5,584 tokens per second per chip, the low end of "~5.6k". The README's own log, at 2,381 to 2,404 per rank, corresponds to about 33%. The same arithmetic shows what the chip actually executes: at 2,800 tokens per second, \(8.576 \times 10^{15} / 14.63\) s is 50.8% of peak in matmul work alone, because MFU does not credit the recompute.
On one convention: this run against TorchTitan¶
The announcement post does not say how it counts FLOPs. Try the candidates and see which reproduces it. With 6N and the active count, every training figure it gives for Muse Glimmer matches within rounding, and so do the prefill figures with 2N; with the embedding included (27.85B), the "38%" row comes out at 40.2 to 40.9% and does not. TorchTitan's recipe numbers, by contrast, include attention: at sequence length 16,384 its count is 173.45 GFLOP per token, and the recipe README's 3,245 tokens per second per device times that is 562.9 TFLOP/s against the README's 562.8, or 48.80% MFU against 48.8%. Every point of the Muse Glimmer scaling chart in the integration post, Integrating TorchTPU into TorchTitan and Optimizing Models for TPU, reproduces to within 0.02 points the same way.
Compare bars of the same colour only. The headline gap between this example's 38% and the TorchTitan recipe's 44% shrinks to under 2 points on the 6N convention, and the rest of the difference is a different sequence length, batch, trainer and attention kernel, not the same run done better.
The comparison is still not like for like. The TorchTitan recipe runs on 64 chips with one sequence of 16,384 tokens per device, Graph Trainer and SimpleFSDP, fp32 weights and optimizer state, Pallas Splash attention with a local mask for the windowed layers, and a memory policy that saves the attention output and the FFN down-projection output instead of recomputing them. Its README measures what that last choice is worth: saving both regions cut the step from about 5.30 s to 5.05 s (4.8%) and raised peak HBM from 76.11 to 78.70 GiB. The closest comparison to this example is the TorchTitan port in the announcement post, the GPU-written TorchTitan model with FlexAttention swapped for plain SDPA, compiled and sharded with SimpleFSDP on the same 4 chips: 36% against this example's 38% at 5,120 tokens, and 29% against 32% at 10,240. Two different pure-PyTorch implementations land within a few points of each other on the same hardware.
At scale¶
The case study is one host. The published TorchTitan numbers say what happens when the same kind of model spreads out, and they are worth reading with the same care:
- Muse Glimmer 30B, 8 to 128 chips (integration post): 6,096 to 5,768 tokens per second per chip, 95% weak-scaling efficiency, 45.84% to 43.36% MFU on TorchTitan's convention.
- Llama 3 405B on 1,024 v7x chips, 8K context (announcement post): 500 tokens per second per chip and "50+% MFU"; the integration post says about 57% from 128 to 1,024 chips. Both hold: with TorchTitan's shape for the model (126 layers, \(d_\text{model}\) 16,384, 128 heads, FFN 53,248), 500 tokens per second per chip is 52.5% on 6N and 56.9% with attention counted.
- Qwen3 235B MoE on up to 8,192 v7x chips, 4K sequence: for the single 1,024-chip slice the announcement post's table gives 2,236 tokens per second per TensorCore and 28.8% MFU, and the integration post gives 4,472 per chip and 32.42%; on 8,192 chips the table gives 2,104 per TensorCore and 27.1%, and the integration post 4,208 per chip and 30.51%. Same throughput in both rows, MFU 12.6% higher in one post at both scales: two FLOP conventions again. The 2,048- and 4,096-chip points of the integration post's scaling chart line up with the announcement table the same way. The announcement post's text also says 28% at 8,192 chips where its table says 27.1%.
- FLUX.1 on v6e (announcement post): from one v6e-8 node to a v6e-256 slice with SimpleFSDP, the per-sample step time rises only from 0.92 s to 1.00 s.
Judging the choices¶
Judge each choice by three things: what evidence supports it, what it costs, and what you would measure next.
| Choice | Evidence for it | What it costs | What to try next, and how you would know |
|---|---|---|---|
Per-layer torch.compile |
Case study: no benefit from a larger scope for this model, much shorter compile; two cached layer kinds | Host dispatch between 52 programs and around the uncompiled embedding, loss loop and optimizer | Graph Trainer or a whole-step compile, as in the TorchTitan recipe; an XProf trace showing idle TensorCore time between layers would justify it |
| Full per-layer checkpointing | Without it, the activations of 52 layers at 40,960 tokens would not fit | 1.79 s of recompute at peak, 23% of the compute floor | Save selected outputs instead of recomputing them; the estimate leaves about 24 GiB of headroom, and TorchTitan measured 4.8% from saving two regions per layer. A memory profile first |
| FSDP without prefetch | Case study: XLA overlaps the collectives on the SparseCore; the estimate (1.6 to 3.1 s against at least 7.8 s of compute) says overlap is possible | Nothing measurable, if the overlap holds | Nothing until a trace shows exposed all-gathers; then the SparseCore and latency-hiding flags of chapter 14 |
| Embedding and LM head replicated | Simplest code; at 8 bytes per parameter it fits | 20 GiB per device; a 5.4 GB all-reduce after backward, in its own compiled call, which nothing overlaps | Shard them like the projections: 17.5 GiB back per device, and their gradient reduction can start as soon as the loss module has produced it, before the backbone's backward |
| Chunked fused loss, 4,096-token chunks | The logits would cost 15.4 GiB | Ten sequential compiled calls with two copies each | Larger chunks if memory allows, or TorchTitan's fused soft-capped cross-entropy kernel, which its README measured about 3% slower than full logits but far lighter in memory |
| bf16 weights and AdamW moments | Fits easily; this is a throughput demonstration | Not a training recipe: the TorchTitan recipe keeps fp32 weights and optimizer state | Switch to fp32 state, and shard the embedding and head at the same time, or it no longer fits (115.8 GiB) |
| Plain SDPA with a dense window mask | Pure PyTorch, runs on GPU unchanged | Possibly full-length attention work in 39 layers; at most 0.62 s by the estimate | A Splash attention kernel with a local mask, as TorchTitan uses; measure the attention ops' time in a trace before and after |
The method generalizes, and it is the scaling book's: estimate, measure, attribute the difference, and pick the experiment that tests the largest unexplained term.
Each pass tests the largest unexplained term and then measures again, including after a cut in FLOPs. The tags are this chapter's run, per device: the estimate explains 7.8 s of a 14.6 to 17.1 s step, and the remaining 7 to 9 s are not matmuls at peak, with matmuls below peak folded into that gap. The estimate already makes exposed collectives the least likely of the three.
Verifying the result¶
An analysis of a run holds up when it reproduces the run's published efficiency from the run's own numbers and explains the difference between the estimate and the measurement.
- Reproduce the MFU. Tokens per rank per step are \(8 \times 5{,}120 = 40{,}960\). A measured step time gives tokens per second per rank; per chip is twice that. With \(N = 26{,}509{,}949{,}440\) and the v7x peak,
mfu(tokens_per_s, params, peak_flops)incode/ch16_case_study/mfu.pyreturns \(6N \times \text{TPS} / \text{peak}\). For the published figure, "~5.6k" covers 5,550 to 5,650 tokens per second per chip, and only its low end matches "38%": \(5{,}550 \times 6 \times 26.51 \times 10^9 / 2.307 \times 10^{15} = 38.3\%\), while 5,600 gives 38.6%. The two figures agree for 5,550 to about 5,584 tokens per second per chip.python code/ch16_case_study/mfu.py --cpu-smokedoes this for all six figures in the announcement post and prints the rounding interval of each;tests/ch16/test_mfu.pyfails if any stops matching, and also checks that counting the embedding does not match. - Reproduce TorchTitan's number on its own convention.
torchtitan_flops_per_token(seq_len=16384)is 173.45 GFLOP; 3,245 tokens per second per device gives 562.9 TFLOP/s and 48.80%, the recipe README's 562.8 and 48.8%. If your number disagrees with a published one by a constant factor, you have the wrong convention or the wrong unit (device against chip), not a wrong measurement. - Check the estimates against your own run. Run the example, discard run 0 (compilation), and confirm that steps 1 to 4 are stable, as the README's are to within 1%. Compare peak HBM from a memory profile with the 72 GiB estimate plus the recomputed layer. Capture an XProf trace (chapter 10) and confirm that the all-gathers sit under matmuls rather than beside idle TensorCore time, that the all-reduce after backward takes about the 0.1 s the ring model predicts, and where the 7 to 9 seconds outside the compute floor go.
- Run the worksheet.
python code/ch16_case_study/estimate.py --cpu-smokeprints every number in this chapter and ends withcpu-smoke: OKwhen all consistency checks hold.
Worked problems¶
Problem 1. The announcement post also reports this example at sequence length 10,240: "~4.6k TPS per TPU with 32% MFU". Reproduce the MFU, and compute it on TorchTitan's convention.
Answer
6N: \(4{,}600 \times 6 \times 26{,}509{,}949{,}440 / 2.307 \times 10^{15} = 31.7\%\); the rounding interval of "~4.6k" gives 31.4 to 32.1%, which contains 32%. TorchTitan's attention term at 10,240 tokens is \(13 \times 6 \times 32 \times 256 \times 10{,}240 + 39 \times 6 \times 32 \times 256 \times 2{,}048 = 10.47 \times 10^9\) FLOPs per token, 6.6% of \(6N\), so \(4{,}600 \times 169.53 \times 10^9 / 2.307 \times 10^{15} = 33.8\%\). The longer the sequence, the more the two conventions differ, because only the global layers' attention grows with it.
Problem 2. How much HBM per device would sharding the embedding and LM head over the 8 ranks free, with the example's 8 bytes per parameter? What happens to their gradient traffic?
Answer
Their state drops from \(2 \times 1{,}344{,}831{,}488 \times 8\) bytes (20.04 GiB) to an eighth of that, 2.5 GiB: about 17.5 GiB freed, and the per-device total goes from 72.3 to 54.8 GiB. The bytes on the wire stay the same: an all-reduce is a reduce-scatter plus an all-gather (chapter 13), and sharding replaces one all-reduce of 5.38 GB with an all-gather in forward and a reduce-scatter in backward. What changes is when the traffic happens. Today the all-reduce runs in its own compiled call after the whole backward, with nothing to overlap; sharded, the head's reduce-scatter can start as soon as the loss module has produced its gradient, while the backbone's backward runs.
Problem 3. For Qwen3 235B, the announcement post reports 2,236 tokens per second per TensorCore and 28.8% MFU on a single slice of 1,024 v7x chips, and 2,104 and 27.1% on 8,192 chips. The integration post reports 4,472 tokens per second per chip and 32.42% for the 1,024-chip slice, and 4,208 and 30.51% on 8,192 chips. Is one of them wrong?
Answer
No measurement disagrees: \(2 \times 2{,}236 = 4{,}472\) and \(2 \times 2{,}104 = 4{,}208\), so both posts report the same throughput. The MFUs differ by \(32.42 / 28.8 = 1.126\) on 1,024 chips and \(30.51 / 27.1 = 1.126\) on 8,192, so the posts assume FLOPs per token that differ by about 13%: different FLOP-counting conventions, such as whether and how attention is counted. A ratio that stays fixed while the chip count grows eightfold is a property of the formula, not of the run. Neither post states its convention, so you cannot tell which is which without recomputing both from the model's shape. Quote throughput when you compare runs from different sources; quote MFU only with its convention.
Problem 4. You move the example to two hosts, 8 chips and 16 devices, keeping 8 sequences of 5,120 tokens per device and one FSDP group. Predict memory per device, collective time per step and throughput per device.
Answer
Sharded layer state halves to 11.72 GiB; the replicated 20.06 GiB, the 26.41 GiB of checkpoints, the gathered layer and the loss chunk do not change: 60.6 GiB. Collectives: \((n-1)/n\) goes from 7/8 to 15/16, so the one-way ring estimate rises from 1.57 to 1.68 s per step. Compute per device is unchanged, so the compute floor stays 7.8 s and the collectives still fit behind it. Prediction: tokens per second per device nearly unchanged. The TorchTitan recipe is evidence of the same kind, 6,096 to 6,064 tokens per second per chip from 8 to 16 chips. The example's launcher is single-host (world_size = 8, one node), so the launch changes too, as in chapter 13.
Problem 5. The case study argues that prefetching the next layer's weights is unnecessary because XLA overlaps the collectives. Test that claim against the estimates. What evidence would settle it?
Answer
The estimate supports it as possible: 1.57 s of collectives per step on a one-way ring, 3.15 s with shared links, against a compute floor of 7.80 s and a measured step of 14.6 to 17.1 s. Per layer that is 30 to 60 ms of gathers and reduce-scatters against at least 150 ms of compute. Without prefetch, one thing cannot overlap: each layer is its own compiled program, so its first gather has nothing earlier in that program to hide behind. The q projection's gather is 54.5 MB, about 0.53 ms on the one-way ring, so even fully exposed in forward and again in recompute it costs about 55 ms per step, under 0.4% of the measured step. Support is not proof: the case study gives no trace or step-time breakdown. An XProf trace showing all-gather and reduce-scatter ops running on the SparseCore while the TensorCore runs matmuls, with no idle TensorCore gaps waiting on them, would settle it; so would comparing the step time with a variant that does prefetch and finding no difference.
Problem 6. You want to train for real with this code: fp32 weights and AdamW moments (16 bytes per parameter), as TorchTitan's recipe does. Which change is required first, and which would you try next? Justify the order.
Answer
First, shard the embedding and LM head. At 16 bytes with them replicated, the device needs 115.8 GiB, more than the 96 it has; sharded, 80.8 GiB, which fits with about 15 GiB for the recomputed layer and temporaries. Nothing else is required to run. Fix the initialization at the same time: replicated weights seeded per rank differ between ranks, which the worker's comment warns about. Next, try trading the remaining headroom for speed: recompute costs 1.79 s of a 7.8 s floor, and TorchTitan measured 4.8% from saving two outputs per layer. That is the largest estimated term you can change without new kernels. Then trace, because 7 to 9 seconds per step are outside the estimate and the trace will rank them.
Quick questions¶
- Why does the example run with a world size of 8 on four chips, and what does each rank hold of a layer's projection weights?
- Which of the model's parameters does the example shard, which does it replicate, and how are the replicated ones' gradients combined?
- Why does the embedding table count towards memory but not towards \(N\) in \(6N\), while the LM head counts towards both?
- Write the bytes per parameter of the example's training state and explain where each byte comes from.
- Why does per-layer activation checkpointing make the chip execute about 1.32 times the model's FLOPs here, and why does MFU not show that work?
- Why must activation checkpointing sit inside the compiled layer rather than outside compiled sub-layers?
- What two numbers would you need to turn "2,800 TPS per rank" into an MFU, and what mistake gives half the right answer?
- Name two published Muse Glimmer MFU figures that use different FLOP conventions, and convert one to the other's convention.
- The collectives take an estimated 1.6 to 3.1 s per step. Why does that not mean the step is 1.6 to 3.1 s longer than its compute?
- Which single estimate in this chapter would you check first with a profile, and why?
Key takeaways¶
- Estimate before measuring: from the shapes and the launch, Muse Glimmer 30B on one v7x host is 27.85B parameters (26.51B active), 8 devices in one FSDP group, 40,960 tokens per device per step, 72 GiB of estimated HBM per device and a compute floor of 7.8 s per step.
- The case study's four choices each answer a visible cost: per-layer compile keeps compilation cheap, checkpointing inside the compiled layer makes 52 layers of activations fit, functional-collective FSDP keeps the collectives inside the compiled program where XLA can overlap them, and the chunked fused loss avoids 15.4 GiB of logits.
- The measured 14.6 to 17.1 s step is about twice the compute floor; the collectives (1.6 to 3.1 s) are not the reason, so the next evidence to gather is a trace of where the other 7 to 9 seconds go.
- The published 38% MFU reproduces as \(6N \times \text{TPS} / \text{peak}\) with the embedding excluded, at the top of the reported throughput range; the README's own log is about 33%.
- MFU figures are only comparable on one FLOP convention and in one unit: the announcement post uses 6N, TorchTitan adds attention, and two posts report the same Qwen3 throughput on 1,024 chips as 28.8% and 32.42%. Recompute before you compare.
- The cheapest wins are structural: shard the replicated embedding and head (17.5 GiB back, and the precondition for fp32 state), then spend the headroom on saving activations instead of recomputing them.
- Part IV ends here with a trained model; Part V turns to serving it, where the same estimate-then-measure method meets prefill, decode and the KV cache.
References¶
- Muse Glimmer 30B: training: the case study, its throughput, and the reasons for each implementation choice
- Pure PyTorch trainloop for Muse Glimmer 30B:
model_fsdp.py,worker.py, the launcher, the GKE job and the README's run log - Introducing TorchTPU: Muse Glimmer 30B training and prefill throughput and MFU, the TorchTitan port, Llama 3 405B, Qwen3 235B and FLUX.1 at scale
- Integrating TorchTPU into TorchTitan and Optimizing Models for TPU: the Muse Glimmer TorchTitan recipe and its scaling from 8 to 128 chips, Llama 3 405B and Qwen3 235B
- Recipe for training Muse Glimmer 30B model on a 128 device TPU ironwood cluster (tpu7x-4x4x4): Graph Trainer, Splash attention, memory policy and the measured MFU
- TorchTitan source: the Muse Glimmer and Llama 3 model shapes and the attention FLOP count
- Training LLaMA 3 on TPUs: counting parameters and FLOPs from a configuration, then estimating memory and time
- Companion code for this chapter




