Elamur Research

Modular Duality in Deep Learning

Paper · 2024 · Jeremy Bernstein and Laker Newhouse

Summary

A gradient tells us how a small change to a neural network’s weights would affect its loss. To turn that information into an update, an optimizer also needs a way to judge the size of a change. Two weight matrices can have the same shape and do different jobs. An embedding matrix selects a representation for a token, while a linear layer typically transforms an activation across many input coordinates. A change spread across the matrix can have different consequences in those two settings. Bernstein and Newhouse propose modular dualization, a way to build an update rule that accounts for what each layer does and where it sits in the network.

The authors start by assigning norms to a layer’s inputs and outputs. A norm measures size, and the choices here express what should count as a small or large change in the layer’s activations. Those choices give the authors a norm for changes to the weights. Using it, they find the direction of a fixed-size weight change that best agrees with the gradient. The direction can then be reversed and scaled for descent. The procedure works differently for different layers. It normalizes individual gradient columns in an embedding and transforms the singular values of a linear-layer gradient. For a convolution, it applies the latter transformation separately to the channel matrix at each kernel position.

The network structure determines how large the updates to the individual layers can be. Layers running in parallel receive shares based on their assigned masses, which control their relative contribution to feature learning. In a sequence, the earlier layer’s share also accounts for how strongly the later layer can amplify a change to its input. The authors show that applying these rules recursively gives a direction for the whole network. For a linear layer, the resulting update brings together the dimension-dependent scaling associated with maximal update parameterization and the matrix transformation associated with Shampoo without gradient accumulation.

The paper also explains how to approximate that matrix transformation with an iteration built from matrix multiplication. A variant based on this iteration was used in a reported NanoGPT training speed record. The paper’s principal result is the derivation of update directions from layer and network geometry. The speed record illustrates one use of the matrix computation, while the effects of training with the full recursive procedure remain open.

Deep dive: Modular Duality in Deep Learning

Modular dualization turns neural network gradients into weight updates using layer-specific norms and the way layers are connected. · about 35 minutes to read

The problem and its context

A gradient describes the effect of a move

Suppose a training step begins with a loss evaluated at the current weights. Locally, increasing a weight can raise or lower that loss. The gradient collects those local responses into an object that can be paired with any proposed change to the weights. The result of that pairing is a real number, the first-order prediction of how much the loss will change. This is what makes the gradient a dual vector. The weight change itself is a primal vector, an element of the space in which the weights live.

In coordinates, both objects can look like arrays with the same dimensions. This makes it easy to multiply the gradient by a learning rate and subtract it from the current weights. The paper asks what geometry justifies that operation. Euclidean geometry supplies a familiar identification between a linear functional and a vector. A network’s loss, however, may bend more sharply along some directions than along others. The same size of move under a Euclidean norm can have very different implications for the network’s activations and for the accuracy of the first-order prediction.

The practical issue appears when an optimizer chooses a direction before choosing how far to go. A large gradient pairing is attractive for descent once its sign is reversed. It becomes less attractive if obtaining that pairing requires a weight change that strongly perturbs the layer’s outputs. To decide between candidate moves, the optimizer needs a measure of their cost. The norm supplies that measure. Changing the norm changes the set of equally costly moves and can therefore change the direction selected by the gradient.

The authors describe the distinction as a type check. In their formulation, the gradient must pass through a duality map before it is used as a weight displacement. A duality map takes a linear functional and returns a vector in the space on which that functional acts. The arrangement makes the geometric choice explicit. Calling the conversion a type check is also a proposal for software design. A training system could carry information about the intended norms and typical sizes of activations, as well as the distinction between a derivative and an update.

From individual layers to a whole architecture

The paper places this idea in an optimization tradition that includes mirror descent, natural gradient descent and steepest descent on a normed space. Its construction uses the last of these. A norm defines what counts as an equally sized update, and the gradient selects the strongest direction among candidates of that size. The authors’ problem is to construct such a norm and compute its direction for a collection of interacting layers.

In the earlier spectral descent work the paper discusses, linear layers were assigned the spectral norm. This norm measures the largest factor by which a matrix stretches a vector under Euclidean length. The earlier authors used bounds on the loss to motivate this geometry and derived a matrix operation called the #-operator. They proposed randomized sketching as a cheaper way to approximate it and considered incorporating preconditioning information of the kind used in RMSprop. Their constructions yielded wall-clock improvements for small networks, as described by Bernstein and Newhouse. The layer operation was derived for a single linear layer, and its use in simultaneous updates across layers relied on additional heuristics.

Flynn’s duality structure gradient descent addressed the full weight space. It combined layer norms through a weighted sum based on a geometric structure for neural networks. A fixed budget for a weighted sum permits tradeoffs between layers. An update can obtain the best first-order value by devoting that budget to a single layer, so simultaneous updates in Flynn’s approach required a further modification. Bernstein and Newhouse use a weighted maximum. Under that rule, each layer has a separate allowance. An all-layer update can use each allowance while respecting the constraint on the whole network.

