Downloads · 30 days
0
MCarreira/cross-prime-v1
cross-prime-v1 is a machine learning model from MCarreira. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for pytorch. The card lists the license as apache-2.0.
A compliant submission to the SAIR Modular Arithmetic Challenge: a neural network that learns to compute (a · b) mod p for a prime p and integers a, b that may be far larger than p.
Downloads · 30 days
0
Access
Public
Updated Jun 8, 2026
Repo size
31.2 MB
Likes
0
Public
Click a slice to open those files.
.pt18.4 MB · 100%
From the Hugging Face model README
A compliant submission to the SAIR Modular Arithmetic Challenge:
a neural network that learns to compute (a · b) mod p for a prime p and
integers a, b that may be far larger than p.
Team MCSC (MAC01-T00008).
A prime-conditioned joint Transformer encoder (~3.2M parameters). The digits
of a mod p, b mod p, and p are tokenized (base-10, fixed width 5, with
learned token / position / segment embeddings) and a 6-layer encoder attends
over all three operands jointly, reading out the answer as 5 base-10 digits via
per-position linear heads.
It deliberately does not use the discrete-log / additive bottleneck of the
reference dlp_grokking model — whose own ablation showed that bias is not the
limiting factor; the wall is generalizing across primes. This model instead
lets attention learn the field operation directly, conditioned on p.
| Tier | p bits | this model | dlp_grokking (best reference) |
|---|---|---|---|
| 1 | 1–3 | 1.00 | 1.00 |
| 2 | 4–8 | 0.35 | 0.12 |
| 3–10 | 9–2048 | ~0.02 | ~0.02 |
| overall_accuracy | 0.150 | 0.127 | |
| highest_tier_above_90 | 1 | 1 |
Beats the strongest shipped baseline on overall_accuracy; tier 2 ~3×. Scores identically on CPU and MPS (deterministic), and runs the full 1100-problem set in ~35s (budget: 5 min).
The answer comes from trained parameters, not a hand-coded algorithm
(SAIR rules/evaluation.md, Principle 2 — perturbing the weights collapses
accuracy):
preprocess_{a,b,p} are pure per-argument identities (no cross-argument leakage).predict_digits reduces a % p and b % p (two operands at a time — the same
legal normalization the reference baselines use) and never forms a · b,
never computes (a·b) % p, and uses no lookup table. The network argmax is the
answer.sympy / gmpy2 / Barrett / CRT in the forward path. For p ≥ 10⁵
(outside the trained width) it emits a constant 0 — an honest out-of-regime
fallback, not an answer shortcut.model.py — architecture + the ModularMultiplicationModel entry class.manifest.json — entry class, output_base = 10, required descriptions.weights.pt — {state_dict, config}.Tiers 3+ (thousands of distinct primes) sit near the floor: the model memorizes the per-prime multiplication tables it was trained on but does not yet generalize the operation to unseen primes — the open problem at the heart of the challenge. A reciprocal/learned-Barrett variant is under development to attack exactly that.