cpchoi commited on
Commit
c7cb870
·
verified ·
1 Parent(s): b5b2ffa

Promote validated compact reducer Teacher-Student v20

Browse files
PROVENANCE.md CHANGED
@@ -1,5 +1,18 @@
1
  # Provenance
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  - Experiment: `experiments/self-clocked-parallel-montgomery-v12.json`
4
  - Run: `runs/self-clocked-parallel-montgomery-v12-20260810-r3/`
5
  - Classification during training: reusable pretraining
@@ -18,6 +31,106 @@ self-clock Teacher was newly initialized and trained by the recorded
18
  experiment. Exact arithmetic appears in offline label generation and
19
  validation only; it is absent from this artifact.
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  The exact packaged inference source was reviewed against official challenge
22
  commit `45eb406c4460d2b7229a41ecde659b773fe1aae1`. The package contains no
23
  training oracle, deterministic full-operand reducer, exact Montgomery
 
1
  # Provenance
2
 
3
+ - Lazy-revision plan: `docs/lazy-revision-cios-v16-plan.md`
4
+
5
+ - Lazy-reducer plan: `docs/lazy-reducer-v17-plan.md`
6
+
7
+ - Compact-Student plan: `docs/compact-reducer-student-v19-plan.md`
8
+ - Compact-combination plan: `docs/compact-reducer-combined-v20-plan.md`
9
+
10
+ - Sparse-dispatch plan: `docs/sparse-judge-first-cios-v15-plan.md`
11
+
12
+ - Candidate architecture experiment:
13
+ `experiments/judge-first-cios-v14-{gpu,cpu}.json`
14
+ - Candidate source plan: `docs/judge-first-cios-v14-plan.md`
15
+
16
  - Experiment: `experiments/self-clocked-parallel-montgomery-v12.json`
17
  - Run: `runs/self-clocked-parallel-montgomery-v12-20260810-r3/`
18
  - Classification during training: reusable pretraining
 
31
  experiment. Exact arithmetic appears in offline label generation and
32
  validation only; it is absent from this artifact.
33
 