The weighted maximum comes from earlier work by Large and colleagues on the modular norm. That work supplied rules for combining modules, controlling their sensitivity and, under further smoothness conditions, deriving bounds on the curvature of compound modules. Those rules also supported modular normalization, in which an update could be divided by its norm. Such normalization determines the length of an existing direction. Bernstein and Newhouse ask a different question about the same geometry. They seek the direction that maximizes the gradient pairing over the norm’s unit set. A norm can favor a direction quite different from a rescaled copy of the raw gradient, as the paper’s matrix examples show.

The recursive organization also reflects a broader line of work that infers properties of computations from their parts. The authors point to disciplined convex programming, where rules for combining expressions help determine convexity, and to work on automatic bounds for majorization methods. The property of interest here is the geometry of a weight update. A library supplies rules for basic layers, and the way those layers are connected tells the optimizer how to combine the rules. This is especially handy when similar parameter arrays play different roles. The shape of a matrix tells the optimizer how it is stored, while the semantics of the layer explain which directions of change matter.

The method, step by step

Separate the direction from the step length

Modular dualization starts with a layer’s forward operation, the calculation that produces activations from inputs and weights. The authors choose measures of size for the layer’s activations and then build a measure of size for its weight changes. They derive a duality map for that measure. Once there is a map for each basic layer, the architecture specifies how to rescale and assemble their outputs. Computing the gradient still uses differentiation through the forward calculation. The new procedure begins with the gradient that differentiation returns.

Constructing an update with modular dualization

The steps in order.

Constructing an update with modular dualizationStep 1: Choose input and output norms for each layer1. Choose input and output norms for each layerStep 2: Define weight norms and input sensitivities2. Define weight norms and input sensitivitiesStep 3: Derive duality maps for the basic layers3. Derive duality maps for the basic layersStep 4: Differentiate the loss with respect to the weights4. Differentiate the loss with respect to the weightsStep 5: Apply each map to its layer gradient5. Apply each map to its layer gradientStep 6: Combine directions using the architecture’s recursive rules6. Combine directions using the architecture’s recursive rulesStep 7: Scale the assembled direction for descent7. Scale the assembled direction for descent

Begin at a particular weight setting and consider a trial displacement. The first-order description used in the paper is the Taylor expansion.

L(w + Δw) = L(w) + (∇w L(w))ᵀ Δw + higher-order terms

Here L is the loss, w is the current weight vector and Δw is a change in that vector. ∇w L(w) is the gradient with respect to the weights at the current setting. The superscript ᵀ denotes transpose so that the product with Δw represents the pairing between the gradient and the change. The higher-order terms account for the part of the loss change beyond the linear prediction.

The first-order expression alone favors taking a large step in any direction that reduces the predicted loss. The paper considers an approximation that penalizes the size of the displacement. A norm can give that penalty different shapes, so the length of a move reflects the intended geometry of the weights.

L(w + Δw) ≈ L(w) + gᵀ Δw + (λ / 2) ‖Δw‖²

Here g abbreviates the weight gradient, λ is a positive sharpness parameter and ‖Δw‖ is the size of the displacement in the chosen norm. The approximation sign indicates that the squared-norm term stands in for the higher-order behavior. The coefficient scales the penalty. The norm describes the relative costs of directions, while sharpness sets the overall cost of displacement in that geometry.

For a fixed-size move, the gradient pairing can be maximized over the unit sphere of the norm. The value and the direction answer different questions. The value measures the gradient’s strength in the selected geometry. The direction gives a candidate displacement to reverse for descent.

‖g‖⋆ = max{gᵀ t : t ∈ ℝⁿ, ‖t‖ = 1}

Here ‖g‖⋆ is the dual norm of g. The variable t is a candidate displacement and ℝⁿ is the real weight space with n coordinates. The condition ‖t‖ = 1 compares candidates with the same primal norm, and the max returns the largest value attained by their pairings with g.

D(g) ∈ arg max{gᵀ t : t ∈ ℝⁿ, ‖t‖ = 1}

Here D is the norm-based duality map. The expression arg max denotes the set of maximizing displacements. Membership in that set means that when several directions attain the same value, the map may select any of them. For matrix or tensor weights, the pairing is defined by flattening both arrays and taking the dot product of corresponding entries. This defines how the gradient evaluates a displacement while preserving the option of a matrix- or tensor-specific norm for measuring that displacement.

In the penalized approximation, symmetry of the norm lets the optimizer use the negative of the chosen maximizing direction. What remains is to minimize over the distance traveled along that direction.

Δw⋆ = −(‖g‖⋆ / λ) D(g)

The symbol Δw⋆ denotes a minimizing weight displacement for the quadratic-penalty problem with positive λ. The negative sign reverses the maximizing direction D(g), and the ratio of the dual norm to the sharpness sets the distance. The formula distinguishes calculating the direction from calculating the step length. A practical optimizer may take the direction as a component and supply its own learning-rate rule. The paper develops the direction in detail and does not prescribe a schedule for every training setting.

A Euclidean example shows how this can reproduce the familiar update. With a non-zero gradient, the maximizing direction is the gradient divided by its Euclidean length. Its dual norm is that same length, so the length in the step formula cancels the normalization of the direction. The paper also gives the infinity norm as an example. When the size of a move is its largest absolute coordinate, each coordinate can use its own allowance. The maximizing direction takes the sign of the gradient separately in each entry, with zero a permissible choice for a zero entry. These examples differ because their norms make different collections of simultaneous coordinate changes affordable. The same logic reappears at the scale of whole layers.

