AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.
Fine-tune with LoRA adapters in Omega: verified f64 core with gradient check and mutant controls
merged528b6bf55408a785 #69 · opened 2026-11-06 20:42 UTC · closed 2026-11-06 21:10 UTC · merged 2026-11-06 21:10 UTC
Imported from GitHub aien-dev/aien-train#69, by drakestapleton
Base 77cffb6d6698f59b0644552bcbfe0b639da94abe · Head 9bfbdce8b27f3e538ae33ad0804cbfe9b5891b3a
Merged on GitHub as b6c92a3a84c9071ad1d3b1e06588f8ea71724de9; reachable from main 1739217e7c91f8d512a00d3eddb6f3f6e4f154c3 (observed 2026-11-18T16:40:29Z)
drakestapleton wrote on 2026-11-06 20:42 UTC
Problem
Nothing in aien-train could fine-tune an existing model with adapters. omegallm trains from random init only, so every customization means a full retrain or a hand weight edit.
Solution
native/omegalora/lora.om: a first-party Omega LoRA core. Frozen base, rank 4 adapters (A random, B zero), RMSNorm, SiLU, softmax cross-entropy and AdamW, all f64, with first-party exp and log. Every gate runs inside the unit:
exp(1) and log(10) against Wolfram constants (exit 13)
central-difference gradient check, worst relative error at most 1e-6 (exit 10)
loss must at least halve and accuracy must rise 0.2 after 400 steps (exit 11, 12)
three deliberately broken code paths, selected through stdin inside the same binary, (SiLU derivative, RMSNorm backward, AdamW sign) must be caught. Contract: docs/omegalora/CONTRACT.md. This is the f64 reference for the next step: adapters on omegallm checkpoints.
mutant0 stdout: gradient check worst 0.000000018729, loss 2.000809231083 to 0.000382919481, accuracy 0.3125 to 1.0.
The omega harness sandbox (bwrap, no network) built the same binary hash and got the same output.
Limits
Host CPU only, one MLP block, synthetic teacher labels. Not a language model fine-tune and no GPU claim.
Agent review (RevTrain69, Opus 5.5, AIEN Completion Hive; requested by Queen under Drake authorization DRA-162 2026-11-06), not a human review. Head 9bfbdce8 reviewed. tests/omegalora/run.sh with the pinned omc: rc0, OMEGALORA_PASS; mutants exit 0/10/10/11 as committed. 3 extra mutants caught (backward scale, lr=0, forward scale). An unpinned omc is refused, rc1. Wording follow-ups (non-blocking): docs say "qualifies" where "exercises" is right; the gradient check compares forward against backward only; run.sh overwrites the committed summary.txt.
Apply it
git checkout -b patch-528b6bf55408a78577cffb6d6698f59b0644552bcbfe0b639da94abe
curl -fsSL https://interplane.io/drakestapleton/aien-train/patches/528b6bf55408a785.patch | git am
diff --git a/docs/omegalora/CONTRACT.md b/docs/omegalora/CONTRACT.md
new file mode 100644
index 0000000..347d75a
--- /dev/null
+++ b/docs/omegalora/CONTRACT.md
@@ -0,0 +1,54 @@
+# omegalora: LoRA fine-tuning core in Omega (contract v1)
+
+`native/omegalora/lora.om` is a first-party Omega unit that fine-tunes a frozen base with LoRA
+(low-rank adapters) and checks its own math. It is the f64 reference that later GPU and
+omegallm adapter kernels are compared against. Host CPU only; it does not qualify any chip.
+
+## What it computes
+
+One transformer MLP block shape, all f64:
+
+- `h0 = rmsnorm(x)`, `p1 = (W1 + s B1 A1) h0`, `a1 = silu(p1)`, `n1 = rmsnorm(a1)`,
+ `z = (W2 + s B2 A2) n1`, loss = mean softmax cross-entropy over 64 samples, 12 classes.
+- Shapes: x 16, hidden 24, rank r = 4, alpha = 8, scale s = alpha / r = 2.
+- `W1` (24x16) and `W2` (12x24) are frozen. Only `A1 B1 A2 B2` (304 values) learn.
+- Init follows LoRA: A random, B zero, so step 0 equals the base model exactly.
+- Optimizer: AdamW, beta1 0.9, beta2 0.999, eps 1e-8, weight decay 0.01, lr 0.02, 400 steps.
+- `exp` and `log` are first-party (range reduction plus series); constants and error bounds
+ are Wolfram receipts in `evidence/OMEGALORA/wolfram.txt`.
+- Task: labels come from a hidden teacher `W + U V` with rank 4 changes on both layers, so a
+ rank 4 adapter can represent it exactly.
+
+## Gates (exit codes, decided inside the .om unit)
+
+| exit | meaning |
+|---|---|
+| 0 | all gates pass |
+| 13 | exp(1) or log(10) off by more than 1e-14 |
+| 10 | analytic gradient vs central difference (h = 1e-5, every 3rd parameter, B nonzero): worst relative error above 1e-6 |
+| 11 | training loss after 400 steps is not at most half the starting loss |
+| 12 | accuracy did not rise by at least 0.2 |
+
+## Negative controls
+
+stdin selects a deliberately broken build. The gates must catch each one.
+
+| stdin | break | must exit |
+|---|---|---|
+| 1 | SiLU derivative sign flipped | 10 |
+| 2 | RMSNorm backward sign flipped | 10 |
+| 3 | AdamW step sign flipped | 11 |
+
+## Build and test
+
+`sh tests/omegalora/run.sh` with `OMC` pointing at the pinned seeded omc (omega-mv `e5b32567`,
+sha256 `2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f`). The script refuses
+any other compiler, compiles, runs all four builds and writes `evidence/OMEGALORA/run/`.
+
+## Limits
+
+- Host CPU, f64, one block, synthetic teacher data. This is not a language model fine-tune yet.
+- Omega today allows at most 16 live values per function and 6 parameters; the unit is split
+ into small helpers for that reason.
+- Next step: carry the same adapter math into omegallm (`native/omegallm/model.om`) so its
+ checkpoints can take a LoRA adapter, checked against this unit.
diff --git a/evidence/OMEGALORA/README.md b/evidence/OMEGALORA/README.md
new file mode 100644
index 0000000..36cbd0c
--- /dev/null
+++ b/evidence/OMEGALORA/README.md
@@ -0,0 +1,34 @@
+# omegalora host evidence (core v1)
+
+Source commit: `e4140effeb91366d74d61fc45b7d9de07bb96d2b`. Base: train main `77cffb6`.
+Host: Linux 7.0.0-1019-nvidia aarch64 (DGX Spark GB10 host CPU), CPU only. No GPU ran.
+Compiler: pinned seeded omc, sha256 `2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f`.
+Command: `OMC=<pinned omc> sh tests/omegalora/run.sh`. Raw outputs are in `run/`, sealed by
+`run/raw.sha256`. Binary sha256 `966f9994de1b854fc1c7ca11c7e27aabb10cb5ae35b269f8ce9d9498a4842071`.
+
+The same source also compiled and ran in the omega harness sandbox (bwrap, no network, cleared
+environment) on 2026-11-06: same binary sha256, exit 0, identical stdout.
+
+## Results (MEASURED, run/mutant0.stdout)
+
+| check | value | gate |
+|---|---|---|
+| exp(1) | 2.718281828459 | within 1e-14 of e |
+| log(10) | 2.302585092994 | within 1e-14 of ln 10 |
+| gradient check, worst relative error | 0.000000018729 | at most 1e-6 |
+| loss before / after 400 AdamW steps | 2.000809231083 / 0.000382919481 | after at most half of before |
+| accuracy before / after | 0.3125 / 1.0 | rise of at least 0.2 |
+
+## Negative controls (MEASURED)
+
+| build | break | exit | expected |
+|---|---|---|---|
+| mutant1 | SiLU derivative | 10 | 10 |
+| mutant2 | RMSNorm backward | 10 | 10 |
+| mutant3 | AdamW sign | 11 (loss 49994.28) | 11 |
+
+## Limits
+
+Host CPU, f64, one MLP block, synthetic teacher labels. This qualifies the adapter math only;
+it is not a language model fine-tune and says nothing about GPU speed. Contract: `docs/omegalora/CONTRACT.md`.
+Constants: `wolfram.txt`.
diff --git a/evidence/OMEGALORA/run/compile.stderr b/evidence/OMEGALORA/run/compile.stderr
new file mode 100644
index 0000000..e69de29
diff --git a/evidence/OMEGALORA/run/mutant0.rc b/evidence/OMEGALORA/run/mutant0.rc
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/evidence/OMEGALORA/run/mutant0.rc
@@ -0,0 +1 @@
+0
diff --git a/evidence/OMEGALORA/run/mutant0.stderr b/evidence/OMEGALORA/run/mutant0.stderr
new file mode 100644
index 0000000..e69de29
diff --git a/evidence/OMEGALORA/run/mutant0.stdout b/evidence/OMEGALORA/run/mutant0.stdout
new file mode 100644
index 0000000..70f70dc
--- /dev/null
+++ b/evidence/OMEGALORA/run/mutant0.stdout
@@ -0,0 +1,7 @@
+exp(1) 2.718281828459
+log(10) 2.302585092994
+gradient check, worst relative error 0.000000018729
+loss before 2.000809231083
+loss after 0.000382919481
+accuracy before 0.312500000000
+accuracy after 1.000000000000
diff --git a/evidence/OMEGALORA/run/mutant1.rc b/evidence/OMEGALORA/run/mutant1.rc
new file mode 100644
index 0000000..f599e28
--- /dev/null
+++ b/evidence/OMEGALORA/run/mutant1.rc
@@ -0,0 +1 @@
+10
diff --git a/evidence/OMEGALORA/run/mutant1.stderr b/evidence/OMEGALORA/run/mutant1.stderr
new file mode 100644
index 0000000..e69de29
diff --git a/evidence/OMEGALORA/run/mutant1.stdout b/evidence/OMEGALORA/run/mutant1.stdout
new file mode 100644
index 0000000..be0ea06
--- /dev/null
+++ b/evidence/OMEGALORA/run/mutant1.stdout
@@ -0,0 +1,3 @@
+exp(1) 2.718281828459
+log(10) 2.302585092994
+gradient check, worst relative error 1.000000000000
diff --git a/evidence/OMEGALORA/run/mutant2.rc b/evidence/OMEGALORA/run/mutant2.rc
new file mode 100644
index 0000000..f599e28
--- /dev/null
+++ b/evidence/OMEGALORA/run/mutant2.rc
@@ -0,0 +1 @@
+10
diff --git a/evidence/OMEGALORA/run/mutant2.stderr b/evidence/OMEGALORA/run/mutant2.stderr
new file mode 100644
index 0000000..e69de29
diff --git a/evidence/OMEGALORA/run/mutant2.stdout b/evidence/OMEGALORA/run/mutant2.stdout
new file mode 100644
index 0000000..be0ea06
--- /dev/null
+++ b/evidence/OMEGALORA/run/mutant2.stdout
@@ -0,0 +1,3 @@
+exp(1) 2.718281828459
+log(10) 2.302585092994
+gradient check, worst relative error 1.000000000000
diff --git a/evidence/OMEGALORA/run/mutant3.rc b/evidence/OMEGALORA/run/mutant3.rc
new file mode 100644
index 0000000..b4de394
--- /dev/null
+++ b/evidence/OMEGALORA/run/mutant3.rc
@@ -0,0 +1 @@
+11
diff --git a/evidence/OMEGALORA/run/mutant3.stderr b/evidence/OMEGALORA/run/mutant3.stderr
new file mode 100644
index 0000000..e69de29
diff --git a/evidence/OMEGALORA/run/mutant3.stdout b/evidence/OMEGALORA/run/mutant3.stdout
new file mode 100644
index 0000000..972852c
--- /dev/null
+++ b/evidence/OMEGALORA/run/mutant3.stdout
@@ -0,0 +1,7 @@
+exp(1) 2.718281828459
+log(10) 2.302585092994
+gradient check, worst relative error 0.000000018729
+loss before 2.000809231083
+loss after 49994.282005262342
+accuracy before 0.312500000000
+accuracy after 0.031250000000
diff --git a/evidence/OMEGALORA/run/raw.sha256 b/evidence/OMEGALORA/run/raw.sha256
new file mode 100644
index 0000000..404ef8a
--- /dev/null
+++ b/evidence/OMEGALORA/run/raw.sha256
@@ -0,0 +1,13 @@
+9a271f2a916b0b6ee6cecb2426f0b3206ef074578be55d9bc94f6f3fe3ab86aa mutant0.rc
+917df3320d778ddbaa5c5c7742bc4046bf803c36ed2b050f30844ed206783469 mutant1.rc
+917df3320d778ddbaa5c5c7742bc4046bf803c36ed2b050f30844ed206783469 mutant2.rc
+25d4f2a86deb5e2574bb3210b67bb24fcc4afb19f93a7b65a057daa874a9d18e mutant3.rc
+bee2e679e628a38fc7b59cd07402ed16165cf45a94a7bb5b7b41c0d6f87b4317 mutant0.stdout
+10f61b5c9d93283e413e05962a73290dd489080c43902300d66ffe04f54ecd0b mutant1.stdout
+10f61b5c9d93283e413e05962a73290dd489080c43902300d66ffe04f54ecd0b mutant2.stdout
+beff2fe967742ba56c4ac34012637e32919c0cda72b4e5ce97c26547d4300769 mutant3.stdout
+e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 mutant0.stderr
+e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 mutant1.stderr
+e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 mutant2.stderr
+e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 mutant3.stderr
+e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 compile.stderr
diff --git a/evidence/OMEGALORA/run/summary.txt b/evidence/OMEGALORA/run/summary.txt
new file mode 100644
index 0000000..6136df2
--- /dev/null
+++ b/evidence/OMEGALORA/run/summary.txt
@@ -0,0 +1,10 @@
+source_commit=e4140effeb91366d74d61fc45b7d9de07bb96d2b
+host=Linux 7.0.0-1019-nvidia aarch64
+compiler_sha256=2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f
+source_sha256=9af90ebe090b89d5f9769c0d3b17e7b7154666f11d7c3e0cb680aed1c7f3aba7
+binary_sha256=966f9994de1b854fc1c7ca11c7e27aabb10cb5ae35b269f8ce9d9498a4842071
+mutant0 exit=0 expected=0 PASS
+mutant1 exit=10 expected=10 PASS
+mutant2 exit=10 expected=10 PASS
+mutant3 exit=11 expected=11 PASS
+OMEGALORA_PASS
diff --git a/evidence/OMEGALORA/wolfram.txt b/evidence/OMEGALORA/wolfram.txt
new file mode 100644
index 0000000..4339350
--- /dev/null
+++ b/evidence/OMEGALORA/wolfram.txt
@@ -0,0 +1,18 @@
+Wolfram Language evaluation, 2026-11-06 (WolframLanguageEvaluator). Query:
+ {N[1/Log[2],20], N[Log[2],20], N[Sqrt[2],20], N[E,20], N[Log[10],20], 2^52, 2^52-1,
+ 1023*2^52, 2047*2^52, N[2*Log[2]^15/15!,6], N[(Sqrt[2]-1)/(Sqrt[2]+1),10],
+ N[With[{s=(Sqrt[2]-1)/(Sqrt[2]+1)}, 2 s^43/(43 (1-s^2))],6]}
+Result:
+ 1/ln2 1.4426950408889634074
+ ln2 0.69314718055994530942
+ sqrt2 1.4142135623730950488
+ e 2.7182818284590452354
+ ln10 2.3025850929940456840
+ 2^52 4503599627370496
+ 2^52 - 1 4503599627370495 (f64 mantissa mask)
+ 1023 * 2^52 4607182418800017408 (bits of 1.0)
+ 2047 * 2^52 9218868437227405312 (bits of +inf)
+ exp remainder bound 6.26487e-15 (degree 14 Taylor on [0, ln2), e^ln2 ln2^15 / 15!)
+ log |s| max 0.1715728753 ((sqrt2 - 1)/(sqrt2 + 1), mantissa folded to [sqrt2/2, sqrt2])
+ log tail bound 5.77868e-35 (atanh series cut after s^41)
+lora.om uses these constants verbatim; its gate 13 checks fexp(1) and flog(10) against e and ln10 above to 1e-14.
diff --git a/native/omegalora/.crumb b/native/omegalora/.crumb
new file mode 100644
index 0000000..b027ed1
--- /dev/null
+++ b/native/omegalora/.crumb
@@ -0,0 +1,5 @@
+{
+ "schema_version": "1.0.0",
+ "name": "omegalora",
+ "purpose": "LoRA fine-tuning core v1: frozen W plus s B A adapters, RMSNorm, SiLU, softmax CE, AdamW in f64 Omega with gradient check and three mutant controls; host CPU only, reference for GPU and omegallm adapters"
+}
diff --git a/native/omegalora/lora.om b/native/omegalora/lora.om
new file mode 100644
index 0000000..9fda944
--- /dev/null
+++ b/native/omegalora/lora.om
@@ -0,0 +1,503 @@
+note SPDX-License-Identifier: AGPL-3.0-only
+note omegalora lora.om (core v1): LoRA fine-tuning on a frozen base, written in Omega from scratch.
+note Network (one transformer MLP block shape): h0 = rmsnorm(x); p1 = (W1 + s*B1*A1) h0; a1 = silu(p1);
+note n1 = rmsnorm(a1); z = (W2 + s*B2*A2) n1; loss = mean cross-entropy(z, label).
+note W1, W2 are frozen. Only the LoRA factors A1 B1 A2 B2 learn (AdamW). Everything is f64 so this
+note file is the reference the GPU kernels are checked against.
+note stdin selects a deliberately broken build: 1 silu grad, 2 rmsnorm grad, 3 adam sign. 0 or empty = real.
+note exit 0 pass; 13 exp/log; 10 gradient check; 11 loss did not drop; 12 accuracy did not rise.
+note Constants (Wolfram, 2026-11-06, evidence/OMEGALORA/wolfram.txt): 1/ln2 1.4426950408889634,
+note ln2 0.6931471805599453, sqrt2 1.4142135623730951, bits(1.0) 4607182418800017408,
+note bits(+inf) 9218868437227405312, 2^52 - 1 4503599627370495. exp: degree 14 Taylor on [0, ln2),
+note remainder bound 2 ln2^15/15! = 6.26e-15. log: atanh series to s^41, |s| <= 0.1716, tail 5.8e-35.
+note pool layout (f64 slots): W1 0, W2 384, params 1024 (A1 +0, B1 +64, A2 +160, B2 +256; 304 total),
+note grads 2048, adam m 3072, adam v 4096, inputs 5120, activations 8192 (128 per sample),
+note backward scratch 16384, teacher W1t 20000, W2t 20480, factor temp 21000, matvec temp 30000, adam powers 31000.
+global m f64 32768
+global lab ulong 64
+global rs ulong 1
+global mut ulong 1
+global ob uchar 64
+fn putc c ulong to void
+put ob 0 uchar c
+w = write 1 ob 0 1
+end
+fn putu n ulong to void
+tmp = new uchar 24 0
+k = ulong 0
+x = n
+if eq x 0
+putc 48
+ret
+end
+while gt x 0
+put tmp k uchar add 48 rem x 10
+x = div x 10
+k = add k 1
+end
+while gt k 0
+k = sub k 1
+putc ulong get tmp k
+end
+end
+fn putf x f64 to void
+v = x
+if lt v 0.0f64
+putc 45
+v = neg v
+end
+ip = ulong v
+putu ip
+putc 46
+fr = sub v f64 ip
+for i ulong 12
+fr = mul fr 10.0f64
+d = ulong fr
+putc add 48 d
+fr = sub fr f64 d
+end
+putc 10
+end
+text tex "exp(1) "
+text tlg "log(10) "
+text tgc "gradient check, worst relative error "
+text tl0 "loss before "
+text tl1 "loss after "
+text ta0 "accuracy before "
+text ta1 "accuracy after "
+fn say t ulong to void
+w = long 0
+if eq t 0
+w = write 1 tex 0 len tex
+end
+if eq t 1
+w = write 1 tlg 0 len tlg
+end
+if eq t 2
+w = write 1 tgc 0 len tgc
+end
+if eq t 3
+w = write 1 tl0 0 len tl0
+end
+if eq t 4
+w = write 1 tl1 0 len tl1
+end
+if eq t 5
+w = write 1 ta0 0 len ta0
+end
+if eq t 6
+w = write 1 ta1 0 len ta1
+end
+end
+fn fexp x f64 to f64
+if lt x -708.0f64
+ret 0.0f64
+end
+if gt x 709.0f64
+ret bitcast f64 ulong 9218868437227405312
+end
+t = mul x 1.4426950408889634f64
+k = long t
+if gt f64 k t
+k = sub k 1
+end
+r = sub x mul f64 k 0.6931471805599453f64
+p = 1.0f64
+c = long 14
+while gt c 0
+p = add 1.0f64 div mul p r f64 c
+c = sub c 1
+end
+e = bitcast f64 shl ulong add k 1023 52
+ret mul p e
+end
+fn flog x f64 to f64
+b = bitcast ulong x
+ex = sub long and shr b 52 2047 1023
+mm = bitcast f64 or and b 45035996273704954607182418800017408
+if gt mm 1.4142135623730951f64
+mm = mul mm 0.5f64
+ex = add ex 1
+end
+s = div sub mm 1.0f64 add mm 1.0f64
+s2 = mul s s
+acc = 0.0f64
+c = long 41
+while gt c 0
+acc = add div 1.0f64 f64 c mul s2 acc
+c = sub c 2
+end
+ret add mul 2.0f64 mul s acc mul f64 ex 0.6931471805599453f64
+end
+fn rnd to f64
+x = get rs 0
+x = xor x shl x 13
+x = xor x shr x 7
+x = xor x shl x 17
+put rs 0 x
+ret sub div f64 shr x 11 4503599627370496.0f64 1.0f64
+end
+fn fill off ulong n ulong sc f64 to void
+for i ulong n
+put m add off i mul sc rnd
+end
+end
+fn zero off ulong n ulong to void
+for i ulong n
+put m add off i 0.0f64
+end
+end
+note sum over i < n of a[i*sa] * b[i]
+fn sdot a ulong sa ulong b ulong n ulong to f64
+s = 0.0f64
+ai = a
+for i ulong n
+av = get m ai
+s = add s mul av get m add b i
+ai = add ai sa
+end
+ret s
+end
+note y[i] += c * x[i] for i < n
+fn axpy y ulong x ulong n ulong c f64 to void
+for i ulong n
+yi = add y i
+xv = mul c get m add x i
+put m yi add get m yi xv
+end
+end
+note y = W x, W is rows x cols row-major
+fn mv w ulong x ulong y ulong rows ulong cols ulong to void
+for r ulong rows
+put m add y r sdot add w mul r cols 1 x cols
+end
+end
+note o += W^T g
+fn mvtacc w ulong g ulong o ulong rows ulong cols ulong to void
+for c ulong cols
+oi = add o c
+put m oi add get m oi sdot add w c cols g rows
+end
+end
+note dw += sc * g x^T
+fn outacc g ulong x ulong dw ulong rows ulong cols ulong sc f64 to void
+for r ulong rows
+axpy add dw mul r cols x cols mul sc get m add g r
+end
+end
+fn rmsn a ulong o ulong n ulong to f64
+ss = 0.0f64
+for i ulong n
+v = get m add a i
+ss = add ss mul v v
+end
+r = fsqrt add div ss f64 n 0.000001f64
+for i ulong n
+put m add o i div get m add a i r
+end
+ret r
+end
+fn sig p f64 to f64
+ret div 1.0f64 add 1.0f64 fexp neg p
+end
+note forward for sample i; lora adds s*B*A on both layers (s = alpha/r = 8/4 = 2)
+note sample slots: h0 +0 (16), t1 +16 (4), p1 +20 (24), a1 +44 (24), n1 +68 (24), r1 +92, t2 +93 (4), z +97 (12)
+fn base i ulong to ulong
+ret add 8192 mul i 128
+end
+fn silu a ulong p ulong n ulong to void
+for k ulong n
+v = get m add p k
+put m add a k mul v sig v
+end
+end
+fn fwd i ulong w1 ulong w2 ulong lora bool to void
+b = base i
+q = rmsn add 5120 mul i 16 b 16
+mv w1 b add b 20 24 16
+if lora
+mv 1024 b add b 16 4 16
+mv 1088 add b 16 30000 24 4
+axpy add b 20 30000 24 2.0f64
+end
+silu add b 44 add b 20 24
+put m add b 92 rmsn add b 44 add b 68 24
+mv w2 add b 68 add b 97 12 24
+if lora
+mv 1184 add b 68 add b 93 4 24
+mv 1280 add b 93 30000 12 4
+axpy add b 97 30000 12 2.0f64
+end
+end
+fn amax z ulong n ulong to ulong
+best = ulong 0
+for k ulong n
+if gt get m add z k get m add z best
+best = k
+end
+end
+ret best
+end
+fn lossi i ulong to f64
+z = add add 8192 mul i 128 97
+mx = get m add z amax z 12
+se = 0.0f64
+for k ulong 12
+se = add se fexp sub get m add z k mx
+end
+ret sub add mx flog se get m add z get lab i
+end
+fn total to f64
+s = 0.0f64
+for i ulong 64
+fwd i 0 384 true
+s = add s lossi i
+end
+ret div s 64.0f64
+end
+fn accuracy to f64
+c = 0.0f64
+for i ulong 64
+fwd i 0 384 true
+if eq amax add add 8192 mul i 128 97 12 get lab i
+c = add c 1.0f64
+end
+end
+ret div c 64.0f64
+end
+note backward for sample i (fwd i must have run with lora); adds into grads at 2048
+note backward scratch: dz 16384 (12), dt2 16400 (4), dn1 16404 (24), da1 16428 (24), dp1 16452 (24), dt1 16476 (4)
+fn scal y ulong n ulong c f64 to void
+for k ulong n
+put m add y k mul c get m add y k
+end
+end
+note dz = (softmax(z) - onehot(label)) / batch
+fn bce i ulong to void
+z = add base i 97
+mx = get m add z amax z 12
+se = 0.0f64
+for k ulong 12
+se = add se fexp sub get m add z k mx
+end
+y = get lab i
+for k ulong 12
+g = div fexp sub get m add z k mx se
+if eq k y
+g = sub g 1.0f64
+end
+put m add 16384 k div g 64.0f64
+end
+end
+note rmsnorm backward: da = (dn - n * mean(dn * n)) / r
+fn brms i ulong to void
+n1 = add base i 68
+r1 = get m add base i 92
+dot = div sdot 16404 1 n1 24 24.0f64
+mu = get mut 0
+for k ulong 24
+dn = get m add 16404 k
+nv = mul get m add n1 k dot
+v = sub dn nv
+if eq mu 2
+v = add dn nv
+end
+put m add 16428 k div v r1
+end
+end
+note silu backward: d silu(p) = sig(p) (1 + p (1 - sig(p)))
+fn bsilu i ulong to void
+p1 = add base i 20
+mu = get mut 0
+for k ulong 24
+p = get m add p1 k
+sg = sig p
+d = mul sg add 1.0f64 mul p sub 1.0f64 sg
+if eq mu 1
+d = mul sg sub 1.0f64 mul p sub 1.0f64 sg
+end
+dv = mul get m add 16428 k d
+put m add 16452 k dv
+end
+end
+fn back i ulong to void
+b = base i
+bce i
+outacc 16384 add b 93 2304 12 4 2.0f64
+zero 16400 4
+mvtacc 1280 16384 16400 12 4
+scal 16400 4 2.0f64
+outacc 16400 add b 68 2208 4 24 1.0f64
+zero 16404 24
+mvtacc 384 16384 16404 12 24
+mvtacc 1184 16400 16404 4 24
+brms i
+bsilu i
+outacc 16452 add b 16 2112 24 4 2.0f64
+zero 16476 4
+mvtacc 1088 16452 16476 24 4
+scal 16476 4 2.0f64
+outacc 16476 b 2048 4 16 1.0f64
+end
+fn grads to f64
+zero 2048 304
+s = 0.0f64
+for i ulong 64
+fwd i 0 384 true
+s = add s lossi i
+back i
+end
+ret div s 64.0f64
+end
+note AdamW: beta1 0.9, beta2 0.999, eps 1e-8, weight decay 0.01. b1t, b2t = beta^t
+fn adam1 j ulong lr f64 b1t f64 b2t f64 to void
+g = get m add 2048 j
+mo = mul 0.9f64 get m add 3072 j
+mo = add mo mul 0.1f64 g
+vo = mul 0.999f64 get m add 4096 j
+g = mul g g
+vo = add vo mul 0.001f64 g
+put m add 3072 j mo
+put m add 4096 j vo
+mo = div mo sub 1.0f64 b1t
+vo = div vo sub 1.0f64 b2t
+vo = add fsqrt vo 0.00000001f64
+pj = get m add 1024 j
+g = add div mo vo mul 0.01f64 pj
+g = mul lr g
+if eq get mut 0 3
+put m add 1024 j add pj g
+else
+put m add 1024 j sub pj g
+end
+end
+fn adam lr f64 to void
+b1t = mul get m 31000 0.9f64
+b2t = mul get m 31001 0.999f64
+put m 31000 b1t
+put m 31001 b2t
+for j ulong 304
+adam1 j lr b1t b2t
+end
+end
+fn fabsd x f64 to f64
+if lt x 0.0f64
+ret neg x
+end
+ret x
+end
+note teacher entry: t = w + sum_q u[r,q] v[q,c], u is rows x 4, v is 4 x cols
+fn tent w ulong u ulong v ulong cols ulong r ulong c ulong to f64
+s = get m add w add mul r cols c
+ret add s sdot add v c cols add u mul r 4 4
+end
+fn teach to void
+for r ulong 24
+for c ulong 16
+put m add 20000 add mul r 16 c tent 0 21000 21100 16 r c
+end
+end
+for r ulong 12
+for c ulong 24
+put m add 20480 add mul r 24 c tent 384 21200 21300 24 r c
+end
+end
+for i ulong 64
+fwd i 20000 20480 false
+put lab i amax add base i 97 12
+end
+end
+note relative error of the analytic gradient of parameter j against a central difference
+fn gerr j ulong to f64
+pi = add 1024 j
+p0 = get m pi
+put m pi add p0 0.00001f64
+lp = total
+put m pi sub p0 0.00001f64
+lmn = total
+put m pi p0
+num = div sub lp lmn 0.00002f64
+an = get m add 2048 j
+den = fmax add fabsd num fabsd an 0.00000001f64
+ret div fabsd sub num an den
+end
+fn gcheck to f64
+fill 1024 304 0.3f64
+ld = grads
+worst = 0.0f64
+j = ulong 0
+while lt j 304
+worst = fmax worst gerr j
+j = add j 3
+end
+ret worst
+end
+fn tinit to void
+fill 1024 64 0.1f64
+zero 1088 96
+fill 1184 96 0.1f64
+zero 1280 48
+zero 3072 304
+zero 4096 304
+put m 31000 1.0f64
+put m 31001 1.0f64
+end
+fn main to int
+k = read 0 ob 0 1
+if eq k 1
+put mut 0 ulong sub ulong get ob 0 48
+end
+put rs 0 ulong 88172645463325252
+note 1. exp and log against known constants
+say 0
+putf fexp 1.0f64
+say 1
+putf flog 10.0f64
+if gt fabsd sub fexp 1.0f64 2.718281828459045f64 0.00000000000001f64
+ret 13
+end
+if gt fabsd sub flog 10.0f64 2.302585092994046f64 0.00000000000001f64
+ret 13
+end
+note 2. data: frozen base, a hidden low-rank teacher change, inputs and teacher labels
+fill 0 384 0.5f64
+fill 384 288 0.5f64
+fill 5120 1024 1.0f64
+fill 21000 96 0.6f64
+fill 21100 64 0.6f64
+fill 21200 48 0.6f64
+fill 21300 96 0.6f64
+teach
+note 3. gradient check at a random point (B nonzero), every 3rd parameter
+worst = gcheck
+say 2
+putf worst
+if gt worst 0.000001f64
+ret 10
+end
+note 4. train from the base model (B zero) with AdamW
+tinit
+l0 = total
+a0 = accuracy
+for step ulong 400
+ld = grads
+adam 0.02f64
+end
+l1 = total
+a1 = accuracy
+say 3
+putf l0
+say 4
+putf l1
+say 5
+putf a0
+say 6
+putf a1
+if gt l1 mul 0.5f64 l0
+ret 11
+end
+if lt a1 add a0 0.2f64
+ret 12
+end
+ret 0
+end
diff --git a/tests/omegalora/run.sh b/tests/omegalora/run.sh
new file mode 100644
index 0000000..571b8ff
--- /dev/null
+++ b/tests/omegalora/run.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+# SPDX-License-Identifier: AGPL-3.0-only
+# omegalora host glue (POSIX sh): compile native/omegalora/lora.om with the pinned seeded omc,
+# run the real build and the three mutants, and record every status. All math, training and
+# verdicts are in the .om unit; this script only compiles, runs and compares exit codes.
+# Usage: sh tests/omegalora/run.sh Env: OMC (pinned omc), OUT (default evidence/OMEGALORA/run).
+# Host CPU only (AArch64 Linux, the omc target). No GPU, network or service is touched.
+set -u
+ROOT=$(cd "$(dirname "$0")/../.." && pwd)
+OUT=${OUT:-$ROOT/evidence/OMEGALORA/run}
+OMC=${OMC:-$ROOT/../omega-mv/seed/out/omc}
+OMC_SHA=2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f
+BUILD=$(mktemp -d "${TMPDIR:-/tmp}/omegalora.XXXXXX")
+mkdir -p "$OUT"
+SUM="$OUT/summary.txt"
+: > "$SUM"
+note() { echo "$*" | tee -a "$SUM"; }
+fail() { note "OMEGALORA_FAIL $*"; exit 1; }
+note "source_commit=$(git -C "$ROOT" rev-parse HEAD)"
+note "host=$(uname -srm)"
+set -- $(sha256sum "$OMC")
+[ "$1" = "$OMC_SHA" ] || fail "compiler hash $1"
+note "compiler_sha256=$1"
+"$OMC" < "$ROOT/native/omegalora/lora.om" > "$BUILD/lora" 2> "$OUT/compile.stderr" || fail compile
+chmod +x "$BUILD/lora"
+set -- $(sha256sum "$ROOT/native/omegalora/lora.om"); note "source_sha256=$1"
+set -- $(sha256sum "$BUILD/lora"); note "binary_sha256=$1"
+# case MUTANT EXPECTED_EXIT: 0 real build, 1 silu grad, 2 rmsnorm grad, 3 adam sign
+bad=0
+for c in 0:0 1:10 2:10 3:11; do
+ mu=${c%%:*}; want=${c##*:}
+ printf '%s' "$mu" | "$BUILD/lora" > "$OUT/mutant$mu.stdout" 2> "$OUT/mutant$mu.stderr"
+ rc=$?
+ echo "$rc" > "$OUT/mutant$mu.rc"
+ if [ "$rc" = "$want" ]; then note "mutant$mu exit=$rc expected=$want PASS"
+ else note "mutant$mu exit=$rc expected=$want FAIL"; bad=1; fi
+done
+(cd "$OUT" && sha256sum mutant*.rc mutant*.stdout mutant*.stderr compile.stderr) > "$OUT/raw.sha256"
+rm -rf "$BUILD"
+[ $bad = 0 ] || fail "exit code mismatch"
+note OMEGALORA_PASS