guldo-cli 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. guldo/__init__.py +0 -0
  2. guldo/_src/COMPILER.md +329 -0
  3. guldo/_src/DEPLOY.md +200 -0
  4. guldo/_src/LAUNCH.md +85 -0
  5. guldo/_src/PROTOCOL.md +294 -0
  6. guldo/_src/RULES.md +25 -0
  7. guldo/_src/SUBMIT.md +170 -0
  8. guldo/_src/__init__.py +0 -0
  9. guldo/_src/attest.py +257 -0
  10. guldo/_src/build_site.py +958 -0
  11. guldo/_src/bundle_templates/check.py +1382 -0
  12. guldo/_src/bundle_templates/qcheck.py +253 -0
  13. guldo/_src/bundle_templates/qscore.py +402 -0
  14. guldo/_src/bundle_templates/score.py +649 -0
  15. guldo/_src/certificate.py +828 -0
  16. guldo/_src/certs_site.py +108 -0
  17. guldo/_src/claims.py +343 -0
  18. guldo/_src/compile_domain.py +1312 -0
  19. guldo/_src/compile_quality.py +286 -0
  20. guldo/_src/count_runner.py +248 -0
  21. guldo/_src/counted.py +274 -0
  22. guldo/_src/declared.py +215 -0
  23. guldo/_src/deploy/Caddyfile +48 -0
  24. guldo/_src/deploy/ledger-backup.service +9 -0
  25. guldo/_src/deploy/ledger-backup.sh +73 -0
  26. guldo/_src/deploy/ledger-backup.timer +10 -0
  27. guldo/_src/deploy/ledger-export.service +12 -0
  28. guldo/_src/deploy/ledger-export.timer +9 -0
  29. guldo/_src/deploy/ledger-web.service +38 -0
  30. guldo/_src/deploy/pin_cpu.sh +34 -0
  31. guldo/_src/deploy/provision_eval.sh +128 -0
  32. guldo/_src/deploy_smoke.py +148 -0
  33. guldo/_src/dlog_experiment.py +165 -0
  34. guldo/_src/domains/aidecode/compiled.json +586 -0
  35. guldo/_src/domains/aidecode/decl.py +134 -0
  36. guldo/_src/domains/aidecode/reference.py +73 -0
  37. guldo/_src/domains/aiinfer/compiled.json +722 -0
  38. guldo/_src/domains/aiinfer/decl.py +91 -0
  39. guldo/_src/domains/aiinfer/reference.py +42 -0
  40. guldo/_src/domains/dlog/compiled.json +248 -0
  41. guldo/_src/domains/dlog/decl.py +41 -0
  42. guldo/_src/domains/dlog/reference.py +10 -0
  43. guldo/_src/domains/maxcut/compiled.json +291 -0
  44. guldo/_src/domains/maxcut/decl.py +46 -0
  45. guldo/_src/domains/maxcut/reference.py +16 -0
  46. guldo/_src/drift_check.py +89 -0
  47. guldo/_src/export_bundle.py +750 -0
  48. guldo/_src/extrapolate.py +326 -0
  49. guldo/_src/families.py +53 -0
  50. guldo/_src/gen_cheat_table.py +36 -0
  51. guldo/_src/gpu_meter.py +634 -0
  52. guldo/_src/gpu_runner.py +63 -0
  53. guldo/_src/harness.py +273 -0
  54. guldo/_src/instances.py +86 -0
  55. guldo/_src/instances_factor.py +40 -0
  56. guldo/_src/instances_mlwe.py +69 -0
  57. guldo/_src/judge.py +278 -0
  58. guldo/_src/limits_plan.py +158 -0
  59. guldo/_src/official.py +189 -0
  60. guldo/_src/ops.py +281 -0
  61. guldo/_src/portal.py +313 -0
  62. guldo/_src/portal_core.py +57 -0
  63. guldo/_src/power.py +174 -0
  64. guldo/_src/prereg.py +173 -0
  65. guldo/_src/public_portal.py +500 -0
  66. guldo/_src/quality_core.py +126 -0
  67. guldo/_src/recheck.py +236 -0
  68. guldo/_src/remeasure.py +88 -0
  69. guldo/_src/report_html.py +493 -0
  70. guldo/_src/results/.keep +0 -0
  71. guldo/_src/rounds.py +846 -0
  72. guldo/_src/runner.py +52 -0
  73. guldo/_src/sandbox/Dockerfile +11 -0
  74. guldo/_src/sandbox/Dockerfile.v2 +19 -0
  75. guldo/_src/sandbox/README.md +40 -0
  76. guldo/_src/sandbox/linux_selftest.py +117 -0
  77. guldo/_src/sandbox/meter.py +89 -0
  78. guldo/_src/sandbox/meter_core.py +28 -0
  79. guldo/_src/site_assets.py +176 -0
  80. guldo/_src/site_live_check.py +79 -0
  81. guldo/_src/solvers/aidecode_flops_kv.py +73 -0
  82. guldo/_src/solvers/aidecode_flops_lossy.py +73 -0
  83. guldo/_src/solvers/aidecode_flops_ref.py +64 -0
  84. guldo/_src/solvers/aidecode_kv.py +76 -0
  85. guldo/_src/solvers/aidecode_kv_f32.py +77 -0
  86. guldo/_src/solvers/aidecode_lossy.py +76 -0
  87. guldo/_src/solvers/aidecode_repeat.py +5 -0
  88. guldo/_src/solvers/aiinfer_batched.py +40 -0
  89. guldo/_src/solvers/aiinfer_f32.py +41 -0
  90. guldo/_src/solvers/aiinfer_gpu_batched.py +42 -0
  91. guldo/_src/solvers/aiinfer_gpu_ref.py +45 -0
  92. guldo/_src/solvers/aiinfer_lossy.py +42 -0
  93. guldo/_src/solvers/baseline_bkz.py +14 -0
  94. guldo/_src/solvers/cheat_lookup.py +24 -0
  95. guldo/_src/solvers/cheat_table.json +1 -0
  96. guldo/_src/solvers/cheat_table_v1_stale.json +1 -0
  97. guldo/_src/solvers/daemon_cpu_hider.py +17 -0
  98. guldo/_src/solvers/dlog_bsgs.py +19 -0
  99. guldo/_src/solvers/dlog_stride4.py +18 -0
  100. guldo/_src/solvers/egg_base.py +11 -0
  101. guldo/_src/solvers/egg_eightaxis.py +68 -0
  102. guldo/_src/solvers/egg_template.py +11 -0
  103. guldo/_src/solvers/factor_brent.py +34 -0
  104. guldo/_src/solvers/factor_floyd.py +19 -0
  105. guldo/_src/solvers/factor_trial_fast_py.py +21 -0
  106. guldo/_src/solvers/factor_trial_np.py +21 -0
  107. guldo/_src/solvers/factor_trial_py.py +12 -0
  108. guldo/_src/solvers/fixed_overhead_ref.py +21 -0
  109. guldo/_src/solvers/fork_bomb.py +18 -0
  110. guldo/_src/solvers/gpu_noop.py +6 -0
  111. guldo/_src/solvers/hostile_probe.py +36 -0
  112. guldo/_src/solvers/kill_meter.py +27 -0
  113. guldo/_src/solvers/memory_bomb.py +10 -0
  114. guldo/_src/solvers/noop.py +5 -0
  115. guldo/_src/solvers/orphan_cpu_hider.py +16 -0
  116. guldo/_src/solvers/planted_peek.py +23 -0
  117. guldo/_src/solvers/sleeping_daemon_hang.py +12 -0
  118. guldo/_src/solvers/small_n_trick.py +22 -0
  119. guldo/_src/solvers/starter_template.py +21 -0
  120. guldo/_src/solvers/stdout_flood.py +9 -0
  121. guldo/_src/solvers/tmp_fill.py +10 -0
  122. guldo/_src/solvers/tuned_bkz.py +25 -0
  123. guldo/_src/static_check.py +214 -0
  124. guldo/_src/submit_check.py +166 -0
  125. guldo/_src/svp.py +889 -0
  126. guldo/_src/tensorops.py +304 -0
  127. guldo/_src/tflops.py +453 -0
  128. guldo/_src/tflops_runner.py +134 -0
  129. guldo/cli.py +60 -0
  130. guldo_cli-0.1.0.dist-info/METADATA +30 -0
  131. guldo_cli-0.1.0.dist-info/RECORD +134 -0
  132. guldo_cli-0.1.0.dist-info/WHEEL +5 -0
  133. guldo_cli-0.1.0.dist-info/entry_points.txt +2 -0
  134. guldo_cli-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,73 @@
