Case study: Muse Glimmer 30B inference¶
Prerequisites: Inference math: prefill, decode, KV cache, vLLM-TorchTPU
TorchTPU's documentation includes an end-to-end inference notebook for Muse Glimmer 30B: pretrained Hugging Face weights loaded into a pure-PyTorch decoder, a 7-token prompt, greedy decoding for 20 steps on one TPU v7x chip, run twice with two different KV caches. A preallocated StaticCache compiled with dynamic=False reaches 23.58 ms per token; a growing DynamicCache compiled with dynamic=None reaches 24.17 ms. Chapter 7 used this table to compare the two caches, and chapter 17 used the 23.58 ms to check a decode floor. This chapter analyzes the whole run the way chapter 16 analyzed the training example: write down the model and the hardware, estimate bytes, floors and compile counts before looking at any measurement, read what the case study did step by step, compare, and judge each choice and the evidence behind it. Every number is quoted from a source or derived with its arithmetic shown, and code/ch22_case_study/analysis.py reproduces all of them.
What this chapter covers¶
- A published inference run broken into its model, hardware, cache, compile settings and the calls it times.
- Weight bytes, KV bytes, prefill and decode floors and compile counts, estimated from first principles before reading any measurement.
- The measured latencies set against those estimates, and the likely causes of each gap.
StaticCacheagainstDynamicCacheon steady-state latency, warm-up cost and restart cost.- The quality of the case study's evidence (what was measured, on what, and what is missing), the next experiment, and what a serving engine would add.
The model and the hardware¶
Start where the scaling book's applied inference chapter starts with LLaMA 3-70B: a table of the model and of the run. For Muse Glimmer 30B both come from the notebook's Config and its benchmark section.
| Quantity | Value | Source |
|---|---|---|
| Layers | 52; every 4th is full causal attention without RoPE (NoPE), the other 39 a sliding window of 2,048 with RoPE | num_layers, swa_size; is_swa=((layer_idx % 4) != 3) |
| \(d_\text{model}\), \(d_\text{ff}\) | 6,656 and 19,968 (SwiGLU) | dmodel, dff |
| Attention | 32 query heads and 2 KV heads of 128, QK norm, a sigmoid output gate | num_q_heads, num_kv_heads, dhead, gate_proj |
| Vocabulary | 202,048; untied LM head with logits for the last position only | vocab_size, self.lm_head(h[:, -1:, :]) |
| Precision | bf16 (torch.set_default_dtype(torch.bfloat16)); the four norms of each block in fp32 |
model_generate cell, DecoderBlock |
| Request | batch 1, "The future of artificial intelligence is", 7 tokens with the BOS token the code prepends when the tokenizer has one, greedy, 20 decode steps | PROMPT, num_decode_steps; section 7 |
| Hardware | "a single TPU v7x chip"; all tensors on one torch.device("tpu") |
section 7; the imports cell |
| Compilation | empty compilation cache (cold start); torch.compile(muse_model, dynamic=False) or dynamic=None |
sections 5 to 7 |
Chapter 17 met the one ambiguity here and resolved it the same way this chapter does. A v7x chip is two PyTorch devices, each with its own 96 GiB of HBM and half the chip's bandwidth (chapter 1). The source says "chip"; the code allocates everything on torch.device("tpu"), one device, and starts no process group. The estimates below use one device's bandwidth and show the per-chip reading next to it.
Everything the decode loop touches sits on one TensorCore. The teal arrow is the cost of a token: all 53 GB of weights the step multiplies by cross it once per step, and the StaticCache next to them is too small to matter at this length.
Loading the weights¶
The notebook does not build the Hugging Face model. It constructs MuseGlimmer30B on the meta device, materializes uninitialized storage on the TPU with to_empty(), and copies each checkpoint tensor straight into m.state_dict(), four tensors at a time from a thread pool. On storage that is not a local file, tensors larger than CHUNK_BYTES (256 MiB) are streamed in chunks instead; the source names the embedding and LM head ("~2.7 GB" each). A local copy is used when MUSE_GLIMMER_CHECKPOINT_DIR is set; otherwise the files come from the Hub repo meta-models/Muse-Glimmer-30B.
The counts check out against the shapes. Each block has 12 tensors (five attention projections, three FFN projections, four norm weights; the QK norm and the embedding norm have no weights), so the state dict holds \(12 \times 52 + 3 = 627\) tensors with the embedding, the final norm and the LM head: the source's "627 tensors". The bytes are chapter 16's parameter count in bf16 with the block norms in fp32: 55.71 GB, the source's "~55.7 GB"; with 4 layers, 9.25 GB, its "~9.3 GB"; and \(202{,}048 \times 6{,}656 \times 2 = 2.69\) GB for each of the embedding and the LM head. The full model fits on one device's 96 GiB (103.1 GB) with about 47 GB to spare.
Estimates before measurements¶
The scaling book's method: bytes first, then the floor each phase cannot beat, then a prediction to check.
Bytes per step¶
| Item | Arithmetic | Bytes |
|---|---|---|
| Weights a step reads | every parameter except the embedding table, a lookup (chapter 17) | 53.02 GB |
| KV per token, all layers | \(2 \times 52 \times 2 \times 128 \times 2\) | 53,248 |
StaticCache |
max_cache_len \(= 7 + 20 = 27\) positions in every layer, allocated up front |
1,437,696 |
DynamicCache after step \(t\) |
\((7 + t) \times 53{,}248\); 1.44 MB after step 20 | grows |
StaticCache sets max_cache_len = prefill_seq_len + num_decode_steps, and the notebook sets prefill_seq_len to the prompt's length, so the cache has 27 positions; Config's default prefill_seq_len of 128 would give 148. The floor is 14.37 ms at either length, because the KV term is about 1.4 MB against 53 GB of weights. The cache does not cap its windowed layers: its docstring notes that 27 positions are far below the 2,048-token window, so the mask alone keeps attention correct. The KV cache is 0.003% of the bytes a step reads. This is a weights-bound workload, nothing like the KV-bound regime of chapter 17's long-context batches.
Floors¶
Prefill. Seven tokens do \(2 \times 26.51 \times 10^9 \times 7 = 3.7 \times 10^{11}\) FLOPs, 0.32 ms at a device's 1,153.5 TFLOP/s, but still read all 53.02 GB of weights. The step's intensity is 7 FLOPs per byte against a ridge of 313, so a prompt this short is memory-bound and its floor is a decode step's:
Decode. Chapter 17's floor, unchanged:
that is, 69.6 tokens per second for the one user. At the practical 3,207 GB/s that chapter 1 recommends for judging measurements, it is 16.53 ms. Had the run used both devices' bandwidth, it would be 7.18 ms.
Compile count¶
Chapter 7's rules predict the warm-up before any timing is read:
StaticCache,dynamic=False: 2 compiles. One for the prefill'sseq_len = 7, one for decode'sseq_len = 1. Every decode step after the first has the same shapes, and the cache length is a 0-D device tensor that Dynamo does not guard on.DynamicCache,dynamic=None: 4 compiles. Prefill and decode step 1 compile with static shapes. At step 2 the cache length changes, Dynamo marks that dimension dynamic, and TorchTPU compiles a bounded program. The dynamic shapes guide's owntorch.catexample shows one more: the bounded program's output has XLA's padded layout, so the next step compiles the same bucket again for that layout. Then nothing more, while the length stays under the bucket's upper bound.
Prediction: about 14.4 ms per decoded token for both caches, plus a few milliseconds of everything the floor leaves out; 2 slow calls for the static run and 4 for the dynamic one; a prefill as slow as a compile, since every prefill in this notebook is a first call.
What the case study did, in order¶
The case study is not an optimization ladder; it is one model run two ways, with the steps a reader repeats. In order:
- Load the checkpoint. 627 tensors, about 55.7 GB, into one device's HBM. "Between ~100 s and ~420 s in our runs, depending on storage read throughput": \(55.7 / 420 = 0.133\) to \(55.7 / 100 = 0.557\) GB/s.
StaticCache, prefill.torch.compile(muse_model, dynamic=False)compiles the 7-token graph: 21,024.81 ms. Nobackend="tpu"is needed: with inputs on the TPU,torch.compilepicks the TorchTPU backend.StaticCache, decode step 1. The second compile, forseq_len = 1: 19,756.86 ms.StaticCache, decode steps 2 to 20. Zero recompilations: 23.58 ms per token on average. Steps 2 and 3 run at 24.66 and 24.29 ms; from step 4 the steps sit between 23.34 and 23.69 ms.- Reset Dynamo,
DynamicCache, prefill and step 1.torch._dynamo.reset()discards the static run's graphs;torch.compile(muse_model, dynamic=None)compiles prefill (18,256.18 ms) and step 1 (19,969.41 ms) with static shapes. DynamicCache, steps 2 and 3. Step 2 is the first step where the cache length changes: Dynamo marks it dynamic and compiles a bounded program, 21,985.62 ms. Step 3 "still includes some compilation": 4,908.23 ms.DynamicCache, steps 4 to 20. No more recompilation: 24.17 ms per token on average.- Rerun with a warm cache. TorchTPU saves compiled programs to PyTorch's on-disk
AOTAutogradCache, so a rerun with unchanged code loads prefill and step 1 from the cache "instead of recompiling; decode times per token are unchanged". No warm timing is published. The dynamic shapes guide adds that bounded-dynamic executables are not serialized to that cache yet and are recompiled in every new process.
The animation below shows the same steps; its frame counter runs to 11 because steps 5 and 6 take two frames each and the last frame compares against the estimate.
Watch the counter on the right and the height of the bars: every call that compiles is three orders of magnitude above the teal floor, and every call that does not lands within a factor of two of it.
Measured results against the estimates¶
Two different questions, two scales. On the left, the 20 tokens themselves are a sliver: cold start is compilation. On the right, the steady state, where the caches differ by 0.6 ms per token and the static line needs two more steps than its average admits to settle.
The decode measurement sits above every floor that describes one device, which is what a floor is for; the per-chip floor would leave 70% of the step unexplained. The prefill panel has no comparison to make, because the one number that would test the prefill floor, a warm prefill, is not in the source.
Four readings follow.
The compile counts match the prediction exactly. Two slow calls for the static run, four for the dynamic one, the source's "two more warmup steps than StaticCache". The counts are what chapter 7's rules and the dynamic shapes guide predict, so the mechanism is understood. What they cost is the larger number: 40.78 s of warm-up for the static run, the time of 1,730 steady tokens; 65.12 s for the dynamic run, 2,694 tokens. The dynamic run pays 24.34 s more, in every new process, because its bounded programs are not cached on disk.
Decode runs at 61% of one device's peak bandwidth. The static loop moves \(53.02 \text{ GB} / 23.58 \text{ ms} = 2{,}249\) GB/s, \(14.37 / 23.58 = 61\%\) of 3,690 GB/s and 70% of the practical 3,207. The 9.21 ms above the floor is not explained by any byte count here: the KV cache is 1.4 MB and the LM head's 2.69 GB is already in the 53.02 GB. Per layer, it is \(9.21 / 52 = 0.18\) ms. Chapter 17 named the candidates, and this chapter adds nothing measured to them: plain F.scaled_dot_product_attention with a dense additive mask built each step; the vector-unit work of four fp32 RMSNorms per block, the QK norm, RoPE in fp32, the sigmoid gate and the soft-capped logits; and one host call per token, since each timed step is a Python call into the compiled model followed by torch.accelerator.synchronize(). Ranking them needs an XProf trace (chapter 10), which the case study does not include.
The growing cache is 2.5% to 3.0% slower, not 2.5%. The published averages use different windows: steps 2 to 20 for the static run, 4 to 20 for the dynamic one. The static window includes its two settling steps. On the same window, steps 4 to 20, the static mean is 23.47 ms and the gap is \(24.17 / 23.47 = 1.030\). The source does not explain the gap. The dynamic shapes guide gives a candidate to test: a bounded program executes on buffers padded to its bucket's upper bound, so its attention works over that bound rather than over the live length.
Prefill cannot be judged from this table. The cold prefill is 21,024.81 ms against a floor of 14.37 ms, 1,463 times it, and the source says the cold call "include[s] one-time XLA compilation". The static and dynamic prefills (21.02 s and 18.26 s) differ by 2.77 s with no explanation, and each is a single cold measurement. A user's TTFT on a warm server is what matters, and it is not reported; a warm rerun from the AOTAutogradCache would measure it.
Evaluating the choices¶
Judge each choice by what 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 |
|---|---|---|---|
StaticCache with dynamic=False |
2 compiles, 23.58 ms per token, programs reusable from AOTAutogradCache; static shapes also work with Pallas kernels (chapter 7) |
You must know max_cache_len up front, and attention reads all of it every step (it masks, it does not slice) |
Nothing at 27 positions. At long contexts, compare the mean step at max_cache_len 4,096 against a paged cache that reads only filled pages |
DynamicCache with dynamic=None |
No model change: it is the default cache in Hugging Face models | 2 more compiles (26.9 s here), 2.5 to 3.0% slower, recompiled in every new process | Use it only when you cannot change the model; then torch._dynamo.mark_dynamic with explicit bounds, as the dynamic shapes guide suggests, and time the first steps |
| Batch 1, greedy | Simplest correct loop; matches the case study's purpose | 42.4 tokens per second from a device whose MXU is idle (intensity about 1) | Batch the requests. Chapter 17's model gives 14.66 ms at batch 8 and 16.73 ms at batch 64 with 4,096-token contexts: 546 and 3,825 tokens per second for nearly the same TPOT |
| One device of the chip | The model fits on one device | Half the chip's HBM bandwidth unused | TP=2 over the chip's two devices: chapter 17's model gives 7.18 ms of reads plus 0.21 ms of all-reduces at batch 1, pessimistic for the die-to-die link. Measure TPOT with both |
| bf16 weights | No accuracy question to answer | The whole floor is weight bytes | fp8 weights halve them: a 7.18 ms floor on one device. Gate it on a parity check (chapter 23) |
| Window layers not capped | Correct and simple for 27 positions | At long contexts, 39 of 52 layers keep positions no query can see | Cap them at 2,048: 13,312 bytes per token past the window instead of 53,248 (chapter 17) |
| Plain SDPA, no custom kernels | Pure PyTorch, the same code runs on GPU | Part of the unexplained 9.21 ms, by hypothesis | Trace the attention ops' time per step before and after a kernel swap |
| Checkpoint read every run | Downloads are cached; a local directory can be named | 100 to 420 s, which the source attributes to storage read throughput: the time of 4,241 to 17,813 steady tokens | Read from fast local files, which are memory-mapped; storage that is not a local file streams the large tensors in chunks. Time the load on each storage you use |
What an engine would add¶
The notebook is a teaching loop, not a server. Chapter 18's vLLM-TorchTPU addresses most rows of the table by construction:
- Continuous batching fills the idle MXU: new requests join the running batch every step, which is the batch-1 row's fix.
- A paged KV cache read by Ragged Paged Attention v3 gives the static cache's fixed shapes without its padding: memory and reads follow each sequence's real length.
- Precompiled token buckets move compilation off the request path. Warm-up still compiles, but before the first request, and the three cache roots keep the programs for the next restart. The 40.78 s this notebook spends on its first two calls becomes startup time instead of a user's TTFT.
- Parallelism, quantization and speculative decoding as flags: the parallelism guide's v7x example pairs TP=2 across the two cores of a chip with data parallelism over chips,
online_fp8quantizes a bf16 checkpoint as it loads, and speculative decoding verifies several tokens per weight read.
One caveat decides whether any of this is a flag or a project. The vLLM-TorchTPU supported-models page does not list Muse Glimmer. It lists Gemma 4 with hybrid sliding-window and global attention, so the engine handles the attention pattern, and it documents --language-model-only for serving a multimodal checkpoint as text only, which is what this checkpoint is ("Text decoder weights live under this prefix in the multimodal checkpoint"). Serving Muse Glimmer there means porting the model (chapter 9), then comparing its TPOT with this notebook's 23.58 ms at batch 1 as the first check.
The scaling book's rule of thumb is that the weight-load bound is often within 1.5x of a real decode step when batches are small and there is little communication. The case study's 1.64x is just outside it, which is why the tree below sends it to a trace.
The 1.5x is the scaling book's rule of thumb for small batches with little communication. The case study's 23.58 ms against a 14.37 ms floor is 1.64x, just outside it, so the next step is a trace, not a guess.
Evidence quality¶
The scaling book's estimates are only as good as the measurements they are checked against. Read the case study's evidence with the same care as its numbers.
| What | Status |
|---|---|
| Per-call latency, 20 decode steps, both caches | Measured: wall clock with time.perf_counter() around each compiled call and torch.accelerator.synchronize(), so host dispatch is included. One run per cache is shown; repeats and variance are not stated |
| Hardware | "a single TPU v7x chip"; the code uses one device; host VM type not stated |
| Software | The docs and notebook are the 0.2.0 docs branch; PyTorch and TorchTPU versions are not printed |
| Load time | A range over "our runs", ~100 s to ~420 s, attributed to storage throughput |
| Warm behaviour | Described, not measured: "decode times per token are unchanged"; no warm prefill time |
| Correctness | One sample of generated text from the full model, at 100 decode steps rather than the benchmark's 20; no comparison against a reference implementation |
| Memory | No HBM usage reported |
| Profile | None |
Three consequences. The 2.5 to 3.0% gap between the caches rests on one run per configuration with no stated variance, so treat it as a direction, not a size. The 61% bandwidth figure depends on the per-device reading; a statement of the device count would settle it. And the decode figures are cold-start runs, so the one measurement a serving engineer most wants, a warm TTFT, is absent.
Where the sources disagree
- The 0.2.0 documentation against the repository. The 0.2.0 documentation has the same numbers as the current repository docs. It differs only in the 4-layer branch: it prints the (meaningless) generated text, where the repository version skips it. This chapter follows the repository docs.
- "No padded memory". The case study says
DynamicCache"uses no padded memory"; the dynamic shapes guide says a bounded program runs on buffers padded to the bucket's upper bound. Both hold at different levels: the Python-level cache holds exactly \(S + t\) positions, and the compiled program's buffers are padded.
Verifying the result¶
You have analyzed the run correctly when you can reproduce its published figures from its own numbers, and explain the difference between your estimate and its measurement.
- Reproduce the averages and the rounding. The 19 static steps from 2 to 20 sum to 447.98 ms: \(447.98 / 19 = 23.578\), the table's 23.58. The 17 dynamic steps from 4 to 20 sum to 410.87 ms: \(410.87 / 17 = 24.169\), the table's 24.17. The prose figures round correctly: 21,024.81 ms is "~21.0 s", 19,756.86 is "~19.8 s", 21,985.62 is "~22.0 s", 4,908.23 is "~4.9 s".
- Reproduce the ratios this chapter uses. \(24.17 / 23.58 = 1.025\) (2.5%), and \(24.17 / 23.47 = 1.030\) on a common window; \(19{,}756.86 / 23.58 = 838\), a compile against a steady step; \((21{,}024.81 + 19{,}756.86) / 23.58 = 1{,}730\) steady tokens of warm-up; \(14.37 / 23.58 = 61\%\) of one device's bandwidth.
python code/ch22_case_study/analysis.py --cpu-smoke(source) prints all of them, finds the steady windows and the compile counts from the data (any call slower than 10 times the median step), checks 627 tensors, 55.71 GB and 9.25 GB against the source's rounded figures, and ends withcpu-smoke: OK. - Check the estimates against your own run. Run the notebook on a v7x VM, save what it prints, and run
python code/ch22_case_study/analysis.py --log run.txt. Expect 2 and 4 compiling calls, a steady mean above 14.37 ms, and a floor-to-measurement ratio near the published 61% if your setup matches. A ratio above 100% means an input is wrong. Rerun once with a warm cache and record the prefill time the case study does not publish. - Explain the gap. Capture an XProf trace of a few steady decode steps and attribute the 9.21 ms per token: time between steps on the host, attention, and the vector-unit ops of each block. Until a trace exists, the attribution in this chapter is a list of hypotheses.
Worked problems¶
Problem 1. With USE_FULL_MODEL = False the notebook loads only the first 4 of the 52 layers. Estimate the bytes a decode step reads and its floor on one device. What fraction of those bytes is the LM head, and what does that imply for using the 4-layer run to predict the full model's TPOT?
Answer
Active parameters with 4 layers: \(4 \times 483{,}917{,}824\) for the blocks plus the LM head's \(1{,}344{,}831{,}488\) plus the norms, 3,280,615,936 in chapter 17's count; in bf16, 6.56 GB. Floor: \(6.56 \times 10^9 / 3{,}690 \times 10^9 = 1.78\) ms. The LM head is \(1.345 / 3.281 = 41\%\) of the parameters read, against 5% in the full model. The 4-layer step is not a scaled-down full step: the head and the per-step fixed costs (host dispatch, mask construction, the final norm and soft-cap) are a far larger share of it. Use the 4-layer run to check that the loop compiles and runs; do not extrapolate its TPOT by \(52/4\).
Problem 2. A colleague reads the table as "DynamicCache costs 2.5% in steady state". Is that the right number, and what would you need to state the gap with confidence?
Answer
It is the ratio of the two published averages, \(24.17 / 23.58 = 1.025\), but those averages use different windows. The static window includes steps 2 and 3 (24.66 and 24.29 ms), which are still settling. On a common window, steps 4 to 20, the static mean is \(399.03 / 17 = 23.47\) ms and the gap is 3.0%. To state it with confidence: several runs of each configuration in fresh processes, the mean and spread of the same steps in each, and enough decode steps that the settling steps do not dominate. With one run each, the direction is supported and the size is not.
Problem 3. How many tokens must a process generate before the DynamicCache run's extra warm-up becomes a small share of its total time? Does it ever catch up with the static run?
Answer
It never catches up: it starts 24.34 s behind (65.12 s against 40.78 s of compiling calls) and loses another \(24.17 - 23.58 = 0.59\) ms per token. After 1,000 tokens the totals are about 64.3 s and 89.2 s; after 10,000, 276.6 s and 306.7 s. The extra warm-up falls below 10% of the dynamic run's time only after about 7,400 tokens (\(24.34 / (65.12 + 0.02417\,n) = 0.1\)). In a server the warm-up is paid once per process, and here it is paid again in every new process, since bounded-dynamic programs are not stored in AOTAutogradCache. For a model you control, that settles it for the static cache, as chapter 7 concluded.
Problem 4. Google's announcement post reports Muse Glimmer 30B prefill on one v7x chip at about 25.7k tokens per second, 59% MFU. Someone uses it to predict this notebook's TTFT. Evaluate the prediction.
Answer
It does not transfer. The post's figure is a different example: prefill at sequence length 5,120, with FSDP over a world size of 2 "because a single TPUv7 chip exposes two devices to PyTorch". That run is compute-bound at thousands of tokens per step and uses both devices. This notebook's prompt is 7 tokens on one device: intensity 7 against a ridge of 313, so its prefill is memory-bound and its floor is the weight read, 14.37 ms, not \(7 / 25{,}700\) s = 0.27 ms. The published 25.7k is evidence about long-prompt throughput; the notebook gives no warm prefill number at all, so its TTFT is unmeasured. Measure it with a warm rerun.
Problem 5. A capacity plan assumes Muse Glimmer 30B decodes at under 8 ms per token at batch 1 with TP=4 over four v7x devices. Nobody has measured it. Evaluate the projection with this chapter's numbers before deciding whether to plan on it.
Answer
The arithmetic allows it. With TP=4 over four devices, chapter 17's model at batch 1 gives 13.25 GB of weights per device, 3.59 ms of reads, plus about 0.42 ms of all-reduces on the ICI ring model: a floor near 4.0 ms. If the TP=4 step ran at the same 1.64 times its floor as the case study's loop, it would take about 6.6 ms, under 8. But that ratio was measured on one device, and 9.21 ms of that step is not weight reads. If the overhead is per step rather than per byte (host dispatch, mask construction, small vector-unit ops), TP does not shrink it, and \(4.0 + 9.21 = 13.2\) ms misses the target. Two smaller points: with 2 KV heads, TP=4 replicates each KV head on two devices, harmless at 1.4 MB of KV but not at long contexts; and four devices are two v7x chips, so a plan that says "4 chips" may mean eight devices. Treat the 8 ms as a hypothesis. Measure TPOT at TP=2 first: how the 9.21 ms changes from one device to two tells you whether the overhead scales with TP.
Problem 6. You have one v7x chip and must serve this model. Users care about TPOT; finance cares about tokens per second per chip. Order the next three experiments and say what result would make you stop.
Answer
First, batch: it costs nothing in TPOT at this size (14.37 ms floor at batch 1, 14.66 ms at batch 8 with 4,096-token contexts) and multiplies throughput, so measure TPOT and throughput at batch 8 and 64 in an engine with continuous batching. Stop if TPOT grows faster than the KV term predicts: something other than bandwidth binds. Second, use both devices: TP=2 halves the weight bytes per device (floor 7.39 ms with the pessimistic all-reduce model), which is the only one of the three that lowers TPOT at batch 1; the alternative, one replica per device, doubles throughput instead. Measure both. Third, fp8 weights: the floor halves again, but only after a parity gate passes; stop if the parity check fails. Throughout, keep the profile from the verification steps: if most of the 9.21 ms above the floor is host time, batching and an engine's step loop help more than any byte reduction.
Quick questions¶
- Why does the state dict hold 627 tensors, and which modules have no weights in it?
- Why is a 7-token prefill bound by HBM bandwidth while a 5,120-token prefill is bound by the MXU?
- Why does the
StaticCachehold 27 positions, and why does it not matter here that it does not cap the window layers? - Predict the compile counts for both caches from chapter 7's rules, and say what happens at each of the dynamic run's first four calls.
- Why is 23.58 ms best compared with one device's bandwidth, and what would the comparison look like per chip?
- Name three candidate causes of the 9.21 ms above the floor, and the measurement that would rank them.
- What is the difference between the published 2.5% and the 3.0% this chapter computes?
- Which number would you most want the case study to add, and why?
Key takeaways¶
- Estimate an inference run's bytes and floors before reading its results: Muse Glimmer 30B on one v7x device reads 53.02 GB of weights per step and only 1.4 MB of KV at this length, so its prefill and decode floors are the same 14.37 ms weight read.
- Compile counts are predictable from chapter 7's rules: 2 for a static cache under
dynamic=False, 4 for a growing cache underdynamic=None. The case study matches both, and each compile costs about 5 to 22 s, the time of hundreds to nearly a thousand tokens. - The steady decode step, 23.58 ms, is 1.64 times the floor: 61% of one device's peak HBM bandwidth. The remaining 9.21 ms is not bytes, and only a trace can say what it is.
StaticCachebeatsDynamicCacheon the axes that matter for serving: 24.34 s less warm-up, 2.5 to 3.0% faster per token, and programs that survive a restart. Prefer it for any model whose code you control.- Read the evidence as carefully as the numbers: one cold run per cache, no warm prefill, no variance, no profile, and "chip" where the code uses one device. Recompute published figures before quoting them, and treat unsourced ones as hypotheses.
- The batch-1 loop leaves the MXU idle and half the chip unused; batching, TP=2 and fp8 weights are the next experiments, and an engine such as vLLM-TorchTPU supplies them once the model is ported.
- Part V ends with a measured decode loop and a list of hypotheses about it; Part VI turns to the parity gates and benchmarks that let you trust such numbers.
References¶
- Muse Glimmer 30B: autoregressive decoding: the case study, its
Config, loading code, caches and benchmark table; also in the 0.2.0 documentation - Dynamic shapes: bounded dynamism, the step-by-step compiles of a
torch.catcache, padded buffers andtorch._dynamo.mark_dynamic - Introducing TorchTPU: Muse Glimmer 30B prefill on one v7x chip
- Supported Models & Features: vLLM-TorchTPU model families,
--language-model-onlyandonline_fp8 - Parallelism & Scaling: two logical devices per v7x chip and TP=2 across them
- Serving LLaMA 3-70B on TPUs: How to Scale Your Model's applied inference chapter, the method this chapter follows
- Companion code for this chapter




