Skip to content

Commit 4347046

Browse files
committed
Experiment 4: harmonic OOD gate — first measurable harmonic win
Two scenarios, both pure-OMC, both audit byte-identical across tree-walk and bytecode VM: Scenario A (uniform [1,90] OOD vs in-dist biased toward small attractors). L2 wins: AUROC 0.961 vs harmonic 0.910. Mechanism is clear from the mean-score table — OOD vectors have larger magnitudes, mean L2 score is 1313 vs 87 for in-dist. L2 gets a free magnitude advantage; harmonic's phi.fold discards magnitude and only catches the OOD when it lands in rare attractor buckets. Scenario B (magnitude-matched: OOD draws from same attractor set but with inverted weights — 10/30/60 small/med/large vs in-dist's 60/30/10). Harmonic edges past L2: AUROC 0.956 vs 0.946. The structural-rarity signal beats the L2 metric once the magnitude giveaway is gone. At low FPR L2 still has an edge (TPR@FPR=1%: 0.60 vs 0.48), but on overall ranking harmonic wins. This is the first measurable harmonic win on this branch and it reproduces the project README's existing thesis (harmonic wins on structural anomalies) in a new domain — OOD gating instead of credential-stuffing detection. Cumulative read across experiments 0-4: harmonic substrate is a structural detector, not a primary computation. Right hybrid is auxiliary, not substitution. Roadmap pivots to a combined gate (alpha-blend of L2 and harmonic) and a layer-norm-matched setup that simulates real transformer activations. One audit-flagged bug squashed: tree-walk lazily binds top-level function definitions while VM registers them up front. `mean_of` was defined after a forward reference in scenario B. Moved its definition earlier to keep the file VM/tree-walk identical.
1 parent 7bc0b33 commit 4347046

2 files changed

Lines changed: 547 additions & 46 deletions

File tree

experiments/hybrid_llm/README.md

Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -87,39 +87,48 @@ OMC_VM=1 ./target/release/omnimcode-standalone experiments/hybrid_llm/experiment
8787
| 1 | Perturbed query (query = true_val + noise), 200 trials per noise level | Softmax wins everywhere. noise=1: 189 vs 170. noise=7: 118 vs 99. noise=50: 42 vs 33. OmniWeight's |k|-normalised denominator pulls toward smaller-magnitude attractors regardless of perturbation direction, which hurts the "recover the original value" objective. |
8888
| 2 | Single-channel PE distinctness + lookup at L = 8 / 14 / 24 / 48 | Sinusoidal wins at short L (8/8 vs 6/8). At L=48 harmonic appears to overtake: 38/48 vs 26/48 (79% vs 54%). Flagged as a likely metric artefact — single-int "closest code" lookup favours monotonic over periodic encodings. |
8989
| 3 | 4-channel PE (harmonic primes 7/11/13/17, sin/cos periods 8/64), L2 lookup, L = 8 → 200 | **Sinusoidal regains its lead decisively at every L ≥ 16.** L=48: 48/48 vs 21/48. L=200: 72/200 vs 34/200. Harmonic saturates at 22 unique vectors by L=64; sinusoidal stays perfectly distinct up to L=64 then saturates at 64. The single-channel L=48 harmonic "win" was a metric artefact, exactly as suspected. |
90-
91-
### Cumulative read across experiments 0–3
92-
93-
The four experiments converge on a single picture:
94-
95-
> **At every fair comparison so far, the standard transformer
96-
> building blocks (softmax attention scoring, sinusoidal positional
97-
> encoding) beat the harmonic alternatives on the specific tasks
98-
> tested.** The harmonic substrate's only apparent wins have been
99-
> traceable to metric artefacts that vanish under proper vector
100-
> similarity.
101-
102-
This doesn't mean OMC's harmonic primitives are useless — the
103-
project's documented wins (the credential-stuffing detector beating
104-
IsolationForest at multi-dim structural anomalies, README's
105-
benchmark table) are real and reproducible. But it does mean:
106-
107-
1. **Drop-replacing transformer components with harmonic ones is the
108-
wrong play.** Per-head softmax → OmniWeight loses (exp 1).
109-
Sinusoidal PE → multi-channel harmonic PE loses (exp 3). The
110-
harmonic substrate is not a better-on-everything substitute.
111-
112-
2. **The harmonic substrate's home is structural-anomaly detection,
113-
not next-token prediction.** That's where it's already shown
114-
measurable wins in the existing codebase, and it's a different
115-
computational task from "rank candidates by relative similarity".
116-
117-
3. **The right hybrid architecture is auxiliary, not substitution.**
118-
Use a standard transformer for the main next-token loss, and add
119-
a harmonic structural-anomaly head as an auxiliary signal — for
120-
detecting OOD inputs, attention-pattern anomalies, or
121-
activations that have drifted off-attractor. That's the pivot
122-
from the roadmap below.
90+
| 4A | Harmonic OOD gate vs L2-NN baseline on 4-dim synthetic vectors (N_REF=300, 150 in-dist test, 150 OOD test). OOD = uniform [1, 90]. | L2 wins. AUROC L2 0.961 vs harmonic 0.910. TPR @ FPR=10%: L2 0.91 vs harmonic 0.71. L2 has a trivial magnitude advantage — mean L2 score 87 (in-dist) vs 1313 (OOD), since OOD vectors are larger on average and harmonic gate's `phi.fold` discards magnitude. |
91+
| 4B | Same gates, **magnitude-matched** structural OOD (inverted attractor weights: 10%/30%/60% small/med/large vs in-dist's 60%/30%/10%). | **Harmonic edges past L2 in AUROC: 0.956 vs 0.946.** At low FPR L2 still wins (TPR@FPR=1%: L2 0.60 vs harmonic 0.48), but on overall ranking the structural rarity signal beats the L2 metric once magnitude is no longer a giveaway. |
92+
93+
### Cumulative read across experiments 0–4
94+
95+
The five experiments converge on a clear, conditional picture:
96+
97+
> **The harmonic substrate is a structural detector, not a primary
98+
> computation.** It loses head-to-head against softmax attention
99+
> (exp 1) and multi-channel sinusoidal PE (exp 3). It loses to a
100+
> trivial L2-NN OOD gate when raw magnitude separates the
101+
> distributions (exp 4A). **It edges past L2-NN when magnitude is
102+
> matched and only structural distribution differs (exp 4B).**
103+
104+
Experiment 4 is the first comparison so far where the harmonic
105+
approach has won under any setup. The condition under which it
106+
wins is the exact condition the project README already documents:
107+
*structural* differences in *multi-dim* feature distributions.
108+
That replicates the credential-stuffing benchmark's regime in a
109+
new domain (synthetic OOD gating) and confirms it wasn't a one-off.
110+
111+
What this means concretely:
112+
113+
1. **The right hybrid architecture is auxiliary, not
114+
substitution.** Don't replace softmax with OmniWeight (exp 1
115+
said no). Don't replace sinusoidal PE with phi-fold (exp 3 said
116+
no). Add a harmonic structural-anomaly head as an *extra*
117+
signal alongside a standard transformer.
118+
119+
2. **Real LM activations are layer-normalised.** That strips the
120+
magnitude advantage L2 had in experiment 4A, putting us closer
121+
to experiment 4B's regime — where harmonic wins. So the
122+
theoretical case for harmonic OOD gating on transformer
123+
activations (rather than raw features) is stronger than the
124+
experiment 4A headline suggests.
125+
126+
3. **The right gate is probably a combination.** Experiment 4A says
127+
L2 owns the magnitude axis; 4B says harmonic owns the
128+
structural axis. A combined gate (e.g., logistic regression
129+
over `[l2_score, harmonic_score]` or simple multiplicative
130+
combination) should beat either alone, and that's the next
131+
experiment.
123132

