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/aien-sovereign-core-mv/patches/09f2e39bcb08ca55 # aien-sovereign-core-mv AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers ## GitHub aien-dev/aien-sovereign-core-mv#806 (code only) closed derived `09f2e39bcb08ca55` #806 Imported from GitHub aien-dev/aien-sovereign-core-mv#806 (code only) GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed). Base `fc3b8626d724ecf9ffb21d573592fc2ea5f44974` · Head `0925d7d05a7b3ec0f1673fbad4e112161844203c` ### Apply it ``` git checkout -b patch-09f2e39bcb08ca55 fc3b8626d724ecf9ffb21d573592fc2ea5f44974 curl -fsSL https://interplane.io/drakestapleton/aien-sovereign-core-mv/patches/09f2e39bcb08ca55.patch | git am ``` Raw patch (mbox) · Diff ### Provenance This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record: ``` github-import 1 aien-dev/aien-sovereign-core-mv 806 0925d7d05a7b3ec0f1673fbad4e112161844203c ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"aien-sovereign-core-mv","number":806,"url":"https://github.com/aien-dev/aien-sovereign-core-mv/pull/806","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:38:04Z","metadata":"unavailable","state_derived":true} ``` ### Changes ``` diff --git a/.crumb b/.crumb index c76c2d5c..7018cf08 100644 --- a/.crumb +++ b/.crumb @@ -119,14 +119,14 @@ } ], "children_root": "sha256:31b31d0c22430a2b7dbaf536741c122daa8e98b3e30440b78e6f0b153415c048", - "compiled_at": "2026-10-29T23:28:09Z", + "compiled_at": "2026-10-30T00:10:08Z", "compiler": "crumb-compile/1", - "digest": "sha256:2e6cb035a7dea0a87501693771e066813fcbaa0b8acb0a397cce1bfab407e660", + "digest": "sha256:b97852c023146eb2939864627f05574ec68033039b1cb459c690af2fb9e3be1e", "evidence_files": 3586, "evidence_root": "sha256:ee29710af304de14c30917f3cc8eb87c5b5e9a42b75dd9d009e842279d8075d0", - "files": 8037, - "generated_at_commit": "729db63a535a4a2bc0b3defa91ea9467e3d91547", - "source_tree": "sha256:9dd769b8dd0582a082ca73f80f8d0e365327c22785e6e1938beb92a56f799b5c" + "files": 8040, + "generated_at_commit": "402025cdb5f2a4d7e8a7f88242273aa910ad1f05", + "source_tree": "sha256:1e10e73b47b8e731b09b4618f6bda1803d041b95c4c0c0623becefc4f5a7b954" } }, "history": [], diff --git a/om/flint/PROFILE-SHARDS.sha256 b/om/flint/PROFILE-SHARDS.sha256 new file mode 100644 index 00000000..56770afe --- /dev/null +++ b/om/flint/PROFILE-SHARDS.sha256 @@ -0,0 +1,15 @@ +68cd9eaa364a7d72216972f96cde0c308167779e70237e5912ef74aeab758007 model-00001-of-00015.safetensors +73c8cab39d0eee3c90bbcf2ed521895434dab3dd624943b3f91507cfabc5c311 model-00002-of-00015.safetensors +ce22b7f058fdf8911c5a5aa851cd497b6bb804587398b1e3294e427d4bdd1052 model-00003-of-00015.safetensors +f1d4f30d95f889e7e1a20cfa13ee43745a240b3e80ae60c9464eea3207ca4e51 model-00004-of-00015.safetensors +fbf98aef1c1a1b125d49e65b73330f1c00b64f0256edd871d4926f9c73685397 model-00005-of-00015.safetensors +842c5070e8fc19b97575b14ec152cca9fd57a248fb0e21c7b53a50f019372ab4 model-00006-of-00015.safetensors +b41e9e17f6b992b383a171d5a3b32efbb624cb3a8cece1ca925c06c339d7aa17 model-00007-of-00015.safetensors +8c791da3f5e8dab4700f76725e6d235f8e7125ea09ce927a11c5261df17a65e6 model-00008-of-00015.safetensors +73b01b243634f802f8945717bbebd4df625dd55de3b5ce392469f0b4fe7f15f2 model-00009-of-00015.safetensors +bc105215b9a6061bca130fbda3d566b9597eaf5b1bf51316da81e624085460bb model-00010-of-00015.safetensors +2105fde6c535b135fc95413279e69016a28569a08e992eb8fea17bad385d9349 model-00011-of-00015.safetensors +ae1d074ba5ca8b456251eaac9d7b54ab0c7c1121821a4abb4a78cceb2ad9641f model-00012-of-00015.safetensors +e91ccbbe2d681c2c128298700595d8c6ac6764ef88b7ff8c6327a6e5cfa5ef8c model-00013-of-00015.safetensors +5c6801977bd0bf6822befa658e490cbf37c81ab4190cdcc72839aac72329b2a8 model-00014-of-00015.safetensors +58635712b79734cbcad6324157606c674d12303665badc2965955496bb8263bc model-00015-of-00015.safetensors diff --git a/om/flint/PROFILE.md b/om/flint/PROFILE.md new file mode 100644 index 00000000..f04ede04 --- /dev/null +++ b/om/flint/PROFILE.md @@ -0,0 +1,109 @@ +# Flint frozen host-forward profile + +Status: IMPLEMENTED and EXERCISED on Spark host CPU only, 2026-10-29. Not a device backend. +Base: sovereign-core fc3b8626d724ecf9ffb21d573592fc2ea5f44974 (#805). +Main fetched during this work: 65e712b7dc58d15ba1f9284e66e2da507a70c380. +Checkpoint: RecursiveSI/flint@2a247be0c0aec895ccb0ac7ca92229ec6df37288, Apache-2.0. + +## Reproduction + +``` +taskset -c 0-4 nice -n 10 ionice -c3 env \ + OMC=/path/to/omega-mv/seed/out/omc \ + FLINT_SRC=/path/to/pinned-source-capture \ + FLINT_SHARDS=/path/to/downloaded-shards \ + FLINT_PY="env PYTHONPATH=/path/to/transformers-a672 /path/to/python" \ + FLINT_FORWARD=1 bash om/flint/check.sh +``` + +Compiler source omega-mv bf54b19f; binary SHA256 +`62775d2a391cfef7cde64e387655caa9809a267093112910ec76bfa568f3712b`. +This is the existing #805 test compiler, not a production compiler-pin change. +Reference runtime: Python 3.12.3, torch 2.14.0+cu130, transformers 5.21.0.dev0 +at a672eb5f474b8b30173e9f96eab66adf292da635, safetensors 0.8.0, numpy 2.5.3. +The config's recorded transformers_version is 5.12.1; this is distinct from the +pinned runtime used for current Flint support. Referee runs single-threaded eager +attention/experts on CPU with deterministic algorithms. + +## Frozen identities (SHA256) + +| Component | SHA256 | +|---|---| +| config.json | a57c33d11f725099105b657043c113149763066d204fd472d0b2ee399abc2ba7 | +| model.safetensors.index.json | e5e9c492685f84c8d2d8369f36c74674b03410715f23f6179313f6f1feb90311 | +| tokenizer.json | a263cce0b7e2b03f7ee07ce809783ef4b47f160c3f268a4ea1524f638da45b68 | +| tokenizer_config.json | 159ac88217e90ffd0a4a294726048bb302829e82e1958dc85bb203aa79138fbf | +| chat_template.jinja | 7940f4ffa3275c36caa4a582f845aaad79da11018b3961e8fbcad6ae29733466 | +| generation_config.json | a499c71895e008abd572558a5ad5904feaed92cf2a3b6e2cb0e9cabf03b96ed3 | +| modeling_flint.py at runtime | f0540832049f0d67eee9eadd2d8ed42e320388b6b3330e74c8821a5c4eac0c09 | +| configuration_flint.py at runtime | 849eee3068846081077a7568663355802c8c4eec3741d92cd578d222bd144d00 | +| conversion_mapping.py | 93a992136d09ac875341cd645294f30d133af46efe073430c85fc20731240834 | +| masking_utils.py | 03912b9f8910358966351495075895ef0e8f5048f15226271d700ea268fef08c | +| transformers source archive | 5d82e0de4bf993484299bcc1f2ef78d1d3f4ff23cee411f42f486b774f5f6615 | +| admitted tensor inventory TSV | 60ff4dbdaa1c3632c934c6935aa60ed5b2def4e15f0ca5083ddc7dd660f083f5 | +| chained forward fixture | b5e4bae28af3c1fa0c8f7454c496e72da1388e17f51bb3ec9e9b0387aac97031 | + +Per-shard hashes are in `PROFILE-SHARDS.sha256`; all 15 downloaded shards were +rehashed and matched the source capture before this work. Storage is BF16, with +no quantization descriptor/scales in this checkpoint. No lossy repack was applied. +Generation defaults in the pinned capture: do_sample=true, temperature=1.0, +top_p=0.95, top_k=20. The forward referee does not sample: token IDs [1001,8920] +are fixed, not produced by a chat template. The tokenizer/template are frozen +for future task workloads but not exercised by this tensor-only fixture. + +## Architecture audit + +Line numbers refer to pinned config.json and modeling_flint.py, respectively. + +| Requested property | Observed evidence | Verdict | +|---|---|---| +| 49 layers, 2 dense + 47 MoE | config:73-82 mlp_only_layers=[0,1], num_hidden_layers=49 | Matches | +| 256 experts, top-6 sigmoid | config:80-81,105; reference:90-101 | Matches | +| Selection-only expert bias | reference:97 explicitly says without expert bias; gate.weight only, no gate bias in inventory | **Mismatch: no expert bias** | +| Ungated shared expert | reference:149,155-157 | Matches | +| Learned attention sinks | config:108; reference:225-227, checkpoint softmax_offset tensors | Matches | +| 35 local layers, window 513 | config:21-70,107 | Matches | +| 14 full layers, no RoPE | config:84-99; reference:280-283 | Matches | + +Wolfram query for counts and modeled sizes is recorded in test/TOLERANCE.md. +Reference behavior, not the inaccurate bias claim, is implemented. Native storage +remains BF16; compute f64 vs reference f32 is an explicit numerical-profile change. +No BF16-activation, GPU, sampled-token, long-context, batching or task-quality +qualification follows from this candidate forward result. + +## Existing GPU contracts + +This bounded CPU verifier is not a second GPU runtime, cache, quantization schema +or MoE scheduler. #156's descriptor remains the GPU format authority; #159 remains +the native grouped-MoE authority; #157 composition and closed #158 cache identities +are unchanged and not exercised by this host verifier. Their GPU integration, +native encoded dispatch and physical receipts remain NOT_RUN, not implicitly reused +by a claim of host tensor parity. + +## Host-loop profiling and numerical invariants + +The initial native CPU profile used `monons` wrappers in an isolated compilation +unit stored with the operator receipts, not in the product source. Timers aggregate +whole calls, not per-element syscalls. They include instrumentation overhead: + +| Loop/helper | Accumulated ns | Calls | +|---|---:|---:| +| bounded dot product `dotr` | 30899920888 | 3201792 | +| tensor read/decode `ld_bytes` | 10814711443 | 2478 | +| inventory search `tsv_find` | 8860325941 | 2478 | +| integration comparisons `fw_cmp` | 88531129 | 300535 | +| MLP activation `mlp_h` | 55114892 | 613 | +| RMSNorm `rmsv` | 11444826 | 3726 | + +These are instrumented call totals, not disjoint percentages of uninstrumented +wall time. The measured hottest loop was `dotr`. The forward-only `matdot` retains +the exact f64 conversions, products and reduction order but omits the two per-product +error sums that the forward integration comparison does not consume. Those slots +are cleared, not left stale. The forward integration budget and every comparison +are unchanged. Router dots retain the bounded implementation for tie reporting; +the existing per-operator checks retain the original bound accumulation. + +`worst_ppm` is the maximum `|native-reference|/(2E)` expressed in millionths. +WolframLanguageEvaluator: `N[694277/1000000*100,6] -> 69.4277`. +Thus the observed `694277` means approximately **69.4% of the comparison budget** +was consumed; it does not mean a 69.4% relative tensor error. diff --git a/om/flint/README.md b/om/flint/README.md index 90f42c9f..11687ac2 100644 --- a/om/flint/README.md +++ b/om/flint/README.md @@ -202,9 +202,27 @@ layer, expert index permuted (255 - e), and window 514. ## Not covered (NOT_RUN for this unit) - bf16-activation parity: the referee runs in f32; -- parity on full layers, other layers and experts, logits and generation; +- generation, bf16 activations and long-context serving remain NOT_RUN; complete two-token + chained layer/intermediate/logit parity is now covered by the optional arm below; - weight streaming and repacking, with peak allocation and residency measured during load; - per-expert layout checks before fusing; - tokenizer and control-token identity, and a load report. This unit has no GPU arm. A GGUF importer, if added, will be a separate optional unit. + +## Complete bounded host forward + +`FLINT_FORWARD=1` adds a full 49-layer chained computation to the same check command. +It starts from two token IDs, loads real BF16 embedding rows and all selected expert weights, +and compares five intermediate tensors per layer, final normalization and every vocabulary logit. +The reference tensors are comparison targets, never teacher-forced inputs. +The full gate prints `OM-FLINT-MANIFEST PASS (92)` with real checkpoint inputs; wrong-token +and skipped-final-normalization source mutants must fail the comparison. + +See [PROFILE.md](PROFILE.md) for the frozen weight/runtime/tokenizer/template identities +and the architecture audit. In particular, this checkpoint has **no expert bias**, unlike +the requested selection-only bias description. [test/TOLERANCE.md](test/TOLERANCE.md) +declares the candidate integration budget separately from the tighter per-operator bounds. +Native f64 computation with BF16 storage is compared to reference f32 computation. +This is host-forward evidence only: no serving API, task completion, quantized model, +KV-cache, long-context batching or GPU/backend qualification is claimed. diff --git a/om/flint/check.sh b/om/flint/check.sh index fabc4c3b..0c2b585a 100755 --- a/om/flint/check.sh +++ b/om/flint/check.sh @@ -14,6 +14,7 @@ # FLINT_SHARDS=dir the 15 downloaded shards (config and index come from FLINT_SRC). # With both set, the forward-operator arm runs ops.om against test/opref.py fixtures; # FLINT_PY is the referee's interpreter (torch + transformers a672eb5f), default python3. +# FLINT_FORWARD=1 additionally runs the full 49-layer, two-token chained forward and mutants. # Needs: python3 (fixture referees only), sha256sum, cmp, timeout. Host only; no network, no GPU. set -u here=$(cd "$(dirname "$0")" && pwd) @@ -257,5 +258,37 @@ else echo "NOT_RUN ops (forward operators; needs FLINT_SRC, FLINT_SHARDS and the FLINT_SHARDS arm's TSV)" fi +# Full chained forward is opt-in because it streams the real checkpoint and runs all 49 layers. +# No intermediate reference tensor is fed back into the native computation. +if [ "${FLINT_FORWARD:-0}" = 1 ]; then + if [ -z "${FLINT_SRC:-}" ] || [ -z "${FLINT_SHARDS:-}" ] || [ ! -s "$b/real.tsv" ]; then + bad "forward requested without FLINT_SRC, FLINT_SHARDS and admitted real.tsv" + elif ! ${FLINT_PY:-python3} "$here/test/fwdref.py" "$FLINT_SRC" "$FLINT_SHARDS" "$b/forward.fx" > "$b/fwdref.out" 2>&1 < /dev/null; then + bad "forward referee: $(cat "$b/fwdref.out")" + elif [ "$(sha "$b/forward.fx")" != b5e4bae28af3c1fa0c8f7454c496e72da1388e17f51bb3ec9e9b0387aac97031 ]; then + bad "forward fixture pin mismatch: $(sha "$b/forward.fx")" + else + cat "$b/fwdref.out" + line=$(timeout 600 "$b/ops" forward "$b/forward.fx" "$b/real.tsv" "$FLINT_SHARDS" 2>&1 < /dev/null) + rc=$? + echo "$line" + if [ "$rc" = 0 ] && [[ $line == *"forward layer 49 "* ]] && [[ $line == *" PASS" ]]; then ok "chained forward, all layers and vocabulary logits"; else bad "forward rc $rc"; fi + s=$(cat "$here/ops.om") + while IFS='|' read -r name from to; do + [ "$(grep -cF -- "$from" "$here/ops.om")" = 1 ] || { bad "forward mutant $name site"; continue; } + printf '%s\n' "${s/"$from"/"$to"}" > "$b/fwdmut.om" + build "$b/fwdmut" "$b/fwdmut.om" || { bad "forward mutant $name compile"; continue; } + line=$(timeout 600 "$b/fwdmut" forward "$b/forward.fx" "$b/real.tsv" "$FLINT_SHARDS" 2>&1 < /dev/null) + rc=$? + if [ "$rc" = 1 ] && [[ $line == *" FAIL" ]]; then ok "CAUGHT forward mutant $name: ${line##*$'\n'}"; else bad "forward mutant $name rc $rc: $line"; fi + done <<'FORWARD_MUTANTS' +wrong-token|id = fx_w add 8 t|id = add fx_w add 8 t 1 +skip-final-norm|put gfh o get gy i|put gfh o get gv i +FORWARD_MUTANTS + fi +else + echo "NOT_RUN chained forward (set FLINT_FORWARD=1)" +fi + n=$((pass + fail)) if [ "$fail" = 0 ]; then echo "OM-FLINT-MANIFEST PASS ($n)"; else echo "OM-FLINT-MANIFEST FAIL ($fail of $n)"; exit 1; fi diff --git a/om/flint/ops.om b/om/flint/ops.om index 37622cb6..9c507be3 100644 --- a/om/flint/ops.om +++ b/om/flint/ops.om @@ -29,7 +29,7 @@ global ga uchar 16384 global gas ulong 8 global gal ulong 8 global gpth uchar 4352 -global gfx uchar 3145728 +global gfx uchar 8388608 global gtsv uchar 8388608 global gstg uchar 4194304 global gw f32 16777216 @@ -69,6 +69,16 @@ global gob uchar 4096 global gdg uchar 24 global gh8 uchar 8 global gstb uchar 128 +global gfh f64 4096 +global gfa f64 4096 +global gfq f64 8192 +global gfo f64 8192 +global gfs ulong 4 +text tofwd "forward" +text tembd "model.embed_tokens.weight" +text tfnorm "model.norm.weight" +text tlmhead "lm_head.weight" +text tdense "mlp." text tu "usage: flint-ops OP FIXTURE INVENTORY SHARD_DIR | flint-ops selftest" text tio "io" @@ -624,6 +634,31 @@ nb = mul k 2 if or ne sub get gst 13 get gst 12 nb gt k len gw op_die 6 tdt end +ld_bytes nb 0 +end + +note ld_rows: bounded row slice of a manifest-admitted BF16 matrix, never allocate the vocabulary. +fn ld_rows rows ulong cols ulong first ulong count ulong to void +tsv_find +if or ne get gst 14 rows ne get gst 15 cols +op_die 6 tdt +end +if or gt first rows gt count sub rows first +op_die 6 tdt +end +n = mul count cols +if gt n len gw +op_die 6 tdt +end +size = mul mul rows cols 2 +extent = sub get gst 13 get gst 12 +if ne extent size +op_die 6 tdt +end +ld_bytes mul n 2 mul mul first cols 2 +end + +fn ld_bytes nb ulong off ulong to void fd = sh_open r = pread int fd gh8 0 8 long 0 if ne r 8 @@ -636,7 +671,7 @@ end if gt hl 100000000 op_die 3 tio end -base = add add 8 hl get gst 12 +base = add add add 8 hl get gst 12 off o = ulong 0 while lt o nb bound 99999 c = sub nb o @@ -674,6 +709,26 @@ fn dote k ulong to f64 ret add get gacc 2 mul gam k get gacc 1 end +note matdot: forward integration has its own fixed comparison budget, not dote bounds. +note Avoid accumulating two unused per-product error sums there. Keep the f64 products +note and reduction order identical to dotr. Router dotr remains bounded for tie reporting; +note every local operator still calls the original bounded dotr path. +fn matdot r ulong k ulong to f64 +if ne get gst 2 8 +ret dotr r k +end +b = mul r k +s = 0.0f64 +for i ulong k +w = f64 get gw add b i +p = mul w get gv i +s = add s p +end +put gacc 1 0.0f64 +put gacc 2 0.0f64 +ret s +end + note rmsv: RMSNorm of gv[0 .. n) with weight gw[wo ..) into gy, bound into gye: note E_i = |w_i| r (E_xi + |x_i| r^2 / n sum |x_j| E_xj) + gamma_(n+6) |y_i| fn rms_rc n ulong to void @@ -1161,6 +1216,9 @@ end fn ld_mlp L ulong ex ulong j ulong I ulong to void nm_lay L +if eq ex 998 +nm_tx tdense +else if lt ex 256 nm_tx texp nm_u ex @@ -1168,6 +1226,7 @@ nm_c 46 else nm_tx tshp end +end if eq j 0 nm_tx tgp ld_t I FHID @@ -1192,7 +1251,7 @@ put gve i get ge0 add b i end for r ulong I o = add mul add t0 t I r -put gx1 o dotr r FHID +put gx1 o matdot r FHID put ge1 o dote FHID end end @@ -1207,7 +1266,7 @@ put gve i get ge0 add b i end for r ulong I o = add mul add t0 t I r -put gx2 o dotr r FHID +put gx2 o matdot r FHID put ge2 o dote FHID end end @@ -1242,7 +1301,7 @@ put gve i get ge1 add b i end for r ulong FHID o = add mul add t0 t FHID r -put gx3 o dotr r I +put gx3 o matdot r I put ge3 o dote I end end @@ -1394,6 +1453,288 @@ r = report tostt ret r end +note Complete bounded host forward, two prompt tokens maximum. No teacher forcing: +note only token IDs are inputs; the fixture's intermediate tensors are comparison targets. +note This f64-compute/BF16-storage numerical profile is NOT bf16-activation qualification. +note Integration acceptance is |om-ref| <= 8 gamma_2048 (1+|ref|), fixed before execution. +note The existing per-operator bounds remain the tighter local checks. +fn fw_cmp n ulong to void +o = get gfs 1 +for i ulong n +r = fx_f add o i +e = mul mul 4.0f64 gam 2048 add 1.0f64 fabs r +cmp get gfa i r e +end +put gfs 1 add o n +end + +fn fw_hidden to void +for i ulong mul get gfs 0 FHID +put gfa i get gfh i +end +fw_cmp mul get gfs 0 FHID +end + +fn fw_norm L ulong post bool to void +nm_lay L +if post +nm_tx tln1 +else +nm_tx tln0 +end +ld_t FHID 0 +for t ulong get gfs 0 +for i ulong FHID +put gv i get gfh add mul t FHID i +put gve i 0.0f64 +end +rmsv FHID 0 +for i ulong FHID +o = add mul t FHID i +put gx0 o get gy i +put ge0 o 0.0f64 +put gfa o get gy i +end +end +fw_cmp mul get gfs 0 FHID +end + +fn fw_proj rows ulong to void +for t ulong get gfs 0 +for i ulong FHID +put gv i get gx0 add mul t FHID i +put gve i 0.0f64 +end +for r ulong rows +put gx1 add mul t rows r matdot r FHID +end +end +end + +fn fw_head t ulong h ulong nh ulong rp bool to void +b = mul add mul t nh h 128 +for d ulong 128 +put gv d get gx1 add b d +put gve d 0.0f64 +end +rmsv 128 0 +if rp +ropev t +end +for d ulong 128 +if eq nh 32 +put gfq add b d get gy d +else +put gx2 add b d get gy d +end +end +end + +fn fw_qk L ulong q bool to void +rows = ulong 512 +nh = ulong 4 +nm_lay L +if q +nm_tx tq +rows = ulong 4096 +nh = ulong 32 +else +nm_tx tk +end +ld_t rows FHID +fw_proj rows +nm_lay L +if q +nm_tx tqn +else +nm_tx tkn +end +ld_t 128 0 +for t ulong get gfs 0 +for h ulong nh +fw_head t h nh fl_swa L +end +end +end + +fn fw_atthead t ulong h ulong to void +b = mul add mul t 32 h 128 +for d ulong 128 +put gv d get gfq add b d +end +g = div h 8 +n = att_sc g t 0 +att_sm n get gsk h get gfs 0 +put gacc 11 0.0f64 +for d ulong 128 +v = pv_d n add mul g 128 d +put gfo add b d v +end +end + +fn fw_att L ulong to void +fw_qk L true +fw_qk L false +nm_lay L +nm_tx tv +ld_t 512 FHID +fw_proj 512 +for i ulong mul get gfs 0 512 +put gx3 i get gx1 i +end +nm_lay L +nm_tx tsnk +ld_t 32 0 +for h ulong 32 +put gsk h f64 get gw h +end +for t ulong get gfs 0 +for h ulong 32 +fw_atthead t h +end +end +nm_lay L +nm_tx tob +ld_t FHID 4096 +for t ulong get gfs 0 +for i ulong 4096 +put gv i get gfo add mul t 4096 i +put gve i 0.0f64 +end +for r ulong FHID +put gfa add mul t FHID r matdot r 4096 +end +end +fw_cmp mul get gfs 0 FHID +for i ulong mul get gfs 0 FHID +put gfh i add get gfh i get gfa i +end +end + +fn fw_moe L ulong to void +T = get gfs 0 +nm_lay L +nm_tx trt +ld_t 256 FHID +for t ulong T +moe_rt t +end +for i ulong mul T FHID +put gacm i 0.0f64 +put gace i 0.0f64 +put gaca i 0.0f64 +end +for t ulong T +moe_ex L t +end +mlp L 999 1024 0 T +for i ulong mul T FHID +put gx3 i add get gacm i get gx3 i +end +end + +fn fw_layer L ulong to void +fw_norm L false +fw_att L +fw_norm L true +if lt L 2 +mlp L 998 6144 0 get gfs 0 +else +fw_moe L +end +for i ulong mul get gfs 0 FHID +put gfa i get gx3 i +end +fw_cmp mul get gfs 0 FHID +for i ulong mul get gfs 0 FHID +put gfh i add get gfh i get gfa i +end +fw_hidden +put gst 3 L +r = report tofwd +if ne r 0 +exit 1 +end +end + +fn fw_embed to void +for t ulong get gfs 0 +id = fx_w add 8 t +if ge id 150144 +op_die 7 tfx +end +put gst 7 0 +nm_tx tembd +ld_rows 150144 FHID id 1 +for i ulong FHID +put gfh add mul t FHID i f64 get gw i +end +end +fw_hidden +end + +fn fw_final to void +put gst 7 0 +nm_tx tfnorm +ld_t FHID 0 +for t ulong get gfs 0 +for i ulong FHID +put gv i get gfh add mul t FHID i +put gve i 0.0f64 +end +rmsv FHID 0 +for i ulong FHID +o = add mul t FHID i +put gfh o get gy i +put gfa o get gy i +end +end +fw_cmp mul get gfs 0 FHID +end + +fn fw_logits to void +for t ulong get gfs 0 +for r ulong 150144 +if eq rem r 2048 0 +put gst 7 0 +nm_tx tlmhead +n = sub ulong 150144 r +if gt n 2048 +n = ulong 2048 +end +ld_rows 150144 FHID r n +for i ulong FHID +put gv i get gfh add mul t FHID i +put gve i 0.0f64 +end +end +v = matdot rem r 2048 FHID +put gfa 0 v +fw_cmp 1 +end +end +end + +fn op_forward to int +T = get gst 4 +if or eq T 0 gt T 2 +op_die 7 tfx +end +note words = header + IDs + embeddings + five tensors/layer + final norm + logits +fx_need add add add 8 T mul mul T FHID 247 mul T 150144 +put gfs 0 T +put gfs 1 add 8 T +fw_embed +for L ulong 49 +fw_layer L +end +fw_final +fw_logits +put gst 3 49 +r = report tofwd +ret r +end + fn op_code to ulong if op_argeq 1 tormsn ret 1 @@ -1416,6 +1757,9 @@ end if op_argeq 1 tomoe ret 7 end +if op_argeq 1 tofwd +ret 8 +end op_die 2 tu ret 0 end @@ -1455,6 +1799,10 @@ put gst 3 fx_w 2 put gst 4 fx_w 3 put gst 5 fx_w 4 put gst 6 fx_w 5 +if eq op 8 +s = op_forward +ret s +end if eq op 1 s = op_rmsn ret s diff --git a/om/flint/test/TOLERANCE.md b/om/flint/test/TOLERANCE.md index 6a2f2ef5..f5b7d39b 100644 --- a/om/flint/test/TOLERANCE.md +++ b/om/flint/test/TOLERANCE.md @@ -191,3 +191,31 @@ flint-op moe layer 24 elems 8192 worst_ppm 6 ties 0 PASS the band is wider than the observed error. The tie tokens still have their weights compared whenever both top-6 sets agree. The reference runs in f32; bf16-activation parity is not measured here. + +## Full chained forward (candidate numerical profile, 2026-10-29) + +`ops.om forward` consumes only token IDs as inputs. It loads real embedding rows, executes +all 49 decoder layers using its own prior outputs, applies final RMSNorm and streams every +vocabulary row of the untied LM head. No teacher forcing or reference router-index adoption. +Each layer compares input norm, attention output, post-attention norm, MLP output and residual +output against the independent pinned reference. Embeddings and final norm are also compared. +The admitted fixture has two tokens, IDs 1001 and 8920. This is a bounded host verifier, +not a serving engine, KV-cache implementation, long-context benchmark or device qualification. +The existing attention operator fixture separately exercises the 513-token window boundary. + +Before the first execution, the integration criterion was fixed as +`|native-reference| <= 8 gamma_2048 (1+|reference|)`. This is an explicit integration +budget, **not** a derived worst-case error theorem for 49 layers. The local operator +tests above retain their tighter propagated bounds. `fw_cmp` passes half this budget +to `cmp`, which already compares against twice the supplied bound. +BF16 checkpoint storage is unchanged; native computation is f64, reference computation +is f32, so this result does not establish BF16-activation, quantized or GPU parity. +There is no numerical tuning or relaxed threshold after observing the fixture. + +WolframLanguageEvaluator: +`{49-2,49-Length[{0,1,5,9,13,17,21,25,29,33,37,41,45,48}], N[2^(-24)*2048/(1-2^(-24)*2048),18], 2*2048*150144, 3*512*2048*2, 6*3*512*2048*2, 49*2*2048*4*5+2*150144*4}` +returned +`{47,35,0.000122085215480405323,615038976,6291456,37748736,5218304}`. +The byte counts are modeled layout sizes, not measured memory usage. +The chained fixture is pinned by SHA256 in `check.sh`; wrong-token and skipped-final-normalization +source mutants must compile and return comparison exit 1, not a trap or setup refusal. diff --git a/om/flint/test/fwdref.py b/om/flint/test/fwdref.py new file mode 100755 index 00000000..0861a1d5 --- /dev/null +++ b/om/flint/test/fwdref.py @@ -0,0 +1,137 @@ +#!/usr/bin/env python3 +"""Read-only pinned Flint referee for ops.om forward, not a runtime dependency. + +Usage: fwdref.py SRC SHARDS OUTPUT +Header matches opref.py, op 8, T=2, then two token IDs, embeddings, +for each of 49 layers: input norm, attention output, post-attention norm, +MLP output, residual output. Finally final norm and all vocabulary logits. +All tensors are contiguous little-endian f32. Weights stay BF16 on disk; +reference computation is float32 on CPU. No sampling or generation is claimed. +""" +import hashlib +import json +import os +import struct +import sys + +import torch +from safetensors import safe_open +from transformers.models.flint import configuration_flint as cf +from transformers.models.flint import modeling_flint as mf + +REF_SHA = "f0540832049f0d67eee9eadd2d8ed42e320388b6b3330e74c8821a5c4eac0c09" +CFG_SHA = "849eee3068846081077a7568663355802c8c4eec3741d92cd578d222bd144d00" +for path, pin in ((mf.__file__, REF_SHA), (cf.__file__, CFG_SHA)): + if hashlib.sha256(open(path, "rb").read()).hexdigest() != pin: + sys.exit("fwdref: reference source pin mismatch: " + path) +if torch.__version__ != "2.14.0+cu130": + sys.exit("fwdref: torch pin mismatch: " + torch.__version__) +torch.set_num_threads(1) +torch.set_grad_enabled(False) +torch.use_deterministic_algorithms(True) +src, shards, output = sys.argv[1:4] +cfg = cf.FlintConfig(**json.load(open(os.path.join(src, "config.json")))) +cfg._attn_implementation = "eager" +cfg._experts_implementation = "eager" +wmap = json.load(open(os.path.join(src, "model.safetensors.index.json")))["weight_map"] +handles = {} + + +def shard(name): + f = wmap[name] + if f not in handles: + handles[f] = safe_open(os.path.join(shards, f), framework="pt") + return handles[f] + + +def tensor(name): + t = shard(name).get_tensor(name) + assert t.dtype == torch.bfloat16, (name, t.dtype) + return t.float() + + +def load(module, prefix, rename=None): + state = {k: tensor(prefix + (rename or {}).get(k, k)) for k in module.state_dict()} + module.load_state_dict(state, strict=True) + return module.float().eval() + + +def norm(prefix): + return load(mf.FlintRMSNorm(cfg.hidden_size, eps=cfg.rms_norm_eps), prefix) + + +class Lazy: + def __init__(self, prefix, part): + self.prefix, self.part = prefix, part + + def __getitem__(self, e): + p = self.prefix + "experts.%d." % int(e) + if self.part == "gate_up": + return torch.cat([tensor(p + "gate_proj.weight"), tensor(p + "up_proj.weight")], dim=0) + return tensor(p + "down_proj.weight") + + +def sparse(prefix): + c = cf.FlintConfig(**cfg.to_dict()) + c._experts_implementation = "eager" + c.num_experts = 1 + ex = mf.FlintExperts(c).float() + del ex.gate_up_proj, ex.down_proj + ex.gate_up_proj, ex.down_proj = Lazy(prefix, "gate_up"), Lazy(prefix, "down") + ex.num_experts = cfg.num_experts + blk = mf.FlintSparseMoeBlock.__new__(mf.FlintSparseMoeBlock) + torch.nn.Module.__init__(blk) + blk.gate = load(mf.FlintTopKRouter(cfg), prefix + "gate.") + blk.experts = ex + blk.shared_expert = load(mf.FlintMLP(cfg, cfg.shared_expert_intermediate_size), prefix + "shared_expert.") + return blk + + +def write(f, x): + f.write(x.detach().float().contiguous().numpy().astype("