Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/spec/empirical-optimizer.md # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / spec / empirical-optimizer.md` 300 lines · 16366 bytes Raw Blame History Source # Omega empirical cost model (OMEGA_EMPIRICAL_OPTIMIZER) Code: `src/runtime/rx_costmodel.{c,h}`. Tests: `tests/runtime/rx_costmodel_unit.c` (`make test-costmodel`, any host) and `tests/runtime/rx_empirical_optimizer.c` (`make test-empirical`, AArch64). Receipt: `evidence/EMPIRICAL/`. ## Rule Omega picks a realization from what it has measured, not from a fixed rule. ``` features of a call ──► predicted cost of every eligible realization, with spread ──► SELECT one or MEASURE two, when a run is worth it runs it chose ──► observations ──► the working model working model ──► judged apart ──► proposed as a generation's `model` blob ──► promoted by the subject holding the promotion right ──► durable; read back after a restart ``` This is not authority learning. No feature comes from a capability. An arm is eligible only if the caller says its verdict passed. The model is a calculator. `rx_costmodel.o` is linked alone first and the build fails if it references the generation store, any authority operation, or anything that maps, forks or runs code (`nm -u` check in the Makefile). It can predict, decide and serialize. It cannot promote itself, run what it chooses, or widen what it may choose from. ## Why `omega_matvec_dispatch` picks with a fixed rule: `unroll2` when N ≤ 8, else `unroll4_dual`. R10 found that rule wrong on the Spark's A725 cores. The probe for this gate (both core classes, 6 × 10 shapes, all five arms) showed how wrong: - `unroll4_dual` is often the slowest arm on both core classes. On A725 it is typically about 2× the reference (2.9× at 16 × 64). On X925 it is up to 1.3× the reference at wide shapes. - `quad4` (R10) is the best arm on X925 for most shapes, but 1.3–2.1× slower than the reference for thin matrices (N ≤ 3). - On A725 the compiled reference is best or tied for most shapes. `quad4` wins only at large sizes. The best choice depends on shape and core class together. A rule of the form "if N > k" cannot express that. ## Features and targets Feature Used how input shape (M, N) fit: log2 M, log2 N, product, (log2 N)², N ≤ 3, N % 4 ≠ 0 state size and memory locality fit: doublings of the working set past the core's private L2 hardware state cell: core class from MIDR (X925, A725, other) resource pressure cell: pressure bucket; learned as a correction (below) semantic operation class cell: matvec only today (`RX_CM_OPS` = 1) thermal state recorded (acpitz °C); not varied, not fit current realization recorded evidence requirement enforced: only arms with a passing verdict are eligible latency and energy budget constraints: an arm whose 90% bound misses the budget is skipped branch count, cognitive requirement constant for matvec (0, none); recorded Target How it is obtained latency measured, ps per call energy cluster meter (`aien_spbm` cpu_p / cpu_e); power per arm above idle; predicted energy = latency × power memory code bytes + working set throughput derived from latency failure probability Beta posterior from verification refusals and wrong results; any failure excludes the arm verification cost measured, ns, per arm recompute cost synthesis + verification ns contention H3 cost over H1 cost for the same job. The quietest core is chosen per phase, so the two tables may come from different cores of the same class. Only cores in the process's affinity mask are candidates; a core class with no allowed core is absent from the run quality exact: output digest equal to the reference's transfer cost not measured: one shared-memory CPU, no device transfer in this operation ## Predictor One Bayesian linear regression per (cell, arm) on log2 ps per call, with a normal-inverse-gamma ridge prior. The basis has eight readable terms (above). Each (cell, arm) keeps only sufficient statistics: X'X, X'y, y'y, n. So the model is a fixed 28,112-byte blob, well under the 64 KiB generation limit. - Predictions are Student-t with mean φ'μ and spread √(σ²(1 + φ'Λ⁻¹φ)) × `sd_scale`. The leverage term widens the spread away from the training data. σ² has a floor of 0.03² (about 2%). - A cell needs 12 observations (`RX_CM_MIN_OBS`) before it predicts. - An unknown semantic operation is not a cell. `rx_cm_cell` returns `RX_CM_CELL_NONE`, which is never used as an index. Prediction, decision and observation refuse it (`RX_CM_ERR_UNSUPPORTED`, decision `RX_CM_REFUSE`) and do not read or write another family's statistics. An unknown core class is still the OTHER bucket, and pressure past the last bucket still saturates. Those are declared buckets, not a catch-all operation. Adding a family widens `RX_CM_OPS`, changes `RX_CM_CELLS`, and bumps the blob version. A blob whose version, basis size, cell count, arm cap or core count disagrees is refused. - Pressure cells do not refit the whole curve. They hold a two-number correction over the quiet cell of the same core class: log2 cost under pressure = quiet prediction + a + b × (doublings past cache). Four observations make it usable. Before that, the quiet prediction is used with its spread widened by `RX_CM_UNSEEN_SHIFT` = 1.0 log2. That is a stated prior: an unseen condition may halve or double cost. - Calibration (split conformal). After training, the learner receives the cost tables of half the validation jobs. It sets `sd_scale` so that the central 80% interval covers 80% of them, never below 1. The judge grades on the other half. `sd_scale` is part of the promoted blob. ## Deciding, and when to measure The chosen arm is the one with the lowest predicted cost among eligible arms that meet the budgets. The competitor is the eligible arm with the largest expected improvement over it: EI = E[max(0, log2 cost(chosen) − log2 cost(competitor))] - MEASURE when EI > `ei_min` (0.08 log2, about 6%) or the competitor has no prediction, and the exploration budget allows it. - Two arms predicted equal and tight are not worth a run. An arm the model knows little about, or two it cannot separate, are worth one. An earlier rule ("measure when P(runner-up better) > 0.2") measured near-ties on nearly every job and ate the gain; it was replaced after the first Spark runs. - A measurement runs the chosen arm for the whole job and probes the competitor on a quarter of the calls. The learner's own timing of a run is the fastest of three chunks of that run's calls. - Budget: exploration may not exceed 5% of chosen work plus 0.5 ms. A measurement starts only below that line, so the total can overshoot it by at most one probe. The receipt checks this over the whole held-out run of a core class, because H1, H2 and H3 share one online model: no measurement may start at or over the line, and the total may exceed the line by no more than the last charge. A held-out group that measures nothing inherits the previous group's overshoot and is judged against that charge, not against zero. A self-test that does no timing drives `rx_cm_decide` through exactly that sequence on every run. The first Spark runs used 10% plus 20 ms, then 10% plus 2 ms. The online learner then failed the 5%-under-the-fixed-rule criterion (0.953 of the rule on X925 H2), and the budget was tightened to 5% plus 0.5 ms after seeing that. The change is recorded here for that reason. - Frozen mode (`allow_measure` = 0) never measures. ## Exploration constraints Constraint How it holds within capability constraints arms outside `eligible` are never chosen or measured: 20,000 random decisions in the unit test, and every held-out decision on the Spark no unapproved external effects the model has no effect path (link check). The harness runs only pure matvec realizations, each verified in a forked child before the parent may run it never self-promotes the model cannot reach `rx_gen_*` (link check). The learner subject's promotion attempts are refused by the native authority, both with its own capability and with the promoter's under its own name. R9 also refuses a proposer promoting its own candidate resource budgets exploration budget above; the gate harness counts violations known-good fallback the reference is always eligible. With no durable model, or a torn model blob (`RX_GEN_ERR_TORN`), Omega runs the reference. Any arm with a failure is excluded ## Promotion - The working model is proposed as an R9 generation. Its blobs are: - `model`: the canonical blob - `evidence`: the validation summary - `realization`: the arm set - `config`: the policy - `provenance` - An independent judge measures its own validation work: 35 shapes per core class, none of them training shapes. Even-numbered jobs go to the learner for calibration. The judge grades on the odd-numbered ones and accepts only if the candidate: - costs at least 5% less than the fixed rule; - costs no more than always running the known-good reference; - costs no more than the model in force. The code checks this, but this gate makes only a first promotion, so that branch is not exercised. Beating the fixed rule alone is not enough. On the first Spark run, a model with its quad4 and scalar knowledge swapped still beat the fixed rule by 5%. - Only a subject holding `RX_GEN_RIGHT_PROMOTE` on the native Aienux authority can promote. - After promotion the store is closed and recovered, then reopened. The model is read back from the active generation and compared by digest. - Online updates made after promotion stay in the working copy. The durable model is unchanged until another promotion. ## The gate `make test-empirical` on the DGX Spark. Every policy is charged from the same per-job cost table. The table times every eligible arm in rotating order and keeps the best of 5. The learner never sees the table. The online learner's cost includes every probe it ran. Policies compared: - the fixed rule; - always the reference; - the best single arm on the training work (quad4 on X925, the reference on A725); - learned, frozen (the durable model); - learned, online (it keeps measuring within budget); - the per-job oracle. Held-out distributions, each run on both core classes: - H1: 60 unseen shapes, log-uniform M ∈ [3, 2048], N ∈ [3, 4096]. No M or N value appears in training or validation. - H2: a thin-heavy mix. 70% have N ∈ 1..7, values training also used, with M values never seen and up to 5,800, beyond the training range of 1,024. 30% are like H1. - H3: H1's jobs under memory pressure from 6 co-running threads. No training data has pressure. A second, independent check replays each policy's choices end to end. The blocks alternate, 7 rounds each. For each policy the replay keeps the fastest block among those where the thread waited for its core less than 1% of the time, using `/proc/thread-self/schedstat`. It also reads the cluster energy meter for that block. PASS requires, for every core class and held-out distribution: - the frozen and the online model each at least 5% under the fixed rule, the online figure including its probes; - the frozen model within 3% of the best single arm, and under it over all held-out work; - replay wall time under the fixed rule; - 80% intervals covering at least 60% on H1 and H2. PASS also requires, overall: - zero output mismatches over every run of every arm; - the planted wrong arm refused and never run in the parent; - no ineligible arm chosen or measured; - no exploration budget violation; - every promotion check. H3 coverage is reported, not gated. The frozen model never saw pressure, so its H3 spread rests on the unseen-shift prior. The first runs had 0.5 as that prior and showed H3 coverage between 1% and 81%, depending on what else was running on the machine. That is why the prior is now 1.0 and why H3 coverage is not a pass condition. This criterion was changed after those runs and is recorded here for that reason. Hosted CI runs the same test on a different AArch64 core with `EMPIRICAL_ALLOW_NO_WIN=1`. There a win is recorded (`CHAIN_PASS_NO_WIN`), not required. ## Findings ### Qualifying run Candidate `ff0109b`, receipt `evidence/EMPIRICAL/7aab6079fab855675c89698e62dfb347af7a7c948ffa5fdd4d85aa0564a008a3.json` (bound, clean tree, AIENOS `c8ab65e`, load average 2.1 to 3.8). 44 checks, 0 failures; 20,212 runs checked against the reference, 0 mismatches; planted arm refused, 0 parent runs; 0 budget violations. Model blob 28,112 bytes. Cost as a fraction of the fixed rule's (table terms; online includes probes): Core Distribution frozen online frozen / best single arm replay wall X925 H1 unseen shapes 0.584 0.641 1.000 (quad4) 0.615 X925 H2 thin-heavy 0.778 0.785 0.788 0.767 X925 H3 pressure 0.583 0.733 1.000 — A725 H1 unseen shapes 0.557 0.562 0.955 (reference) 0.557 A725 H2 thin-heavy 0.694 0.710 0.979 0.695 A725 H3 pressure 0.704 0.833 1.011 — Validation: 0.610 of the fixed rule; 80% intervals covered 0.859. Held-out 80% coverage: H1 0.83 / 0.88, H2 0.74 / 0.79 (X925 / A725); H3, not gated, 0.97 / 0.65. The best single arm differs by core class (quad4 on X925, the reference on A725): no single fixed arm is right for the machine, and on X925 thin-heavy work the learned choice is 21% under quad4-everywhere. ### Development runs on the Spark (before the qualifying run) Each was a full `test-empirical` run on the shared Spark (load average 2–7, other Omega sessions testing at the same time). Run Change before it Outcome 1 first version judge accepted a poisoned model (swapped quad4/scalar still beat the fixed rule by 5%); online learner measured on 154 of 154 training jobs; A725 H1 coverage 0.16 2 judge also requires ≤ always-reference online cost above the fixed rule on X925 H2 (1.36): near-ties measured every job 3 EI rule; probes a quarter job; chunked timing; split calibration; quietest core all frozen criteria met; online 1.017 of the rule on X925 H3; A725 H3 coverage 0.07 4 pressure as a correction; unseen-shift prior 0.5 online 0.953 of the rule on X925 H2 5 prior 1.0; budget 5% + 0.5 ms; H3 coverage reported, not gated replay on X925 H2 1.506 of the rule (energy 1.488): the core was shared for all five blocks 6 none (debug readout of replay blocks) every criterion met — replay: 7 rounds, blocks with core waiting ≥ 1% skipped stability runs below Stability: 3 of 3 runs passed every criterion (same code as the qualifying candidate, before the rebase onto main). Run 2 was paused partway through by the R15 quiet-machine marker (SIGSTOP until the marker was removed) and still passed. Frozen ratios to the fixed rule ranged 0.56–0.82; online 0.58–0.82; replay 0.56–0.86. H3 coverage, reported but not gated, ranged 0.53–1.00. The frozen model was 0.50–0.86 of the fixed rule on every core class and distribution in every one of the six runs. The criteria that moved between runs were the online learner's cost and the replay. - On a shared machine, costs are floors: best of 5 per table entry, fastest chunk per learner run, least-contended block per replay. Load average and the timed CPUs per phase are in the receipt. - The cluster energy meter includes other tenants and updates about every 0.1 s. Per-arm power (a few hundred mW above idle) is noisy. Replay energy ratios are reported, not gated. ## Not claimed - Integration into the resident `omega.select` reaction. The R10 faculty still selects by its own measurement. Wiring the model into it is a follow-up. - Operations other than integer matvec. Graphics-processor realizations. - Thermal or cognitive features varied in a controlled way. - Energy per call. Energy is measured per arm window and per replay block. - Transfer cost. - The Aienux kernel. The authority runs as a host library, as in R7–R14.