Modular addition without black-boxes: Compressing explanations of MLPs that compute numerical integration

Chun Hei Yip, Rajashree Agrawal, Lawrence Chan, Jason Gross

TL;DR

Mechanistic interpretability often treats Multi-Layer Perceptron (MLP) layers as uninterpretable black boxes because compressing nonlinear feature-maps is incredibly difficult. This paper cracks open the MLP layer of a transformer trained on modular addition, proving that it implements a numerical integration (quadrature) scheme to double trigonometric frequencies. By viewing the MLP through the lens of an infinite-width limit, the authors provide a compressed explanation that can be formally verified in linear time.

What Problem Does This Paper Address?

Mechanistic interpretability aims to reverse-engineer neural networks into human-understandable algorithms. While researchers have successfully mapped model activations to discrete linear features, compressing nonlinear feature-maps—like MLP layers—remains a major open problem.

Without compressing these layers, interpretations retain too many free parameters, making it impossible to provide worst-case performance guarantees or reliably detect anomalies. Even in simple toy settings like modular addition (e.g., learning $a + b \pmod p$), prior work treated the MLP layer as a black box or relied on brute-force enumeration of all inputs. Brute-force verification fails to scale to larger models and offers zero algorithmic compression.

Methods

The authors introduce a rigorous framework to analyze and compress the ReLU MLP using several key techniques:

  • The Infinite-Width Lens: By analyzing the MLP as a finite approximation of its infinite-width limit, post-activation matrix multiplications are mathematically transformed into continuous integrals. This allows the network's nonlinear operations to be studied analytically.
  • Amplitude-Phase Fourier Form: The authors convert the network's internal representations into polar coordinates. This transformation reveals cyclic relationships and phase alignments that are hidden in standard coordinate spaces.
  • Quadrature Scheme Interpretation: They show that the finite number of neurons in the MLP acts as a numerical quadrature scheme (like a Riemann sum), where each neuron computes the area of a rectangle under a specific trigonometric integral identity curve.
  • Linear-Time Verification: To prove their explanation is truly "compressed," they derive mathematical bounds on the MLP's error that can be verified in time linear in the parameter count ($O(d_{mlp}d_{model} + p)$), rather than checking every possible input combination ($O(p^2 \cdot d_{mlp}d_{model})$).
Figure 1: (Left) There are finitely many neurons in the model (indexed by i). The function fx(ξi) is ReLU applied to the inputs x. The weight of the connection to each output c is gc(ξi) times a neuron-specific output-independent normalization factor wi. (Right) Taking the limit as the number of neurons goes to infinity turns the sum over neurons into an integral. Compressing the resulting analytic expression allows us to compress the MLP.

Datasets

The paper uses a synthetic dataset for the modular addition task: $M(a, b) = (a + b) \pmod{59}$. The models are one-layer transformers trained on 80% of all possible input pairs and validated on the remaining 20%, achieving 100% accuracy. The authors deeply analyze one "mainline" model and validate their findings across 150 additional models trained with different random seeds.

Key Insights and Ideas

  • Neuron Clustering by Frequency: Neurons within the MLP are not performing random computations; they can be cleanly divided into clusters based on a single "primary frequency" for both their inputs and outputs.
  • Phase Doubling: For a neuron's primary frequency, its output phase shift ($\psi_i$) is almost exactly twice its input phase shift ($\phi_i$). This phase doubling is the engine behind the network's frequency-doubling step in the modular addition algorithm.
Figure 3: The input (ϕi) and output (ψi) phase shift angles for frequency k = 12, where ψi ≈2ϕi (mod 2π) for the primary frequency of each neu- ron. The line has R2 > 0.99 and the intervals between angles have mean width 0.054, and stan- dard deviation 0.049. This shows that the angles are roughly uniform.
  • MLP as a Numerical Integrator: Instead of a black-box matrix multiplication, the MLP layer is literally performing numerical integration. The weights of the trained model naturally define the widths and heights of rectangles used to approximate a continuous trigonometric integral.
  • The Role of Secondary Frequencies: The authors resolve a long-standing puzzle in modular addition models: why do these models empirically produce logits that look like the "clock" algorithm instead of the "pizza" algorithm they were categorized under? They discover that neurons utilize a "secondary frequency" (exactly twice the primary frequency) to compensate for edge cases where the pizza algorithm naturally fails (when $k(a-b) \approx \pi$).

Key Results

  • The authors successfully derived the first non-vacuous, linear-time verifiable error bounds for a nonlinear MLP layer.
  • The formal relative error bounds range from 0.48 to 0.70 (where a value less than 1 indicates a meaningful, non-vacuous bound).
  • The actual empirical error of the integration approximation computed via brute force is incredibly low, sitting between 0.03 and 0.05, proving that the numerical integration interpretation is highly accurate.
  • These structural properties (primary/secondary frequency relationships and phase doubling) were confirmed to generalize across 82% of the 151 independently trained models.

Limitations and Future Work

  • High Manual Effort: The current derivation is highly labor-intensive and requires bespoke mathematical exploration for this specific task. Automated tools are needed to scale this approach to other architectures and problems.
  • Loose Analytical Bounds: The analytical bounds, while non-vacuous, are still significantly higher than the actual empirical error (0.48–0.70 vs 0.03–0.05). This is because the current math does not fully account for how adjacent error terms cancel each other out when box densities overlap.
  • Simplifications: The analysis omits certain residual components, attention biases, and the exact behavior of the identity component of the ReLU activation, which the authors flag for future technical work.

Summary updated

BibTeX
@misc{yip2024modular,
  author = {Chun Hei Yip and Rajashree Agrawal and Lawrence Chan and Jason Gross},
  title = {{Modular addition without black-boxes: Compressing explanations of MLPs that compute numerical integration}},
  year = {2024},
  eprint = {2412.03773},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2412.03773},
}
Figure