Give each module a geometry

The paper’s abstract module carries a forward function, a mass, a sensitivity and a norm on the weights. The forward function specifies the calculation. The mass is a non-negative hyper-parameter that governs how much feature learning the module is allowed to contribute inside a larger module. Sensitivity controls how changes to the input can appear at the output. The weight norm measures a change in the module’s parameters. Mass allocates room for a change and sensitivity controls its propagation, so the two play different roles even when both influence the eventual update size.

The paper calls a module well-normed when its derivative satisfies bounds with respect to weight changes and input changes. The first bound measures how much an infinitesimal weight move can affect the output while the input is fixed.

‖(∇w F(w, x)) Δw‖ᵧ ≤ N(Δw)

Here F is the module’s forward function, w is its weight setting and x is its input. The derivative ∇w F(w, x) acts on a weight perturbation Δw to give a first-order output perturbation. The notation ‖·‖ᵧ denotes the norm on the output space, and N is the module’s weight norm. The inequality normalizes the bound on the effect of a weight change to the size of that change under N.

‖(∇x F(w, x)) Δx‖ᵧ ≤ s ‖Δx‖ₓ

The derivative ∇x F(w, x) acts on a perturbation Δx of the input at fixed weights. The notation ‖·‖ₓ is the input norm, and s is the module’s assigned sensitivity. This bound measures how strongly an incoming perturbation can be amplified. In these formulas applying a derivative to a vector or tensor perturbation amounts to summing over the matching indices.

For the paper’s trainable layer examples, the bounds hold in the stated unit-ball regime for activations and weights. This matters even for a plain matrix multiplication. A perturbation to the weight matrix acts on the current input, so the bound on its effect depends on the input’s size. Likewise, the current weight matrix acts on input perturbations, so the bound for that operation depends on the size of the weights. Normalizing the geometry gives each of these dependencies a common scale.

The standard tool for defining the weight norm is an induced operator norm. It measures the largest gain achievable by a matrix when the sizes of its input and output are measured in specified ways.

‖A‖α→β = max{‖Ax‖β / ‖x‖α : x ∈ ℝᵈⁱⁿ, x ≠ 0}

Here A is a matrix mapping from the input vector space into the output space. The variable x ranges over non-zero inputs, and dᵢₙ, written in the space’s superscript as dⁱⁿ, is the input dimension. The symbols α and β identify the input and output norms. The ratio measures the gain for an individual input, and α→β identifies the ordering of the two norms. Excluding zero keeps the denominator defined. The operator norm makes every direction of input relevant to sizing the matrix, with the choice of input norm determining which directions count as equally large.

Once the weight norm is set, the duality map is a separate calculation. It takes a gradient and asks which matrix or tensor of the permitted size would produce the strongest pairing. This separation is important because the matrix defining the forward operation and the gradient of that matrix occupy different roles. The first may be constrained so that its action on activations stays bounded. The second supplies the linear objective for choosing the next displacement.

Linear layers measure change across activation coordinates

The Linear module multiplies an input vector by a weight matrix. Its input and output are both treated as dense activation vectors with a typical root mean square, or RMS, size near the unit scale. RMS measures the size of entries without making a vector larger merely because it contains more entries of a similar magnitude.

‖v‖RMS = ‖v‖₂ / √d

Here v is a vector with d entries. The notation ‖v‖₂ is its Euclidean length, the square root of the sum of squared entries. Dividing by the square root of the dimension gives the root mean square of the entries.

The RMS-to-RMS norm measures the largest gain between vectors sized this way. Because both norms are scaled versions of Euclidean length, it can be written using the spectral norm of the same matrix.

‖W‖RMS→RMS = √(dᵢₙ / dₒᵤₜ) ‖W‖spectral

Here W is the Linear weight matrix, dᵢₙ is its input dimension and dₒᵤₜ is its output dimension. The spectral norm ‖W‖spectral is the largest singular value of W, or its largest gain measured with Euclidean lengths. The square-root factor comes from measuring the output per coordinate and dividing by an input size measured per coordinate. It matters when the two widths differ.

To see what the corresponding update does, consider a singular value decomposition of the layer gradient. A singular value decomposition separates a matrix into input directions, output directions and a set of non-negative gains connecting them.

G = U Σ Vᵀ

Here G is the matrix of derivatives with respect to the Linear weights. The columns of V give right singular directions in the input space, and the columns of U give the corresponding left singular directions in the output space. The diagonal matrix Σ contains the singular values, and Vᵀ is the transpose of V. In the compact form on the non-zero singular subspaces, the product uses the directions corresponding to positive singular values.

DLinear(G) = √(dₒᵤₜ / dᵢₙ) U Vᵀ

Here DLinear is Linear’s duality map. The matrices U and V come from the gradient decomposition. Their product acts along the supported singular directions with unit gain before scaling. The square root of the output-to-input dimension ratio turns that product into a direction in the RMS-to-RMS unit geometry. The map keeps the gradient’s pairing of input and output directions and changes their relative gains, giving the active singular directions the same magnitude.