34
+ V14 changes no parameter or checkpoint byte. It moves the existing learned
35
+ cancellation judge before the full cancellation scan: the judge observes the
36
+ proposed cancelled low digit, selects the proposed or learned revised factor,
37
+ and one learned MAC scan applies that factor. Protected v12 instead evaluated
38
+ both complete cancellation memories before selecting one. The raw interface,
39
+ learned reducer, self-clock, arithmetic Students, judge/revision, final memory,
40
+ and checkpoint are identical.
41
+
42
+ V15 changes no parameter byte. It uses the trained self-clock Teacher's
43
+ operation token for dynamic Student dispatch instead of evaluating every
44
+ unused Student candidate on every turn. Randomizing that Teacher destroys the
45
+ operation schedule; randomizing the arithmetic weights destroys the selected
46
+ Student outputs.
47
+
48
+ V16 changes no parameter byte. The cancellation review head still runs on
49
+ every row; its revision head is dynamically evaluated only for the batch rows
50
+ that receive a learned rejection.
51
+
52
+ V17 changes no parameter byte. The raw-input reducer still evaluates its
53
+ proposal Student and learned judge on every token. It evaluates the learned
54
+ quotient revisor and second Student transition only for rows that the learned
55
+ judge rejects. The rotated comparison is recorded at
56
+ `runs/lazy-reducer-v17-20260811-r1/paired-tier10.json`.
57
+
58
+ Fresh v17 validation artifacts:
59
+
60
+ - local smoke and isolation:
61
+ `runs/lazy-reducer-v17-20260811-r1/local-smoke-110.json`;
62
+ - randomized-weight control:
63
+ `runs/lazy-reducer-v17-20260811-r1/randomized-100.json`;
64
+ - official sandbox result:
65
+ `runs/lazy-reducer-v17-20260811-r1/sandbox-output/result.json`;
66
+ - identical-seed protected-v16 sandbox result:
67
+ `runs/lazy-reducer-v17-20260811-r1/v16-sandbox-output/result.json`.
68
+
69
+ The official four-CPU, 8-GB, no-network, read-only sandbox scored v17 at
70
+ 1,000/1,000 Tier 1--10 cases in 115.1 seconds. The immediately following v16
71
+ control used the same seed and scored 1,000/1,000 in 150.1 seconds. Repository
72
+ regression testing passed 392 tests.
73
+
74
+ V19 replaces only the learned raw-reducer Student. It was initialized with seed
75
+ 19102 and trained on the RTX A6000 for 1,550 epochs on the complete 131,072-
76
+ state local domain. It exactly reproduces both teacher outputs with minimum
77
+ margin 0.410. Training is recorded at
78
+ `runs/compact-reducer-student-v19b-gpu-20260811-r1/results.json`.
79
+
80
+ V20 replaces only the learned sequence comparator on top of v19. It was newly
81
+ initialized and trained for 125 AdamW steps on all 256 digit-pair states and
82
+ all nine comparison-state pairs, reaching 265/265 exact decisions and minimum
83
+ margin 3.803. Training and first raw evaluation are recorded at
84
+ `runs/compact-reducer-combined-v20-gpu-20260811-r1/results.json`.
85
+
86
+ - V17 checkpoint SHA-256:
87
+ `aedf12d00877a4f9569f3ee010eb1f7a583a5bd131710f4ba1527340da4380f2`
88
+ - V19 checkpoint SHA-256:
89
+ `0ca6318f0561bc090bb098605cc9f3436afa3cd6cb87f055669ae4b8e5dbc238`
90
+ - V20 checkpoint SHA-256:
91
+ `1cfd6f501fffd0092635221444a104d181cd5117a0c67c8c1ac484701bb7669a`
92
+
93
+ The second unseen 200-case all-tier evaluation is
94
+ `runs/compact-reducer-combined-v20-gpu-20260811-r1/unseen-200.json`. The
95
+ six-round full-workload CPU comparison is `paired-all-tier-100.json` in the
96
+ same directory and measures v20 at 0.8478 times v17's median runtime.
97
+
98
+ Final v20 validation artifacts in that run directory are:
99
+
100
+ - packaged local smoke: `package-smoke-110.json`;
101
+ - randomized-weight control: `package-randomized-100.json`;
102
+ - official sandbox result: `sandbox-output/result.json`;
103
+ - identical-seed v17 control: `v17-sandbox-output/result.json`.
104
+
105
+ The official four-CPU, 8-GB, no-network, read-only sandbox scored v20 at
106
+ 1,000/1,000 Tier 1--10 cases in 75.8 seconds. The immediately following v17
107
+ control used the same seed and scored 1,000/1,000 in 116.6 seconds. Both result
108
+ JSON files have SHA-256
109
+ `a4f4e3de7e2d20d308b89d5c1e16b3304376d45f3b5227e3ccdb8f7a7773a10c`,
110
+ proving identical tier totals and predictions. Randomized packaged weights
111
+ scored 0/78 nonzero-answer cases. Repository regression testing passed 392
112
+ tests.
113
+
114
+ Fresh v16 validation artifacts:
115
+
116
+ - local smoke and isolation:
117
+ `runs/lazy-revision-cios-v16-package-20260811-r1/local-smoke-110.json`;
118
+ - randomized-weight control:
119
+ `runs/lazy-revision-cios-v16-package-20260811-r1/randomized-100.json`;
120
+ - official sandbox result:
121
+ `runs/lazy-revision-cios-v16-package-20260811-r1/sandbox-output/result.json`;
122
+ - same-seed protected-v12 sandbox result:
123
+ `runs/lazy-revision-cios-v16-package-20260811-r1/protected-sandbox-output/result.json`;
124
+ - rotated Tier-10 runtime comparison:
125
+ `runs/sparse-judge-first-cios-v15-package-20260811-r1/paired-tier10-v16.json`.
126
+
127
+ The official four-CPU, 8-GB, no-network, read-only sandbox scored v16 at
128
+ 1,000/1,000 Tier 1--10 cases in 133.8 seconds. The immediately following
129
+ protected-v12 control used the same seed and scored 1,000/1,000 in 153.8
130
+ seconds. The rotated in-process comparison independently measured v16 at
131
+ 0.8724 times the protected runtime. Repository regression testing passed
132
+ 391 tests.
133
+
134
  The exact packaged inference source was reviewed against official challenge
135
  commit `45eb406c4460d2b7229a41ecde659b773fe1aae1`. The package contains no
136
  training oracle, deterministic full-operand reducer, exact Montgomery
README.md CHANGED
@@ -1,28 +1,112 @@
1
- # Self-clocked Montgomery Teacher--Student v12
2
 
3
- Status: locally validated submission candidate. It has passed the current
4
- official static, packaging, determinism, accuracy, runtime, and sandbox gates.
5
- Final eligibility always remains subject to organizer review.
 
6
 
7
  The model receives raw `(a, b, p)` values through lossless per-argument base-16
