interplane.Get Omega
Read in your language

aien-train

AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.

Brought by drakestapleton

branch main Branches Tags History

aien-train / tools / omegallm / wpatch / README.md

196 lines · 10634 bytes Raw Blame History Rendered
1# wpatch
2
3CPU-only checked patches for Drake's OLLMCK02 checkpoints. The product, its build
4driver and its test driver are Omega. It does not import model weights, run
5inference, open a GPU, or claim a quality improvement. One small Python file is a
6labeled ORACLE (a digest calculator); it is not part of the product or the build.
7
8## Files
9
10| File | Role |
11| --- | --- |
12| `wpatch.om` | The product: inspect, diff, show, validate, apply, verify, revert, bind, checkbind. |
13| `wpbuild.om` | Omega build driver. Builds `wpatch` and `wpcheck`. |
14| `wpcheck.om` | Omega test driver. Runs every case, owns all exit codes, files, refusals and PASS/FAIL. |
15| `wporacle.py` | ORACLE only. Answers digest requests from wpcheck; never decides PASS or FAIL. |
16
17## Build
18
19From the repository root, with the pinned omega-mv checkout beside it, compile
20the build driver once with the pinned compiler and run it:
21
22```sh
23OMC=../omega-mv/seed/out/omc
24taskset -c 0 nice -n 19 "$OMC" < tools/omegallm/wpatch/wpbuild.om > /tmp/wpbuild && chmod +x /tmp/wpbuild
25taskset -c 0 nice -n 19 /tmp/wpbuild . "$HOME/work/wsp/wpatch-build" "$OMC" ../omega-mv 0
26```
27
28Arguments are `REPO OUT OMC OMEGA_MV CORE`; all five are required. OUT is created
29when absent. The driver:
30
311. requires the compiler's SHA-256 to equal the pin below;
322. extracts `om/sha256/sha256-om2.om` at the omega-mv pin with git and requires
33 its SHA-256 to equal the pin below;
343. vendors it in Omega: the SHA layout goes before every function, `export fn`
35 becomes `fn`, and SHA private symbols receive a `ws` prefix. The exact source
36 transformation is written to `OUT/sha256.diff` as a review record;
374. composes `OUT/wpcheck-all.om` (SHA layout, SHA functions, `wpcheck.om`) and
38 compiles it to `OUT/wpcheck`;
395. checks the three vendored net sources with `OUT/wpcheck sum`, the Omega
40 SHA-256, against their pins (below);
416. composes `OUT/ollm.om` in Omega exactly as the aarch64 ollm build does: the
42 line `om2`, then these files from `native/omegallm/` concatenated in order:
43 `net/http.om net/json.om net/jsonw.om math.om data.om lpool.om model.om
44 adam.om ckpt.om bpe.om cli.om lio.om serve.om nogpu.om`; compiles it to
45 `OUT/ollm`;
467. composes `OUT/wpatch-all.om` (SHA layout, ollm with its entry point renamed
47 `wpollm`, SHA functions, `wpatch.om`) and compiles it to `OUT/wpatch`;
488. prints the SHA-256 of the compiler, the SHA source, `ollm.om`, ollm, both
49 other compositions and both other binaries, and ends with `WPBUILD PASS`.
50
51Every compile runs on CORE. Exit codes: 0 PASS, 2 usage, 3 a pinned digest
52differs (compiler, SHA source or a net source; the line names which), 4 the
53ollm source does not hold exactly one `fn main to int`, 5 I/O or capacity, 6 a
54host tool failed (its status is printed), otherwise the compiler's own status.
55`native/omegallm` is never changed. The `ollm`, `ollm.om`, `wpatch` and
56`wpatch-all.om` outputs are byte-identical to the earlier shell build (SHA-256
57below).
58
59Compiler: omega-mv `e5b32567a7aff3ce594e3254a622a846a6cd190b`, omc SHA-256
60`2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f`.
61SHA source: `om/sha256/sha256-om2.om` at that revision, SHA-256
62`dbf002dd6aa36585632b9d01d98ac3f0bd2fa0f0475082940de53638847994bb`.
63Net source pins (SHA-256): `net/http.om`
64`aff258ecd3858454056811a5e6fe1f660f9d650a7207d6c41885105110e046a7`,
65`net/json.om` `456254fc754ea35103ced480407b24fc1a3896d094b90ae0e9623e7b6594e2d2`,
66`net/jsonw.om` `464f649e8207495f5d67fe8795d31e42ea3ccebd9ed547274dab802d4f7c5f21`.
67ollm: SHA-256 `819664d5a2284189cd9baca67681675ed2b4685e19d1d976ce071b0f6fcaa5ea`,
68from `ollm.om` SHA-256 `2d13b609945a97ad95dba8626e67588d87c6aec64043affbaf4c107af246eb96`.
69wpatch: SHA-256 `bf993a780c7421cc2cd23d42fef5692135e9bd339f19a90059d4ef7f17be0847`,
70from `wpatch-all.om` SHA-256 `7e8b3ca2cf378af25029ce42ca6c760c880fa3612691216e2f2339c369c22591`.
71
72Host tools the build driver runs (pinned build tools, not product code): the
73compiler, git, sha256sum (for the compiler and SHA source pins, which cannot be
74checked by the SHA they are about to build), diff, taskset and nice.
75
76## Commands
77
78```text
79wpatch inspect CK
80wpatch inspect CK KIND LAYER R0 R1 C0 C1
81wpatch diff BASE EDITED POLICY PARAMS_FILE RATIONALE_FILE OUTDIR
82wpatch show PATCH
83wpatch validate PATCH BASE
84wpatch apply PATCH BASE OUT
85wpatch verify PATCH CK
86wpatch revert PATCH EDITED OUT
87wpatch bind PATCH CK RUNTIME_BIN OUT
88wpatch checkbind BINDING CK RUNTIME_BIN
89```
90
91Indices are zero-based. Slice ends are exclusive. Tensor kinds are `wte`, `wpe`,
92`g1`, `wq`, `wk`, `wv`, `wo`, `g2`, `w1`, `w2`, `gf`. Use layer zero for the three
93nonlayer tensors. `w1` is D by F and `w2` is F by D, in checkpoint row-major order.
94Offsets printed by inspect are flat weight indices, not byte offsets. Decimal
95values are diagnostic; the adjacent 16-digit hexadecimal word is authoritative.
96Inspect prints all header fields and per-tensor SHA, RMS, maximum absolute finite
97value, and nonfinite count. The scaled RMS accumulates finite values, treating
98nonfinite values as zero in its full-tensor denominator. Check the nonfinite
99count before interpreting either statistic.
100
101`diff` requires matching headers apart from FNV and bit-identical m/v arrays.
102It records the changed weight words and applies the requested optimizer policy
103to its expected output, not to either input. Policy 0 keeps m/v; policy 1 clears
104changed m; policy 2 clears changed m and v. Policies 1 and 2 save old m/v words
105for exact rollback. Changes that disappear in f32 remain in the manifest.
106Params and rationale are exact UTF-8 file contents, each at most 16 MiB. They may
107be empty. Params need not be JSON. OUTDIR must exist. The result path is printed.
108
109`show` emits JSON with identities, policy, total changed count, the first twenty
110entries, params and rationale. `validate` checks the base, all entries and tensor
111records, and the complete simulated output including its f32 identity. `apply`
112writes a new file only after this check and rechecks the written bytes. `verify`
113checks an applied checkpoint and reports total edits and edits surviving f32.
114`revert` restores the exact old weight and optimizer words and requires the base
115SHA to match. All checkpoint-writing commands refresh the payload FNV.
116
117`bind` first verifies the applied checkpoint, then binds checkpoint SHA, f32
118weight SHA, runtime executable SHA and manifest SHA in a checksummed record.
119`checkbind` checks that record and the checkpoint/runtime identities. It takes no
120manifest argument, never rereads the manifest, and cannot detect a replaced
121manifest. It also does not load a model or invalidate an existing runtime cache.
122A serving caller must retain the intended manifest identity, run checkbind,
123discard cached weights and KV state, and load the exact bound files before
124claiming a repaired run. Merely creating a binding is not deployment.
125
126No output is overwritten, including a symlink or an output equal to BASE. Patches
127and bindings are created read-only. Checkpoints are mode 0600. Inputs are mapped
128privately, never written. Keep all inputs and the output directory stable while
129a command runs. These are integrity checks, not cryptographic signatures or
130protection against a malicious concurrent writer. A crash or forced termination
131can leave a partial newly created output; do not use it without verification.
132
133The full binary format, limits and refusal codes are in
134[`docs/omegallm/WSP-PATCH.md`](../../../docs/omegallm/WSP-PATCH.md).
135
136## Acceptance: wpcheck
137
138`wpcheck` is built by wpbuild into the same OUT directory. WORK must not exist;
139wpcheck creates it. ORACLE is the path of `wporacle.py`.
140
141```sh
142B="$HOME/work/wsp/wpatch-build"
143taskset -c 0 nice -n 19 "$B/wpcheck" small "$B" "$HOME/work/wsp/ck/wpatch-small-new" \
144 tools/omegallm/wpatch/wporacle.py
145```
146
147Exit codes: 0 PASS, 1 FAIL (the first failed check is printed and the run stops),
1482 usage. Output is plain text: a header with the Omega SHA-256 of the wpatch under
149test; for each child process its argument list, its stdout as `| ` lines, and
150`EXIT got=X want=Y elapsed_ns=T`; one `PASS label` line per check; and a last line
151`WPCHECK PASS checks=N commands=M` or `WPCHECK FAIL ...`. Children run through
152fork, execprog and waitpid with an empty environment and stdout captured through
153a pipe.
154
155`wpcheck sum FILE` prints the Omega SHA-256 of FILE (the vendored SHA, not the
156ORACLE) as 64 hex digits and a newline. wpbuild uses it for the net source pins.
157An unreadable FILE is a FAIL with exit 1; an empty FILE gives the digest of no
158bytes.
159
160The small mode trains an own-model small checkpoint, runs every command and all
161three optimizer policies, parses every manifest, tensor record, entry and binding
162field, checks f32 cast boundaries, and exercises each corruption with its exact
163refusal code and no output left behind. It builds the expected output bytes
164directly from BASE and the requested edits, including optimizer resets, without
165taking expected values from a manifest. A fully rehashed manifest for a different
166finite value passes product verify but is rejected by this independent byte
167comparison; that in-run negative control must be rejected for the run to PASS.
168
169The real mode takes the pinned round40 checkpoint as a fifth argument. It
170requires the pinned base SHA-256, changes ten layer-3 w2 entries in a copy,
171performs diff/validate/apply/verify/revert, compares every output byte against the
172independently built expectation, and checks the restored SHA and expected f32 SHA.
173It never writes into the source model directory. Queue behind other authorized
174core-19 work:
175
176```sh
177flock -w 3600 -o "$HOME/handoffs/hive/queen/pool-19.lock" \
178 taskset -c 19 nice -n 10 "$B/wpcheck" real "$B" "$HOME/work/wsp/ck/wpatch-real-new" \
179 tools/omegallm/wpatch/wporacle.py "$HOME/.local/share/omega-tool-model/round40/model.ck"
180```
181
182Do not run on reserved cores 3, 7 or 15.
183
184## ORACLE
185
186`wporacle.py` (Python 3.12.3 standard library: hashlib, struct, mmap) is the only
187Python. It is an ORACLE: wpcheck writes a request file, runs
188`/usr/bin/python3 wporacle.py REQUEST`, and compares each answer line itself. It
189answers three requests: SHA-256 of a byte range, SHA-256 of the IEEE f32 casts of
190the checkpoint weights, and a count of entries whose old and new values differ
191after the f32 cast. It shares no code with wpatch or wpcheck, and nothing in the
192product or the build calls it. Any malformed request makes it exit nonzero, which
193wpcheck reports as FAIL.
194
195Evidence: `evidence/OMEGALLM/wsp-patch-20261107/pure-omega/`. Host CPU execution is
196not GPU qualification, a model-quality result, a merge, or a deployment.