The maximization helps explain the transformation. In the singular bases of the gradient, each singular value weights the contribution from its associated pair of directions. The constraint on the largest gain of a trial matrix limits how much it can contribute along any such pair. A matrix can reach the allowed gain on all of the supported pairs at once because their directions are orthogonal. Thus smaller positive singular values influence which directions appear in the result, even though their original magnitudes disappear from it. Simply scaling the original gradient would keep its original relative magnitudes and would leave some of the available gain unused.

The dimension factor and the singular-direction operation account for the paper’s connection to earlier training methods. The factor implements the spectral update scaling associated with maximal update parameterization, or µP, and choosing the initial weights at unit operator norm recovers the corresponding initialization scaling. The product of singular direction matrices is the transformation the authors identify with Shampoo without accumulation. One part of the rule determines how the update should scale when the input and output dimensions change. The other selects a matrix direction from the observed gradient. Both follow from the same norm.

Embed layers measure change in the selected column

An Embed module also multiplies a weight matrix by an input vector. In this case, the intended input is one-hot, with a single active coordinate selecting a column of the matrix. An output may still be a dense vector of typical unit RMS size. The authors therefore keep the RMS output norm and use the ℓ₁ norm, the sum of absolute coordinate values, for the input. It gives the input a natural measure of total weight assigned to columns.

‖W‖ℓ₁→RMS = maxⱼ ‖colⱼ(W)‖RMS

Here W is the embedding matrix, j indexes its input columns and colⱼ(W) is the column selected by that index. The maximum over column RMS lengths is the induced norm. For any input with bounded ℓ₁ norm, the output is a linear combination of columns with a bounded sum of absolute coefficients. Its size is therefore bounded by the largest column size. Selecting that column with a one-hot input attains the bound.

A trial change to an embedding matrix satisfies a bound on its largest column if every column stays within the individual allowance. The contribution of each gradient column to the pairing can consequently be maximized on its own.

colⱼ(DEmbed(G)) = colⱼ(G) / ‖colⱼ(G)‖RMS

Here DEmbed is the Embed duality map, G is the embedding weight gradient and j is any index with a non-zero gradient column. The denominator is the RMS size of that column, so its image has unit RMS size. A zero gradient column contributes zero to the pairing regardless of its choice within the allowance. It can be given a zero update without weakening the maximization. When the entire gradient is zero, there is no first-order preference and a zero weight step is appropriate.

This example shows why a matrix shape alone cannot determine the update geometry. In the Linear case, a dense input can combine the effects of many columns, and the operator norm bounds the maximum amplification of that combination. In Embed, a one-hot input can directly realize the largest column size, and the geometry gives all columns their own allowances. Column normalization and singular-value transformation are therefore answers to different questions, even though the forward expressions can both be written as a matrix times a vector.

Conv2D measures channel changes at each location

For Conv2D, the paper considers a square convolution kernel. At each kernel position, the weights include a matrix sending input channels to output channels. The convolution applies channel matrices to neighboring input locations and sums the contributions. To describe the size of an activation array, the authors measure the RMS of the channels at each location and use the largest of those values. This is a bound on the intensity of a channel vector anywhere in the array.

‖x‖ₓ = max_{p,q} ‖x[p,q,:]‖RMS

Here x is an input activation array, p and q index its spatial positions and the colon inside the brackets selects all the channels at that position. The maximum ranges over the input’s spatial extent. The same definition on the output array gives its output norm, using the output positions and channels. This geometry lets the convolution bound track a large local response even if the rest of the array has small values.

NConv(W) = k² max_{i,j} ‖W[:,:,i,j]‖RMS→RMS

Here NConv is the Conv2D weight norm, W is its kernel tensor and k is the side length of the square kernel. The indices i and j specify an offset in that kernel. The colons retain all output and input channels, so W[:,:,i,j] is the channel matrix at that offset. The factor k² counts the matrices whose contributions can add at one output position. Multiplying the largest slice norm by that count bounds the sum of the contributions.

The maximum again separates the optimization. A slice can use its own allowance, which is the reciprocal of the number of kernel positions before applying its Linear width factor.

DConv(G)[:,:,i,j] = (1 / k²) √(dₒᵤₜ / dᵢₙ) Uᵢⱼ Vᵢⱼᵀ

Here DConv is the map on the convolution gradient tensor G. The matrices Uᵢⱼ and Vᵢⱼ contain the left and right singular directions of its channel matrix at offset i,j. The dimensions dᵢₙ and dₒᵤₜ count input and output channels. The scale 1 / k² accounts for the slice allowance, while the square-root factor comes from converting the slice’s Euclidean geometry to RMS geometry. The resulting tensor is assembled from these separately transformed slices.

The distinction between the two maxima in this construction matters. The spatial maximum measures activations over positions in an image or feature array. The kernel maximum measures weight matrices over offsets of a filter. Using the first allows the effects of an individual channel matrix to be bounded at each output location. Using the second provides a common bound on all the terms that can contribute there. The duality map separates across kernel offsets because the weight constraint has a maximum over slices.

The authors also include bonds, modules with no trainable weights. A ReLU nonlinearity is their example. Its weight space contains only the zero vector, so the weight norm and the duality map both send that vector to zero. A bond can still affect the transmission of perturbations through the network. This is the role of its input sensitivity in a compound module. The recursive construction can thus account for an operation between two trainable layers without asking for a gradient update to that operation.