8
- tokenization and emits final base-16 answer digits. A fixed feedback-free loop
9
- feeds the raw tokens. Multiplication then uses one generic learned recurrence:
10
- the Teacher emits `ROW`, a boundary operation, or `HALT`; the Student evaluates
11
- all next-memory candidates; and the Teacher token selects the complete next
12
- memory. Python supplies neither the phase nor the row index. `R^2` is emitted
13
- by the learned reducer from the fixed digit stream `1` followed by zeros.
14
-
15
- Evidence for the exact packaged checkpoint:
16
-
17
- - two untouched Tier 1--10 suites: 400/400;
18
- - every individual tier: 20/20 on both seeds;
19
- - official local evaluator: 1,000/1,000 scored cases, 100/100 in each tier;
20
- - official isolated four-CPU sandbox: 1,000/1,000 scored cases, completed
21
- within the 300-second limit;
22
- - randomized packaged weights: 0/76 nonzero-answer cases;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  - official static analysis and preprocessing isolation: passed;
24
- - repository tests: 359 passed;
 
25
  - finite learned clock: all 1,539 states exact, minimum logit margin 5.006.
26
 
27
  Tier 0 is an unscored multiplication diagnostic; this modular model scored
28
- 70/100 there. All results above are local evidence, not an organizer result.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Compact reducer Teacher--Student v20
2
 
3
+ Status: validated and promoted to `submission/`. It retains the
4
+ validated v17 architecture while replacing two reducer networks with exact
5
+ GPU-distilled smaller versions. Final eligibility always remains subject to
6
+ organizer review.
7
 
8
  The model receives raw `(a, b, p)` values through lossless per-argument base-16
9
+ tokenization and emits final base-16 answer digits. A fixed feedback-free loop
10
+ feeds the raw tokens. Multiplication uses one generic learned recurrence: the
11
+ Teacher emits `ROW`, a boundary operation, or `HALT`, and only the corresponding
12
+ Student transition is evaluated. Python supplies neither the phase nor the row
13
+ index. `R^2` is emitted by the learned reducer from the fixed digit stream `1`
14
+ followed by zeros.
15
+
16
+ The only v14 architecture change is the cancellation-judge order. V12 formed
17
+ both the proposed and revised full cancellation memories and selected one.
18
+ V14 lets the same learned judge select the factor from the proposed low digit,
19
+ then performs one full learned cancellation scan. All learned modules and
20
+ weights are unchanged.
21
+
22
+ V15 additionally evaluates only the Student named by the learned Teacher's
23
+ operation token. A learned `ROW` runs the arithmetic Student; a learned
24
+ boundary runs canonical subtraction and its memory transition; learned `HALT`
25
+ runs no arithmetic Student. Python does not derive the operation, phase, or row
26
+ from the operands.
27
+
28
+ V16 retains the learned judge on every row but evaluates its learned revision
29
+ head only for rows the review head rejects. Accepted proposed factors proceed
30
+ directly to the one full cancellation scan. No parameter or checkpoint byte
31
+ changes.
32
+
33
+ V17 applies the same principle to raw-input reduction. The proposal Student and
34
+ learned review still run for every input token. The learned quotient revisor and
35
+ second Student transition run only for batch rows rejected by that review.
36
+ Python neither verifies the proposal nor calculates the revised instruction.
37
+ No parameter or checkpoint byte changes.
38
+
39
+ Fresh v16 package evidence:
40
+
41
+ - local 110-case smoke: 100/100 scored Tier 1--10 cases and 7/10 unscored
42
+ Tier-0 multiplication cases;
43
+ - official isolated four-CPU, 8-GB, no-network, read-only sandbox: 1,000/1,000
44
+ scored cases, 100/100 in every Tier 1--10, in 133.8 seconds;
45
+ - identical protected-v12 sandbox control: 1,000/1,000 in 153.8 seconds;
46
+ - rotated in-process Tier-10 benchmark: 5/5 exact in every round and median
47
+ runtime 0.8724 times the protected model;
48
+ - randomized packaged weights: 0/74 nonzero-answer cases;
49
  - official static analysis and preprocessing isolation: passed;
50
+ - package checksums: passed;
51
+ - repository tests: 391 passed;
52
  - finite learned clock: all 1,539 states exact, minimum logit margin 5.006.
53
 
54
  Tier 0 is an unscored multiplication diagnostic; this modular model scored
