cleanup submission: model.py
Browse files
model.py
CHANGED
|
@@ -66,6 +66,14 @@ class ModMulBP(ModularMultiplicationModel):
|
|
| 66 |
self.regime = self.base ** self.W
|
| 67 |
else:
|
| 68 |
self.regime = 10 ** self.W
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
# Trained prime span (for router dispatch): derived from the ckpt's
|
| 70 |
# tier list via the official tier geometry; fallback = full regime.
|
| 71 |
self.p_lo, self.p_hi = 2, self.regime - 1
|
|
@@ -96,7 +104,13 @@ class ModMulBP(ModularMultiplicationModel):
|
|
| 96 |
@torch.no_grad()
|
| 97 |
def predict_digits_batch(self, inputs):
|
| 98 |
out = [[0]] * len(inputs)
|
| 99 |
-
if self.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
prompt_fn = lambda p, x, y, W: cenc.prompt_str( # noqa: E731
|
| 101 |
x, y, p, W, self.base, self.subpad)
|
| 102 |
n_gen = cenc.gen_len(self.W, self.scratch, self.cursor, self.subpad,
|
|
@@ -116,9 +130,12 @@ class ModMulBP(ModularMultiplicationModel):
|
|
| 116 |
else enc.decode_answer)
|
| 117 |
prompts, idx = [], []
|
| 118 |
for i, (a, b, p) in enumerate(inputs):
|
| 119 |
-
if p >= self.regime: # outside trained width -> honest 0
|
| 120 |
-
continue
|
| 121 |
x, y = a % p, b % p
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
prompts.append(prompt_fn(p, x, y, self.W))
|
| 123 |
idx.append((i, x, y, p))
|
| 124 |
if not prompts:
|
|
|
|
| 66 |
self.regime = self.base ** self.W
|
| 67 |
else:
|
| 68 |
self.regime = 10 ** self.W
|
| 69 |
+
self.mulonly = bool(ckpt.get("mulonly", False))
|
| 70 |
+
if self.mulonly:
|
| 71 |
+
# Tier-0 member: pure multiplication. p never enters the trace --
|
| 72 |
+
# the operand width is the only constraint, so claim every p the
|
| 73 |
+
# specialists don't (router sorts by regime, this sorts last).
|
| 74 |
+
self.regime = 10 ** (2 * self.W)
|
| 75 |
+
self.p_lo, self.p_hi = 2, 2 ** 4096
|
| 76 |
+
return
|
| 77 |
# Trained prime span (for router dispatch): derived from the ckpt's
|
| 78 |
# tier list via the official tier geometry; fallback = full regime.
|
| 79 |
self.p_lo, self.p_hi = 2, self.regime - 1
|
|
|
|
| 104 |
@torch.no_grad()
|
| 105 |
def predict_digits_batch(self, inputs):
|
| 106 |
out = [[0]] * len(inputs)
|
| 107 |
+
if self.mulonly:
|
| 108 |
+
prompt_fn = lambda p, x, y, W: cenc.prompt_str( # noqa: E731
|
| 109 |
+
x, y, p, W, 10, mulonly=True)
|
| 110 |
+
n_gen = cenc.gen_len(self.W, mulonly=True)
|
| 111 |
+
decode_fn = lambda g, W: cenc.decode_answer( # noqa: E731
|
| 112 |
+
g, W, 10, mulonly=True)
|
| 113 |
+
elif self.composed:
|
| 114 |
prompt_fn = lambda p, x, y, W: cenc.prompt_str( # noqa: E731
|
| 115 |
x, y, p, W, self.base, self.subpad)
|
| 116 |
n_gen = cenc.gen_len(self.W, self.scratch, self.cursor, self.subpad,
|
|
|
|
| 130 |
else enc.decode_answer)
|
| 131 |
prompts, idx = [], []
|
| 132 |
for i, (a, b, p) in enumerate(inputs):
|
|
|
|
|
|
|
| 133 |
x, y = a % p, b % p
|
| 134 |
+
if self.mulonly:
|
| 135 |
+
if max(x, y) >= 10 ** self.W: # operands don't fit -> honest 0
|
| 136 |
+
continue
|
| 137 |
+
elif p >= self.regime: # outside trained width -> honest 0
|
| 138 |
+
continue
|
| 139 |
prompts.append(prompt_fn(p, x, y, self.W))
|
| 140 |
idx.append((i, x, y, p))
|
| 141 |
if not prompts:
|