Combine module rules according to the network

When two modules run in sequence, the output of the first is the input of the second. A change to the first module’s weights perturbs the final output by way of the second module’s input. A change to the second module’s weights acts directly on the final output. The norms of these weight changes enter the compound geometry with different coefficients. For modules of positive mass and positive downstream sensitivity, the composition norm has the following form.

Nseq(w₁, w₂) = max{(m / m₁) s₂ N₁(w₁), (m / m₂) N₂(w₂)}

Here Nseq is the compound weight norm, w₁ and w₂ are the two weight-space arguments, and N₁ and N₂ are the respective child norms. The masses are m₁ and m₂, with m their sum. The factor s₂ is the sensitivity of the downstream module to an input perturbation. The compound sensitivity is the product of the two child sensitivities, because an input change to the sequence passes through both modules. The mass fractions specify the part of the resulting perturbation budget attributed to each child.

Consider what it means for this maximum to be at most unit size. The upstream weight change must satisfy a limit determined by its mass share and the downstream sensitivity. The downstream weight change must satisfy a limit determined by its mass share alone. The limits can be enforced separately. The gradient pairing is also a sum of contributions from the two weight blocks, so each block can choose its own maximizing direction and scale it to fit.

Dseq(g₁, g₂) = ((m₁ / m) D₁(g₁) / s₂, (m₂ / m) D₂(g₂))

Here Dseq is the map for the sequence, g₁ and g₂ are the gradients in its two weight blocks and D₁ and D₂ are the child maps. The other symbols retain their meanings from the norm formula. A larger downstream sensitivity reduces the upstream allocation because a smaller change can already have the allowed effect on the final output. Each child’s input to its duality map is its own block of the gradient of the loss. Differentiation through the downstream module supplies the upstream gradient. The separate factor involving s₂ sets the upstream allowance in the norm.

For module concatenation, the children take the same input and return a pair of outputs. Each child has a direct path to its own part of the returned pair. The paper uses the sum of their sensitivities for the tuple module, and the weight norm places the child mass shares in the two allowances without a downstream sensitivity factor.

Ntuple(w₁, w₂) = max{(m / m₁) N₁(w₁), (m / m₂) N₂(w₂)}

Here Ntuple is the norm of the module returning the pair. The arguments w₁,w₂ belong to the children’s weight spaces, the functions N₁,N₂ are the corresponding norms and m is the sum of m₁,m₂. The maximum ensures each branch satisfies its own weighted bound. Maximizing the gradient pairing again separates into the two weight blocks.

Dtuple(g₁, g₂) = ((m₁ / m) D₁(g₁), (m₂ / m) D₂(g₂))

Here Dtuple is the map for the paired outputs, g₁,g₂ are the two gradient blocks and D₁,D₂ are the same kinds of child maps as in the sequential case. Each positive-mass child receives its share of the compound direction. In the paper’s norm definitions, a child of zero mass is handled by setting its term in the maximum to zero. The displayed positive-mass formulas describe the active blocks. Where a coefficient vanishes or the total mass is zero, the divisions require care. A weightless bond has the separate zero-space rule.

Since a compound module has the same kind of attributes as a basic module, it can serve as a child of another compound module. If a parallel block feeds a downstream sequence, the block has a combined mass, norm and sensitivity that the sequential rule can use. Its own allocation is then passed to its children through the concatenation rule. Repeating this decomposition is how the authors turn layer formulas into a direction for an architecture. The same argument applies whenever a compound weight constraint is a maximum of independent weighted bounds. There is no need to solve a new coupled maximization over all the parameters after deriving the child maps.

Compute the matrix maps with multiplication

Embed’s column normalization uses vector norms. Linear and each Conv2D slice need the product of singular-direction matrices. An explicit singular value decomposition gives this product, but it also computes the singular values that the final map discards. For a training step repeated on many matrices, the paper looks for cheaper approximations.

One option is sketching, which uses randomized low-rank approximations. It can capture dominant singular directions economically. The authors point out a tension with the goal here. A small positive singular value can be of little consequence when approximating the original gradient, yet the exact duality map assigns its associated direction the same gain as a direction with a large singular value. A sketch that is good at reproducing the matrix in its original geometry may lose directions that matter to the transformed matrix.

Another option uses inverse roots of Gram matrices, which are products of a matrix and its transpose. On a side where the Gram matrix is invertible, the identity can be expressed as follows.

UVᵀ = (GGᵀ)⁻¹ᐟ² G   or   UVᵀ = G (GᵀG)⁻¹ᐟ²

Here G is the gradient matrix, U and V are its singular direction matrices, and ᵀ denotes transpose. The exponent −1/2 denotes an inverse square root. For a rectangular full-rank matrix, the ordinary inverse formula applies on the side with the nonsingular Gram matrix. The operation rescales singular directions by the reciprocal of their singular values and cancels the original gains. The paper also gives a form with inverse fourth roots on both sides.

UVᵀ = (GGᵀ)⁻¹ᐟ⁴ G (GᵀG)⁻¹ᐟ⁴

Here −1/4 denotes an inverse fourth root. When a Gram matrix has null directions, the inverse-root expression needs to be understood on its supported subspace to describe the same product. Each factor removes part of the original gain. The authors discuss iterative methods for such roots and flag the numerical difficulty of working with inverses when some singular values are very small.

