cire77 commited on
Commit
cd4d949
·
verified ·
1 Parent(s): ec9691c

Add model card

Browse files
Files changed (1) hide show
  1. README.md +63 -0
README.md ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ library_name: pytorch
4
+ tags:
5
+ - modular-arithmetic
6
+ - scratchpad
7
+ - grokking
8
+ - transformer
9
+ - sair-challenge
10
+ ---
11
+
12
+ # modmul-tier3 — learned modular multiplication
13
+
14
+ A submission to the **SAIR Modular Arithmetic Challenge**: compute `(a · b) mod p`
15
+ with the arithmetic produced entirely by **trained parameters** — no `%`, `//`,
16
+ Barrett, Montgomery, or CRT on the product.
17
+
18
+ ## What it does
19
+
20
+ Two trained networks behind one interface, routed by the size of `p`:
21
+
22
+ | `p` range | Model |
23
+ |---|---|
24
+ | `p < 512` (tiers 1–2) | joint-attention Transformer with a classification head over the residue |
25
+ | `512 ≤ p < 65536` (tier 3) | **autoregressive "abacus" decoder** that emits an interleaved modular-multiply scratchpad |
26
+ | `p ≥ 65536` | out of trained range → returns `[0]` |
27
+
28
+ Operands are reduced per-argument (`a mod p`, `b mod p`) before the network runs;
29
+ the **product's** reduction is learned.
30
+
31
+ ## The tier-3 idea
32
+
33
+ A one-shot 5-digit × 5-digit multiply is a hard learnability wall. Instead the model
34
+ runs **Horner's method**, reducing mod `p` at every step so no intermediate ever
35
+ exceeds ~6 digits — the regime the decoder handles reliably. Every intermediate is
36
+ written to the scratchpad and supervised:
37
+
38
+ ```
39
+ BOS x MUL y MOD p EQ d:q1:r1:pp:t:q2:r2 STEP … EOS
40
+ ```
41
+
42
+ per `y`-digit: shift-reduce (`q1,r1`), single-digit partial product (`pp`),
43
+ the explicit add `t = r1 + pp`, then add-reduce (`q2,r2`). Emitting `t` explicitly
44
+ was the decisive fix — leaving that addition implicit capped end-to-end accuracy.
45
+
46
+ ## Results
47
+
48
+ Verified through the official `modchallenge evaluate-hf` pipeline:
49
+
50
+ | Tier | Accuracy |
51
+ |---|---|
52
+ | 1 | 1.00 |
53
+ | 2 | 0.99 |
54
+ | **3** | **1.00** |
55
+
56
+ **`highest_tier_above_90 = 3`**, deterministic, static-compliance check passed.
57
+ A 30-seed local sweep gave htop90 = 3 on all 30 (tier-3 min 0.95 / mean 0.986).
58
+
59
+ ## Files
60
+
61
+ - `model.py` — the `EBMModMul` entry class (loader + abacus decoder)
62
+ - `manifest.json` — entry class, `output_base=10`, descriptions
63
+ - `weights.pt` — trained weights for both routed models