55
+ 70/100 in the full sandbox. All results above are local evidence, not an
56
+ organizer result.
57
+
58
+ Initial v17 evidence:
59
+
60
+ - eager/lazy equivalence on a forced mixed accept/reject batch: passed;
61
+ - strict checkpoint loading and raw-answer agreement: passed;
62
+ - rotated four-CPU Tier-10 benchmark: 5/5 exact in every one of six rounds;
63
+ - median runtime: 3.246 seconds versus v16's 4.231 seconds, or 0.7673 times
64
+ the protected-v16 runtime.
65
+
66
+ Final v17 package evidence:
67
+
68
+ - official isolated four-CPU, 8-GB, no-network, read-only sandbox: 1,000/1,000
69
+ scored cases, 100/100 in every Tier 1--10, in 115.1 seconds;
70
+ - identical-seed protected-v16 sandbox control: 1,000/1,000 in 150.1 seconds;
71
+ - randomized packaged weights: 0/76 nonzero-answer cases;
72
+ - official static analysis, determinism, and preprocessing isolation: passed;
73
+ - package checksums: passed;
74
+ - repository tests: 392 passed.
75
+
76
+ V19 GPU-distills the reducer Student on its complete 131,072-state local
77
+ domain. The 256-hidden candidate is the smallest tested network that reaches
78
+ exactness: 131,072/131,072 emitted digits and 131,072/131,072 next states. The
79
+ 192-hidden candidate misses one digit after 5,000 epochs; the 128-hidden
80
+ candidate misses 342. The exact Student has 102,640 parameters instead of
81
+ 230,576.
82
+
83
+ V20 newly distills a 2,642-parameter sequence comparator on all 265 of its
84
+ local decisions and combines it with the exact compact Student. The resulting
85
+ model has 938,028 parameters, 13.0% fewer than v17.
86
+
87
+ Initial v20 evidence:
88
+
89
+ - compact Student domain: 131,072/131,072 digits and states, minimum margin
90
+ 0.410;
91
+ - compact comparator domain: 265/265 decisions, minimum margin 3.803;
92
+ - two unseen raw Tier 1--10 suites: 100/100 and 200/200;
93
+ - rotated full-workload comparison: 100/100 exact in all six rounds;
94
+ - median runtime: 9.633 seconds versus v17's 11.362 seconds, or 0.8478 times
95
+ v17 runtime.
96
+
97
+ Final v20 package evidence:
98
+
99
+ - package checker, static analysis, determinism, and preprocessing isolation:
100
+ passed;
101
+ - fresh local suite: 100/100 scored Tier 1--10 cases;
102
+ - official isolated four-CPU, 8-GB, no-network, read-only sandbox: 1,000/1,000
103
+ scored cases, 100/100 in every Tier 1--10, in 75.8 seconds;
104
+ - identical-seed v17 control: 1,000/1,000 in 116.6 seconds, making v20's
105
+ inference time 0.6501 times v17's in this adjacent comparison;
106
+ - randomized packaged weights: 0/78 correct nonzero-answer cases;
107
+ - package checksums: passed;
108
+ - repository tests: 392 passed.
109
+
110
+ Tier 0 remains an unscored multiplication diagnostic; v20 and v17 both scored
111
+ 70/100 there on the identical sandbox set. All results are local evidence, not
112
+ an organizer result.
SHA256SUMS CHANGED
@@ -1,12 +1,14 @@
1
  5aa8f8dd7beb2365d1be489a328dd32c7b75ef240ea8e1402b7fbe7955953c75 LICENSE
2
- c606c286bc09f288ee3429147e3a0b06c56f9126d2c60dda88d17094d2476de2 PROVENANCE.md
3
- b394a18d2a7b0f351a2f5a40e5ad59c74d15c46abd2a35317f805ff24c4906f4 README.md
4
- fb2f6a4018ac791d44fd8b493a9b6ee3b907c3c3ef7bbc97c7af0e34007d4200 manifest.json
5
- 0f8ac6a01f3d536aed36065cb1c530ca3fcc2ee695b46b2a843f132bbd925caa model.py
6
  1a4a298962ac26ac2cca18656a290f6b151b9edd122a3337c786ca3876898d2e src/__init__.py
 
 
7
  abd0dbae9acd4ef8082e58cdd8e16160f6c967c19412410375d7a57121aa20a6 src/self_clocked_parallel_montgomery_teacher_student.py
8
  3b07879c00188c97e6fbdf24138e7351f02e7b9c6ebd5de7d5c41a6a45087f64 src/submission_components_v12.py
9
  c32a96a1e7569c6946a0ff09ed8b0203a90fbcea0dbafc5b11dc6cb05bad9b05 src/submission_reducer_v12.py