The third option is the rectangular Newton–Schulz iteration. The authors introduce it by adapting an iteration for the matrix sign function, a transformation related to replacing scalar magnitudes with unit magnitudes. They also recognize earlier work on the rectangular iteration. The process starts by dividing the gradient by its spectral norm or its Frobenius norm. The latter measures the Euclidean length of its flattened entries and is also enough to bound the starting singular values. A zero gradient can be handled before normalization.

X₀ = G / ‖G‖spectral   or   X₀ = G / ‖G‖F

Here X₀ is the starting matrix and G is the non-zero gradient matrix. The two denominators are its spectral and Frobenius norms, respectively. In either case, dividing by a scalar preserves the singular directions. The initialization brings the singular values into a range where the iteration can move them toward the desired values.

Xₜ₊₁ = (3 / 2) Xₜ − (1 / 2) Xₜ Xₜᵀ Xₜ

Here Xₜ is the current matrix at iteration index t, and Xₜ₊₁ is the next. The transposed factor makes the product well-defined for a rectangular matrix and leaves the result with the same shape as Xₜ. The coefficients 3 / 2 and 1 / 2 give the linear and cubic terms. To see the effect of the equation, substitute a singular value decomposition for Xₜ. Orthogonality of the singular vectors leaves the input and output directions in place and applies the following scalar function to each singular value within the starting regime.

f(a) = (3 / 2) a − (1 / 2) a³

Here a is a scalar singular value and f(a) is its transformed value. From the normalized starting scale, positive singular values move toward unit size under repeated application, and zero singular values remain zero. As the iteration converges, the result is the product of singular-direction matrices on the supported subspaces. At a finite iteration count, a small singular value can still be below its target. The computation works on all the singular directions at once, using products of matrices and avoiding inverse roots.

The authors generalize the calculation to higher-degree odd polynomials.

Xₜ₊₁ = aXₜ + b(XₜXₜᵀ)Xₜ + c(XₜXₜᵀ)²Xₜ + … + z(XₜXₜᵀ)ⁿXₜ

Here Xₜ and Xₜ₊₁ are successive matrices. The letters a,b,c,…,z are scalar coefficients, and n is the highest Gram-matrix power used. Each power reduces to an even power of a singular value in its singular bases. The extra factor of Xₜ makes the resulting scalar polynomial odd.

p(u) = au + bu³ + cu⁵ + … + zu²ⁿ⁺¹

Here p is the scalar polynomial, u is its argument and the coefficients and highest power index n correspond to the matrix iteration. The authors suggest choosing the coefficients so the polynomial approximates the scalar sign function on a suitable range. Applying it repeatedly can approach the matrix transformation without factoring the gradient. Their suggestion to tune the coefficients empirically opens a design choice involving per-iteration work, approximation quality and training behavior. The paper derives that family of possible computations and describes Modula as a planned testbed for the broader design based on typed modules.

Experiments and results

What the NanoGPT record establishes

The empirical example in the paper is a NanoGPT training record credited to Keller Jordan. The authors say that the run used a duality map based on Newton–Schulz and that they had communicated the method through their earlier workshop paper. The numerical detail appears in the description of the cited run. For the 124M-parameter NanoGPT setup, it reports 3.28 Fineweb validation loss after 3.7B training tokens. The parameter count describes the setup, the loss is measured on the Fineweb validation split, and the token count describes training. These measurements tell the reader the scale of the run and the reported validation outcome.

The paper describes the run as a training speed record and discusses partial implementations in connection with wall-clock gains. It gives no elapsed time or matched previous run from which to establish the size of a speed advantage. The training-token figure measures the amount of training data processed in the run. It cannot establish how long that training took. The paper also provides no breakdown of how much runtime went into the matrix iteration, the rest of the optimizer or the forward and backward passes. Those distinctions matter when attributing an improvement to a particular computation.

The run illustrates the use of a Newton–Schulz-based map in training. The broader procedure includes choices about the norms of individual layers, their masses and sensitivities, and how the rules combine across the architecture. The paper does not give a run in which those choices are varied or the full recursive construction is compared with a baseline. It mentions an optimization competition result for a variant of Shampoo as background on fast training. That result belongs to a separate setting and supplies no baseline for the NanoGPT run.

What the formal layer comparison establishes

The paper compares layer geometries by deriving their norms and directions. One numerical constant the authors assign consistently across the trainable examples is input sensitivity. This is an analytic bound in each module’s own activation norms under the stated unit-ball assumptions. It has no dataset or split. Displaying the constant across the examples makes clear that their different update directions arise even when the modules use the same numerical sensitivity.

Assigned input sensitivity in the Linear, Embed and Conv2D derivations

The modules share the same sensitivity bound in their respective activation norms.

Assigned input sensitivity in the Linear, Embed and Conv2D derivationsLinear (this paper): 1Linear (this paper)1Embed: 1Embed1Conv2D: 1Conv2D1
The numbers
System or settinginput sensitivity bound
Linear (this paper)1
Embed1
Conv2D1

