interplane.Get Omega
Read in your language

aien-train

AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.

Brought by drakestapleton

branch main Branches Tags History

aien-train / evidence / ADTRAIN / oracle / query.wl

51 lines · 2978 bytes Raw Blame History
1gbits = {1012531200,3200499712,1038315520,1057377920,3192803328,1044633088,1072657216,1059866112,3210915840,1051499520,3214650560,3215344960,3179126784,3206203264,3214120640,3221337216,3191130112,1026220032,3196256768,3213141312,3167682560,3209066880,3211721344,3216259840,3208305408,3193594880,3211001984,3221852992,3206473216,3220845952,3205072128,3224286976,1066432512,1050025984,1068422656,1077000192,3213832192,1074026496,3190120448,1082103808,3210985600,3208587392,3212141952,3213871040,3214739904,3190289408,3222396032,1060899584,3205229568,1056598016,3222220288,1052957696,3223806656,1039037440,3227447552,1067773184,3239437312,1054441472};
2kref = {5,7,-3,5,-8,2,0,-4,7,0};
3l0bits = 1090364420;
4(* SPDX-License-Identifier: AGPL-3.0-only *)
5(* adtrain exact-rational gradient oracle (Wolfram Language; verification only).
6 Inputs, prepended by the caller from one run of the suite:
7 gbits = {58 integers} bit patterns of the `G <i> <bits>` rows (run/G.stdout)
8 kref = {10 integers} the `K <i> <k>` rows (run/D.stdout)
9 l0bits = integer the `L 0 <bits>` row (run/T.stdout)
10 Regenerates the seed-17 data and initial parameters exactly, fixes the relu
11 pattern (x > 0, the tape's rule) from the exact forward, differentiates the
12 exact loss symbolically, and compares every tape value against the declared
13 bound |om - exact| <= 2^-16 Max[1, |exact|]. *)
14mask64 = 2^64 - 1;
15xs[x_] := Module[{y = x},
16 y = BitXor[y, BitAnd[BitShiftLeft[y, 13], mask64]];
17 y = BitXor[y, BitShiftRight[y, 7]];
18 BitXor[y, BitAnd[BitShiftLeft[y, 17], mask64]]];
19ks = Mod[Rest[NestList[xs, 17, 96]], 17] - 8;
20xv = Partition[ks[[1 ;; 32]]/8, 4];
21tv = Partition[ks[[33 ;; 48]]/8, 2];
22w1v = Partition[ks[[49 ;; 80]]/16, 8];
23w2v = Partition[ks[[81 ;; 96]]/16, 2];
24w1s = Array[a, {4, 8}]; b1s = Array[b, 8]; w2s = Array[c, {8, 2}]; b2s = Array[d, 2];
25params = Join[Flatten[w1s], b1s, Flatten[w2s], b2s];
26point = Thread[params -> Join[Flatten[w1v], ConstantArray[0, 8], Flatten[w2v], ConstantArray[0, 2]]];
27pre = xv . w1s + ConstantArray[b1s, 8];
28preV = pre /. point;
29relu = Map[Boole[# > 0] &, preV, {2}];
30y = (relu*pre) . w2s + ConstantArray[b2s, 8];
31loss = Total[(y - tv)^2, 2];
32gex = D[loss, {params}] /. point;
33lex = loss /. point;
34f32[u_] := Module[{s = BitShiftRight[u, 31], e = BitAnd[BitShiftRight[u, 23], 255],
35 m = BitAnd[u, 2^23 - 1]},
36 (-1)^s If[e == 0, m 2^-149, (2^23 + m) 2^(e - 150)]];
37gom = f32 /@ gbits;
38bound = 2^-16 Max[1, Abs[#]] & /@ gex;
39diff = Abs[gom - gex];
40lom = f32[l0bits];
41<|"kMatch" -> (ks[[1 ;; 10]] === kref),
42 "zeroPreActivations" -> Count[Flatten[preV], 0],
43 "reluActive" -> Total[Flatten[relu]],
44 "n" -> Length[gex],
45 "allWithin" -> And @@ Thread[diff <= bound],
46 "exactEqual" -> Count[diff, 0],
47 "maxDiffOverBound" -> N[Max[diff/bound]],
48 "maxAbsDiff" -> N[Max[diff]],
49 "lossExact" -> lex, "lossOm" -> lom,
50 "lossWithin" -> (Abs[lom - lex] <= 2^-16 Max[1, Abs[lex]]),
51 "lossRelErr" -> N[Abs[lom - lex]/Abs[lex]]|>