1
+ """aidecode in the counted-operations API, SPEEDUP: a KV cache. Same tokens as the reference with O(1) projections per step."""
2
+ import math
3
+
4
+ import tensorops as tp
5
+
6
+ V, D, H, DH, FF, L, PROMPT = 64, 128, 4, 32, 512, 2, 8
7
+ W_SCALE, POS_SCALE = 4.0, 3.0
8
+
9
+
10
+ def take_param(off, seed, shape, scale):
11
+ n = 1
12
+ for s in shape:
13
+ n *= s
14
+ a = tp.stream(seed, off[0], n, shape) * scale
15
+ off[0] += n
16
+ return a
17
+
18
+
19
+ def build(seed, T):
20
+ off = [0]
21
+ sd = W_SCALE * math.sqrt(3.0 / D)
22
+ sf = W_SCALE * math.sqrt(3.0 / FF)
23
+ P = {"tok": take_param(off, seed, (V, D), math.sqrt(3.0)), "layers": []}
24
+ for i in range(L):
25
+ P["layers"].append({"Wq": take_param(off, seed, (D, D), sd), "Wk": take_param(off, seed, (D, D), sd), "Wv": take_param(off, seed, (D, D), sd),
26
+ "Wo": take_param(off, seed, (D, D), sd), "W1": take_param(off, seed, (D, FF), sd), "W2": take_param(off, seed, (FF, D), sf)})
27
+ P["pos"] = take_param(off, seed, (PROMPT + T, D), POS_SCALE * math.sqrt(3.0))
28
+ u = tp.stream(seed, off[0], PROMPT).tolist()
29
+ P["prompt"] = [min(int((x + 1.0) * 0.5 * V), V - 1) for x in u]
30
+ return P
31
+
32
+
33
+ def rms(x):
34
+ return x / tp.sqrt(tp.mean(x * x, -1, True) + 1e-6)
35
+
36
+
37
+ def softmax_rows(s):
38
+ s = s - tp.max(s, -1, True)
39
+ a = tp.exp(s)
40
+ return a / tp.sum(a, -1, True)
41
+
42
+
43
+ def decode(P, T, layers_used):
44
+ n = PROMPT + T
45
+ K = [tp.zeros((n, D)) for i in range(L)]
46
+ Vv = [tp.zeros((n, D)) for i in range(L)]
47
+ seq = list(P["prompt"])
48
+ out = []
49
+ for p in range(n - 1):
50
+ x = tp.take(P["tok"], seq[p]) + P["pos"][p]
51
+ li = 0
52
+ for l in P["layers"]:
53
+ if li >= layers_used:
54
+ break
55
+ h = rms(x)
56
+ q = tp.reshape(h @ l["Wq"], (H, DH))
57
+ K[li][p] = h @ l["Wk"]
58
+ Vv[li][p] = h @ l["Wv"]
59
+ kc = tp.reshape(K[li][0:p + 1], (p + 1, H, DH))
60
+ vc = tp.reshape(Vv[li][0:p + 1], (p + 1, H, DH))
61
+ a = softmax_rows(tp.einsum("hd,thd->ht", q, kc) / math.sqrt(DH))
62
+ x = x + tp.reshape(tp.einsum("ht,thd->hd", a, vc), (D,)) @ l["Wo"]
63
+ x = x + tp.relu(rms(x) @ l["W1"]) @ l["W2"]
64
+ li += 1
65
+ if p >= PROMPT - 1:
66
+ t = tp.argmax(rms(x) @ tp.transpose(P["tok"], (1, 0)))
67
+ out.append(t)
68
+ seq.append(t)
69
+ return out
70
+
71
+
72
+ def solve(seed, prompt_len, T):
73
+ return decode(build(seed, T), T, L)
@@ -0,0 +1,73 @@
1
+ """aidecode counted-operations RED TEAM: skips the second layer (fewer operations, wrong tokens). The verifier must reject it."""
2
+ import math
3
+
4
+ import tensorops as tp
5
+
6
+ V, D, H, DH, FF, L, PROMPT = 64, 128, 4, 32, 512, 2, 8
7
+ W_SCALE, POS_SCALE = 4.0, 3.0
8
+
9
+
10
+ def take_param(off, seed, shape, scale):
11
+ n = 1
12
+ for s in shape:
13
+ n *= s
14
+ a = tp.stream(seed, off[0], n, shape) * scale
15
+ off[0] += n
16
+ return a
17
+
18
+
19
+ def build(seed, T):
20
+ off = [0]
21
+ sd = W_SCALE * math.sqrt(3.0 / D)
22
+ sf = W_SCALE * math.sqrt(3.0 / FF)
23
+ P = {"tok": take_param(off, seed, (V, D), math.sqrt(3.0)), "layers": []}
24
+ for i in range(L):
25
+ P["layers"].append({"Wq": take_param(off, seed, (D, D), sd), "Wk": take_param(off, seed, (D, D), sd), "Wv": take_param(off, seed, (D, D), sd),
26
+ "Wo": take_param(off, seed, (D, D), sd), "W1": take_param(off, seed, (D, FF), sd), "W2": take_param(off, seed, (FF, D), sf)})
27
+ P["pos"] = take_param(off, seed, (PROMPT + T, D), POS_SCALE * math.sqrt(3.0))
28
+ u = tp.stream(seed, off[0], PROMPT).tolist()
29
+ P["prompt"] = [min(int((x + 1.0) * 0.5 * V), V - 1) for x in u]
30
+ return P
31
+
32
+
33
+ def rms(x):
34
+ return x / tp.sqrt(tp.mean(x * x, -1, True) + 1e-6)
35
+
36
+
37
+ def softmax_rows(s):
38
+ s = s - tp.max(s, -1, True)
39
+ a = tp.exp(s)
40
+ return a / tp.sum(a, -1, True)
41
+
42
+
43
+ def decode(P, T, layers_used):
44
+ n = PROMPT + T
45
+ K = [tp.zeros((n, D)) for i in range(L)]
46
+ Vv = [tp.zeros((n, D)) for i in range(L)]
47
+ seq = list(P["prompt"])
48
+ out = []
49
+ for p in range(n - 1):
50
+ x = tp.take(P["tok"], seq[p]) + P["pos"][p]
51
+ li = 0
52
+ for l in P["layers"]:
53
+ if li >= layers_used:
54
+ break
55
+ h = rms(x)
56
+ q = tp.reshape(h @ l["Wq"], (H, DH))
57
+ K[li][p] = h @ l["Wk"]
58
+ Vv[li][p] = h @ l["Wv"]
59
+ kc = tp.reshape(K[li][0:p + 1], (p + 1, H, DH))
60
+ vc = tp.reshape(Vv[li][0:p + 1], (p + 1, H, DH))
61
+ a = softmax_rows(tp.einsum("hd,thd->ht", q, kc) / math.sqrt(DH))
62
+ x = x + tp.reshape(tp.einsum("ht,thd->hd", a, vc), (D,)) @ l["Wo"]
63
+ x = x + tp.relu(rms(x) @ l["W1"]) @ l["W2"]
64
+ li += 1
65
+ if p >= PROMPT - 1:
66
+ t = tp.argmax(rms(x) @ tp.transpose(P["tok"], (1, 0)))
67
+ out.append(t)
68
+ seq.append(t)
69
+ return out
70
+
71
+
72
+ def solve(seed, prompt_len, T):
73
+ return decode(build(seed, T), T, 1)
@@ -0,0 +1,64 @@
1
+ """aidecode in the counted-operations API, REFERENCE: recompute the whole sequence for every generated token (no KV cache)."""
2
+ import math
3
+
4
+ import tensorops as tp
5
+
6
+ V, D, H, DH, FF, L, PROMPT = 64, 128, 4, 32, 512, 2, 8
7
+ W_SCALE, POS_SCALE = 4.0, 3.0
8
+
9
+
10
+ def take_param(off, seed, shape, scale):
11
+ n = 1
12
+ for s in shape:
13
+ n *= s
14
+ a = tp.stream(seed, off[0], n, shape) * scale
15
+ off[0] += n
16
+ return a
17
+
18
+
19
+ def build(seed, T):
20
+ off = [0]
21
+ sd = W_SCALE * math.sqrt(3.0 / D)
22
+ sf = W_SCALE * math.sqrt(3.0 / FF)
23
+ P = {"tok": take_param(off, seed, (V, D), math.sqrt(3.0)), "layers": []}
24
+ for i in range(L):
25
+ P["layers"].append({"Wq": take_param(off, seed, (D, D), sd), "Wk": take_param(off, seed, (D, D), sd), "Wv": take_param(off, seed, (D, D), sd),
26
+ "Wo": take_param(off, seed, (D, D), sd), "W1": take_param(off, seed, (D, FF), sd), "W2": take_param(off, seed, (FF, D), sf)})
27
+ P["pos"] = take_param(off, seed, (PROMPT + T, D), POS_SCALE * math.sqrt(3.0))
28
+ u = tp.stream(seed, off[0], PROMPT).tolist()
29
+ P["prompt"] = [min(int((x + 1.0) * 0.5 * V), V - 1) for x in u]
30
+ return P
31
+
32
+
33
+ def rms(x):
34
+ return x / tp.sqrt(tp.mean(x * x, -1, True) + 1e-6)
35
+
36
+
37
+ def softmax_rows(s):
38
+ s = s - tp.max(s, -1, True)
39
+ a = tp.exp(s)
40
+ return a / tp.sum(a, -1, True)
41
+
42
+
43
+ def forward_last(P, toks):
44
+ n = len(toks)
45
+ x = tp.take(P["tok"], toks) + P["pos"][0:n]
46
+ mask = tp.causal_mask(n)
47
+ for l in P["layers"]:
48
+ h = rms(x)
49
+ q = tp.transpose(tp.reshape(h @ l["Wq"], (n, H, DH)), (1, 0, 2))
50
+ k = tp.transpose(tp.reshape(h @ l["Wk"], (n, H, DH)), (1, 0, 2))
51
+ v = tp.transpose(tp.reshape(h @ l["Wv"], (n, H, DH)), (1, 0, 2))
52
+ a = softmax_rows((q @ tp.transpose(k, (0, 2, 1))) / math.sqrt(DH) + mask)
53
+ o = tp.reshape(tp.transpose(a @ v, (1, 0, 2)), (n, D))
54
+ x = x + o @ l["Wo"]
55
+ x = x + tp.relu(rms(x) @ l["W1"]) @ l["W2"]
56
+ return rms(x[n - 1]) @ tp.transpose(P["tok"], (1, 0))
57
+
58
+
59
+ def solve(seed, prompt_len, T):
60
+ P = build(seed, T)
61
+ seq = list(P["prompt"])
62
+ for step in range(T):
63
+ seq.append(tp.argmax(forward_last(P, seq)))
64
+ return seq[PROMPT:]
@@ -0,0 +1,76 @@
1
+ """aidecode speedup 1: a KV cache in float64 (the textbook inference optimisation). Same tokens as the reference.
2
+ """
3
+ import math
4
+
5
+ import numpy as np
6
+
7
+ V, D, H, DH, FF, L, PROMPT = 64, 128, 4, 32, 512, 2, 8
8
+ W_SCALE, POS_SCALE = 4.0, 3.0
9
+ _GOLD = 0x9E3779B97F4A7C15
10
+ _C1 = 0xBF58476D1CE4E5B9
11
+ _C2 = 0x94D049BB133111EB
12
+
13
+
14
+ def _uniform(seed, start, n):
15
+ u = np.uint64
16
+ with np.errstate(over="ignore"):
17
+ z = (np.arange(start, start + n, dtype=u) + u(1)) * u(_GOLD) + u(seed)
18
+ z = (z ^ (z >> u(30))) * u(_C1)
19
+ z = (z ^ (z >> u(27))) * u(_C2)
20
+ z = z ^ (z >> u(31))
21
+ return (z >> u(11)).astype(np.float64) * 2.0 ** -52 - 1.0
22
+
23
+
24
+ def _params(seed, T):
25
+ o = [0]
26
+
27
+ def take(shape, scale):
28
+ n = int(np.prod(shape))
29
+ a = (_uniform(seed, o[0], n) * scale).reshape(shape)
30
+ o[0] += n
31
+ return a
32
+ sd, sf = W_SCALE * math.sqrt(3.0 / D), W_SCALE * math.sqrt(3.0 / FF)
33
+ P = {"tok": take((V, D), math.sqrt(3.0)), "layers": []}
34
+ for _ in range(L):
35
+ P["layers"].append({"Wq": take((D, D), sd), "Wk": take((D, D), sd), "Wv": take((D, D), sd), "Wo": take((D, D), sd),
36
+ "W1": take((D, FF), sd), "W2": take((FF, D), sf)})
37
+ P["pos"] = take((PROMPT + T, D), POS_SCALE * math.sqrt(3.0))
38
+ P["prompt"] = np.minimum(((_uniform(seed, o[0], PROMPT) + 1.0) * 0.5 * V).astype(np.int64), V - 1)
39
+ return P
40
+
41
+
42
+ def _rms(x):
43
+ return x / np.sqrt((x * x).mean(axis=-1, keepdims=True) + 1e-6)
44
+
45
+
46
+ def _decode(P, T, dt):
47
+ """Greedy decoding with a KV cache in dtype `dt`: one token's projections per step instead of the whole sequence's."""
48
+ n = PROMPT + T
49
+ layers = [{k: w.astype(dt) for k, w in l.items()} for l in P["layers"]]
50
+ tok, pos = P["tok"].astype(dt), P["pos"].astype(dt)
51
+ K = [np.zeros((n, D), dt) for _ in range(L)]
52
+ Vv = [np.zeros((n, D), dt) for _ in range(L)]
53
+ seq = [int(t) for t in P["prompt"]]
54
+ out = []
55
+ for p in range(n - 1):
56
+ x = tok[seq[p]] + pos[p]
57
+ for li, l in enumerate(layers):
58
+ h = _rms(x)
59
+ q = (h @ l["Wq"]).reshape(H, DH)
60
+ K[li][p], Vv[li][p] = h @ l["Wk"], h @ l["Wv"]
61
+ kc = K[li][:p + 1].reshape(p + 1, H, DH)
62
+ vc = Vv[li][:p + 1].reshape(p + 1, H, DH)
63
+ s = np.einsum("hd,thd->ht", q, kc) / dt(math.sqrt(DH))
64
+ s -= s.max(-1, keepdims=True)
65
+ a = np.exp(s)
66
+ a /= a.sum(-1, keepdims=True)
67
+ x = x + np.einsum("ht,thd->hd", a, vc).reshape(D) @ l["Wo"]
68
+ x = x + np.maximum(_rms(x) @ l["W1"], 0) @ l["W2"]
69
+ if p >= PROMPT - 1:
70
+ t = int(np.argmax(_rms(x) @ tok.T))
71
+ out.append(t)
72
+ seq.append(t)
73
+ return out
74
+
75
+ def solve(seed, prompt_len, T):
76
+ return _decode(_params(seed, T), T, np.float64)
@@ -0,0 +1,77 @@
1
+ """aidecode speedup 2: a KV cache AND float32 (parameters cast after the exact float64 regeneration).
2
+ Passes the verifier's tolerance on tokens whose margin exceeds float32 noise; an inexact path would be rejected.
3
+ """
4
+ import math
5
+
6
+ import numpy as np
7
+
8
+ V, D, H, DH, FF, L, PROMPT = 64, 128, 4, 32, 512, 2, 8
9
+ W_SCALE, POS_SCALE = 4.0, 3.0
10
+ _GOLD = 0x9E3779B97F4A7C15
11
+ _C1 = 0xBF58476D1CE4E5B9
12
+ _C2 = 0x94D049BB133111EB
13
+
14
+
15
+ def _uniform(seed, start, n):
16
+ u = np.uint64
17
+ with np.errstate(over="ignore"):
18
+ z = (np.arange(start, start + n, dtype=u) + u(1)) * u(_GOLD) + u(seed)
19
+ z = (z ^ (z >> u(30))) * u(_C1)
20
+ z = (z ^ (z >> u(27))) * u(_C2)
21
+ z = z ^ (z >> u(31))
22
+ return (z >> u(11)).astype(np.float64) * 2.0 ** -52 - 1.0
23
+
24
+
25
+ def _params(seed, T):
26
+ o = [0]
27
+
28
+ def take(shape, scale):
29
+ n = int(np.prod(shape))
30
+ a = (_uniform(seed, o[0], n) * scale).reshape(shape)
31
+ o[0] += n
32
+ return a
33
+ sd, sf = W_SCALE * math.sqrt(3.0 / D), W_SCALE * math.sqrt(3.0 / FF)
34
+ P = {"tok": take((V, D), math.sqrt(3.0)), "layers": []}
35
+ for _ in range(L):
36
+ P["layers"].append({"Wq": take((D, D), sd), "Wk": take((D, D), sd), "Wv": take((D, D), sd), "Wo": take((D, D), sd),
37
+ "W1": take((D, FF), sd), "W2": take((FF, D), sf)})
38
+ P["pos"] = take((PROMPT + T, D), POS_SCALE * math.sqrt(3.0))
39
+ P["prompt"] = np.minimum(((_uniform(seed, o[0], PROMPT) + 1.0) * 0.5 * V).astype(np.int64), V - 1)
40
+ return P
41
+
42
+
43
+ def _rms(x):
44
+ return x / np.sqrt((x * x).mean(axis=-1, keepdims=True) + 1e-6)
45
+
46
+
47
+ def _decode(P, T, dt):
48
+ """Greedy decoding with a KV cache in dtype `dt`: one token's projections per step instead of the whole sequence's."""
49
+ n = PROMPT + T
50
+ layers = [{k: w.astype(dt) for k, w in l.items()} for l in P["layers"]]
51
+ tok, pos = P["tok"].astype(dt), P["pos"].astype(dt)
52
+ K = [np.zeros((n, D), dt) for _ in range(L)]
53
+ Vv = [np.zeros((n, D), dt) for _ in range(L)]
54
+ seq = [int(t) for t in P["prompt"]]
55
+ out = []
56
+ for p in range(n - 1):
57
+ x = tok[seq[p]] + pos[p]
58
+ for li, l in enumerate(layers):
59
+ h = _rms(x)
60
+ q = (h @ l["Wq"]).reshape(H, DH)
61
+ K[li][p], Vv[li][p] = h @ l["Wk"], h @ l["Wv"]
62
+ kc = K[li][:p + 1].reshape(p + 1, H, DH)
63
+ vc = Vv[li][:p + 1].reshape(p + 1, H, DH)
64
+ s = np.einsum("hd,thd->ht", q, kc) / dt(math.sqrt(DH))
65
+ s -= s.max(-1, keepdims=True)
66
+ a = np.exp(s)
67
+ a /= a.sum(-1, keepdims=True)
68
+ x = x + np.einsum("ht,thd->hd", a, vc).reshape(D) @ l["Wo"]
69
+ x = x + np.maximum(_rms(x) @ l["W1"], 0) @ l["W2"]
70
+ if p >= PROMPT - 1:
71
+ t = int(np.argmax(_rms(x) @ tok.T))
72
+ out.append(t)
73
+ seq.append(t)
74
+ return out
75
+
76
+ def solve(seed, prompt_len, T):
77
+ return _decode(_params(seed, T), T, np.float32)
@@ -0,0 +1,76 @@
1
+ """aidecode RED TEAM: fast but wrong, it skips the second transformer layer. The teacher-forced verifier must reject it.
2
+ """
3
+ import math
4
+
5
+ import numpy as np
6
+
7
+ V, D, H, DH, FF, L, PROMPT = 64, 128, 4, 32, 512, 2, 8
8
+ W_SCALE, POS_SCALE = 4.0, 3.0
9
+ _GOLD = 0x9E3779B97F4A7C15
10
+ _C1 = 0xBF58476D1CE4E5B9
11
+ _C2 = 0x94D049BB133111EB
12
+
13
+
14
+ def _uniform(seed, start, n):
15
+ u = np.uint64
16
+ with np.errstate(over="ignore"):
17
+ z = (np.arange(start, start + n, dtype=u) + u(1)) * u(_GOLD) + u(seed)
18
+ z = (z ^ (z >> u(30))) * u(_C1)
19
+ z = (z ^ (z >> u(27))) * u(_C2)
20
+ z = z ^ (z >> u(31))
21
+ return (z >> u(11)).astype(np.float64) * 2.0 ** -52 - 1.0
22
+
23
+
24
+ def _params(seed, T):
25
+ o = [0]
26
+
27
+ def take(shape, scale):
28
+ n = int(np.prod(shape))
29
+ a = (_uniform(seed, o[0], n) * scale).reshape(shape)
30
+ o[0] += n
31
+ return a
32
+ sd, sf = W_SCALE * math.sqrt(3.0 / D), W_SCALE * math.sqrt(3.0 / FF)
33
+ P = {"tok": take((V, D), math.sqrt(3.0)), "layers": []}
34
+ for _ in range(L):
35
+ P["layers"].append({"Wq": take((D, D), sd), "Wk": take((D, D), sd), "Wv": take((D, D), sd), "Wo": take((D, D), sd),
36
+ "W1": take((D, FF), sd), "W2": take((FF, D), sf)})
37
+ P["pos"] = take((PROMPT + T, D), POS_SCALE * math.sqrt(3.0))
38
+ P["prompt"] = np.minimum(((_uniform(seed, o[0], PROMPT) + 1.0) * 0.5 * V).astype(np.int64), V - 1)
39
+ return P
40
+
41
+
42
+ def _rms(x):
43
+ return x / np.sqrt((x * x).mean(axis=-1, keepdims=True) + 1e-6)
44
+
45
+
46
+ def _decode(P, T, dt):
47
+ """Greedy decoding with a KV cache in dtype `dt`: one token's projections per step instead of the whole sequence's."""
48
+ n = PROMPT + T
49
+ layers = [{k: w.astype(dt) for k, w in l.items()} for l in P["layers"]]
50
+ tok, pos = P["tok"].astype(dt), P["pos"].astype(dt)
51
+ K = [np.zeros((n, D), dt) for _ in range(L)]
52
+ Vv = [np.zeros((n, D), dt) for _ in range(L)]
53
+ seq = [int(t) for t in P["prompt"]]
54
+ out = []
55
+ for p in range(n - 1):
56
+ x = tok[seq[p]] + pos[p]
57
+ for li, l in enumerate(layers[:1]):
58
+ h = _rms(x)
59
+ q = (h @ l["Wq"]).reshape(H, DH)
60
+ K[li][p], Vv[li][p] = h @ l["Wk"], h @ l["Wv"]
61
+ kc = K[li][:p + 1].reshape(p + 1, H, DH)
62
+ vc = Vv[li][:p + 1].reshape(p + 1, H, DH)
63
+ s = np.einsum("hd,thd->ht", q, kc) / dt(math.sqrt(DH))
64
+ s -= s.max(-1, keepdims=True)
65
+ a = np.exp(s)
66
+ a /= a.sum(-1, keepdims=True)
67
+ x = x + np.einsum("ht,thd->hd", a, vc).reshape(D) @ l["Wo"]
68
+ x = x + np.maximum(_rms(x) @ l["W1"], 0) @ l["W2"]
69
+ if p >= PROMPT - 1:
70
+ t = int(np.argmax(_rms(x) @ tok.T))
71
+ out.append(t)
72
+ seq.append(t)
73
+ return out
74
+
75
+ def solve(seed, prompt_len, T):
76
+ return _decode(_params(seed, T), T, np.float64)
@@ -0,0 +1,5 @@
1
+ """aidecode RED TEAM: a shortcut that costs nothing: repeat one token. The verifier must reject it."""
2
+
3
+
4
+ def solve(seed, prompt_len, T):
5
+ return [seed % 64] * T
@@ -0,0 +1,40 @@
1
+ """aiinfer speedup 1: the same float64 network, the whole batch in one BLAS matmul per layer.
2
+ """
3
+ import math
4
+
5
+ import numpy as np
6
+
7
+ _GOLD = 0x9E3779B97F4A7C15
8
+ _C1 = 0xBF58476D1CE4E5B9
9
+ _C2 = 0x94D049BB133111EB
10
+ _CLASSES = 10
11
+
12
+
13
+ def _uniform(seed, start, n):
14
+ u = np.uint64
15
+ with np.errstate(over="ignore"):
16
+ z = (np.arange(start, start + n, dtype=u) + u(1)) * u(_GOLD) + u(seed)
17
+ z = (z ^ (z >> u(30))) * u(_C1)
18
+ z = (z ^ (z >> u(27))) * u(_C2)
19
+ z = z ^ (z >> u(31))
20
+ return (z >> u(11)).astype(np.float64) * 2.0 ** -52 - 1.0
21
+
22
+
23
+
24
+ def _model(seed, d, batch):
25
+ s = math.sqrt(3.0 / d)
26
+ o = 0
27
+ W1 = (_uniform(seed, o, d * d) * s).reshape(d, d)
28
+ o += d * d
29
+ W2 = (_uniform(seed, o, d * d) * s).reshape(d, d)
30
+ o += d * d
31
+ W3 = (_uniform(seed, o, _CLASSES * d) * s).reshape(_CLASSES, d)
32
+ o += _CLASSES * d
33
+ X = _uniform(seed, o, batch * d).reshape(batch, d)
34
+ return W1, W2, W3, X
35
+
36
+ def solve(seed, d, batch):
37
+ W1, W2, W3, X = _model(seed, d, batch)
38
+ h = np.maximum(X @ W1.T, 0.0)
39
+ h = np.maximum(h @ W2.T, 0.0)
40
+ return [int(c) for c in (h @ W3.T).argmax(axis=1)]
@@ -0,0 +1,41 @@
1
+ """aiinfer speedup 2: batched AND float32 (weights and inputs cast after the exact float64 regeneration). Passes the verifier's tolerance.
2
+ """
3
+ import math
4
+
5
+ import numpy as np
6
+
7
+ _GOLD = 0x9E3779B97F4A7C15
8
+ _C1 = 0xBF58476D1CE4E5B9
9
+ _C2 = 0x94D049BB133111EB
10
+ _CLASSES = 10
11
+
12
+
13
+ def _uniform(seed, start, n):
14
+ u = np.uint64
15
+ with np.errstate(over="ignore"):
16
+ z = (np.arange(start, start + n, dtype=u) + u(1)) * u(_GOLD) + u(seed)
17
+ z = (z ^ (z >> u(30))) * u(_C1)
18
+ z = (z ^ (z >> u(27))) * u(_C2)
19
+ z = z ^ (z >> u(31))
20
+ return (z >> u(11)).astype(np.float64) * 2.0 ** -52 - 1.0
21
+
22
+
23
+
24
+ def _model(seed, d, batch):
25
+ s = math.sqrt(3.0 / d)
26
+ o = 0
27
+ W1 = (_uniform(seed, o, d * d) * s).reshape(d, d)
28
+ o += d * d
29
+ W2 = (_uniform(seed, o, d * d) * s).reshape(d, d)
30
+ o += d * d
31
+ W3 = (_uniform(seed, o, _CLASSES * d) * s).reshape(_CLASSES, d)
32
+ o += _CLASSES * d
33
+ X = _uniform(seed, o, batch * d).reshape(batch, d)
34
+ return W1, W2, W3, X
35
+
36
+ def solve(seed, d, batch):
37
+ W1, W2, W3, X = _model(seed, d, batch)
38
+ W1, W2, W3, X = (a.astype(np.float32) for a in (W1, W2, W3, X))
39
+ h = np.maximum(X @ W1.T, 0.0)
40
+ h = np.maximum(h @ W2.T, 0.0)
41
+ return [int(c) for c in (h @ W3.T).argmax(axis=1)]
@@ -0,0 +1,42 @@
1
+ """aiinfer on a GPU, SPEEDUP: the whole batch in one matmul per layer on the device, one read-back at the end. Same float32 numbers as aiinfer_gpu_ref.
2
+ UNRUN: written without a GPU or torch."""
3
+ import math
4
+
5
+ import numpy as np
6
+ import torch
7
+
8
+ _GOLD = 0x9E3779B97F4A7C15
9
+ _C1 = 0xBF58476D1CE4E5B9
10
+ _C2 = 0x94D049BB133111EB
11
+ _CLASSES = 10
12
+
13
+
14
+ def _uniform(seed, start, n):
15
+ u = np.uint64
16
+ with np.errstate(over="ignore"):
17
+ z = (np.arange(start, start + n, dtype=u) + u(1)) * u(_GOLD) + u(seed)
18
+ z = (z ^ (z >> u(30))) * u(_C1)
19
+ z = (z ^ (z >> u(27))) * u(_C2)
20
+ z = z ^ (z >> u(31))
21
+ return (z >> u(11)).astype(np.float64) * 2.0 ** -52 - 1.0
22
+
23
+
24
+ def _model(seed, d, batch):
25
+ s = math.sqrt(3.0 / d)
26
+ o = 0
27
+ W1 = (_uniform(seed, o, d * d) * s).reshape(d, d)
28
+ o += d * d
29
+ W2 = (_uniform(seed, o, d * d) * s).reshape(d, d)
30
+ o += d * d
31
+ W3 = (_uniform(seed, o, _CLASSES * d) * s).reshape(_CLASSES, d)
32
+ o += _CLASSES * d
33
+ X = _uniform(seed, o, batch * d).reshape(batch, d)
34
+ return W1, W2, W3, X
35
+
36
+
37
+ def solve(seed, d, batch):
38
+ dev = torch.device("cuda")
39
+ W1, W2, W3, X = (torch.from_numpy(a).to(dev, dtype=torch.float32) for a in _model(seed, d, batch))
40
+ h = torch.relu(X @ W1.T)
41
+ h = torch.relu(h @ W2.T)
42
+ return (h @ W3.T).argmax(dim=1).tolist()
@@ -0,0 +1,45 @@
1
+ """aiinfer on a GPU, REFERENCE: float32 on the device, one sample at a time (a matrix-vector product per input, one synchronising read-back per sample).
2
+ UNRUN: written without a GPU or torch. The model definition is exactly domains/aiinfer/reference.py's (regenerated on the host, then moved to the device)."""
3
+ import math
4
+
5
+ import numpy as np
6
+ import torch
7
+
8
+ _GOLD = 0x9E3779B97F4A7C15
9
+ _C1 = 0xBF58476D1CE4E5B9
10
+ _C2 = 0x94D049BB133111EB
11
+ _CLASSES = 10
12
+
13
+
14
+ def _uniform(seed, start, n):
15
+ u = np.uint64
16
+ with np.errstate(over="ignore"):
17
+ z = (np.arange(start, start + n, dtype=u) + u(1)) * u(_GOLD) + u(seed)
18
+ z = (z ^ (z >> u(30))) * u(_C1)
19
+ z = (z ^ (z >> u(27))) * u(_C2)
20
+ z = z ^ (z >> u(31))
21
+ return (z >> u(11)).astype(np.float64) * 2.0 ** -52 - 1.0
22
+
23
+
24
+ def _model(seed, d, batch):
25
+ s = math.sqrt(3.0 / d)
26
+ o = 0
27
+ W1 = (_uniform(seed, o, d * d) * s).reshape(d, d)
28
+ o += d * d
29
+ W2 = (_uniform(seed, o, d * d) * s).reshape(d, d)
30
+ o += d * d
31
+ W3 = (_uniform(seed, o, _CLASSES * d) * s).reshape(_CLASSES, d)
32
+ o += _CLASSES * d
33
+ X = _uniform(seed, o, batch * d).reshape(batch, d)
34
+ return W1, W2, W3, X
35
+
36
+
37
+ def solve(seed, d, batch):
38
+ dev = torch.device("cuda")
39
+ W1, W2, W3, X = (torch.from_numpy(a).to(dev, dtype=torch.float32) for a in _model(seed, d, batch))
40
+ out = []
41
+ for i in range(batch):
42
+ h = torch.relu(W1 @ X[i])
43
+ h = torch.relu(W2 @ h)
44
+ out.append(int(torch.argmax(W3 @ h)))
45
+ return out
@@ -0,0 +1,42 @@
1
+ """aiinfer RED TEAM: a fast but inaccurate model (only the first d/8 hidden units are kept). The verifier must reject it: a speedup that
2
+ breaks the accuracy condition is worth nothing.
3
+ """
4
+ import math
5
+
6
+ import numpy as np
7
+
8
+ _GOLD = 0x9E3779B97F4A7C15
9
+ _C1 = 0xBF58476D1CE4E5B9
10
+ _C2 = 0x94D049BB133111EB
11
+ _CLASSES = 10
12
+
13
+
14
+ def _uniform(seed, start, n):
15
+ u = np.uint64
16
+ with np.errstate(over="ignore"):
17
+ z = (np.arange(start, start + n, dtype=u) + u(1)) * u(_GOLD) + u(seed)
18
+ z = (z ^ (z >> u(30))) * u(_C1)
19
+ z = (z ^ (z >> u(27))) * u(_C2)
20
+ z = z ^ (z >> u(31))
21
+ return (z >> u(11)).astype(np.float64) * 2.0 ** -52 - 1.0
22
+
23
+
24
+
25
+ def _model(seed, d, batch):
26
+ s = math.sqrt(3.0 / d)
27
+ o = 0
28
+ W1 = (_uniform(seed, o, d * d) * s).reshape(d, d)
29
+ o += d * d
30
+ W2 = (_uniform(seed, o, d * d) * s).reshape(d, d)
31
+ o += d * d
32
+ W3 = (_uniform(seed, o, _CLASSES * d) * s).reshape(_CLASSES, d)
33
+ o += _CLASSES * d
34
+ X = _uniform(seed, o, batch * d).reshape(batch, d)
35
+ return W1, W2, W3, X
36
+
37
+ def solve(seed, d, batch):
38
+ W1, W2, W3, X = _model(seed, d, batch)
39
+ k = max(1, d // 8)
40
+ h = np.maximum(X @ W1[:k].T, 0.0)
41
+ h = np.maximum(h @ W2[:k, :k].T, 0.0)
42
+ return [int(c) for c in (h @ W3[:, :k].T).argmax(axis=1)]
@@ -0,0 +1,14 @@
1
+ """Reference baseline: progressive BKZ with exact (unpruned) enumeration."""
2
+ from fpylll import BKZ, LLL, IntegerMatrix
3
+
4
+
5
+ def solve(basis, bound2):
6
+ n = len(basis)
7
+ A = IntegerMatrix.from_matrix(basis)
8
+ LLL.reduction(A)
9
+ for beta in list(range(10, n + 1, 4)):
10
+ if sum(x * x for x in A[0]) <= bound2:
11
+ break
12
+ BKZ.reduction(A, BKZ.Param(block_size=beta, flags=BKZ.AUTO_ABORT | BKZ.MAX_LOOPS, max_loops=8))
13
+ v = [int(x) for x in A[0]]
14
+ return v if sum(x * x for x in v) <= bound2 else None