feel: Omega tunes its own kernels while a model runs
Status: the decision core is specified here and checked against Wolfram (section 5). Wiring into an inference engine and every GPU measurement are NOT_RUN (section 7). What the core does not do, and what its checks do not show, is section 6: read it before relying on any sentence of sections 1 to 3.
1. Intent (Drake, 2026-11-18, verbatim)
"build omega to be able to dynamically adjust kernels to optimize speed while the model is running." "I want omega to be able to feel enough to be able to adjust itself to make itself as fast as possible and use wolfram to verify." "I want Omega to go the other way. It should be able to adapt to whatever model is there."
In one line: while any model runs, Omega measures its own kernels, moves to the faster way of running
each one, and every decision can be recomputed in Wolfram from the recorded timings. Scope of "never
runs a way that gives different results": a way is not run as the incumbent until its output was bit-for-bit equal
to the reference's on V launches it was shadowed on (3.2), and one unequal output bans it. After it is
admitted its output is not checked again by this core (section 6, item 1).
2. Shape
Three parts, and only the middle one is in this repository so far.
- Senses (the engine): the time each kernel launch took, and whether a candidate's output equals the reference output on the same input (2.1).
- feel (this repository, seeded Omega): decides, per class, which arm runs next.
- Muscles (the engine): the settings a launch can take without a rebuild.
Nothing in feel knows a model. A class is whatever the engine says is "the same work": a kernel kind plus its shape (rows, columns, element type, batch). A new model brings new classes; feel makes a table entry the first time it sees one, and no table has a fixed size (section 4, limits). An arm is one way to run a class: a kernel variant or a launch setting. Arm 0 is always the reference the engine would have used without feel. A class has 2 or more arms.
2.1 Terms
- Equal outputs. Bitwise: every byte of every output buffer the kernel writes is the same, so the
same values, the same signs of zero and the same NaN payloads. The engine reports 1 to
verdictonly for that. There is no tolerance in this core, for any dtype. A tolerance would be a change to what "never runs a way that gives different results" means; it is Drake's decision, not an engine option. - An eligible arm is one the engine can show gives bitwise-equal output to arm 0 on every input, by construction (it performs each output element's arithmetic in the same order). Eligible: launch settings that do not change that order (grid and block shape of an element-wise or gather kernel, vector width of loads and stores, buffer placement or caching), a tile shape whose per-output accumulation order is the same. Not eligible: a split-K, a different warp or tree reduction, atomics, any variant that changes the order of a floating-point reduction. Such a variant would be banned by its first unequal launch, which is the intended behaviour. An arm that is not bitwise-reproducible against itself is banned the same way. Whether enough eligible arms exist to speed up a real model is NOT_RUN (section 7).
- A trial is any launch in which a challenger runs: a shadow launch (3.2, run into scratch memory in addition to the real launch) or a timed launch of a duel (3.3). The cost of a trial is whatever its time turns out to be; the core cannot know it beforehand (section 6, item 2).
3. The rules (exact; all arithmetic is on non-negative integers)
Constants: H = 12, NMIN = 32, NMAX = 256, V = 3, WARM = 64, REST0 = 1024,
RESTMAX = 65536, MNUM = 63, MDEN = 64 (the 64 * and 63 * of adopt by mean below).
tests/run.sh requires each of these to be a const of feel.om with this value.
State of one class: K arms; status[a] in {0 untested, 1 admitted, 2 banned}, status[0] = 1;
incumbent inc = 0; mode in {rest, shadow, duel}, starting at rest; rest = WARM;
restlen = REST0; round-robin pointer next = 0; challenger ch; vcount; duel counters
k, w, l, sI, sC, hI, hC, n; tfirst; order bit o; generator z = 1; launch counter i = 0;
counts[a] = 0.
Each launch of the class is one step, in this order.
3.1 Choose. i += 1. The arm to run is inc unless the duel rule below says otherwise.
- mode rest,
rest > 0:rest -= 1. - mode rest,
rest = 0: look at arms(next + s) mod Kfors = 1..Kand take the first that is notincand not banned. If there is none:rest = restlen. Otherwise it becomeschandnext = ch; ifstatus[ch] = 0the mode becomes shadow withvcount = 0, else a duel starts. - mode shadow (also when just entered): the engine runs
incfor real and also runschon the same input into scratch memory, and reports whether the two outputs are equal. - mode duel (also when just entered): if
kis even,z = (z * 1103515245 + 12345) mod 2^31ando= bit 16 ofz. The arm isincwhen (keven ando = 0) or (kodd ando = 1), elsech. This launch is timed. counts[arm] += 1.
A duel starts with k = w = l = sI = sC = hI = hC = n = 0.
3.2 Verdict (only in shadow mode). Not equal: status[ch] = 2, event B, mode rest,
rest = restlen. Equal: vcount += 1; at vcount = V: status[ch] = 1, event M, and a duel
starts (the launch that carried the last verdict is not part of it).
3.3 Observe (only for a timed launch; t is its time). k even: tfirst = t. k odd: the
pair is complete; tC is the challenger's time and tI the incumbent's; sI += tI; sC += tC;
w += 1 if tC < tI; l += 1 if tC > tI; n += 1; if n = NMAX / 2 then hI = sI, hC = sC.
Then the first of these that holds ends the duel:
n >= NMINandl - w >= HandsC >= sI: reject (eventR).n >= NMAX. With the first half(hI, hC)and the second half(sI - hI, sC - hC):hC < hIandsC - hC < sI - hIandw - l >= H: adopt (eventA);- otherwise
64 * hC < 63 * hIand64 * (sC - hC) < 63 * (sI - hI): adopt by mean (eventAm); - otherwise draw (event
D).
Adopt: inc = ch, restlen = REST0. Reject or draw: restlen = min(2 * restlen, RESTMAX). In both
cases rest = restlen and the mode is rest. Finally k += 1.
Why these rules:
- Pairs, in an order the launch schedule cannot line up with, so that drift and periodic disturbance fall on both arms alike.
- Losses can reject a challenger early after the minimum pair count. Adoption by count waits for the last pair. Section 5 models these endpoints assuming both sum conditions agree with the count and each pair has a winner. The separate full-rule simulation includes the sum conditions and adoption by mean.
- The sums say what throughput cares about, the mean. A slower challenger is turned away early,
as soon as the count and the sums agree. Nothing is adopted early: an arm that is usually faster
but sometimes stalls looks best in a short duel, so adoption waits for all
NMAXpairs and needs the challenger's sum to be lower in both halves, with either the count on its side or a margin of 1/64 in both halves. One outside stall cannot decide a duel, because it falls in one half only. A stall rarer than about one launch inNMAXcan still go unseen by a whole duel (section 6, item 3). (An earlier draft adopted as soon as rule 1's mirror held after 32 pairs; Wolfram's simulation showed it adopting a challenger with a rare stall of its own about a third of the time. That draft's figures are in the result file as committed at 55d738f, history; the file is regenerated since.) - A candidate is not run for real as the incumbent before
Vequal outputs, and one unequal output bans it for the life of the process. Nothing re-checks an admitted arm (section 6, item 1). - After a duel the class rests on its incumbent, twice as long after each duel that changed nothing and from the start again after one that did. So the cost of looking falls toward a floor, and a change in the machine or the workload is still noticed.
4. The program and the engine entries
feel reads a trace on standard input and writes events on standard output.
Input lines: c CLASS K declares class CLASS with K arms (2..49 in a trace); `t CLASS t0 .. t(K-1)
OKMASK` is one launch of that class: the time each arm would take on this launch, and a mask whose
bit a says arm a's output equals the reference on this launch. The parser validates every field. The decision uses the time of the chosen arm and the mask bit for the shadowed arm. Any other line, a class used before
it is declared, a class declared twice, or a count outside its range: exit 2 and one line on standard
error.
Output lines, one per event, in the order they happen: CLASS B ARM I, CLASS M ARM I, and
CLASS A|R|Am|D ARM I N W L SI SC, where ARM is the challenger and I the class's launch counter.
At end of input, for each declared class in increasing order:
CLASS F INC RESTLEN COUNTS.. STATUS...
Exactly, as feel.om does it. A line is its fields with one space between them and a newline at its
end, the last line included; nothing else, so an empty line is refused. A number is 1 to 15 decimal
digits (leading zeros allowed). OKMASK is below 2^K. On bad input the events already decided stay
printed (gate case "a bad line after 67 launches"), then the one line feel: bad input, line N goes to
standard error, the exit status is 2 and no F line is written. If standard input cannot be read or
standard output cannot be written the exit status is 3. If the host refuses memory for the class
tables the events decided so far stay printed, the one line feel: out of memory, line N goes to
standard error and the exit status is 4. In 3.1, a launch that finds no arm to try sets rest = restlen
and does not count it down.
4.1 The engine entries
These four are what an engine calls; the trace reader calls the same four, so every decision in a
trace is a decision of the same code. Each checks its arguments and the order of calls before it
changes anything: a refused call changes nothing (the gate builds tests/api-main.om against
feel.om and compares what the entries return, tests/api-expected.txt, worked out by hand from this
section). A refusal is a returned code, never a trap and never a write to the wrong place.
| Call | Does | Returns |
|---|---|---|
setup c K | declares class c with K arms, once | 0, or a code |
choose c | one launch of class c, steps 3.1 | arm + 65536 * ch + 2^32 * owed, or ERR + code |
verdict c equal | 3.2: equal is 1 for bitwise-equal outputs, else 0 | 0, or a code |
observe c t | 3.3: t is the time the chosen arm took | 0, or a code |
In choose's result, arm (bits 0..15) is the arm to run; owed (bits 32..33) is 0 (nothing), 1 (a
verdict on arm ch, bits 16..31, run on the same input into scratch memory) or 2 (the time of this
launch). ERR is 2^63; a result below it is never an error.
Codes: 1 class not declared; 2 call out of order; 3 argument out of range; 4 class already declared; 5 the host refused memory. When several apply, the lowest number is returned, which is the order the checks run in.
Order of calls, per class (the illegal transitions are the refused ones). choose is allowed only when
nothing is owed from the last choose of that class. After a choose that owes a verdict only
verdict is allowed, after one that owes a time only observe; each settles the debt. A choose
that owes nothing needs no other call. Every other call is code 2. Different classes are independent.
4.2 Limits, and what kind each is
No table has a fixed size. Every per-class and per-arm table is a run-time pool that grows when a class
is declared (setup), and the trace reader's time buffer grows with the arms. What remains is stated
here with its reason (Drake, 2026-11-11: a limit stays only where it is a width of the machine or
the host's memory).
| Limit | Value | Kind |
|---|---|---|
| a time | below 10^15 | width of the 64-bit word: the largest sum is 256 * 64 * (10^15 - 1), below 2^64 (Wolfram, below). 10^15 is 11.57 days in nanoseconds |
| a class number | below 2^52 | conservative API input ceiling. One 64-bit table at that size alone would require 32 PiB. Memory is proportional to the largest class number declared: number classes from 0 upward |
| arms per class, API | 2 to 65535 | width of the fields of choose's result (16 bits) |
| arms per class, trace | 2 to 49 | width of the mask: it is written as a decimal below 10^15; 2^49 - 1 is below that and 2^50 - 1 is not, so 49 arms fit and 50 do not (Wolfram, below) |
| memory | what the host gives | a refusal is code 5 / exit 4. Gate: a class number past the address space, and a million classes in 64 MiB |
| the input and output buffers (65536 bytes) | none | read and write chunk sizes, not limits |
Wolfram: WolframLanguageEvaluator: {64*256*(10^15-1) < 2^64, N[64*256*(10^15-1)], N[2^64], N[10^15/(10^9*86400)], 2^49-1 < 10^15, 2^50-1 < 10^15} -> {True, 1.6383999999999984*^19, 1.8446744073709552*^19, 11.574074074074074, True, False}.
The alarm in place of a cap on classes (Drake, 2026-11-11: "just put a TEST that will alarm"): tests/run.sh
declares 100000 classes with the address space limited to 48 MiB and prints ALARM with the figures
when the program no longer fits. The threshold is about 500 bytes per class; it was set above what the
tables needed when it was written, so a table that starts growing faster, or an arm table per class
sized for the worst case, trips it. It tells someone to look. It does not stop the program.
The caller must serialize these entries. They share mutable tables across classes, including during growth.
How feel.om is called: setup c K declares a class; choose c, verdict c equal and
observe c t are the three steps; finals prints the F lines. The same three steps (choose, verdict,
observe) are what an engine will call; the trace form exists so that every decision can be replayed and
recomputed.
5. What Wolfram checked
The result files are produced by the scripts, not typed: each script's final value is one string and
the file is that string. tests/wolfram.sha256 (written by sh tests/seal.sh) records the SHA-256 of
each script and of its result; tests/run.sh fails when either changed without the other being
evaluated and sealed again. That catches drift. It cannot show that a result came from its script: the
independent re-evaluation of a script on a fresh Wolfram kernel does that, and the figures are not
quoted here: read them in the result files.
tests/oracle.wl->tests/expected-wolfram.txt: the whole state machine of section 3 in exact integers over synthetic traces. The traces: a 5% faster arm, a 10% slower one, a faster arm that is wrong, equal arms, a challenger with rare long stalls, a reference with rare long stalls, a change of which arm is faster part-way, two classes at once, times that are often exactly equal, a run long enough to reach the longest rest, a gain only in the second half, a gain only in the first, equal sums, a faster arm that is wrong on every 500th launch after its admission (lateWrong: shows the admitted arm is never banned, section 6 item 1), and an adopt by mean with the challenger winning fewer pairs than it loses (meanWin:Amwithw < l, which the count chain does not bound). The gate regenerates each trace with a second generator (tests/gen.py), checks its SHA-256 against Wolfram's, and requiresfeelto print exactly Wolfram's events.tests/wolfram-duel.wlcomputes an exact finite two-outcome walk. It removes rejected mass starting at NMIN and evaluates adoption once at NMAX. It assumes the relevant sums agree with the count. The full-rule simulation measures the effect of the sum and mean rules.tests/wolfram-rules-sim.wl->tests/wolfram-rules-sim-result.txt: 2000 simulated duels per row under the full rules of 3.3, with lognormal noise and outside stalls on both arms, one seed. A rate of 0 in 2000 is not 0: the column "95% upper bound of P(either adoption)" is the one-sided 95% upper bound of the adopt rate (for 0 in 2000,1 - (1/20)^(1/2000)), and it is the figure to quote. The rows with a stall of the challenger's own say what an unlucky arm costs (section 6, item 3).tests/wolfram-slow-trial.wl->tests/wolfram-slow-trial-result.txt: the exact cost of a challenger that loses every pair, as a share of the reference's time (section 6, item 2). Its rejection launches are required by the gate to equal theRlaunches of scenariocap.
These are properties of the model in section 3 on synthetic times. They say nothing yet about a real kernel on a real chip.
6. Scope: what the rules do not do, and what the checks do not show
- An admitted arm is not checked again. An arm that gave equal outputs on
Vshadowed launches is trusted for the life of the process; the incumbent is never compared with the reference again. An arm that is wrong only now and then (scenariolateWrong) is admitted, adopted and never banned; its wrong outputs are delivered. The claim is: the core does not adopt an arm that differed on any of itsVshadowed launches. Periodic re-verification would need the engine to shadow the incumbent now and then; it is not part of this core and not built. - A trial of unpredictable slowness. The core sees a launch's time only after the launch, and it
cannot interrupt a launch. What it bounds is the number of launches given to a challenger: a
challenger that loses every pair, however slow, is turned away by rule 1 at pair
NMIN, so it getsNMINtimed launches per duel (andVshadow launches the first time). It then rests forrestlenlaunches, twice as long after each reject, up toRESTMAX. What it does not bound is the time those launches take: with a challengerXtimes slower, in units of one incumbent launch, the extra time isV Xonce andNMIN (X-1)per duel, and the share of the whole run it adds is intests/wolfram-slow-trial-result.txt: it falls towardNMIN (X-1) / (RESTMAX + 2 NMIN)and is large for a very slowX(read thelimitlines). A launch that never returns is outside the core; the engine must give every trial a deadline and report the deadline as its time. No early stop for a catastrophic challenger is built (a rule such as "sum abovektimes the incumbent's after a few pairs" would need its own simulation, its own false-reject figures and a new oracle). Until it is, an engine offers only arms whose slowest plausible case it can afford at that rate. - Rare stalls. A challenger whose own stalls are rarer than about one launch in
NMAXcan pass a whole duel without showing one. The row for one stall in 128 launches shows adoption of a challenger that is slower on average. The one-in-512 challenger is faster on average. - Adopt by mean needs no win count, by design (3.3.2): the challenger can win fewer pairs than it
loses and still be adopted when its sums are lower in both halves by 1/64 (scenario
meanWin). - What the gate shows.
feel.omequals the oracle on the synthetic traces (the oracle was written from section 3; it is evidence that the program implements these rules, not that the rules are the right ones); the engine entries refuse what 4.1 says (the driver and its expected output were derived by hand); each of the single-line changes to the program or its checks thattests/run.shlists is caught (mutants); the Wolfram files are the sealed outputs of their scripts, and the constants SPEC and the scripts restate arefeel.om's. It does not show behaviour on a chip, or that a real kernel pair is eligible (2.1). - Timing on a GPU perturbs what it measures. A per-launch time on a GPU needs a per-launch event or a synchronisation; that overhead is paid by every timed launch, can be larger than the difference between two arms, and can change the schedule of the work. It is not modelled anywhere here. The first engine measurement has to measure it.
7. Not built, not run
- The engine side: calling
choose,verdictandobservefrom an inference engine; arms for real kernels; the equality check on real outputs (2.1). NOT_RUN. - Any measurement on a GPU. NOT_RUN. No speed is claimed.
- Interaction between classes (an arm that makes the next kernel slower) is not seen by a per-class duel; the end-to-end check for that is part of the engine work.