The star identifies Linear, the example the authors use to connect their derivation to µP and Shampoo. All the settings tie on the displayed bound. A smaller valid sensitivity would give a tighter bound within the same geometry, while the chart compares assigned constants in different geometries. In Linear, the constant concerns dense RMS-normalized vectors. In Embed, the input is sized by ℓ₁, and in Conv2D the activation norms use a spatial maximum. The shared constant makes the composition rule applicable in each case. It gives no ordering of their training performance.

The formal outcome goes beyond the individual expressions. When the weight geometry for a compound module takes a weighted maximum, the gradient maximization splits across children even if the forward computation depends on both. The result supplies a whole-network direction by recursively combining layer maps. The closed forms and the matrix iteration answer different questions. The former identify the desired direction under the chosen norms. The latter gives a way to approximate an operation required to realize that direction. The training record shows that the approximation can be used in a specific run. Comparable training measurements for several settings are unavailable in the paper.

What the ablations show

The paper has no empirical ablations. Its analyses instead isolate parts of the method mathematically, through comparisons of layer norms, composition rules and algorithms for approximating the matrix map. Those comparisons explain where changes to an update come from. They do not estimate the effect of an individual component on runtime or validation loss.

Changing the input geometry changes the update

Linear and Embed offer the closest counterpart to a controlled comparison. In both cases the forward operation is matrix multiplication, and both use RMS for their output activations. Changing the input norm changes the weight constraint. Under RMS-to-RMS geometry, a candidate update must control its gain in any input direction. Under ℓ₁-to-RMS geometry, it is enough to control the largest column RMS. As a consequence, the Linear rule acts on singular values and the Embed rule treats columns separately.

The comparison isolates the consequence of changing the intended input space even when the parameter array and the type of arithmetic match. It clarifies what the authors mean by tailoring the optimizer to a layer. The direction depends on the kind of input the layer is meant to receive. There is no training comparison between the two geometries applied to the same embedding or linear layer. Any relative advantage in accuracy or speed would require separate evidence.

Changing the compound norm changes how layers share a step

The contrast with a weighted sum explains what the modular maximum adds to the method. With a sum constraint, increasing the size of one child’s update leaves less available for the other child. A linear objective can spend the whole allowance at the best rate of return and update only one layer. With the maximum, every child can reach its own bound at the same time. The resulting direction includes contributions from all active child blocks with non-zero gradients.

The sequence and tuple formulas also isolate the effect of a downstream transformation. When the modules are paired, one branch cannot amplify the other branch’s weight perturbation within the tuple operation. Their allocation depends on the masses. When one module feeds another, the upstream perturbation passes through the downstream module, so the first allocation must account for downstream sensitivity. The comparison is between two ways to connect layers and shows exactly which factor their connection contributes to the direction.

Changing the matrix computation changes which directions are recovered

The algorithm discussion distinguishes three sources of error or cost. A low-rank sketch can discard small singular directions. An inverse-root method has to contend with very small values in its denominators. The rectangular polynomial acts on the full gradient matrix without inversion. Its finite-step approximation can still leave the smallest positive singular values far below the target. These are different reasons for a numerical result to depart from the exact map.

The paper’s analysis of the cubic explains why matrix multiplication can serve this purpose. Working in singular coordinates reduces the recurrence to the same scalar function applied across the spectrum. This gives a convergence argument from a normalized starting point and explains the behavior of zero singular values. The paper does not report controlled runs with different iteration counts, polynomial coefficients or approximation algorithms. Its analysis helps identify what each proposed computation preserves, while leaving their comparative costs and effects in training unresolved.

The decomposition of the Linear rule provides another analytical comparison. The width factor corresponds to spectral update scaling, and the singular-direction product corresponds to instantaneous Shampoo. The identification is an algebraic result about an update direction. The paper supplies no intervention that switches either factor off and measures the change in learning-rate transfer or speed. The comparison answers how the rules are related without measuring how valuable the relationship is in a particular run.

Limitations

Limits the authors identify

The choice of activation geometry is supplied by the designer. The paper gives reasons for treating dense activations by RMS, one-hot inputs by ℓ₁ and spatial activation arrays by the maximum channel RMS. Those choices suit the stated uses of the layers. The authors’ proposal for a type system would record both the intended norm and the intended activation size, making these assumptions explicit. Their plan to use Modula as a testbed describes future work on that broader design.

The authors make the practical choice of matrix approximation conditional on factors such as the gradient’s condition number and the available computation. A gradient with widely separated positive singular values presents different issues for each method. Sketching may underrepresent the small values, inverse-root computations become sensitive near zero, and finite polynomial iterations may need work to bring small values up towards the target. The paper gives a convergence argument for the normalized cubic and offers higher-degree polynomials as a family to explore. It does not identify a single coefficient set, runtime or accuracy tradeoff across training settings.

The discussion of alignment and width is also conditional. Alignment asks whether an update acts strongly on the incoming activations and therefore changes the features by the intended amount. The authors suggest that singular values of equal magnitude can simplify this question. For a rectangular matrix, the action still depends on which singular subspace contains an input. An activation component in a null direction sees no change. For a convolution, the layer output also combines contributions across offsets. The equal-gain result describes the transformed matrix or slice, giving a starting point for an analysis of activation changes.

