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 Rendered 1 # Omega empirical cost model (OMEGA_EMPIRICAL_OPTIMIZER) 2 3 Code: `src/runtime/rx_costmodel.{c,h}`. Tests: `tests/runtime/rx_costmodel_unit.c` 4 (`make test-costmodel`, any host) and `tests/runtime/rx_empirical_optimizer.c` 5 (`make test-empirical`, AArch64). Receipt: `evidence/EMPIRICAL/`. 6 7 ## Rule 8 9 Omega picks a realization from what it has measured, not from a fixed rule. 10 11 ``` 12 features of a call ──► predicted cost of every eligible realization, with spread 13 ──► SELECT one or MEASURE two, when a run is worth it 14 runs it chose ──► observations ──► the working model 15 working model ──► judged apart ──► proposed as a generation's `model` blob 16 ──► promoted by the subject holding the promotion right 17 ──► durable; read back after a restart 18 ``` 19 20 This is not authority learning. No feature comes from a capability. An arm is 21 eligible only if the caller says its verdict passed. 22 23 The model is a calculator. `rx_costmodel.o` is linked alone first and the 24 build fails if it references the generation store, any authority operation, 25 or anything that maps, forks or runs code (`nm -u` check in the Makefile). 26 It can predict, decide and serialize. It cannot promote itself, run what it 27 chooses, or widen what it may choose from. 28 29 ## Why 30 31 `omega_matvec_dispatch` picks with a fixed rule: `unroll2` when N ≤ 8, else 32 `unroll4_dual`. R10 found that rule wrong on the Spark's A725 cores. The probe 33 for this gate (both core classes, 6 × 10 shapes, all five arms) showed how 34 wrong: 35 36 - `unroll4_dual` is often the slowest arm on both core classes. On A725 it is 37 typically about 2× the reference (2.9× at 16 × 64). On X925 it is up to 38 1.3× the reference at wide shapes. 39 - `quad4` (R10) is the best arm on X925 for most shapes, but 1.3–2.1× slower 40 than the reference for thin matrices (N ≤ 3). 41 - On A725 the compiled reference is best or tied for most shapes. `quad4` wins 42 only at large sizes. 43 44 The best choice depends on shape and core class together. A rule of the form 45 "if N > k" cannot express that. 46 47 ## Features and targets 48 49 | Feature | Used how | 50 |---|---| 51 | input shape (M, N) | fit: log2 M, log2 N, product, (log2 N)², N ≤ 3, N % 4 ≠ 0 | 52 | state size and memory locality | fit: doublings of the working set past the core's private L2 | 53 | hardware state | cell: core class from MIDR (X925, A725, other) | 54 | resource pressure | cell: pressure bucket; learned as a correction (below) | 55 | semantic operation class | cell: matvec only today (`RX_CM_OPS` = 1) | 56 | thermal state | recorded (acpitz °C); not varied, not fit | 57 | current realization | recorded | 58 | evidence requirement | enforced: only arms with a passing verdict are eligible | 59 | latency and energy budget | constraints: an arm whose 90% bound misses the budget is skipped | 60 | branch count, cognitive requirement | constant for matvec (0, none); recorded | 61 62 | Target | How it is obtained | 63 |---|---| 64 | latency | measured, ps per call | 65 | energy | cluster meter (`aien_spbm` cpu_p / cpu_e); power per arm above idle; predicted energy = latency × power | 66 | memory | code bytes + working set | 67 | throughput | derived from latency | 68 | failure probability | Beta posterior from verification refusals and wrong results; any failure excludes the arm | 69 | verification cost | measured, ns, per arm | 70 | recompute cost | synthesis + verification ns | 71 | 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 | 72 | quality | exact: output digest equal to the reference's | 73 | transfer cost | not measured: one shared-memory CPU, no device transfer in this operation | 74 75 ## Predictor 76 77 One Bayesian linear regression per (cell, arm) on log2 ps per call, with a 78 normal-inverse-gamma ridge prior. The basis has eight readable terms (above). 79 Each (cell, arm) keeps only sufficient statistics: X'X, X'y, y'y, n. So the 80 model is a fixed 28,112-byte blob, well under the 64 KiB generation limit. 81 82 - **Predictions** are Student-t with mean φ'μ and spread 83 √(σ²(1 + φ'Λ⁻¹φ)) × `sd_scale`. The leverage term widens the spread away 84 from the training data. σ² has a floor of 0.03² (about 2%). 85 - **A cell** needs 12 observations (`RX_CM_MIN_OBS`) before it predicts. 86 - **An unknown semantic operation** is not a cell. `rx_cm_cell` returns 87 `RX_CM_CELL_NONE`, which is never used as an index. Prediction, decision 88 and observation refuse it (`RX_CM_ERR_UNSUPPORTED`, decision `RX_CM_REFUSE`) 89 and do not read or write another family's statistics. An unknown core class 90 is still the OTHER bucket, and pressure past the last bucket still saturates. 91 Those are declared buckets, not a catch-all operation. Adding a family 92 widens `RX_CM_OPS`, changes `RX_CM_CELLS`, and bumps the blob version. A 93 blob whose version, basis size, cell count, arm cap or core count disagrees 94 is refused. 95 - **Pressure cells** do not refit the whole curve. They hold a two-number 96 correction over the quiet cell of the same core class: log2 cost under 97 pressure = quiet prediction + a + b × (doublings past cache). Four 98 observations make it usable. Before that, the quiet prediction is used with 99 its spread widened by `RX_CM_UNSEEN_SHIFT` = 1.0 log2. That is a stated 100 prior: an unseen condition may halve or double cost. 101 - **Calibration (split conformal).** After training, the learner receives the 102 cost tables of half the validation jobs. It sets `sd_scale` so that the 103 central 80% interval covers 80% of them, never below 1. The judge grades on 104 the other half. `sd_scale` is part of the promoted blob. 105 106 ## Deciding, and when to measure 107 108 The chosen arm is the one with the lowest predicted cost among eligible arms 109 that meet the budgets. The competitor is the eligible arm with the largest 110 expected improvement over it: 111 112 EI = E[max(0, log2 cost(chosen) − log2 cost(competitor))] 113 114 - **MEASURE** when EI > `ei_min` (0.08 log2, about 6%) or the competitor has 115 no prediction, and the exploration budget allows it. 116 - Two arms predicted equal and tight are not worth a run. An arm the model 117 knows little about, or two it cannot separate, are worth one. An earlier 118 rule ("measure when P(runner-up better) > 0.2") measured near-ties on nearly 119 every job and ate the gain; it was replaced after the first Spark runs. 120 - A measurement runs the chosen arm for the whole job and probes the 121 competitor on a quarter of the calls. The learner's own timing of a run is 122 the fastest of three chunks of that run's calls. 123 - **Budget:** exploration may not exceed 5% of chosen work plus 0.5 ms. A 124 measurement starts only below that line, so the total can overshoot it by 125 at most one probe. The receipt checks this over the whole held-out run of a 126 core class, because H1, H2 and H3 share one online model: no measurement 127 may start at or over the line, and the total may exceed the line by no more 128 than the last charge. A held-out group that measures nothing inherits the 129 previous group's overshoot and is judged against that charge, not against 130 zero. A self-test that does no timing drives `rx_cm_decide` through exactly 131 that sequence on every run. 132 The first Spark runs used 10% plus 20 ms, then 10% plus 2 ms. The online 133 learner then failed the 5%-under-the-fixed-rule criterion (0.953 of the rule 134 on X925 H2), and the budget was tightened to 5% plus 0.5 ms after seeing 135 that. The change is recorded here for that reason. 136 - **Frozen mode** (`allow_measure` = 0) never measures. 137 138 ## Exploration constraints 139 140 | Constraint | How it holds | 141 |---|---| 142 | 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 | 143 | 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 | 144 | 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 | 145 | resource budgets | exploration budget above; the gate harness counts violations | 146 | 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 | 147 148 ## Promotion 149 150 1. The working model is proposed as an R9 generation. Its blobs are: 151 - `model`: the canonical blob 152 - `evidence`: the validation summary 153 - `realization`: the arm set 154 - `config`: the policy 155 - `provenance` 156 2. An independent judge measures its own validation work: 35 shapes per core 157 class, none of them training shapes. Even-numbered jobs go to the learner 158 for calibration. The judge grades on the odd-numbered ones and accepts 159 only if the candidate: 160 - costs at least 5% less than the fixed rule; 161 - costs no more than always running the known-good reference; 162 - costs no more than the model in force. The code checks this, but this 163 gate makes only a first promotion, so that branch is not exercised. 164 165 Beating the fixed rule alone is not enough. On the first Spark run, a model 166 with its quad4 and scalar knowledge swapped still beat the fixed rule by 5%. 167 3. Only a subject holding `RX_GEN_RIGHT_PROMOTE` on the native Aienux 168 authority can promote. 169 4. After promotion the store is closed and recovered, then reopened. The model 170 is read back from the active generation and compared by digest. 171 5. Online updates made after promotion stay in the working copy. The durable 172 model is unchanged until another promotion. 173 174 ## The gate 175 176 `make test-empirical` on the DGX Spark. Every policy is charged from the same 177 per-job cost table. The table times every eligible arm in rotating order and 178 keeps the best of 5. The learner never sees the table. The online learner's 179 cost includes every probe it ran. 180 181 **Policies compared:** 182 - the fixed rule; 183 - always the reference; 184 - the best single arm on the training work (quad4 on X925, the reference on A725); 185 - learned, frozen (the durable model); 186 - learned, online (it keeps measuring within budget); 187 - the per-job oracle. 188 189 **Held-out distributions**, each run on both core classes: 190 191 - **H1:** 60 unseen shapes, log-uniform M ∈ [3, 2048], N ∈ [3, 4096]. No M 192 or N value appears in training or validation. 193 - **H2:** a thin-heavy mix. 70% have N ∈ 1..7, values training also used, 194 with M values never seen and up to 5,800, beyond the training range of 195 1,024. 30% are like H1. 196 - **H3:** H1's jobs under memory pressure from 6 co-running threads. No 197 training data has pressure. 198 199 A second, independent check replays each policy's choices end to end. The 200 blocks alternate, 7 rounds each. For each policy the replay keeps the fastest 201 block among those where the thread waited for its core less than 1% of the 202 time, using `/proc/thread-self/schedstat`. It also reads the cluster energy 203 meter for that block. 204 205 **PASS requires, for every core class and held-out distribution:** 206 - the frozen and the online model each at least 5% under the fixed rule, the 207 online figure including its probes; 208 - the frozen model within 3% of the best single arm, and under it over all 209 held-out work; 210 - replay wall time under the fixed rule; 211 - 80% intervals covering at least 60% on H1 and H2. 212 213 **PASS also requires, overall:** 214 - zero output mismatches over every run of every arm; 215 - the planted wrong arm refused and never run in the parent; 216 - no ineligible arm chosen or measured; 217 - no exploration budget violation; 218 - every promotion check. 219 220 H3 coverage is reported, not gated. The frozen model never saw pressure, so 221 its H3 spread rests on the unseen-shift prior. The first runs had 0.5 as that 222 prior and showed H3 coverage between 1% and 81%, depending on what else was 223 running on the machine. That is why the prior is now 1.0 and why H3 coverage 224 is not a pass condition. This criterion was changed after those runs and is 225 recorded here for that reason. 226 227 Hosted CI runs the same test on a different AArch64 core with 228 `EMPIRICAL_ALLOW_NO_WIN=1`. There a win is recorded (`CHAIN_PASS_NO_WIN`), 229 not required. 230 231 ## Findings 232 233 ### Qualifying run 234 235 Candidate `ff0109b`, receipt 236 `evidence/EMPIRICAL/`7aab6079fab855675c89698e62dfb347af7a7c948ffa5fdd4d85aa0564a008a3`.json` 237 (bound, clean tree, AIENOS `c8ab65e`, load average 2.1 to 3.8). 44 checks, 0 238 failures; 20,212 runs checked against the reference, 0 mismatches; planted arm 239 refused, 0 parent runs; 0 budget violations. Model blob 28,112 bytes. 240 241 Cost as a fraction of the fixed rule's (table terms; online includes probes): 242 243 | Core | Distribution | frozen | online | frozen / best single arm | replay wall | 244 |---|---|---|---|---|---| 245 | X925 | H1 unseen shapes | 0.584 | 0.641 | 1.000 (quad4) | 0.615 | 246 | X925 | H2 thin-heavy | 0.778 | 0.785 | 0.788 | 0.767 | 247 | X925 | H3 pressure | 0.583 | 0.733 | 1.000 | — | 248 | A725 | H1 unseen shapes | 0.557 | 0.562 | 0.955 (reference) | 0.557 | 249 | A725 | H2 thin-heavy | 0.694 | 0.710 | 0.979 | 0.695 | 250 | A725 | H3 pressure | 0.704 | 0.833 | 1.011 | — | 251 252 Validation: 0.610 of the fixed rule; 80% intervals covered 0.859. Held-out 253 80% coverage: H1 0.83 / 0.88, H2 0.74 / 0.79 (X925 / A725); H3, not gated, 254 0.97 / 0.65. The best single arm differs by core class (quad4 on X925, the 255 reference on A725): no single fixed arm is right for the machine, and on X925 256 thin-heavy work the learned choice is 21% under quad4-everywhere. 257 258 ### Development runs on the Spark (before the qualifying run) 259 260 Each was a full `test-empirical` run on the shared Spark (load average 2–7, 261 other Omega sessions testing at the same time). 262 263 | Run | Change before it | Outcome | 264 |---|---|---| 265 | 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 | 266 | 2 | judge also requires ≤ always-reference | online cost above the fixed rule on X925 H2 (1.36): near-ties measured every job | 267 | 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 | 268 | 4 | pressure as a correction; unseen-shift prior 0.5 | online 0.953 of the rule on X925 H2 | 269 | 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 | 270 | 6 | none (debug readout of replay blocks) | every criterion met | 271 | — | replay: 7 rounds, blocks with core waiting ≥ 1% skipped | stability runs below | 272 273 **Stability: 3 of 3 runs passed every criterion** (same code as the 274 qualifying candidate, before the rebase onto main). Run 2 was paused 275 partway through by the R15 quiet-machine marker (SIGSTOP until the marker 276 was removed) and still passed. Frozen ratios to the fixed rule ranged 277 0.56–0.82; online 0.58–0.82; replay 0.56–0.86. H3 coverage, reported but 278 not gated, ranged 0.53–1.00. 279 280 The frozen model was 0.50–0.86 of the fixed rule on every core class and 281 distribution in every one of the six runs. The criteria that moved between runs 282 were the online learner's cost and the replay. 283 284 - On a shared machine, costs are floors: best of 5 per table entry, fastest 285 chunk per learner run, least-contended block per replay. Load average and 286 the timed CPUs per phase are in the receipt. 287 - The cluster energy meter includes other tenants and updates about every 288 0.1 s. Per-arm power (a few hundred mW above idle) is noisy. Replay energy 289 ratios are reported, not gated. 290 291 ## Not claimed 292 293 - Integration into the resident `omega.select` reaction. The R10 faculty 294 still selects by its own measurement. Wiring the model into it is a 295 follow-up. 296 - Operations other than integer matvec. Graphics-processor realizations. 297 - Thermal or cognitive features varied in a controlled way. 298 - Energy per call. Energy is measured per arm window and per replay block. 299 - Transfer cost. 300 - The Aienux kernel. The authority runs as a host library, as in R7–R14.