10
  89693321ff57a797c8b57bf73813b58916e94d64a995c80a341833e09df238c4 src/submission_student_v12.py
11
  7b691ca4b2a3309f6028f516a67d44eb175db8f148f8a258e4b12b0baf9736aa src/top_window_quotient_teacher.py
12
- aedf12d00877a4f9569f3ee010eb1f7a583a5bd131710f4ba1527340da4380f2 weights.pt
 
1
  5aa8f8dd7beb2365d1be489a328dd32c7b75ef240ea8e1402b7fbe7955953c75 LICENSE
2
+ 327b84de6422aa3d433d1a47081ef30ed76925e33e27b6f584e535d29d314839 PROVENANCE.md
3
+ d18086a9b7efce75c01623a769097667d6a9ce621d3ced0de87eebc7580d9a49 README.md
4
+ 37991a5177a78f8283a9574437e9ee91f7bdc5ff743ca52cea86ef2a2e0534f0 manifest.json
5
+ 441a996ebbcbac711c753bd564756697a54ae09b4cc44c82b9a0b276e0f88ab3 model.py
6
  1a4a298962ac26ac2cca18656a290f6b151b9edd122a3337c786ca3876898d2e src/__init__.py
7
+ 56bfa76794aaccb3cfd2c7c425a200023bf610bd092d15a5a718daa255baa617 src/judge_first_cios_self_clocked_montgomery.py
8
+ 2584e24b8402cef2f1fc5e3e5d5faad738321541eac8342171eec0145af7f400 src/lazy_reducer_self_clocked_montgomery.py
9
  abd0dbae9acd4ef8082e58cdd8e16160f6c967c19412410375d7a57121aa20a6 src/self_clocked_parallel_montgomery_teacher_student.py
10
  3b07879c00188c97e6fbdf24138e7351f02e7b9c6ebd5de7d5c41a6a45087f64 src/submission_components_v12.py
11
  c32a96a1e7569c6946a0ff09ed8b0203a90fbcea0dbafc5b11dc6cb05bad9b05 src/submission_reducer_v12.py
12
  89693321ff57a797c8b57bf73813b58916e94d64a995c80a341833e09df238c4 src/submission_student_v12.py
13
  7b691ca4b2a3309f6028f516a67d44eb175db8f148f8a258e4b12b0baf9736aa src/top_window_quotient_teacher.py
14
+ 1cfd6f501fffd0092635221444a104d181cd5117a0c67c8c1ac484701bb7669a weights.pt
manifest.json CHANGED
@@ -2,6 +2,6 @@
2
  "entry_class": "model.SelfClockedMontgomerySubmission",
3
  "output_base": 16,
4
  "framework": "pytorch",
5
- "model_description": "A 1.08M-parameter learned Teacher-Student recurrent model. Raw base-16 input tokens update learned residue memory. A trained self-clock Teacher emits row, boundary, phase, counter, and HALT decisions; trained local Students emit arithmetic state transitions; learned judges review and revise intermediate instructions. The final memory is emitted directly as base-16 answer digits.",
6
- "training_description": "All answer-producing modules were trained from random initialization with gradient descent on synthetic arithmetic traces or exhaustive finite local domains. The raw-reduction Teacher, local Student, comparator, quotient revisor, Montgomery factor, cancellation judge/revisor, subtraction cell, and p=2 router were transferred from validated checkpoints and frozen. The new self-clock Teacher was trained from random initialization for 55 AdamW steps on the complete 1539-state phase/clock domain and reached exact decisions with minimum logit margin 5.006. No evaluation answers were used for training."
7
  }
 
2
  "entry_class": "model.SelfClockedMontgomerySubmission",
3
  "output_base": 16,
4
  "framework": "pytorch",
5
+ "model_description": "A 938K-parameter learned Teacher-Student recurrent model. Raw base-16 input tokens update learned residue memory through a compact learned Student and comparator; revision runs only for rows rejected by the learned judge. A trained self-clock Teacher dynamically selects the learned multiplication Student. In each CIOS row the learned cancellation judge selects its factor before one full learned cancellation scan, and its revision head runs only for learned rejections. The final learned memory is emitted directly as base-16 answer digits.",
6
+ "training_description": "All answer-producing modules were trained from random initialization with gradient descent on synthetic arithmetic traces or exhaustive finite local domains. The compact reducer Student was newly initialized and GPU-distilled on all 131072 combinations of digit pair, instruction, and local state, reaching 131072/131072 exact digit and state decisions. The compact comparator was newly initialized and GPU-distilled on all 256 digit pairs and all nine comparison-state pairs, reaching 265/265 exact decisions. The remaining raw-reduction Teacher, judge/revisor, self-clock Teacher, Montgomery Student, factor, cancellation judge/revisor, subtraction cell, and p=2 router were transferred from validated checkpoints and frozen. No evaluation answers were used for training."
7
  }