The paper relates this discussion to Scaling Exponents Across Parameterizations and Optimizers, which it cites in connection with the alignment question. Bernstein and Newhouse also suggest that increasing the stable rank of updates could yield substantial weight movement even under the Frobenius norm at large width, provided the batch size is adequate. Stable rank describes how much matrix magnitude is spread across its singular directions relative to the strongest one. Its increase for a transformed update motivates the suggestion. The authors frame the resulting claim about the movement of the weights as an expectation, with the batch-size qualification, instead of a measured outcome across widths.

Limits that follow from the setup

A duality map gives a maximizing direction for a norm. A descent step additionally needs a scale, and the derivation based on a squared penalty assumes that the selected norm and sharpness describe the local higher-order behavior well enough. The decomposition of a network provides a way to construct the norm. It gives no universal value for the sharpness or a demonstrated learning-rate schedule. The exact solution of the local penalized problem therefore establishes a conditional result about the next move. It cannot on its own establish convergence speed, generalization or consistent feature learning.

The atomic examples show the role of maintaining the assumed scale. Their calculations bound perturbations on unit balls for inputs and weights. Since a large input can increase the output effect of a given weight perturbation, and a large weight operator can increase the effect of an input perturbation, the constant taken for granted in the composition rule depends on those conditions. An implementation needs a way to know when its training states remain in the intended regime. The derivation of an update direction and the behavior of sequences of updates under those bounds are separate matters.

Several definitions also require attention at degenerate cases. A zero gradient does not supply a preferred direction. A zero gradient column need not be normalized to choose an optimal embedding displacement. The inverse-root expressions have to account for rectangular and rank-deficient matrices, and a Newton–Schulz normalization needs a convention for a zero matrix. The paper’s composition norm gives zero-mass branches a separate convention, and weightless bonds have a trivial map. The positive-mass composition formulas still rely on their denominators being meaningful for the active blocks. A full implementation would need to make these conventions explicit wherever it accepts such modules or tensors.

The composition result follows for the architecture expressed in terms of compatible basic modules, sequential composition and concatenation. This condition carries real content. The output geometry of one module must be compatible with the next input geometry, and the norm needs to suit the forward operation of each atomic module. The paper derives atomic maps for Linear, Embed and Conv2D and describes the general handling of bonds. Other trainable operations require an appropriate geometry and a way to compute its map. The recursion explains how a library of such rules can be extended as architectures are assembled. The examples alone do not establish how costly it will be to supply every rule required for a particular system.

Finally, the NanoGPT report is practical evidence about a variant of the matrix operation in a single setting. Its validation loss and training-token count give details of the reported run, while leaving the elapsed time and matched baseline unspecified. They also leave open which choices would be needed to reproduce the same outcome with the full modular procedure. Claims of broad speed or width scalability would need measurements that vary those conditions and distinguish the contribution of the norm construction from that of the numerical kernel.

What came after

Amsel and colleagues’ The Polar Express takes up the matrix-sign side of the problem and applies it to Muon. Its stated focus is on how to construct effective matrix sign methods. That question arises directly in Bernstein and Newhouse’s treatment of the rectangular iteration. Once the target is a product of singular direction matrices, an optimizer still needs a way to reach a suitable approximation with a practical amount of computation. Modular duality explains why the target appears in the first place. The later work’s focus is the numerical operation used to approach it and its application in an optimizer.

The relation is clearest in the distinction between a target transformation and a finite computation. The Linear derivation specifies the target using the gradient’s supported singular directions. A polynomial applies a chosen scalar transformation to the singular values, and its coefficients determine how rapidly different parts of the spectrum approach the intended gains. The matrix-sign problem can therefore be studied in its own right without rederiving the norms for a network’s layers. The application to Muon connects that numerical question back to a training algorithm.

Pang and colleagues’ HTMuon addresses Muon through heavy-tailed spectral correction. Its stated contribution concerns the treatment of the spectrum. In Bernstein and Newhouse’s Linear map, the spectrum is the part of the gradient that changes while the supported singular directions are kept. That gives a precise point of contact with later work on spectral correction. Once an update has been expressed in singular coordinates, both the numerical approximation and the intended treatment of singular values become choices with consequences for the update.

These citations follow the matrix operation into two different parts of optimizer design. The Polar Express concerns how a matrix-sign transformation is computed. HTMuon concerns how spectral correction is used to improve a Muon update. Their stated contributions concern those narrower problems. The recursive combination of layer norms, which is the broader result of modular duality, remains a separate claim from the design of a matrix transformation or its use in Muon.

Cite

Cite as Jeremy Bernstein and Laker Newhouse. 2024. Modular Duality in Deep Learning. arXiv:2410.21265.

The paper itself, not this page. BibTeX from the library's record of the work. DOI 10.48550/arxiv.2410.21265 · arXiv 2410.21265

@misc{bernstein2024modular,
  title = {{Modular Duality in Deep Learning}},
  author = {Jeremy Bernstein and Laker Newhouse},
  year = {2024},
  doi = {10.48550/arxiv.2410.21265},
  eprint = {2410.21265},
  archivePrefix = {arXiv},
  url = {https://doi.org/10.48550/arxiv.2410.21265}
}

↑ back to top

This page in Markdown https://md.research.elamur.ai/free/en/papers/bernstein-2024-modular-duality-deep-learning/