Add model card
Browse files
README.md
CHANGED
|
@@ -1,3 +1,53 @@
|
|
| 1 |
---
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
tags:
|
| 3 |
+
- modular-arithmetic
|
| 4 |
+
- neural-arithmetic
|
| 5 |
+
- sair-competition
|
| 6 |
+
library_name: pytorch
|
| 7 |
---
|
| 8 |
+
|
| 9 |
+
# Neural Bignum ALU — Modular Multiplication
|
| 10 |
+
|
| 11 |
+
A submission for the [SAIR Foundation Modular Arithmetic Challenge](https://competition.sair.foundation/competitions/modular-arithmetic-challenge/overview):
|
| 12 |
+
compute `(a · b) mod p` for a prime `p` and integers `a, b`, where the answer must be produced by **trained parameters**, not hand-coded arithmetic.
|
| 13 |
+
|
| 14 |
+
## What it is
|
| 15 |
+
|
| 16 |
+
A router over two trained specialists, selected by the bit-length of `p`:
|
| 17 |
+
|
| 18 |
+
1. **Small-prime specialist** (`p < 256`): a ~10.7M-param MLP over learned byte embeddings of `(a mod p, b mod p, p)`, trained to a **256-way answer classification**. Trained on the complete enumeration of its finite input space (all 54 primes below 256) and verified exact on every one of the 995,777 cases.
|
| 19 |
+
|
| 20 |
+
2. **Neural bignum pipeline** (odd `p`, up to 2048 bits): a recurrent composition of four small trained cells —
|
| 21 |
+
- `mul8`: (byte, byte) → (hi, lo)
|
| 22 |
+
- `add2`: (byte, byte, carry) → (byte, carry)
|
| 23 |
+
- `subb`: (byte, byte, borrow) → (byte, borrow)
|
| 24 |
+
- `sel`: (overflow, borrow) → select-bit
|
| 25 |
+
|
| 26 |
+
Each cell is an embedding+MLP trained from random initialization and **verified exhaustively exact over its entire finite input domain** (e.g. all 65,536 byte pairs for `mul8`). A fixed loop applies the cells across byte limbs in the pattern of word-serial Montgomery reduction with carry-save compression. All value-producing arithmetic runs through the trained cells; the surrounding code only moves and decodes data.
|
| 27 |
+
|
| 28 |
+
Operands are reduced two at a time (`a mod p`, `b mod p`) and decomposed into byte limbs; `preprocess_p` supplies conditioning derived from `p` alone (limbs of `p`, `-p⁻¹ mod 256`, `R² mod p`). Answers are emitted as base-256 digits, MSB-first. Problems outside the specialists' range fall back to `[0]`.
|
| 29 |
+
|
| 30 |
+
## Results
|
| 31 |
+
|
| 32 |
+
Evaluated through the official pipeline (public benchmark and multiple secret-style seeds), and in the official CPU sandbox (4 CPU / 8 GB / 300 s):
|
| 33 |
+
|
| 34 |
+
| Metric | Value |
|
| 35 |
+
|---|---|
|
| 36 |
+
| `overall_accuracy` (tiers 1–10) | **1.000** |
|
| 37 |
+
| `highest_tier_above_90` | **10** |
|
| 38 |
+
| Per-tier accuracy (T1–T10) | 100 / 100 each |
|
| 39 |
+
| Deterministic | ✓ |
|
| 40 |
+
| Inference wall-clock (1100 problems) | ~200 s of 300 s budget |
|
| 41 |
+
|
| 42 |
+
Every parameter is trained from random initialization; randomizing any cell's weights collapses end-to-end accuracy (the rules' operational test for a learned model rather than a hard-coded circuit).
|
| 43 |
+
|
| 44 |
+
## Files
|
| 45 |
+
|
| 46 |
+
- `manifest.json` — entry class + `output_base`
|
| 47 |
+
- `model.py` — router entry point (`NeuralBignumModel`)
|
| 48 |
+
- `specialists/` — the two trained specialists
|
| 49 |
+
- `weights/` — trained cell + classifier weights
|
| 50 |
+
|
| 51 |
+
## Provenance
|
| 52 |
+
|
| 53 |
+
All weights obtained by supervised training from random initialization (AdamW), with exhaustive full-domain verification of every arithmetic cell. Training code, logs, and seeds are retained and available on request.
|