model.py CHANGED
@@ -8,8 +8,8 @@ from typing import Sequence
8
  import torch
9
 
10
  from modchallenge.interface.base_model import ModularMultiplicationModel
11
- from src.self_clocked_parallel_montgomery_teacher_student import (
12
- SelfClockedParallelMontgomeryTeacherStudent,
13
  )
14
 
15
 
@@ -33,7 +33,7 @@ class SelfClockedMontgomerySubmission(ModularMultiplicationModel):
33
  """Raw arguments to learned recurrent memory and final base-16 digits."""
34
 
35
  def __init__(self) -> None:
36
- self.model: SelfClockedParallelMontgomeryTeacherStudent | None = None
37
  self.device: torch.device | None = None
38
 
39
  def load(self, model_dir: str) -> None:
@@ -45,7 +45,7 @@ class SelfClockedMontgomerySubmission(ModularMultiplicationModel):
45
  map_location=self.device,
46
  weights_only=True,
47
  )
48
- self.model = SelfClockedParallelMontgomeryTeacherStudent(
49
  **payload["model_config"]
50
  )
51
  self.model.load_state_dict(payload["state_dict"], strict=True)
 
8
  import torch
9
 
10
  from modchallenge.interface.base_model import ModularMultiplicationModel
11
+ from src.lazy_reducer_self_clocked_montgomery import (
12
+ LazyReducerSelfClockedMontgomery,
13
  )
14
 
15
 
 
33
  """Raw arguments to learned recurrent memory and final base-16 digits."""
34
 
35
  def __init__(self) -> None:
36
+ self.model: LazyReducerSelfClockedMontgomery | None = None
37
  self.device: torch.device | None = None
38
 
39
  def load(self, model_dir: str) -> None:
 
45
  map_location=self.device,
46
  weights_only=True,
47
  )
48
+ self.model = LazyReducerSelfClockedMontgomery(
49
  **payload["model_config"]
50
  )
51
  self.model.load_state_dict(payload["state_dict"], strict=True)
