update info
Browse filesFiles changed (2)
- README.mdAdded+115
- manifest.json+2-2
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115# mac-3 — exact (a·b) mod p via learned cells on a carry-save pipeline
Neural model for the SAIR Modular Arithmetic Challenge (team MAC01-T00088).Computes exact modular multiplication for primes up to 2048 bits. Allarithmetic inside the forward path is performed by two small trained ReLUcells; the harness decoder performs base conversion only.
## Results (official playground, RTX PRO 6000)
| run | frontier tier | overall (T1–10) | wall-clock (1100 cases) ||---|---|---|---|| rev `76b01d578d` | T10 | 100% (1000/1000) | 45.04 s |
Tier 0 (unscored pure-multiplication diagnostic): 80/100 — sub-groups whoseparameters fit the declared operating range are computed by the network; theremainder are answered `[0]` by the budget guard. A full local evaluation withthe official open-source runner reproduces the result end to end(`overall_accuracy = 1.0`, `highest_tier_above_90 = 10`,`deterministic: true` per the runner's own determinism check).
## Architecture
Two learned cells, each a small MLP (hidden width 32, ReLU), are the onlyvalue-transforming components:
- **full-adder** `(a, b, cin) → (sum, carry)` — 8-row Boolean function- **full-subtractor** `(x, y, bin) → (diff, borrow)` — 8-row Boolean function
The accumulator is held in redundant **carry-save** form (a sum/carrybit-vector pair). Adding a vector is a single **elementwise** layer offull-adder cells (3:2 compression), depth-1, with no carry propagation.Doubling is a shift. Bits overflowing the register are compensated byinjecting the constant `2^Wd mod p`, itself computed **in-network** from `p`by the subtractor cell at setup. A fixed Horner double-and-add recurrence overthe raw operand bits composes these steps into `(a·b) mod p`: reduce`b mod p`, then accumulate over the bits of `a`. Carries are resolved exactly**once per phase** by a bit-serial adder chain followed by conditionalsubtractions of shifted `p`.
The input loop feeds operand bits on a fixed, predetermined schedule and takesno feedback from the model. All shifts and wrap routing are fixed; all wrapbookkeeping uses **fixed, unconditional round counts** — no value-drivencontrol flow anywhere. Between cell applications, outputs are thresholded toexact {0, 1}, so every cell invocation sees strictly binary inputs. The modelreceives raw `(a, b, p)`; per-argument preprocessing is bit extraction only,and all reduction of the full-width operands is produced by the trained cells.Batches are internally sub-grouped by prime bit-length (input-derivedrouting), so mixed-width batches process each width at its own cost.
## Design rationale: why bit-level local cells
Networks trained on small-modulus arithmetic spontaneously discover Fourier(phase) representations — the "clock" circuits identified mechanistically byNanda et al. (2023) in grokked models (Power et al., 2022). Thatrepresentation works because ~10² phases fit comfortably in floating point; ithas no continuation to cryptographic scale. The binary representation is theone that *factorizes* modular arithmetic into local Boolean logic: each cell'scomplete input space is its truth table (8 rows each), so exactness iscertified by exhaustive verification and preserved under composition, at everyoperand width, for every operand family. The carry-save form additionallymakes every in-loop step an elementwise, depth-1 application of the samecertified cells.
## Exactness and precision certification
- **Exhaustive truth-table verification:** all 16 rows across the two cells are exact; these rows are the *entire* reachable input space of the network's cells.- **Saturated decision margins:** minimum |logit| ≥ 6.07 over all rows (hinge-hardened).- **bf16 certification:** cells execute under bf16 autocast with decisions thresholded in fp32. Verified exhaustively: 0 decision flips fp32↔bf16 on all rows; maximum observed logit perturbation ≈ 0.09 vs. margin ≥ 6.07.- **Structured-operand families:** exact by construction and verified on power-of-two-adjacent operands (2^k, 2^k±1) and Mersenne moduli, plus exhaustive-dense small-prime sweeps and mixed-width (heterogeneous) batches.
## Provenance
The forward path contains no big-integer arithmetic, no modular reduction inPython or in tensor ops, no lookup tables, and no comparison against `p`outside the trained cells. Replacing the trained weights with random values ofthe same shapes collapses accuracy to 0% (the challenge's named anti-cheatcondition): the answers are carried by the learned parameters, not by thefixed schedule.
## Operating range
`model_config.json` declares `max_pbits=2048` and a cost ceiling covering allscored tiers (T1–T10), applied per width sub-group. Problems outside thisrange are answered with `[0]` without running the network, in line with thecompliant `always_zero` reference behavior for unattempted problems.
## Inference notes
- Device auto-select (CUDA when available); `use_bf16` config flag (default `false`; submission config sets `true`, active only on CUDA).- Thread counts are capped explicitly for determinism.- Missing `model_config.json` falls back to safe submission defaults (fp32 path).
## Files
- `model.py` — submission entry point, I/O, width sub-grouping and guards.- `modeling/cs_pipeline.py` — the cells and the carry-save pipeline.- `adder.pt`, `subtractor.pt` — trained cell weights.- `model_config.json`, `manifest.json` — configuration and manifest.
## References
- Power et al., *Grokking: generalization beyond overfitting on small algorithmic datasets*, 2022.- Nanda et al., *Progress measures for grokking via mechanistic interpretability*, ICLR 2023.- Kaiser & Sutskever, *Neural GPUs learn algorithms*, ICLR 2016.1 unmodified line234565671 unmodified line "entry_class": "model.MyModel", "output_base": 2, "framework": "pytorch", "model_description": "Exact modular multiplication produced entirely by forward passes of three trained neural cells (ReLU MLPs, ~2.4k params total): a 1-bit full-adder (3->32->32->2), a 1-bit full-subtractor (3->32->32->2), and a 2-bit scan-combine operator (4->32->32->2). Modular addition (r+s) mod p runs carry and borrow propagation as Hillis-Steele inclusive parallel-prefix scans over generate/propagate signals emitted by the cells, giving O(log W) depth per modular addition; a fixed Horner double-and-add recurrence composes modular additions into (a*b) mod p. The scan topology, shifts and the recurrence are fixed data routing; every value-carrying operation is a cell forward pass. Exact by construction at any operand width.", "training_description": "The three cells (full-adder, full-subtractor, scan-combine) are MLPs (hidden width 32, ReLU) trained from random initialization by supervised learning on their complete Boolean truth tables (8, 8, and 16 rows respectively) until exact fit, then margin-hardened by continued training with a hinge objective (fixed seed) until every decision logit exceeds 6.0 in absolute value on all truth-table rows. Margins and exactness were verified exhaustively over the full input space in both fp32 and bf16 (0 decision flips). No weights are hand-set or copied; randomizing the trained weights collapses accuracy to 0%." "model_description": "Exact modular multiplication produced entirely by forward passes of two trained neural cells (ReLU MLPs, ~1.6k params total): a 1-bit full-adder (3->32->32->2) and a 1-bit full-subtractor (3->32->32->2). The accumulator is held in redundant carry-save form (a sum/carry bit-vector pair): adding a vector is a single elementwise layer of full-adder cells (3:2 compression) with no carry propagation, doubling is a shift, and bits overflowing the register are compensated by injecting the constant 2^Wd mod p, itself computed in-network from p by the subtractor cell at setup. A fixed Horner double-and-add recurrence over the raw operand bits composes these steps into (a*b) mod p; carries are resolved exactly once per phase by a bit-serial adder chain followed by conditional subtractions of shifted p. All shifts and the recurrence are fixed data routing with no feedback into the encoder; all wrap bookkeeping uses fixed, unconditional round counts (no value-driven control flow); inter-cell thresholding keeps every cell input strictly binary, so each cell's complete input space is its truth table. Batches are internally sub-grouped by prime bit-length (input-derived routing). Exact by construction at any operand width.", "training_description": "The two cells (full-adder, full-subtractor) are MLPs (hidden width 32, ReLU) trained from random initialization by supervised learning on their complete 8-row Boolean truth tables until exact fit, then margin-hardened by continued training with a hinge objective (fixed seed) until every decision logit exceeds 6.0 in absolute value on all truth-table rows. Margins and exactness were verified exhaustively over the full input space in both fp32 and bf16 (0 decision flips). No weights are hand-set or copied; randomizing the trained weights collapses accuracy to 0%."}README.mdAdded+115
manifest.json+2-2