Learning Large-Scale Modular Addition with an Auxiliary Modulus

Hanato Kikuchi, Ryosuke Masuya, Kazuhiko Kawamoto, Hiroshi Kera

TL;DR

Researchers have developed a novel way to teach neural networks modular addition—a notoriously difficult task due to its extreme sensitivity to small input changes. By introducing an auxiliary modulus during training, the method reduces the complexity of the problem without distorting the data distribution, leading to massive gains in sample efficiency and robustness compared to previous state-of-the-art techniques.

What Problem Does This Paper Address?

Modular addition (computing $\sum x_i \pmod q$) is a fundamental building block for complex symbolic tasks and cryptographic attacks, such as those targeting the "Learning With Errors" (LWE) problem. However, it is a nightmare for deep learning models. Because the output "wraps around" the modulus $q$ many times, a tiny change in a single input can completely flip the result. This "input sensitivity" often leads to stagnated training because the loss gradient has very low variance.

A recent state-of-the-art approach (Saxena et al., 2025) tried to solve this by training on "sparse" sequences—inputs filled with many zeros. This makes the math easier because there are fewer "wraps" to learn. The downside? It introduces a covariate shift: the model learns on sparse data but is tested on dense, uniform data. This shift creates a significant generalization gap and makes the model's success highly dependent on specific architectural "hacks" like specific weight initializations or disabling dropout.

Methods

The authors propose a "covariate-shift-free" method. Instead of changing the inputs to make the problem easier, they change the targets using an Auxiliary Modulus.

  1. The Core Idea: During training, for any given input $x$, the model is asked to predict the sum modulo $q$ with probability $(1-r)$, and the sum modulo $Kq$ (where $K > 1$) with probability $r$.
  2. Why it works: By using a larger modulus $Kq$, the number of "wraps" around the modulus decreases significantly. This provides a "simpler" version of the task that shares the same underlying structure as the target task.
  3. Implementation: The authors suggest two ways to handle this:
  4. Approach 1 (Vocabulary Extension): Simply increase the output layer size to accommodate the larger $Kq$ range.
  5. Approach 2 (Dual Angular Embedding): Map the scalars to a 4D unit circle representing both $q$ and $Kq$ periodicities, using Mean Squared Error (MSE) loss. This is more efficient for very large moduli.

Crucially, because the input distribution remains uniform throughout, there is no covariate shift between training and testing.

Datasets

The study uses synthetically generated datasets of sequences $x = [x_1, \dots, x_N]$ where $x_i \in \{0, \dots, q-1\}$.

  • Scale: They tested sequence lengths $N$ from 8 up to 128 and moduli $q$ ranging from small primes (31) to very large numbers (974,269).
  • Evaluation: Models were evaluated on 1 million uniformly generated test samples.
  • Metrics: They used "Match Accuracy" (exact integer match) and "$\tau$-accuracy" (allowing a small relative error tolerance, crucial for large-scale cryptographic applications).

Key Insights and Ideas

  • Wraparound is the Real Enemy: The difficulty of modular addition isn't the addition itself, but the "wrapping" frequency. The paper proves that the auxiliary modulus $Kq$ reduces this frequency just as effectively as the "sparse input" method, but without the statistical side effects.
  • Stability is Feature, Not a Bug: One of the most striking findings is how robust this method is. While the previous "sparse" method would often fail completely if you added Dropout or changed the normalization layer, the auxiliary modulus method remained stable across 16 different architectural configurations.
  • Sample Efficiency: Because the model isn't fighting a distribution shift, it learns much faster. The authors found they could achieve better results with 10x fewer training samples than the baseline method.

Key Results

The performance gap is most visible at large scales ($N=64, q=974,269$):

  • With 100K samples: The proposed method achieved 97.0% $\tau$-accuracy, while the previous sparse method managed only 9.5%.
  • Scaling: Even when the sparse method was given 1 million samples, it only reached 93.9%—still falling short of the proposed method's performance with a fraction of the data.
  • Exact Match: In smaller-scale tests ($N=16, q=257$), the proposed method hit 93.0% accuracy with 100K samples, whereas the baseline was stuck at 11.8%.

Limitations and Future Work

  • Task Specificity: Currently, the method is specifically designed for modular addition. The authors acknowledge the need to extend this logic to other operations like modular multiplication.
  • Hyperparameter Tuning: The values for $K$ (the modulus multiplier) and $r$ (the probability of the auxiliary task) are currently found via grid search. The authors aim to develop a more principled, automated strategy for selecting these in the future.
  • Theoretical Depth: While they provide a proof for the reduction in "wraps," a deeper theoretical understanding of how the model's internal "periodic structures" (neurons learning Fourier-like patterns) adapt to dual moduli is still an open question.

Summary updated

BibTeX
@inproceedings{kikuchi2026learning,
  author = {Hanato Kikuchi and Ryosuke Masuya and Kazuhiko Kawamoto and Hiroshi Kera},
  title = {{Learning Large-Scale Modular Addition with an Auxiliary Modulus}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=AuqtRdsHrh},
}
Figure