The Case for Co-Designing Model Architectures with Hardware
Paper · 2024 · Quentin Anthony, Jacob Hatef, Deepak Narayanan et al.
Summary
Two transformers can have almost the same number of parameters and still make very different use of the same GPU. One reason is that the accelerator executes matrix multiplications whose dimensions depend on choices such as the width of a layer, the number of attention heads, and the amount of work assigned to each device. A small change can make those multiplications fit the hardware better without adding parameters. The paper follows these relationships from the design of a layer down to the GPU routines that run it. Its subject is the decoder-only design used widely in language generation, a member of the family built around the transformer and attention.
The authors start with general matrix multiplication, or GEMM, the operation behind the major linear transformations in a transformer. They show how layer dimensions determine the rows and columns of these multiplications, then measure how the resulting shapes affect throughput. This explains why nearby dimensions can behave differently. Some line up well with the GPU’s specialized arithmetic units. Some fill its work blocks evenly. Others leave just enough work to require an additional round of execution, even though most of the GPU has nothing to do in that round.
The practical consequence is that a familiar architecture can be worth reshaping before training. The paper reports a 1.18× speed-up for a redesign of the widely copied GPT-3 2.7B architecture and describes that comparison using transformer single-layer throughput. Its conclusion reports throughput gains of up to 38.9% while maintaining accuracy. The paper also shows why the components worth optimizing vary with scale. In its layer breakdown, GEMMs account for 68.3% of latency at medium size and 94.9% at large size. The query, key, and value projection and the feed-forward block are particularly important at the large end of the measurements.
The case studies give the recommendations their boundaries. Replacing the ordinary attention calculation with FlashAttention v2 changes which sizing rules matter for attention. Adding a gated feed-forward block changes the matrix dimensions that need to align. Splitting a layer across a different number of GPUs changes the dimensions each device actually sees. An inference comparison within the Pythia family also finds an unusually efficient architecture whose test loss follows the family’s trend, although the compared variants differ in several ways. The paper makes a case for choosing dimensions with the intended hardware and software in view, and for checking runtime gains alongside the quality of the resulting system.
Deep dive: The Case for Co-Designing Model Architectures with Hardware
How GPU-aware transformer dimensions improve training and inference throughput, and what matrix benchmarks reveal about where the gains come from. · about 34 minutes to read
The problem and its context
Parameter count leaves out the shape of the work
A parameter count describes how many learned values an architecture contains. It gives only an indirect account of the work the hardware will perform. A decoder can distribute its parameters among many narrower layers or fewer wider ones. Within a layer, it can divide the same hidden representation among different numbers of attention heads. These choices change the shapes and sometimes the number of operations the GPU receives. The paper asks how to use that freedom to improve the efficiency of training and serving a language model.
Consider the attention head count. An attention head uses a portion of the representation to compare token positions and combine information from them. At a fixed hidden width, more heads mean narrower portions. The large linear projection that prepares those portions can still have the same overall width. The subsequent attention calculations, though, now involve more separate multiplications with narrower inputs. A parameter count can leave that distinction entirely invisible. It matters to a GPU because the width of each multiplication affects how well its arithmetic units can process the work.
The paper describes an additional reason that inefficient shapes persist. When researchers want a clean comparison with earlier work, reusing a published architecture is often sensible. It holds some design choices steady. But inherited dimensions can then be treated as standard even when the original choice leaves performance on the table. The authors use the GPT-3 2.7B configuration as an example. Related choices appeared in GPT-Neo, Pythia, and OPT.
At the scale the authors are concerned with, an apparently minor loss in hardware utilization can affect substantial training work. The same architectural choice can also recur each time the trained system serves a request. This gives dimension selection two different stakes. During training it affects how quickly the network can be fit. During inference it can affect the cost of repeatedly running the forward computation. The authors expect the clearest transfer when both stages use the same GPU type.
The missing connection between architecture and kernels
A GPU kernel is a routine that runs an operation on the device. The paper places its work in a line of research that profiles these routines, improves matrix multiplication, and exploits specialized hardware for arithmetic. It also describes earlier efforts to improve the movement of data and the organization of computation. Work on Tensor Cores had already addressed their use in deep learning and in scientific applications such as iterative solvers and sparse linear algebra.
The paper identifies a gap between knowing how to optimize an individual routine and knowing what to do when choosing an architecture. A kernel guide may say which matrix dimensions suit a particular device. A transformer designer still has to determine which quantities generate those dimensions. A head width is a quotient of architectural choices. The number of matrix rows in a linear layer may depend on both sequence length and microbatch size. Tensor parallelism, which distributes portions of a computation over devices, can further change the width that any individual kernel receives.
Some of this knowledge was already circulating. The authors describe recommendations found in informal technical discussions, notes in other papers, and comments in training software. That material could tell a practitioner to align a vocabulary or pay attention to tile sizes. The contribution here is to show which multiplication each decision changes and to connect that multiplication to the runtime of the larger layer. This places the work within GPU and parallel computing.
The authors distinguish their focus from two other kinds of performance study. Earlier accelerator comparisons looked across generations and hardware families to help match devices to workloads. The present paper also measures different devices, but its main design question runs in the other direction. Given an accelerator and an implementation, which dimensions produce a more suitable workload? The two questions intersect because an architecture that maps well to one configuration can create awkward local dimensions in another.
They also compare the study with earlier kernel characterization for recurrent and convolutional networks. Those networks give earlier examples of studying the operations actually executed, but the transformer assembles different operations and exposes different adjustable dimensions. The distributed training work they identify as closest in practical intent studies how ways of splitting a large workload interact. The present analysis takes much of that partitioning as given and examines the matrix operations left on each device. The relevant earlier work is Megatron-LM’s study of large-scale GPU training.
Why a decoder is a useful starting point
The authors use a decoder-only transformer of the kind popularized by GPT-2. Its layers repeat a recognizable sequence of computations. An attention block builds relationships among positions, and a feed-forward block transforms the representation at each position. The same dimensions recur throughout the stack. A poor choice in a often executed multiplication can therefore recur from one layer to the next.
That repeated structure makes the paper’s analysis possible. The authors can write down the matrix dimensions of each operation, examine individual kernels under different shapes, and then ask which findings remain visible at the level of a transformer layer. A decoder also gives them a concrete scope. They expect much of the reasoning to apply to encoder-only designs. Their accounting offers less direct guidance for encoder–decoder systems because the transition between the two parts introduces a different arrangement of operations.
The study treats accuracy and runtime as separate questions about a proposed architecture. Similar parameter budgets make a comparison of shapes meaningful, while throughput measurements reveal how the GPU handles those shapes. An architecture can also change how information is processed, even when the parameter budget barely moves. The authors’ treatment of attention head count illustrates that distinction. It is a performance variable because it changes a matrix dimension, and an architectural variable because it changes how attention is divided.
The method, step by step
The authors work from the transformer forward pass to the operations executed on a GPU. They first identify the large matrix multiplications and express their dimensions in terms of the network’s settings. They then look at the dimensions after partitioning the layer, relate those dimensions to the device’s execution rules, and use controlled benchmarks to see which effects survive in practice. The same accounting also tells them where to look when the implementation changes.
From transformer dimensions to measured GPU throughput
The steps in order.
Start with the multiplication the GPU sees
Matrix multiplication takes rows from one input and columns from another. It combines each row and column to produce a value in the output. The input matrices share an inner dimension, which determines the length of the calculation for each output value. The two outer dimensions determine how many values the output contains. Changing the inner dimension and changing an outer dimension can therefore create different workloads even when both changes increase the arithmetic.
The paper presents general matrix multiplication in its accumulation form.
C = αAB + βC
A and B are the two input matrices. In their product AB, the column count of A equals the row count of B. C on the left is the updated output matrix, while C on the right is the matrix before the update. The scalar α scales the new product and the scalar β scales the contribution from the existing output. The plus sign combines those terms. With α set to 1 and β set to 0, the result is the simple product. A layer can use the existing-output term when the computation calls for accumulating a contribution.
Attention requires groups of products with matching shapes. The paper describes these as batched matrix multiplication, or BMM. A batch in this sense groups separate matrix operations so the GPU can execute them as a single call. This meaning is related to, but distinct from, a microbatch of input sequences. The attention calculation creates matrix pairs for sequences and heads within that microbatch.
Cᵢ = αAᵢBᵢ + βCᵢ, i = 1, …, N
The index i selects a product from the batch, and N is the number of products. The ellipsis covers all indices from the first through the last. Aᵢ and Bᵢ are the inputs at index i. Cᵢ on the right is the corresponding existing matrix, and Cᵢ on the left is its updated value. The scalars α and β again set the weights of the new product and the existing value. Each matrix pair contributes to its own output.
Account for alignment and the GPU’s rounds of work
The paper uses m and n for the outer dimensions of a GEMM and k for the shared inner dimension. These dimensions matter even when a multiplication is valid mathematically. For the FP16 arithmetic discussed in the paper, each element occupies 2 bytes. The authors give alignment targets of 16 bytes on V100 and 128 bytes on A100, corresponding to multiples of 8 and 64 FP16 elements, respectively. Tensor Cores are specialized units for this kind of calculation, and the A100 benchmarks show how effectively they can be used as matrix dimensions approach the preferred alignment. When the preferred multiple is impractical, the authors look for dimensions divisible by larger powers of two.
An additional constraint comes from tiling. The kernel partitions the output into rectangular regions called tiles and assigns blocks of work to streaming multiprocessors, or SMs. A tile at the edge of an output may extend beyond the required rows or columns. The kernel still executes the block even when only part of its output is needed. The paper calls the resulting loss tile quantization. It discusses 128 × 256 as an efficient tile shape in its analysis, while observing that the backend can select different shapes for different multiplications.
Wave quantization concerns how the resulting blocks are scheduled. The paper illustrates it with an A100, which has 108 SMs in the example. A workload of 109 blocks needs a full wave followed by a tail wave with 1 block under the scheduling model used to explain the effect. That last round can take almost as long as the first while contributing much less useful work. As more blocks fill the tail, throughput can rise again. Crossing the next boundary can introduce another underfilled wave. This is the mechanism behind the repeated peaks and troughs in some of the benchmarks.
⌈X/t₁⌉ · ⌈Y/t₂⌉ ≡ 0 (mod S)
or
⌈X/t₂⌉ · ⌈Y/t₁⌉ ≡ 0 (mod S)
X and Y are the row and column dimensions of the output matrix. The tile sides are t₁ and t₂, with the subscripts distinguishing the two lengths. The ceiling signs, ⌈ and ⌉, round a division upward so a partial tile still counts. The centered dot multiplies the tile counts along the two axes. S denotes the number of SMs. The congruence to 0 modulo S says that the tile count is divisible by that number. The two alternatives describe the two orientations of the tile. This condition addresses complete waves for a chosen tiling. Padding within an edge tile is a separate issue.
Follow tokens through a decoder layer
The architecture uses a vocabulary of size v, a sequence length s, a microbatch size b, and a hidden width h. The microbatch is the set of sequences processed together for the operation being examined. Each token first selects a vector from an embedding table of shape v × h. In the reference design, the network combines those vectors with learned positional embeddings of shape s × h. The input to the stack of transformer layers has shape s × b × h. The same shape is available at the output of every layer, so the analysis can trace a representative layer without describing a new interface at each depth.
A linear projection can treat the sequence and microbatch axes as a single collection of token positions. That is why the authors write a row dimension of b · s for these projections. Tensor parallelism divides parts of the layer among t devices. The expressions that follow use h for the full hidden width and show the widths of the local pieces explicitly. This matters because hardware alignment is a property of the local operands.
The first large product in the attention block forms queries, keys, and values. Queries and keys are the representations used to calculate which positions attend to which others. Values are the representations combined once those relationships have been weighted. The reference implementation can produce all three representations in one projection.
(b · s, h) × (h, 3h/t) → (b · s, 3h/t)
A parenthesized pair gives the rows and columns of a matrix. The symbol × between pairs denotes multiplication of the matrices, and the arrow points to the output shape. The row dimension b · s combines the microbatch size b with sequence length s. The input width is h. The factor 3 comes from the query, key, and value projections combined, and dividing by the tensor-parallel degree t gives the local output width 3h/t.
The attention score operation then works at the level of individual heads. The paper uses a for the head count and assumes equal widths, with a projection width of h/a per head. One score matrix records how positions in a sequence score against other positions for one head. The width that mattered in the combined linear projection is now divided among the heads.
(b · a/t, s, h/a) × (b · a/t, h/a, s) → (b · a/t, s, s)
Here a parenthesized triple gives the batch count, rows, and columns. The operator × applies a matrix multiplication to each matching pair in the batch, and the arrow gives the output shape. The batch count b · a/t comes from b sequences and the share of the a heads assigned under tensor parallelism of degree t. The sequence length s governs both axes of the output, and the inner dimension h/a is the width of one head. This is why toggling the head count at a fixed hidden width changes the shape of the score multiplication.
The next multiplication uses attention weights to combine the values. It also works separately for each sequence and head. The sequence-to-sequence dimension is now inside the multiplication, and the result has a column for each feature in the head’s representation.
(b · a/t, s, s) × (b · a/t, s, h/a) → (b · a/t, s, h/a)
The triples again denote batch count followed by rows and columns. The × applies the product in each batch entry and the arrow gives the resulting shape. The batch count combines microbatch size b and head count a with tensor-parallel degree t. The length s is the number of positions in a sequence. The width h/a comes from dividing hidden width h among the heads. Both attention multiplications consequently expose the per-head dimension to GPU alignment, though it appears in different places in the respective products.
The outputs of the heads contribute to a projection that restores the hidden width used between layers. This operation has a per-device input width set by tensor parallelism.
(b · s, h/t) × (h/t, h) → (b · s, h)
The pairs show matrix rows and columns, × is the matrix product, and the arrow shows its shape. The row count b · s covers the positions across the microbatch. With hidden width h and tensor-parallel degree t, the width of the local input and the shared inner dimension are h/t. The output width is h.
The feed-forward block, also called a multilayer perceptron or MLP, operates on each token’s representation. In the reference design, its first projection expands the representation from h to 4h, and its second brings it back to h. The expansion is partitioned in the dimension accounting for a single GPU.
(b · s, h) × (h, 4h/t) → (b · s, 4h/t)
The row and column pairs describe the operands and the output. The × multiplies the operands and the arrow gives the output shape. The row count b · s again combines the microbatch size b and sequence length s. The hidden width h is the shared inner dimension. The expansion factor is 4, with the tensor-parallel degree t determining the local expanded width 4h/t.
(b · s, 4h/t) × (4h/t, h) → (b · s, h)
The notation again gives the operand dimensions and the result of their matrix product. The number of rows is b · s. The expanded width on one device, 4h/t, is now the shared inner dimension. The output has h columns and can feed the next layer at the original hidden width. Both projections change when the hidden width or partitioning changes, which is why the efficiency of the feed-forward block deserves its own measurements.
The stack ends with a projection into the vocabulary dimension. For each position it produces scores, called logits, over vocabulary entries. Those scores are used in the cross-entropy loss, which evaluates the prediction against the target token. The presence of v in the last projection gives vocabulary size a performance consequence separate from the way tokens are embedded at the input. The authors benchmark the output projection as a function of both v and h.
Keep parameter budget and arithmetic in view
The paper writes a parameter count for its reference architecture. It is useful when considering designs with different widths and depths, and it also makes clear why selecting a different head count can leave the budget almost unchanged.
P = 12h²L + 13hL + (v + s)h
P is the total number of parameters, L the number of transformer layers, h the hidden width, v the vocabulary size, and s the sequence length in the learned position embeddings. The squared term has the coefficient 12 and scales with depth and the square of the width. The term with coefficient 13 also scales with depth but only linearly with width. The last term groups the vocabulary and position embedding sizes. Juxtaposition denotes multiplication, the superscript ² means squaring, and the plus signs add the contributions.
P ≈ 12h²L
The approximate-equality sign shows that the paper retains the leading term when making a rough comparison. P remains the parameter count, h² the square of hidden width, and L the layer count. The approximation drops the terms that grow linearly with h for fixed values of the other dimensions. Head count a appears in neither expression. Under the paper’s assumption that the total projection width is split among heads, changing how it is split can change the kernels without changing this accounting.
The paper also gives an operation count for a forward pass in training, using the same assumptions about the head projection width. The expression describes the arithmetic of the mapped layer operations.
24bsh² + 4bs²h = 24bsh²(1 + s/(6h))
Here b is microbatch size, s is sequence length, and h is hidden width. The terms with coefficients 24 and 4 distinguish the contribution proportional to the square of hidden width from the contribution proportional to the square of sequence length. The squared symbols mark those powers. The right side factors out the first contribution, and the parenthesized expression includes the relative contribution of the second. The equality says that the two forms express the same count. This arithmetic gives a reason to track both hidden width and sequence length when judging which parts of a layer are important. The timing measurements are needed to show how the GPU handles that work.
Choose local dimensions and revisit them when the layer changes
In the standard setup, the authors recommend making v divisible by 64 and giving the GPU as large a microbatch as practical. They look for useful power-of-two divisibility in b · s, h/a, and h/t, with their stated recommendation ending at 64. A sequence length with suitable divisibility can already align the product b · s, so the same requirement need not be imposed on b by itself. The authors also require an integral b · a/t for the attention batch count and prefer a small tensor-parallel degree. When pipeline stages divide the stack of layers, they recommend distributing the layers evenly across those stages.
Their procedure uses these quantities together. Increasing width to improve a head dimension can change the parameter budget substantially. Reducing head count can achieve an alignment change without the same increase in parameters. A width that is well aligned before partitioning may yield an awkward width on each GPU. And because a layer contains several differently shaped multiplications, choosing a shape that fills GPU waves for one operation can still leave a tail in another.
Several architectural variants change the mapping. The paper contrasts the ordering of a sequential attention and MLP block with a parallel arrangement. The equations describe which representation each operation consumes.
y = x + MLP(Norm(x + Attn(Norm(x))))
The input is x and the output is y. Norm denotes normalization, Attn the attention operation, and MLP the feed-forward block. Parentheses identify the input to each operation. The inner plus adds the attention result to x before the resulting representation is normalized for the MLP in the expression. The outer plus adds the MLP result to x. The formula is the paper’s description of the dependency it wants to contrast with the parallel arrangement.
y = x + MLP(Norm(x)) + Attn(Norm(x))
The variables x and y again denote layer input and output. Norm normalizes x, and MLP and Attn act on that normalized input. The plus signs add the branch outputs to the original input. The paper attributes a practical speed benefit to fusing work into one kernel. It says the branches need not execute simultaneously for that benefit, and it keeps the matrix-sizing analysis for the branches themselves.
The authors also discuss Rotary and ALiBi positional methods. Their treatment concerns the cost of integrating positional information and the availability of custom routines for rotary computation. They leave the central sizing analysis intact for these variants. FlashAttention v2 changes the attention measurements more directly because it changes the routine used to compute attention. In that case, the authors examine width through a new sweep, while keeping their earlier treatment of the MLP.
SwiGLU changes the feed-forward mapping because it adds a learned matrix. The paper describes reducing the expanded width to keep the feed-forward parameter allocation near that of the original arrangement.
d_ff = 4h
The symbol d_ff denotes the intermediate width of the feed-forward block. The hidden width is h, and 4 is the expansion factor used for the original block.
d_ff = (8/3)h
The symbols d_ff and h retain their meanings. The fraction 8/3 is the suggested expansion factor for the gated block, with the slash indicating division. The authors treat it as a parameter-budget guide. They search around the resulting width for a dimension that is friendlier to matrix multiplication. This is the same procedure applied to a new architectural component. Identify the dimension that reaches the GPU, then evaluate nearby choices that are acceptable for the network’s design.
Use measured workloads to test the mapping
The experimental implementation is based on GPT-NeoX. The primary workloads are matrix multiplications, individual transformer operations, and transformer layers configured with different dimensions. The paper varies quantities such as width and head count and measures the resulting kernels. Its appendix also uses PyTorch’s linear function to check whether alternative arrangements of the same activation tensor lead to different performance. Finally, the authors use DeepSpeed-MII for an inference comparison on existing Pythia variants. That comparison connects the shape analysis to serving without introducing a new pretraining procedure.
Experiments and results
Hardware, software, and measures
The study uses NVIDIA V100, A100, and H100 devices as well as AMD MI250X devices. Compute came from laboratories, a supercomputing center, and cloud providers. The software differs across platforms. The V100 setup uses PyTorch 1.12.1 with CUDA 11.3. The A100 uses PyTorch 1.13.1 with CUDA 11.7, and the H100 uses PyTorch 2.1.0 with CUDA 12.2.2. The MI250X setup uses PyTorch 2.1.1 with ROCM 5.6.0. The findings therefore characterize the measured combinations of hardware and software. The backend and its choice of kernels are part of the experimental setting.
There are several distinct comparisons. The matrix benchmarks measure arithmetic throughput in teraFLOP/s while sweeping operand dimensions. The component profiles measure the share of layer latency spent in different operations. The architecture comparison uses a familiar GPT-3 shape as a baseline for alternative shapes. The inference case uses latency measurements across the Pythia suite and discusses test loss within that family. These comparisons answer different questions. A profile shows where the time went, a kernel benchmark shows how a specific operation responds to shape, and the inference results indicate how those effects can appear amid the other operations run in serving.
For the kernel and layer benchmarks, the data are workloads defined by tensor shapes. The paper describes the dimensions of the inputs and the computation performed. It supplies no named linguistic test split for those timings. The Pythia case uses the existing suite as the basis for comparisons. The paper identifies test loss as a quality measure there but gives the relationship to the family’s trend in prose, without giving a numerical loss for the two variants singled out. The headline statement about preserved accuracy likewise comes without a named accuracy benchmark and score attached to the best gain.
Isolated multiplications explain where throughput changes
The standalone GEMM sweeps show why small and large matrices can respond differently to an increase in size. The paper describes the small cases as limited by memory. As the computation becomes more arithmetic-intensive, the GPU achieves more operations per second, and a large case can instead become limited by computing capacity. This is a statement about the rate of work. A multiplication with higher arithmetic throughput can still take more time when it performs substantially more arithmetic.
The sweeps also show local declines in throughput as the matrix becomes larger. In the paper’s analysis, some sizes require another wave of blocks with little useful work assigned to it. Once that wave fills in, utilization improves again. At larger sizes, the PyTorch backend can choose a different tile shape that reduces some of the visible fluctuations. The important result is the coexistence of the broad improvement with size and the abrupt reversals at scheduling boundaries. The broad curve alone would miss the behaviour that makes nearby architectures worth comparing.
The batched matrix benchmarks have a similar broad increase in throughput with size and arithmetic intensity. The authors note that the same scheduling mechanism can apply to batched products, but wave quantization was absent from the particular standalone BMM sizes and platforms they discuss there. In the attention-specific sweeps, they do observe clear peaks and troughs for attention over values. These findings refer to different workloads. The generic batched benchmark shows that batching does not guarantee a visible wave effect, while the attention sweep shows a case where the effect appears.
Layer profiles identify where better kernels matter most
The component breakdown measures one transformer layer across sizes. The paper reports that GEMMs account for 68.3% of the latency for the medium-size case and 94.9% for the large-size case. These are shares of latency within the profiled workloads. The comparison shows how much of the layer’s execution time a matrix-focused investigation covers at each size.
GEMM share of single-layer latency by transformer size in the component-profile workloads
Matrix multiplication accounts for a larger share of layer latency in the large setting.
The numbers
| System or setting | share of layer latency % |
|---|---|
| Medium transformer | 68.3 |
| Large transformer (this paper) | 94.9 |
A higher share in this comparison identifies a layer whose latency is more concentrated in GEMMs. The underlying latency can differ across settings. The profile also shows which GEMMs matter most within the large setting. The large query, key, and value projection and the MLP are prominent, while the attention-over-value product accounts for a relatively small part of latency. A change that makes the latter product much faster can therefore have a smaller effect on the whole layer than a more modest improvement to a dominant projection.
This helps explain the authors’ choice to report operation-specific comparisons. The attention score and attention-over-value products both depend on the width of a head, so they may benefit from the same alignment decision. The MLP has different input and expanded widths and can respond differently. Running a single timing for the whole layer can establish overall speed, but the decomposition is what connects that speed to a design choice.
The reused GPT-3 shape and nearby alternatives
The GPT-3 2.7B shape is the paper’s main example of an architecture copied across multiple projects. The baseline described in the text has hidden width 2560 and 32 attention heads. Its head width is 80, which misses the multiple of 64 targeted in the A100 analysis. The authors describe two ways to change the alignment. Raising the hidden width to 4096 would take the comparison to a 6.7 billion parameter architecture. Changing the head count to 20 is an alternative that avoids increasing the hidden width.
The authors report a 1.18× speed-up for reshaping this architecture. The comparison is presented in the figure on transformer single-layer throughput. That figure also labels alternatives C1 and C2 with the same hidden width of 2560 and head counts of 64 and 40, respectively. The caption and the worked explanation therefore discuss different candidate counts. The paper’s prose gives the speed-up and the alignment reasoning, while the caption identifies designs in the figure. The headline speed-up can be reported without assigning it a specific bar value that the prose does not state.
The paper’s overall conclusion gives an upper reported gain of 38.9% in GPU throughput with accuracy maintained. Its abstract expresses the headline as up to 39% higher throughput for efficiently shaped architectures at similar parameter counts. The architecture example with the 1.18× speed-up is a separate, specifically described result. The larger headline establishes the upper extent of the authors’ stated findings. The single-layer comparison gives the reader a concrete configuration and baseline for understanding one of the gains.
Inference and a hardware comparison
The inference case study measures Pythia with DeepSpeed-MII. The paper singles out Pythia-1B as more efficient than Pythia-410M in inference, despite the larger parameter count in its name. It describes the larger variant as having fewer heads and layers and a wider hidden representation. The authors also report higher training throughput for that variant and describe its test loss as consistent with the trend across the suite. The reported comparison is between existing architectures, with several dimensions changing at once.
The inference result adds a different kind of evidence from the layer microbenchmarks. The same classes of forward operations are relevant in serving, and architecture effects are still visible in a serving system. At the same time, the result is reported as a family comparison. The largest claimed speed gain in the paper cannot be assigned to this Pythia comparison, and the prose does not give latency values for the two highlighted variants.
The discussion also considers whether representative matrix kernels can help benchmark hardware. The paper cites a 3:1 BERT benchmark performance ratio between H100- and A100-based systems and says the direction and scale agree with the authors’ kernel observations for those devices. The ratio refers to the BERT benchmark comparison. The authors use the agreement as partial evidence that relatively quick kernel measurements can inform hardware evaluations for transformer workloads. Their case rests on the large share of time attributable to these operations and on whether the kernel workload represents the architecture that will actually run.
What the ablations show
Head width helps explain performance within attention
The most informative attention sweeps separate hidden width from the width of an individual head. In the conventional attention calculation, head width is the dimension h/a. The A100 plots group shapes by the largest power of two dividing that dimension. The authors report better throughput as divisibility improves up to a head width of 64 in that analysis. They see the pattern in both the score product and the product that combines attention weights with values. The shared dimension explains why a single architectural change can affect both operations.
A related comparison changes the head count at a given hidden width. Reducing the count makes the individual matrices wider and decreases the number of matrices grouped in the batch. In the memory-bound regimes the authors discuss, the larger components make the operation more efficient. This is distinct from crossing an alignment boundary, even when both effects occur together. A change can improve the fit to Tensor Cores while also changing the balance between matrix size and batch count. The paper’s sweeps support both mechanisms and illustrate why the net change is worth measuring.
The fixed-head-width sweeps give a complementary view. The paper shows A100 attention score and attention-over-value throughput with h/a held at 64. Holding this quotient steady controls one source of variability, the divisibility of head width. The sweeps can still change the overall amount and arrangement of work. In attention over values, the curves exhibit recurring peaks and valleys, and the authors relate their spacing to how quickly the workload grows at different head counts. The alignment condition can already be satisfied while wave effects still matter.
The appendix extends these comparisons across many head counts. That makes it possible to see whether the divisibility effect recurs under changes in architecture. The result is most useful as a description of the ordinary attention products the authors measured. A lower head count has representational consequences as well as timing consequences, and the sweeps measure kernel throughput. The paper explicitly raises the possibility that reducing heads can hurt accuracy.
Wider linear layers and vocabulary alignment
The authors sweep hidden width for individual projections using 128 attention heads in the appendix benchmarks. Across many of those projections, throughput generally rises as width increases and the kernel has a larger matrix to process. The MLP sweeps exhibit the tendency towards saturation that the authors refer to in their design discussion. Attention operations whose shape contains h/a continue to show the influence of divisibility. A hidden-width sweep therefore mixes a broad change in work size with local alignment changes in the kernels that use a per-head dimension.
The vocabulary projection provides a controlled check of a different dimension. The paper’s logit-layer benchmark varies hidden width and vocabulary size and reports its best performance when both are multiples of 64. This links the recommendation to pad the vocabulary to a specific operation. In this experiment, the final projection benefits from the padded dimension because that is a width of the matrix workload. The timing result concerns the projection. It gives no direct evidence about the quality of a different inventory of tokens.
The appendix also tests how the way a linear layer is called affects the measurements. The authors compare inputs with shape (2048, 4, n), (4, 2048, n), and (8192, n), in each case with a multiplication against a matrix of shape (n, 3n). Here n is the width they vary, and the last dimension of the second matrix represents the combined projection width. The first two inputs put the batched axes in a different order, while the third uses the flattened form. The authors find the same speed for the tested arrangements. This supports using b · s as the row dimension when analyzing these linear operations under the tested implementation.
Tensor-parallel degree also appears in a dedicated comparison of the query, key, and value projection. Splitting this projection changes the local output width. That is the operational reason the authors’ dimension rules refer to the share of the network on one GPU. A benchmark at the full-layer width would leave out a shape change that the distributed implementation introduces before invoking the kernel.
FlashAttention changes which explanation applies
For FlashAttention v2, the authors hold the head count at 128 and sweep hidden width on A100. They describe the resulting trend using a roofline model, which relates achievable performance to the amount of work performed for the data moved, up to the hardware’s compute limit. Under this kernel and sweep, their advice for attention reduces to using a large hidden width where possible. The recommendations for the separate feed-forward block remain in place.
This comparison tests the reach of the conventional attention analysis. With separate score and value products, the dimensions of each batched multiplication are central to the explanation. With FlashAttention v2, the measured operation has a different implementation, and the authors state a simpler sizing conclusion for attention. The same architectural parameter can still matter, but the evidence for why it matters comes from the routine that now executes the operation.
The layer profile also informs the authors’ treatment of this alternative. They regard the attention change as particularly relevant when those attention products occupy a larger portion of the runtime. For larger networks in their profile, the expensive projections offer more scope for improving the whole layer. The combination of a kernel sweep and a component breakdown distinguishes a faster implementation of a familiar operation from an optimization that matters in the total runtime.
The case studies vary the partition and the feed-forward width
The discussion of machines with 6 GPUs per node illustrates how a successful shape can run into trouble after changing the partition. On Summit, the paper considers a tensor-parallel degree of 6 when matching the degree to a node. A width common on an 8-GPU node can become incompatible with the partition or yield a poorly aligned h/t. The authors also raise the reverse problem. A design shaped for pretraining on such a node may later be used on a node with 2, 4, or 8 GPUs. The same hidden width then faces a different set of per-device dimensions. RedPajama 3B and 7B provide the examples of architectures trained on Summit that motivate the discussion.
This is a case analysis of competing partition choices instead of a controlled comparison of all those deployments. It shows how to locate the possible problem before expecting a result from one system to carry over to another. The combination of divisibility and alignment can be checked at each intended tensor-parallel degree. Runtime still depends on the resulting kernels and, for distributed training, on the communication system that accompanies the partition.
The SwiGLU example varies a different dimension. The authors report that Llama-2’s 7B variant uses an intermediate width of 11,008 with hidden width 4096, giving the reported expansion coefficient of 2.6875. The paper gives 2.667 as a decimal representation of the suggested coefficient. Its 70B example uses intermediate width 28,672 and hidden width 8192, with an expansion coefficient of 3.5. These examples establish that the implemented widths can depart from the suggested ratio, with the larger example allocating more parameters to the MLP than the paper’s comparison with a typical ungated block would suggest.
In a brute-force search around the intermediate width of the 7B variant, the authors find that the chosen size is among the best-performing values in that range. This supports searching over intermediate widths once hidden width is fixed. It does not isolate an effect of the activation function on output quality. The measured target is the performance of the resulting multiplications. The example shows that a width selected near a parameter-budget target can exploit alignment without being fixed at the value obtained from the suggested coefficient.
Limitations
Limits the authors state
The paper concentrates on the operations executed on an individual GPU. It accounts for tensor parallelism when it changes local matrix dimensions, and it leaves a fuller treatment of pipeline and sequence parallelism to future work. The authors point to the speed and bandwidth of inter-node connections as factors in deciding whether pipeline parallelism helps. Their layer-balance recommendation addresses the assignment of layers to stages. The best stage layout for a particular distributed training job also depends on effects outside the per-kernel analysis.
The detailed mapping is for a decoder-only architecture. The authors expect much of it to apply to an encoder-only design, but they largely set aside encoder–decoder architectures because of the transition between the encoder and decoder. Earlier encoder work such as RoBERTa helps locate that scope. The paper’s dimension-by-dimension treatment is centered on the operations of the decoder.
Inference transfer is conditional in the paper’s own account. The authors give their strongest expectation to training and serving on the same GPU type and suggest the guidance can still help when the devices differ. Their case study about node configuration shows how architecture portability can conflict with an efficient pretraining partition. Their attention measurements also show that a software change can alter the relevant performance rule even when the architecture and device are held within the same general family.
The authors explicitly flag the quality risk of reducing head count. Head count can change matrix alignment at the same width, which makes it an appealing adjustment for runtime. It also alters how the network partitions attention. The paper’s advice therefore includes other routes, such as using FlashAttention v2 for smaller designs or improving the width of the large projections where their throughput is still rising. The latency breakdown gives a reason to choose among these options according to which work occupies the layer.
The treatment of wave quantization has a practical limit as well. The paper gives a condition for filling waves under a chosen tile shape, but it argues that a single transformer configuration cannot satisfy every illustrated preferred alignment and wave condition under its assumed efficient tiling. The software may also choose different tile shapes across operations. The modular condition helps explain observed dips and identify possible problems. It gives no guarantee that imposing one common hidden width will remove tail waves from the layer.
Limits evident from the comparisons
The microbenchmarks establish how the measured kernels respond to particular input shapes. A timing improvement for a single layer is evidence about computation repeated in the network. A complete pretraining run also includes work beyond that layer, including distributed execution where applicable. The size of an end-to-end gain depends on which work is accelerated and how much of the original runtime it occupies. The paper provides component profiles, a layer comparison, and an inference case, so the evidence is most precise at the levels actually measured.
The accuracy statement needs to be read at the level of detail supplied. The authors report that their largest throughput gain preserves accuracy, and they give the example of Pythia-1B following the existing suite’s test-loss trend. They do not attach a named evaluation dataset, split, or numerical score to the 38.9% headline. The test-loss observation in the Pythia case also covers a change in more than one architectural dimension. It supports compatibility between an efficient shape and the reported quality trend for that variant. It leaves open how a specific head-count change would affect quality under a matched training and evaluation procedure.
The Pythia comparison has similar limits as a runtime attribution. The two named variants differ in width, depth, and head count. That makes them informative examples of real architectures whose parameter counts do not predict runtime simply. It leaves the contribution of each dimension to be inferred from the more controlled kernel work. The inference system demonstrates that shape can matter in that setting. The comparison by itself cannot give a measured effect of changing head count while holding width and depth fixed.
The accelerator comparisons combine differences in hardware with differences in software versions. This is useful if the unit of interest is an actual hardware and software setup. It makes an exact attribution to the GPU more difficult. The authors themselves show that backend tile selection affects the measured curve, which is a reason to be careful when carrying numerical alignment or scheduling advice to a different stack. The paper’s detailed Tensor Core discussion is framed around NVIDIA devices and FP16. The inclusion of MI250X broadens the experimental hardware, while the exact NVIDIA rules remain grounded in the devices and precision for which they are described.
Finally, the qualitative agreement between representative GEMMs and the cited BERT benchmark supplies evidence for a proxy. Different transformer implementations can spend different shares of execution time in projections or attention, and their kernels can respond differently to width and partitioning. The paper’s own profiles explain both the promise and the limit of this approach. Where matrix products dominate the workload, their measurements cover a large portion of the work. Where that share is smaller or different products dominate, the choice of representative kernel matters more.
What came after
Two later papers cite the study and approach the cost of transformers from different parts of the computation. One concerns a bidirectional encoder designed for efficient use during adaptation and inference. The other concerns the algorithms used during generation after training. Their topics make the relationship to the co-design paper visible at two different levels. The citation identifies that relationship in the literature, while the descriptions establish the scope of the later work.
The encoder paper presents a modern bidirectional design aimed at speed, memory efficiency, and long-context use in both inference and adaptation to downstream tasks. The connection is architectural. Anthony and colleagues begin with a decoder and suggest that much of the matrix-shape reasoning can extend to encoders. A study that puts runtime and memory among the goals of encoder design addresses part of that broader question. Its bidirectional architecture also has its own workload to account for, so the relationship can be described without assuming it uses the same head counts, tile choices, or measured gains. The citing work is Smarter, Better, Faster, Longer.
The generation paper concerns inference-time algorithms. Its scope places attention on the computation selected when generating output, whereas the co-design study examines the cost of executing the operations that a given architecture induces. A generation procedure and the shape of its underlying forward operations are both relevant to serving, but they describe different decisions. The citation links the two areas. The description of the later work establishes its focus on generation algorithms and leaves the use of any particular alignment rule or benchmark unspecified. The citing work is From Decoding to Meta-Generation.
Cite
Cite as Quentin Anthony, Jacob Hatef, Deepak Narayanan, Stella Biderman, Stas Bekman, Junqi Yin, Aamir Shafi, Hari Subramoni and Dhabaleswar Panda. 2024. The Case for Co-Designing Model Architectures with Hardware. arXiv:2401.14489.
@misc{anthony2024case,
title = {{The Case for Co-Designing Model Architectures with Hardware}},
author = {Quentin Anthony, Jacob Hatef, Deepak Narayanan, Stella Biderman, Stas Bekman, Junqi Yin, Aamir Shafi, Hari Subramoni and Dhabaleswar Panda},
year = {2024},
doi = {10.48550/arxiv.2401.14489},
eprint = {2401.14489},
archivePrefix = {arXiv},
url = {https://doi.org/10.48550/arxiv.2401.14489}
}This page in Markdown https://md.research.elamur.ai/free/en/papers/anthony-2024-case-co-designing-model-architectures/