src/judge_first_cios_self_clocked_montgomery.py ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Judge-first CIOS recurrence using the trained v12 arithmetic modules."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import torch
6
+
7
+ from src.self_clocked_parallel_montgomery_teacher_student import (
8
+ OP_ENCODE_BOUNDARY,
9
+ OP_HALT,
10
+ OP_PRODUCT_BOUNDARY,
11
+ OP_ROW,
12
+ RADIX,
13
+ SelfClockedMemory,
14
+ SelfClockedParallelMontgomeryTeacherStudent,
15
+ )
16
+
17
+
18
+ class JudgeFirstCIOSSelfClockedMontgomery(
19
+ SelfClockedParallelMontgomeryTeacherStudent
20
+ ):
21
+ """Select the learned factor before one full cancellation scan."""
22
+
23
+ def _reviewed_factor(
24
+ self,
25
+ proposal_low: torch.Tensor,
26
+ modulus_low: torch.Tensor,
27
+ digit_table: torch.Tensor,
28
+ ) -> tuple[torch.Tensor, torch.Tensor]:
29
+ proposal = self._factor_instruction(
30
+ proposal_low, modulus_low, digit_table
31
+ )
32
+ local = proposal * (RADIX**2) + modulus_low * RADIX + proposal_low
33
+ cancelled_low = digit_table[local, 0]
34
+ review, revision = self.cancellation_teacher(
35
+ proposal_low,
36
+ modulus_low,
37
+ proposal,
38
+ cancelled_low,
39
+ )
40
+ accepted = review.argmax(-1).eq(0)
41
+ return torch.where(accepted, proposal, revision.argmax(-1)), accepted
42
+
43
+ def _row_candidate(
44
+ self,
45
+ memory: SelfClockedMemory,
46
+ digit_table: torch.Tensor,
47
+ carry_table: torch.Tensor,
48
+ ) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
49
+ multiplier = memory.right_lsf[:, :1].expand_as(memory.left_lsf)
50
+ proposal = self._mac_memory(
51
+ memory.left_lsf,
52
+ multiplier,
53
+ memory.work_lsf,
54
+ digit_table,
55
+ carry_table,
56
+ )
57
+ factor, accepted = self._reviewed_factor(
58
+ proposal[:, 0], memory.modulus_lsf[:, 0], digit_table
59
+ )
60
+ cancelled = self._mac_memory(
61
+ factor[:, None].expand_as(memory.modulus_lsf),
62
+ memory.modulus_lsf,
63
+ proposal,
64
+ digit_table,
65
+ carry_table,
66
+ )
67
+ if bool(cancelled[:, 0].ne(0).any().item()):
68
+ raise RuntimeError("learned reviewed CIOS factor did not cancel")
69
+ zero = torch.zeros(
70
+ (cancelled.shape[0], 1), dtype=torch.long, device=cancelled.device
71
+ )
72
+ return (
73
+ torch.cat((cancelled[:, 1:], zero), 1),
74
+ torch.cat((memory.right_lsf[:, 1:], zero), 1),
75
+ accepted,
76
+ )
77
+
78
+
79
+ class SparseJudgeFirstCIOSSelfClockedMontgomery(
80
+ JudgeFirstCIOSSelfClockedMontgomery
81
+ ):
82
+ """Evaluate only the Student selected by the learned Teacher."""
83
+
84
+ def recurrent_step(
85
+ self,
86
+ memory: SelfClockedMemory,
87
+ *,
88
+ width: int,
89
+ digit_table: torch.Tensor,
90
+ carry_table: torch.Tensor,
91
+ subtract_digits: torch.Tensor,
92
+ subtract_borrows: torch.Tensor,
93
+ ) -> tuple[SelfClockedMemory, torch.Tensor, torch.Tensor]:
94
+ operation = self.controller.instruction(memory.phase, memory.clock)
95
+ operation_id = int(operation[0].item())
96
+ if not bool(operation.eq(operation_id).all().item()):
97
+ raise RuntimeError("learned Teacher diverged within a width group")
98
+ zeros = torch.zeros_like(memory.work_lsf)
99
+ accepted = torch.zeros_like(operation, dtype=torch.bool)
100
+ left = memory.left_lsf
101
+ right = memory.right_lsf
102
+ work = memory.work_lsf
103
+ answer = memory.answer_lsf
104
+
105
+ if operation_id == OP_ROW:
106
+ work, right, accepted = self._row_candidate(
107
+ memory, digit_table, carry_table
108
+ )
109
+ elif operation_id == OP_ENCODE_BOUNDARY:
110
+ left = self._canonical_candidate(
111
+ memory.work_lsf,
112
+ memory.modulus_lsf,
113
+ subtract_digits,
114
+ subtract_borrows,
115
+ )
116
+ right = memory.saved_right_lsf
117
+ work = zeros
118
+ elif operation_id == OP_PRODUCT_BOUNDARY:
119
+ answer = self._canonical_candidate(
120
+ memory.work_lsf,
121
+ memory.modulus_lsf,
122
+ subtract_digits,
123
+ subtract_borrows,
124
+ )
125
+ elif operation_id != OP_HALT:
126
+ raise RuntimeError("learned Teacher emitted an unknown operation")
127
+
128
+ phase, clock = self.controller.advance(
129
+ memory.phase, memory.clock, operation, width=width
130
+ )
131
+ return (
132
+ SelfClockedMemory(
133
+ left,
134
+ right,
135
+ memory.modulus_lsf,
136
+ memory.saved_right_lsf,
137
+ work,
138
+ answer,
139
+ phase,
140
+ clock,
141
+ ),
142
+ operation,
143
+ accepted,
144
+ )
145
+
146
+
147
+ class LazyRevisionSparseJudgeFirstCIOS(
148
+ SparseJudgeFirstCIOSSelfClockedMontgomery
149
+ ):
150
+ """Run the learned revision head only for learned rejections."""
151
+
152
+ def _reviewed_factor(
153
+ self,
154
+ proposal_low: torch.Tensor,
155
+ modulus_low: torch.Tensor,
156
+ digit_table: torch.Tensor,
157
+ ) -> tuple[torch.Tensor, torch.Tensor]:
158
+ proposal = self._factor_instruction(
159
+ proposal_low, modulus_low, digit_table
160
+ )
161
+ local = proposal * (RADIX**2) + modulus_low * RADIX + proposal_low
162
+ cancelled_low = digit_table[local, 0]
163
+ teacher = self.cancellation_teacher
164
+ review = teacher.review(teacher.cancelled(cancelled_low))
165
+ accepted = review.argmax(-1).eq(0)
166
+ if bool(accepted.all().item()):
167
+ return proposal, accepted
168
+
169
+ rejected = ~accepted
170
+ revision = teacher.revise(
171
+ torch.cat(
172
+ (
173
+ teacher.low(proposal_low[rejected]),
174
+ teacher.modulus(modulus_low[rejected]),
175
+ teacher.proposal(proposal[rejected]),
176
+ teacher.cancelled(cancelled_low[rejected]),
177
+ ),
178
+ -1,
179
+ )
180
+ ).argmax(-1)
181
+ selected = proposal.clone()
182
+ selected[rejected] = revision
183
+ return selected, accepted
184
+
185
+
186
+ __all__ = [
187
+ "JudgeFirstCIOSSelfClockedMontgomery",
188
+ "LazyRevisionSparseJudgeFirstCIOS",
189
+ "SparseJudgeFirstCIOSSelfClockedMontgomery",
190
+ ]
src/lazy_reducer_self_clocked_montgomery.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Self-clocked Montgomery model with lazy learned reducer revision."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import torch
6
+
7
+ from src.judge_first_cios_self_clocked_montgomery import (
8
+ LazyRevisionSparseJudgeFirstCIOS,
9
+ )
10
+ from src.submission_reducer_v12 import (
11
+ FastStreamingMemoryReducer,
12
+ ParallelStateStudentPrediction,
13
+ )
14
+
15
+
16
+ class LazyRevisionFastStreamingMemoryReducer(FastStreamingMemoryReducer):
17
+ """Evaluate the learned revision Student only for learned rejections."""
18
+
19
+ def transition(
20
+ self,
21
+ state_msb: torch.Tensor,
22
+ next_digit: torch.Tensor,
23
+ modulus_msb: torch.Tensor,
24
+ *,
25
+ width_class: int,
26
+ digit_maps: torch.Tensor,
27
+ state_maps: torch.Tensor,
28
+ ) -> tuple[torch.Tensor, torch.Tensor]:
29
+ batch, width = state_msb.shape
30
+ shifted_lsf = torch.cat((next_digit[:, None], state_msb.flip(1)), 1)[
31
+ :, :width
32
+ ]
33
+ modulus_lsf = modulus_msb.flip(1)
34
+ teacher_width = torch.full(
35
+ (batch,),
36
+ min(int(width_class), self.teacher.window_digits + 1),
37
+ dtype=torch.long,
38
+ device=state_msb.device,
39
+ )
40
+ instruction = self.teacher(
41
+ self._top_window(state_msb, self.teacher.window_digits),
42
+ self._top_window(modulus_msb, self.teacher.window_digits),
43
+ next_digit,
44
+ teacher_width,
45
+ ).argmax(-1)
46
+ proposal = self.student(
47
+ shifted_lsf, modulus_lsf, instruction, digit_maps, state_maps
48
+ )
49
+ review = self._review(state_msb, modulus_msb, proposal)
50
+ accepted = review.argmax(-1).eq(1)
51
+ if bool(accepted.all().item()):
52
+ return proposal.digits_lsf.flip(1), accepted
53
+
54
+ rejected = ~accepted
55
+ revised_instruction = self.quotient_step(
56
+ instruction[rejected], review[rejected]
57
+ ).argmax(-1)
58
+ revision: ParallelStateStudentPrediction = self.student(
59
+ shifted_lsf[rejected],
60
+ modulus_lsf[rejected],
61
+ revised_instruction,
62
+ digit_maps,
63
+ state_maps,
64
+ )
65
+ selected = proposal.digits_lsf.clone()
66
+ selected[rejected] = revision.digits_lsf
67
+ return selected.flip(1), accepted
68
+
69
+
70
+ class LazyReducerSelfClockedMontgomery(LazyRevisionSparseJudgeFirstCIOS):
71
+ """V16 arithmetic with lazy learned revision in both major recurrences."""
72
+
73
+ def __init__(self, **config: dict) -> None:
74
+ super().__init__(**config)
75
+ self.reducer = LazyRevisionFastStreamingMemoryReducer(**config["reducer"])
76
+
77
+
78
+ __all__ = [
79
+ "LazyReducerSelfClockedMontgomery",
80
+ "LazyRevisionFastStreamingMemoryReducer",
81
+ ]
weights.pt CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:aedf12d00877a4f9569f3ee010eb1f7a583a5bd131710f4ba1527340da4380f2
3
- size 4344987
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1cfd6f501fffd0092635221444a104d181cd5117a0c67c8c1ac484701bb7669a
3
+ size 3787433