124133
### What changed between experiment 2 and experiment 3
125134

@@ -145,18 +154,23 @@ result.
145154

146155
## Roadmap on this branch
147156

148-
- **0** Copy task: OmniWeight vs softmax scoring (no learning). ✓ done
157+
- **0** Copy task: OmniWeight vs softmax scoring. ✓ done
149158
- **1** Perturbed-query divergence study. ✓ done
150159
- **2** Single-channel positional-encoding distinctness + lookup. ✓ done
151-
- **3** Multi-channel PE with L2 lookup — fair comparison. ✓ done
152-
- **4** *Pivot.* Stop trying to substitute transformer components.
153-
Build a harmonic structural-anomaly head as an auxiliary signal:
154-
given a sequence of intermediate activations from a tiny
155-
transformer, flag tokens whose `harmonic_index` score against a
156-
reference distribution is anomalous. Re-use the credential-stuffing
157-
detector machinery (`harmonic_anomaly.omc`) over activation vectors
158-
instead of request features. Pure-OMC first, torch port second.
159-
- **5** With torch available: train a 2-layer transformer on a tiny
160-
char-level corpus. Add the experiment-4 anomaly head as an
161-
auxiliary loss term and measure whether it improves loss curves,
162-
OOD detection, or attention sharpness.
160+
- **3** Multi-channel PE with L2 lookup. ✓ done
161+
- **4** Harmonic OOD gate vs L2-NN baseline, two scenarios. ✓ done
162+
- **5** Combined gate: feed both `harmonic_score` and `l2_score` into a
163+
simple linear combiner (no learning — just `α·harmonic + (1−α)·l2`,
164+
sweep α) and re-run experiments 4A and 4B. Expectation: combined
165+
gate matches L2 on 4A, beats both on 4B.
166+
- **6** Realistic regime: pre-normalise reference and test vectors to
167+
unit L2 norm (simulating layer-norm). Re-run 4A under that
168+
normalisation. Hypothesis: harmonic gate's loss in 4A was driven
169+
entirely by magnitude separation, which vanishes under L2-norm.
170+
If harmonic's AUROC stays flat or rises past L2's after
171+
normalisation, that's strong evidence for the structural-detector
172+
thesis on transformer activations.
173+
- **7** Once torch is available: replicate experiment 6 on actual
174+
transformer activations from a tiny pretrained model. In-dist =
175+
activations from typical input; OOD = activations from adversarial
176+
or shuffled input.

0 commit comments

Comments
 (0)