Shape rules align model tensor dimensions, batch divisibility, and runtime execution shapes with the TPU compiler and MXU datapath. They carry low to near-zero model-quality risk and belong in every new model definition before the first training run.
Make d_model, FFN and expert intermediate dimensions (d_ff), latent widths (ℓ), attention projection widths, and padded vocabulary sizes multiples of 256 per device (TensorCore) after applying model sharding (d_ff / TP, and ℓ / TP if sharded; tensor parallelism leaves d_model unsharded), matching the MXU's 256×256 systolic array (a 2,880-wide model,
Strictly, systolic tile alignment binds a matmul's contracting (reduction) and output dimensions; token and batch axes stream freely through the array, and counts such as query/KV heads, layers, and experts are exempt so long as the underlying head and hidden widths are aligned. Because every model width listed above acts as a contracting or output axis in at least one forward or backward GEMM, aligning all of them to 256 avoids wasted cycles across the entire step.
The most frequently missed dimension is head_dim: at head_dim = 128 or 64, the head_dim = 256 with proportionally fewer Q and KV heads, preserving total projection widths, parameter count, FLOPs, and logical KV cache bytes. This reshape changes how attention is computed, so it applies when you design and train a new model: an existing checkpoint cannot adopt it without retraining. Coordinated-reshape ablations confirm iso-quality on large models, which still have enough Q and KV heads after halving: in two-seed training runs at the Qwen3-30B-A3B shape, the loss difference between head_dim = 128 and 256 stayed within seed-to-seed variation. On smaller models, halving head count can leave too few heads or limit decode TP sharding, so run a quick ablation first.
Measured: Reshaping Qwen3-30B MoE attention from 32 heads × 128 to 16 heads × 256 (identical parameters and FLOPs) accelerated end-to-end training on Ironwood, with the speedup widening at longer sequence lengths as quadratic attention takes a larger share of step time:
MXU-aligned grouped-matmul tiles added a further ~+15% speedup on the MoE expert GEMMs.
Non-quadratic and linear attention: These alignment rules apply to chunkwise linear and recurrent attention kernels as well. Notably, Gated DeltaNet ablations in Yang et al. (2025) report on-par or better model quality at head_dim = 256 while matching wide systolic tiles.
Precedent from GPU co-designed models: NVIDIA revised Nemotron 3's final dimensions so the hidden width entering all-to-all dispatch was divisible by 512 (a DeepEP requirement), and Microsoft's MAI-Base-1 ladder sets hidden size
Choose model dimensions and batch sizes so a single parallelism plan scales cleanly across every deployment tier: debuggable on 4 chips, high-MFU on a full ICI slice, and scalable across pods using only DP, FSDP, or PP over DCN, never EP or TP (Principle 10 covers the physical link mapping). One direct constraint follows: the global batch size must divide evenly across the batch-sharding axes of every mesh configuration you plan to run.
Across DCN, both flavors of data parallelism work:
- Plain DP replicates weights across slices and synchronizes gradients once per optimizer step.
- Multi-slice FSDP shards weights across DCN as well, saving HBM at the cost of re-gathering weights over DCN.
Without gradient accumulation, DP and FSDP move comparable bytes over DCN and both can hide behind compute. With gradient accumulation, every microbatch repeats FSDP's weight re-gather over DCN while plain DP still synchronizes gradients only once per step. Default to plain DP over DCN (less network traffic, one easy-to-hide sync) and switch to DCN FSDP only when the model requires cross-slice HBM capacity; confirm either choice with a short profiled run. For the same reason, multi-slice FSDP combines poorly with pipeline parallelism (PP): PP executes many microbatches per step and each microbatch would repeat the DCN weight re-gather, so pair PP with plain DP whenever HBM allows.
Measured: Scaling across two slices with plain DP over DCN is near-free in practice, costing only ~1% of per-chip throughput.
XLA compiles each program for exact input tensor shapes and dtypes, so every buffer has a fixed shape, while loop bounds and addresses within a buffer can still be runtime values (as in jax.lax.while_loop); introducing a new shape at runtime triggers recompilation and a host stall. Dynamic workloads still fit this execution model cleanly: the key is to separate the compile-time shape of a buffer from the runtime extent of the data inside it.
- Bucketing, masking, and packing: At the program level, pad serving requests to a small set of precompiled sequence-length and batch-slot buckets (warmed up at server startup), replace data-dependent branches with attention or loss masks rather than shape-changing slices, and pack multiple training examples into fixed-length sequences with segment masking (
packing=Truein open-source MaxText, enabled by default) so padding tokens never reach the MXU. - Scalar prefetch (
PrefetchScalarGridSpecinSMEM): Dynamic ragged structure arises every step in dropless MoE layers, which route a different number of tokens to each expert, and in paged attention, where every sequence has its own KV length, its own scattered set of cache pages, and in a mixed batch its own phase (prefill or decode).
Instead of padding every expert group to the largest group or every sequence to the maximum context length, keep the underlying HBM buffers at fixed shapes (tokens sorted by expert and padded only at the tail; the KV cache allocated as a fixed pool of pages) and describe the ragged layout with small int32 metadata arrays (group_sizes and group_offset for MoE; kv_lens, page_indices, and cu_q_lens for paged attention). Pallas prefetches those integers into the TensorCore's scalar memory (SMEM) before the kernel grid starts via PrefetchScalarGridSpec, and the scalar unit reads them to compute the next DMA tile address and bound its inner loops, masking only tiles that straddle an expert boundary or a partially filled final page. Data dependence becomes a runtime address and trip count rather than a tensor shape, so one compiled binary serves every routing split and batch composition at the unpadded FLOP count.
- Dropless MoE routing in practice (
Megabloxand Tokamax GMM): Enable TPU ragged grouped-matmul kernels (sparse_matmul=Truewith Megablox by default in MaxText, oruse_tokamax_gmm=Truevia open-source Tokamax scalar-prefetch GMMs). Both dropless and capacity-factor routing preserve static outer buffer shapes; the difference is model quality. Capacity-factor routing drops overflow tokens when an expert exceeds its capacity budget, degrading loss and skewing MoE architecture ablations even at low drop rates (MAI-Thinking-1), while still burning dense matmul FLOPs across padded capacity slots. Ragged-GMM kernels remove the speed penalty for dropless routing altogether. (The dense-dropless fallbacksparse_matmul=Falseis strictly a correctness debugging baseline, not a performance path.)
Frontier routing precedent: Avoiding capacity-drop artifacts pushed the MAI-Thinking-1 team to fully dropless MoE training, which TPU ragged-GMM kernels support natively. Kimi K3 co-designs the router itself around this property, using quantile-based expert balancing to achieve balanced expert-parallel training with static shapes and zero host synchronization on the critical path.


