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/ddaceae8993e13e2 # 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#835 (code only) closed derived `ddaceae8993e13e2` #835 Imported from GitHub aien-dev/aien-sovereign-core-mv#835 (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 `85a185816307d435e89a77666de327c293c26961` · Head `e275b0edfbf5ce7b4d852e3d592692b0ef86f1b0` ### Apply it ``` git checkout -b patch-ddaceae8993e13e2 85a185816307d435e89a77666de327c293c26961 curl -fsSL https://interplane.io/drakestapleton/aien-sovereign-core-mv/patches/ddaceae8993e13e2.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 835 e275b0edfbf5ce7b4d852e3d592692b0ef86f1b0 ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"aien-sovereign-core-mv","number":835,"url":"https://github.com/aien-dev/aien-sovereign-core-mv/pull/835","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:38:05Z","metadata":"unavailable","state_derived":true} ``` ### Changes ``` diff --git a/.crumb b/.crumb index a1d85d4c..723f2c1b 100644 --- a/.crumb +++ b/.crumb @@ -125,14 +125,14 @@ } ], "children_root": "sha256:05d34c0deec7c4a6cd3aa12640dca0c20bd8b2d4a4df809b234090822f422b4f", - "compiled_at": "2026-10-30T16:18:51Z", + "compiled_at": "2026-10-30T18:02:13Z", "compiler": "crumb-compile/1", - "digest": "sha256:af06cb85279b46470d7276e59a224e62adca55445ced89329d916e34a5374eda", + "digest": "sha256:54fc201cc31d30459d219d1460240689ea44cd3d8b41a63c0e8ab4cf7eb0acd8", "evidence_files": 3602, "evidence_root": "sha256:1b8069934a4cc67803874ebd2ad5de32671fae5ccce1a3ea70aeb532fe8ea86b", - "files": 8110, - "generated_at_commit": "37c2d29a321eaf169288f2b32403eff2e37197b7", - "source_tree": "sha256:66f00cf6eeab30f6701a7ec8f8a42484bfd8c2125336c6cdf39e9804f90c7e46" + "files": 8111, + "generated_at_commit": "c2841638def7bc19564d08664c84ef4ba970fafd", + "source_tree": "sha256:c186533bcf5f9e0348297a4c84b685c3825c718d2ed3e6aa3b10a2da9e16b8ee" } }, "history": [], diff --git a/om/flint/README.md b/om/flint/README.md index 11687ac2..a13eddd2 100644 --- a/om/flint/README.md +++ b/om/flint/README.md @@ -123,6 +123,22 @@ status is N. | 41 | header-missing-tensor | a tensor the index assigns to a shard is absent from its header | | 42 | shard-capacity | over 4096 tensors in one shard, or a header that fills the JSON tape | | 43 | output-capacity | TSV over 8388608 bytes; a defensive guard that no admitted layout reaches (the full output is 4269125 bytes) | +| 44 | expert-layout | a MoE layer's routed expert extents are not laid out in tensor-name order inside each shard (e.g. expert e and 255 - e trade data_offsets); checked at load, before any fused expert read | +| 45 | load-report | per-class report accounts do not reconcile with the running tensor, parameter, routed and byte totals (or bytes ≠ 2 × parameters) | + +## Load report + +`flint-manifest CONFIG INDEX SHARD_DIR TOKDIR` runs the same admission and then replaces the TSV on +stdout with a line-oriented report: `file` lines (sha256 and bytes of config, index, +`tokenizer.json`, `tokenizer_config.json`, `chat_template.jinja`, `generation_config.json` read +from TOKDIR, and of the inventory TSV itself), the admitted control tokens, one `shard` line per +shard (file bytes, header bytes, header sha256, tensors), 22 `kind` lines (tensors, parameters and +bytes per tensor class) and the `total` line. Hashing is `om/vendor/sha256.om`, so the manifest +builds as `json.om sha256.om manifest.om`. `test/load-report.txt` is the frozen report of revision +2a247be0; the gate requires it byte for byte from the published headers (FLINT_SRC) and from the +downloaded shards (FLINT_SHARDS), and requires its layout lines plus sha256sum-equal file lines on +the synthetic checkpoint. Report mutants (one class's parameters double-counted; down projections +folded into the gate class) must be refused (45) or change the report. Hugging Face cache snapshots are directories of symlinks, so they are refused with 4. Point `SHARD_DIR` at real files, for example after `huggingface-cli download --local-dir`. @@ -205,8 +221,8 @@ layer, expert index permuted (255 - e), and window 514. - 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. +- tokenizer execution (the report pins the tokenizer files and control-token ids, it does not run + the tokenizer). This unit has no GPU arm. A GGUF importer, if added, will be a separate optional unit. @@ -216,7 +232,7 @@ This unit has no GPU arm. A GGUF importer, if added, will be a separate optional 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 +The full gate prints `OM-FLINT-MANIFEST PASS (99)` with real checkpoint inputs (92 plus the seven #834 load-report and expert-layout lines); 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 diff --git a/om/flint/check.sh b/om/flint/check.sh index 0c2b585a..df9865b8 100755 --- a/om/flint/check.sh +++ b/om/flint/check.sh @@ -37,8 +37,8 @@ fail=0 ok() { pass=$((pass + 1)); echo "ok $*"; } bad() { fail=$((fail + 1)); echo "FAIL $*"; } -build() { # out source - { printf 'om2\n'; cat "$root/om/vendor/json.om" "$2"; } | "$OMC" > "$1" 2> "$1.err" || { echo "compile: $(cat "$1.err")"; return 1; } +build() { # out source [vendor units placed between json.om and source] + { printf 'om2\n'; cat "$root/om/vendor/json.om" "${@:3}" "$2"; } | "$OMC" > "$1" 2> "$1.err" || { echo "compile: $(cat "$1.err")"; return 1; } chmod 700 "$1" } gen() { rm -rf "$b/fx"; python3 "$here/test/gen.py" "$here/test/config.json" "$b/fx" "$1" < /dev/null; } @@ -47,7 +47,8 @@ run() { # binary; sets rc, leaves out.tsv and err in $b/fx rc=$? } -build "$b/fm" "$here/manifest.om" || exit 1 +SHA256_OM="$root/om/vendor/sha256.om" +build "$b/fm" "$here/manifest.om" "$SHA256_OM" || exit 1 # 1. synthetic checkpoint must load gen base || exit 1 @@ -57,7 +58,7 @@ if [ "$rc" = 0 ] && cmp -s "$b/fx/out.tsv" "$b/fx/expected.tsv" && [ "$(cat "$b/ else bad "base: rc $rc, $(head -c 200 "$b/fx/err")" fi -for args in "" "a" "a b" "a b c d"; do +for args in "" "a" "a b" "a b c d e"; do # shellcheck disable=SC2086 "$b/fm" $args > "$b/u.out" 2> /dev/null < /dev/null r=$? @@ -102,7 +103,8 @@ hdr-dup 39 hdr-mismatch 40 hdr-missing 41 hdr-unknown 23 -shard-cap 42' +shard-cap 42 +exp-perm 44' while read -r m want; do gen "$m" || { bad "$m: fixture generator failed"; continue; } run "$b/fm" @@ -116,7 +118,7 @@ done <<< "$FIX" # 3. guard mutants: the reader with one guard removed must stop producing that guard's code s=$(cat "$here/manifest.om") mutant() { # name want fixture; reads $b/mut.om - build "$b/mut" "$b/mut.om" || { bad "mutant $1: does not compile"; return; } + build "$b/mut" "$b/mut.om" "$SHA256_OM" || { bad "mutant $1: does not compile"; return; } gen "$3" || { bad "mutant $1: fixture generator failed"; return; } run "$b/mut" if [ "$rc" = "$2" ]; then bad "mutant $1: still exits $2 on $3, so the guard is not what refuses it"; else ok "mutant $1: $3 now exits $rc, not $2"; fi @@ -144,7 +146,8 @@ GUARD='3 shard-absent 39 hdr-dup 40 hdr-mismatch 41 hdr-missing -42 shard-cap' +42 shard-cap +44 exp-perm' nl=$'\n' while read -r code fx; do t=${s//"fm_die $code tr$code$nl"/"put gst 14 get gst 14$nl"} @@ -158,6 +161,46 @@ if [ "$t" = "$s" ]; then bad "mutant no-nofollow: open flags not found"; else mutant no-nofollow 4 shard-symlink fi +# 3b. load report (issue #834): with a fourth argument TOKDIR the reader prints its own report. +# test/load-report.txt is frozen from the pinned checkpoint and was checked line by line against +# sha256sum of the source files and a Python sum over the shard headers. On the synthetic +# checkpoint the layout-derived lines (version, control, kind, total) must equal the frozen ones +# and every file line must carry sha256sum's hash; each report mutant must be caught (refusal +# 45 from the loader's own reconciliation, or a line that differs from the frozen report). +REP="$here/test/load-report.txt" +repkeep() { grep -E '^(flint-load-report|control|kind|total) ' "$1"; } +mkdir -p "$b/tok" +for f in tokenizer.json tokenizer_config.json chat_template.jinja generation_config.json; do printf '%s\n' "$f" > "$b/tok/$f"; done +report() { # binary; sets rc, leaves rep.txt in $b/fx + (cd "$b/fx" && timeout 60 "$1" config.json index.json shards "$b/tok" > rep.txt 2> rep.err < /dev/null) + rc=$? +} +gen base || exit 1 +report "$b/fm" +want=$(printf 'file config sha256 %s bytes %s\n' "$(sha "$b/fx/config.json")" "$(stat -c %s "$b/fx/config.json")" + printf 'file index sha256 %s bytes %s\n' "$(sha "$b/fx/index.json")" "$(stat -c %s "$b/fx/index.json")" + for f in tokenizer.json tokenizer_config.json chat_template.jinja generation_config.json; do + printf 'file %s sha256 %s bytes %s\n' "$f" "$(sha "$b/tok/$f")" "$(stat -c %s "$b/tok/$f")" + done + printf 'file inventory sha256 %s bytes %s\n' "$(sha "$b/fx/expected.tsv")" "$(stat -c %s "$b/fx/expected.tsv")") +if [ "$rc" = 0 ] && [ "$(repkeep "$b/fx/rep.txt")" = "$(repkeep "$REP")" ] && [ "$(grep '^file ' "$b/fx/rep.txt")" = "$want" ] && [ "$(cat "$b/fx/rep.err")" = "$SUMMARY" ]; then + ok "report: synthetic layout lines equal test/load-report.txt, file hashes equal sha256sum" +else + bad "report: rc $rc, $(head -c 200 "$b/fx/rep.err")" +fi +RMUT='report-double-params|put gkp q add get gkp q np|put gkp q add get gkp q mul 2 np +report-drop-down|ret add 19 rem sub k 16 3|ret add 19 rem sub k 16 2' +while IFS='|' read -r name from to; do + t=${s//"$from"/"$to"} + if [ "$t" = "$s" ] || [ "$(grep -cF -- "$from" "$here/manifest.om")" != 1 ]; then bad "mutant $name: site not found exactly once"; continue; fi + printf '%s\n' "$t" > "$b/mut.om" + build "$b/mut" "$b/mut.om" "$SHA256_OM" || { bad "mutant $name: does not compile"; continue; } + report "$b/mut" + if [ "$rc" != 0 ]; then ok "mutant $name: refused, $(head -c 80 "$b/fx/rep.err")" + elif [ "$(repkeep "$b/fx/rep.txt")" != "$(repkeep "$REP")" ]; then ok "mutant $name: report differs from test/load-report.txt" + else bad "mutant $name: report unchanged"; fi +done <<< "$RMUT" + # 4. real checkpoint arms if [ -n "${FLINT_SRC:-}" ]; then if [ "$(sha "$FLINT_SRC/config.json")" != "$CFG_PIN" ] || [ "$(sha "$FLINT_SRC/model.safetensors.index.json")" != "$IDX_PIN" ]; then @@ -181,6 +224,9 @@ PY else bad "FLINT_SRC: rc $r, $(head -c 200 "$b/hdr.err")" fi + timeout 60 "$b/fm" "$FLINT_SRC/config.json" "$FLINT_SRC/model.safetensors.index.json" "$b/hdr" "$FLINT_SRC" > "$b/hdr.rep" 2> /dev/null < /dev/null + r=$? + if [ "$r" = 0 ] && cmp -s "$b/hdr.rep" "$REP"; then ok "FLINT_SRC: load report equals test/load-report.txt"; else bad "FLINT_SRC: load report rc $r or differs from test/load-report.txt"; fi fi else echo "NOT_RUN FLINT_SRC (pinned header capture of RecursiveSI/flint 2a247be0)" @@ -193,6 +239,9 @@ if [ -n "${FLINT_SHARDS:-}" ] && [ -n "${FLINT_SRC:-}" ]; then else bad "FLINT_SHARDS: rc $r, $(head -c 200 "$b/real.err")" fi + timeout 600 "$b/fm" "$FLINT_SRC/config.json" "$FLINT_SRC/model.safetensors.index.json" "$FLINT_SHARDS" "$FLINT_SHARDS" > "$b/real.rep" 2> /dev/null < /dev/null + r=$? + if [ "$r" = 0 ] && cmp -s "$b/real.rep" "$REP"; then ok "FLINT_SHARDS: load report equals test/load-report.txt"; else bad "FLINT_SHARDS: load report rc $r or differs from test/load-report.txt"; fi else echo "NOT_RUN FLINT_SHARDS (the 15 downloaded shards; needs FLINT_SRC too)" fi diff --git a/om/flint/manifest.om b/om/flint/manifest.om index 5987f0e3..cb9ad1c6 100644 --- a/om/flint/manifest.om +++ b/om/flint/manifest.om @@ -1,17 +1,21 @@ note flint-manifest: bounded reader for the pinned Flint BF16 checkpoint (aien-architecture-mv#353, -note Core #802 P0). Usage: flint-manifest CONFIG INDEX SHARD_DIR. It admits config.json, +note Core #802 P0). Usage: flint-manifest CONFIG INDEX SHARD_DIR [TOKDIR]. It admits config.json, note model.safetensors.index.json and every safetensors header named by the index, and refuses note anything outside the pinned layout. On success stdout is the tensor inventory TSV (one row per note tensor: name, shard, dtype, shape, begin, end; shards in name order, rows in header order) and -note stderr carries one summary line. On refusal nothing is written to stdout, stderr carries -note "refused N reason" and the exit status is N (table in om/flint/README.md). -note Compose: { printf 'om2\n'; cat om/vendor/json.om om/flint/manifest.om; } | omc +note stderr carries one summary line. With TOKDIR, stdout is instead the load report (file, tokenizer +note and inventory sha256, control tokens, per-shard header identity, per-class tensor counts, +note parameters and bytes, reconciled totals). On refusal nothing is written to stdout, stderr +note carries "refused N reason" and the exit status is N (table in om/flint/README.md). +note Compose: { printf 'om2\n'; cat om/vendor/json.om om/vendor/sha256.om om/flint/manifest.om; } | omc note Canonical tensor id (slot): 0 embed, 1 final norm, 2 lm_head, then 3 + layer * 784 + kind. note Kinds 0..8 every layer, 9..11 dense MLP (layers 0 and 1), 12..15 router and shared expert, note 16 + 3 * expert + j routed expert projections (j 0 gate, 1 up, 2 down), MoE layers 2..48. const FMX ulong 99999 const FMNS ulong 38419 +const FBOS ulong 150000 +const FPAD ulong 150001 global ga uchar 16384 global gas ulong 8 global gal ulong 8 @@ -30,13 +34,28 @@ global gh8 uchar 8 global geb uchar 512 global gdg uchar 24 global gob uchar 8388608 +global gsb ulong 38419 +global glx ulong 256 +global gxc ulong 64 +global gkc ulong 24 +global gkp ulong 24 +global gkb ulong 24 +global ghs uchar 4352 +global gsz ulong 64 +global ghl ulong 64 +global gsc ulong 64 note gst: 0 index tensors, 1 total_size, 2 params, 3 routed params, 4 tensor bytes, 5 stdout fill, note 6 header tensors, 7 index cursor, 8 index length, 9 last fstat size, 10 shard index, note 11 shard data length, 12 shard entries, 13 shard count, 14 stderr fill, 15 string start, -note 16 string length, 17 number end, 18 mantissa, 19 biased exponent, 20 mantissa end. - -text tr2 "usage: flint-manifest CONFIG INDEX SHARD_DIR" +note 16 string length, 17 number end, 18 mantissa, 19 biased exponent, 20 mantissa end, +note 21 report mode (TOKDIR given), 22 config bytes. +note gsb: slot -> data begin; glx: experts in name order; gxc: per-shard cursor of the layout walk; +note gkc/gkp/gkb: per report class tensors, parameters, bytes; ghs: 64 hex sha256 per shard +note header, then slot 64 config, 65 index, 66 inventory TSV, 67 last TOKDIR file; +note gsz/ghl/gsc: per shard file bytes, header bytes, tensors. + +text tr2 "usage: flint-manifest CONFIG INDEX SHARD_DIR [TOKDIR]" text tr3 "io" text tr4 "not-regular-file" text tr10 "config-json" @@ -62,6 +81,27 @@ text tr40 "shard-mismatch" text tr41 "header-missing-tensor" text tr42 "shard-capacity" text tr43 "output-capacity" +text tr44 "expert-layout" +text tr45 "load-report" +text trpv "flint-load-report 1" +text trfile "file " +text trsha " sha256 " +text trcfg "config" +text tridx "index" +text trtok "tokenizer.json" +text trtkc "tokenizer_config.json" +text trtpl "chat_template.jinja" +text trgen "generation_config.json" +text trinv "inventory" +text trctl "control bos " +text trpad " pad " +text treos " eos" +text trsh "shard " +text trhdr " header " +text trkind "kind " +text trstar "*." +text trten " tensors " +text trtot "total tensors " text tref "refused " text tsok "flint-manifest ok tensors " text tspar " params " @@ -1010,7 +1050,7 @@ if eq id 3 ret fm_cdec src tape v 0 0 end if eq id 4 -ret fm_cu src tape v 150000 +ret fm_cu src tape v FBOS end if eq id 5 ret fm_cu src tape v 1 @@ -1070,7 +1110,7 @@ if or eq id 23 eq id 34 ret or eq ty jstrue eq ty jsfalse end if eq id 24 -ret fm_cu src tape v 150001 +ret fm_cu src tape v FPAD end if eq id 25 ret fm_cdec src tape v 1 99994 @@ -1601,7 +1641,44 @@ fm_ou get gen c fm_ob 10 end -note fm_acct: count slot s (extent c) into the tensor, parameter, routed and byte totals +note ======== load report hashing (om/vendor/sha256.om) ======== + +note fm_hfin: finish the running sha256 into ghs slot r (64 lowercase hex bytes) +fn fm_hfin r ulong to void +if not hfinal +fm_die 45 tr45 +end +for i ulong 64 +put ghs add mul r 64 i get hd i +end +end + +note fm_hsh: sha256 of b[0 .. n) into ghs slot r +fn fm_hsh b view uchar * n ulong r ulong to void +hreset +for i ulong n +if not hpush get b i +fm_die 45 tr45 +end +end +fm_hfin r +end + +note fm_cls: report class of slot s: 0 embed, 1 final norm, 2 lm_head, 3 + per-layer kind 0..15, +note 19 + j routed expert projection (j 0 gate, 1 up, 2 down) +fn fm_cls s ulong to ulong +if lt s 3 +ret s +end +k = fm_kd s +if lt k 16 +ret add 3 k +end +ret add 19 rem sub k 16 3 +end + +note fm_acct: count slot s (extent c) into the tensor, parameter, routed and byte totals and into +note its report class fn fm_acct s ulong c ulong to void put gst 12 add c 1 put gst 6 add get gst 6 1 @@ -1612,7 +1689,12 @@ if ge fm_kd s 16 put gst 3 add get gst 3 np end end -put gst 4 add get gst 4 sub get gen c get gbg c +nby = sub get gen c get gbg c +put gst 4 add get gst 4 nby +q = fm_cls s +put gkc q add get gkc q 1 +put gkp q add get gkp q np +put gkb q add get gkb q nby end fn fm_entry src view uchar 983040 tape view uint 262160 nb edit uchar 256 k ulong to void @@ -1640,6 +1722,7 @@ fm_die 42 tr42 end fm_eval src tape add k 1 s put gsee s uchar add get gst 10 1 +put gsb s get gbg c fm_acct s c fm_orow nb n s c end @@ -1697,6 +1780,11 @@ fm_die 31 tr31 end fm_pfull fd src hl 8 fm_close fd +if eq get gst 21 1 +fm_hsh src hl si +put gsz si sz +put ghl si hl +end put gst 10 si put gst 11 sub sub sz 8 hl put gst 12 0 @@ -1720,6 +1808,383 @@ fm_entry src tape nb k k = js_mnext tape k end fm_tile +put gsc si get gst 12 +end + +note ======== expert layout (checked before the routed experts are fused) ======== + +note fm_lxe: the expert whose decimal name has the 3-place key k (digit + 1 per place, 0 past the +note end, so key order is the byte order of the names), FMX when k spells no expert 0..255 +fn fm_lxe k ulong to ulong +a = div k 121 +b = rem div k 11 11 +c = rem k 11 +if eq a 0 +ret FMX +end +if and eq b 0 ne c 0 +ret FMX +end +if and eq a 1 ne b 0 +ret FMX +end +v = sub a 1 +if ne b 0 +v = add mul v 10 sub b 1 +end +if ne c 0 +v = add mul v 10 sub c 1 +end +if ge v 256 +ret FMX +end +ret v +end + +note fm_xord: glx = the 256 experts in tensor name order (0, 1, 10, 100, 101, .., 99) +fn fm_xord to void +n = ulong 0 +for k ulong 1331 +e = fm_lxe k +if ne e FMX +if ge n 256 +fm_die 44 tr44 +end +put glx n e +n = add n 1 +end +end +if ne n 256 +fm_die 44 tr44 +end +end + +note fm_xone: projection j of expert e in MoE layer l must begin, inside its shard, exactly where +note the previous expert tensor of that layer in name order ended +fn fm_xone l ulong e ulong j ulong to void +s = add add 3 mul l 784 add 16 add mul e 3 j +sh = get gsee s +if eq sh 0 +fm_die 44 tr44 +end +x = sub ulong sh 1 +b = get gsb s +cu = get gxc x +if and ne cu FMX ne b cu +fm_die 44 tr44 +end +put gxc x add b mul 2 fm_np s +end + +note fm_xlay: bind expert index to data offset before fusing. The safetensors writer lays a +note shard's tensors out in name order, so each MoE layer's 768 expert tensors (names .. .E.down, +note .E.gate, .E.up for E in name order) must tile every shard they occupy in that order. Names +note and shapes are bound per tensor (23, 36, 37); this binds the index to the bytes: two experts +note whose extents trade places, or any other permutation, refuses 44 before any forward math. +fn fm_xlay to void +fm_xord +for l ulong 47 +for i ulong 64 +put gxc i FMX +end +for k ulong 256 +for jj ulong 3 +fm_xone add l 2 get glx k rem add jj 2 3 +end +end +end +end + +note ======== load report ======== + +note fm_krec: the per-class accounts must reconcile with the running totals: tensors, parameters, +note routed parameters (classes 19..21), bytes, and bytes = 2 * parameters (BF16) +fn fm_krec to void +t = ulong 0 +p = ulong 0 +r = ulong 0 +by = ulong 0 +for q ulong 22 +t = add t get gkc q +p = add p get gkp q +by = add by get gkb q +if ge q 19 +r = add r get gkp q +end +end +if or ne t get gst 6 ne p get gst 2 +fm_die 45 tr45 +end +if or ne r get gst 3 ne by get gst 4 +fm_die 45 tr45 +end +if ne by mul 2 p +fm_die 45 tr45 +end +end + +fn fm_ohex r ulong to void +for i ulong 64 +fm_ob get ghs add mul r 64 i +end +end + +note fm_ofile: "file LABEL sha256 HEX bytes N" with the hash from ghs slot r +fn fm_ofile t view uchar * r ulong n ulong to void +fm_otx trfile +fm_otx t +fm_otx trsha +fm_ohex r +fm_otx tsby +fm_ou n +fm_ob 10 +end + +note fm_tpath: TOKDIR/t into gpth, its length +fn fm_tpath t view uchar * to ulong +dn = get gal 4 +if or eq dn 0 gt dn 3900 +fm_die 2 tr2 +end +o = get gas 4 +for i ulong dn +put gpth i get ga add o i +end +put gpth dn 47 +for j ulong len t +put gpth add add dn 1 j get t j +end +ret add add dn 1 len t +end + +note fm_hfile: stream TOKDIR/t through b into sha256 and write its file line +fn fm_hfile t view uchar * b edit uchar 983040 to void +fd = fm_open fm_tpath t +n = get gst 9 +hreset +o = ulong 0 +while lt o n bound 999999 +m = sub n o +if gt m len b +m = len b +end +fm_pfull fd b m o +for i ulong m +if not hpush get b i +fm_die 45 tr45 +end +end +o = add o m +end +fm_close fd +fm_hfin 67 +fm_ofile t 67 n +end + +note fm_hidx: sha256 of the admitted index bytes gx[0 .. gst 8) into slot 65 +fn fm_hidx to void +hreset +n = get gst 8 +o = ulong 0 +while lt o n bound 999999 +m = sub n o +if gt m 65536 +m = 65536 +end +for i ulong m +if not hpush get gx add o i +fm_die 45 tr45 +end +end +o = add o m +end +fm_hfin 65 +end + +note fm_hinv: sha256 of the inventory TSV built in gob into slot 66 (loops stay under the bound) +fn fm_hinv to void +hreset +n = get gst 5 +o = ulong 0 +while lt o n bound 999999 +m = sub n o +if gt m 65536 +m = 65536 +end +for i ulong m +if not hpush get gob add o i +fm_die 45 tr45 +end +end +o = add o m +end +fm_hfin 66 +end + +note fm_octl: the control tokens config admission pinned (bos, pad, eos list) +fn fm_octl to void +fm_otx trctl +fm_ou FBOS +fm_otx trpad +fm_ou FPAD +fm_otx treos +for i ulong fm_alen 0 +fm_ob 32 +fm_ou fm_aval 0 i +end +fm_ob 10 +end + +fn fm_oshd si ulong to void +fm_otx trsh +for j ulong get gsl si +fm_ob get gsn add mul si 128 j +end +fm_otx tsby +fm_ou get gsz si +fm_otx trhdr +fm_ou get ghl si +fm_otx trsha +fm_ohex si +fm_otx trten +fm_ou get gsc si +fm_ob 10 +end + +fn fm_otk k ulong to void +if eq k 0 +fm_otx tk0 +end +if eq k 1 +fm_otx tk1 +end +if eq k 2 +fm_otx tk2 +end +if eq k 3 +fm_otx tk3 +end +if eq k 4 +fm_otx tk4 +end +if eq k 5 +fm_otx tk5 +end +if eq k 6 +fm_otx tk6 +end +if eq k 7 +fm_otx tk7 +end +if eq k 8 +fm_otx tk8 +end +if eq k 9 +fm_otx tk9 +end +if eq k 10 +fm_otx tk10 +end +if eq k 11 +fm_otx tk11 +end +if eq k 12 +fm_otx tk12 +end +if eq k 13 +fm_otx tk13 +end +if eq k 14 +fm_otx tk14 +end +if eq k 15 +fm_otx tk15 +end +end + +note fm_okn: the name pattern of report class q (* for the layer and the expert index) +fn fm_okn q ulong to void +if eq q 0 +fm_otx tembed +ret +end +if eq q 1 +fm_otx tnorm +ret +end +if eq q 2 +fm_otx tlmh +ret +end +fm_otx tlayers +fm_otx trstar +if lt q 19 +fm_otk sub q 3 +ret +end +fm_otx texp +fm_otx trstar +j = sub q 19 +if eq j 0 +fm_otx tgate +end +if eq j 1 +fm_otx tup +end +if eq j 2 +fm_otx tdown +end +end + +fn fm_okind q ulong to void +fm_otx trkind +fm_okn q +fm_otx trten +fm_ou get gkc q +fm_otx tspar +fm_ou get gkp q +fm_otx tsby +fm_ou get gkb q +fm_ob 10 +end + +fn fm_otot to void +fm_otx trtot +fm_ou get gst 6 +fm_otx tspar +fm_ou get gst 2 +fm_otx tsrt +fm_ou get gst 3 +fm_otx tsby +fm_ou get gst 4 +fm_otx tssh +fm_ou get gst 13 +fm_ob 10 +end + +note fm_rep: replace the inventory TSV on stdout with the load report (its sha256 is a report line) +fn fm_rep src edit uchar 983040 to void +ni = get gst 5 +fm_hinv +fm_hidx +put gst 5 0 +fm_otx trpv +fm_ob 10 +fm_ofile trcfg 64 get gst 22 +fm_ofile tridx 65 get gst 8 +fm_hfile trtok src +fm_hfile trtkc src +fm_hfile trtpl src +fm_hfile trgen src +fm_ofile trinv 66 ni +fm_octl +for j ulong get gst 13 +fm_oshd get gord j +end +for q ulong 22 +fm_okind q +end +fm_otot end fn fm_summary to void @@ -1740,11 +2205,11 @@ end fn main to int c = argcnt -if ne c 4 +if and ne c 4 ne c 5 fm_die 2 tr2 end o = ulong 0 -for i ulong 4 +for i ulong ulong c r = argread i ga o sub len ga o if lt r 0 fm_die 2 tr2 @@ -1756,7 +2221,14 @@ end src = new uchar 983040 0 tape = new uint 262160 0 nb = new uchar 256 0 +if eq c 5 +put gst 21 1 +end n = fm_rcfg src +if eq get gst 21 1 +fm_hsh src n 64 +put gst 22 n +end fm_cfg src tape n fm_ridx fm_ohdr @@ -1767,9 +2239,14 @@ for j ulong get gst 13 fm_shard src tape nb get gord j end fm_hmiss +fm_xlay if ne get gst 4 get gst 1 fm_die 25 tr25 end +fm_krec +if eq get gst 21 1 +fm_rep src +end fm_oflush fm_summary ret 0 diff --git a/om/flint/test/gen.py b/om/flint/test/gen.py index 5d7ca58f..37c3ba9e 100755 --- a/om/flint/test/gen.py +++ b/om/flint/test/gen.py @@ -173,6 +173,21 @@ elif mut == "hdr-meta": extra_head = '"__metadata__":{"format":"pt"},' elif mut == "hdr-entry": extra_entry = ',"extra":1' +elif mut == "exp-perm": + # the data analogue of the forward mutant 255 - e: layer 2's expert e and 255 - e trade + # data_offsets (same extents, so tiling and every per-tensor check still hold) + pre = "model.layers.2.mlp.experts." + loc = {r[0]: r for rows in shards for r in rows} + sh = {r[0]: i for i, rows in enumerate(shards) for r in rows} + swapped = 0 + for e in range(128): + for p in ("gate_proj", "up_proj", "down_proj"): + a = loc["%s%d.%s.weight" % (pre, e, p)] + b = loc["%s%d.%s.weight" % (pre, 255 - e, p)] + if sh[a[0]] == sh[b[0]]: + a[3], a[4], b[3], b[4] = b[3], b[4], a[3], a[4] + swapped += 1 + assert swapped > 0 elif mut not in ("base", "hdr-json", "hdr-len-be", "hdr-len-big", "shard-short", "shard-absent", "shard-symlink", "shard-dir", "shard-cap"): sys.exit("gen.py: unknown mutant " + mut) diff --git a/om/flint/test/load-report.txt b/om/flint/test/load-report.txt new file mode 100644 index 00000000..187f1d93 --- /dev/null +++ b/om/flint/test/load-report.txt @@ -0,0 +1,47 @@ +flint-load-report 1 +file config sha256 a57c33d11f725099105b657043c113149763066d204fd472d0b2ee399abc2ba7 bytes 2451 +file index sha256 e5e9c492685f84c8d2d8369f36c74674b03410715f23f6179313f6f1feb90311 bytes 3329405 +file tokenizer.json sha256 a263cce0b7e2b03f7ee07ce809783ef4b47f160c3f268a4ea1524f638da45b68 bytes 10879128 +file tokenizer_config.json sha256 159ac88217e90ffd0a4a294726048bb302829e82e1958dc85bb203aa79138fbf bytes 30439 +file chat_template.jinja sha256 7940f4ffa3275c36caa4a582f845aaad79da11018b3961e8fbcad6ae29733466 bytes 2328 +file generation_config.json sha256 a499c71895e008abd572558a5ad5904feaed92cf2a3b6e2cb0e9cabf03b96ed3 bytes 202 +file inventory sha256 60ff4dbdaa1c3632c934c6935aa60ed5b2def4e15f0ca5083ddc7dd660f083f5 bytes 4269125 +control bos 150000 pad 150001 eos 150001 150003 150005 150018 +shard model-00001-of-00015.safetensors bytes 5369025064 header 315936 sha256 67337967567f0eee1b8feb2396a6a6b7df1f1e8bc87f262046f8e027c76401e7 tensors 2560 +shard model-00002-of-00015.safetensors bytes 5369025168 header 316040 sha256 87c0c3a37d063335df1142b2b96d506cd49ccaed9e31ebc13791501e565b46e3 tensors 2559 +shard model-00003-of-00015.safetensors bytes 5369026736 header 317608 sha256 47b4d1a5e42839d383edf6270de06bcb3edbd84dcbed2932eaf01d9bcdf91cd7 tensors 2558 +shard model-00004-of-00015.safetensors bytes 5369027984 header 318856 sha256 07ada28647d9e13744acd17d4cc69370f80f6f6b27d7c620ac0e159248c31ec5 tensors 2560 +shard model-00005-of-00015.safetensors bytes 5369027520 header 318392 sha256 b3e73559b03293b790e9a3b6f6d18808857d3a1e16656c6e269054889cbcbfa7 tensors 2559 +shard model-00006-of-00015.safetensors bytes 5369027848 header 318720 sha256 6c03c2923011a5973eb4fd00d571e90d22ac46022b5df37d0b22bed6f3987314 tensors 2560 +shard model-00007-of-00015.safetensors bytes 5369027984 header 318856 sha256 4175697f99179fa4dc9514d5ec8ce01485e1dfcfdb52059d0f8b02d6ef6f60a6 tensors 2560 +shard model-00008-of-00015.safetensors bytes 5369027632 header 318504 sha256 c4e761259055d94db75dfbd371ad5b130a580407b1126e3a968117eec158b317 tensors 2560 +shard model-00009-of-00015.safetensors bytes 5369027848 header 318720 sha256 3212e41927f4968d026a4f3fe4ee85cc3be915cd69a2401dd4e492ed483d58fc tensors 2560 +shard model-00010-of-00015.safetensors bytes 5369027984 header 318856 sha256 0308b39bf000fc87fc030d041ca0687f8ad4e4b80723e73d98bb773ae0ebce3e tensors 2560 +shard model-00011-of-00015.safetensors bytes 5369027632 header 318504 sha256 75763778b5c0c9b6690157dd868771b565cbd6cdcfe6058da163058d87892fe3 tensors 2560 +shard model-00012-of-00015.safetensors bytes 5367976344 header 295824 sha256 53a799b7c90b3a6da3a115139412a47ec4f5e9b146cd6dbee77fa68a5312b4ad tensors 2385 +shard model-00013-of-00015.safetensors bytes 5368466032 header 279656 sha256 9ea26e01d03f4be32d916607f797d80799eabd86ce0a01b7985495390d6c57d7 tensors 2244 +shard model-00014-of-00015.safetensors bytes 5369027736 header 318608 sha256 b0fe8d2d8ae39586e7f22cee86563cb916b94d486cd8a7e74bb08cf2b36dc856 tensors 2560 +shard model-00015-of-00015.safetensors bytes 4410368544 header 169944 sha256 eb27335baaf56b56bf6de959472a3d8b7de636d2dc3782883b106fcea377be70 tensors 1389 +kind model.embed_tokens.weight tensors 1 params 307494912 bytes 614989824 +kind model.norm.weight tensors 1 params 2048 bytes 4096 +kind lm_head.weight tensors 1 params 307494912 bytes 614989824 +kind model.layers.*.input_layernorm.weight tensors 49 params 100352 bytes 200704 +kind model.layers.*.post_attention_layernorm.weight tensors 49 params 100352 bytes 200704 +kind model.layers.*.self_attn.q_proj.weight tensors 49 params 411041792 bytes 822083584 +kind model.layers.*.self_attn.k_proj.weight tensors 49 params 51380224 bytes 102760448 +kind model.layers.*.self_attn.v_proj.weight tensors 49 params 51380224 bytes 102760448 +kind model.layers.*.self_attn.o_proj.weight tensors 49 params 411041792 bytes 822083584 +kind model.layers.*.self_attn.q_norm.weight tensors 49 params 6272 bytes 12544 +kind model.layers.*.self_attn.k_norm.weight tensors 49 params 6272 bytes 12544 +kind model.layers.*.self_attn.softmax_offset tensors 49 params 1568 bytes 3136 +kind model.layers.*.mlp.gate_proj.weight tensors 2 params 25165824 bytes 50331648 +kind model.layers.*.mlp.up_proj.weight tensors 2 params 25165824 bytes 50331648 +kind model.layers.*.mlp.down_proj.weight tensors 2 params 25165824 bytes 50331648 +kind model.layers.*.mlp.gate.weight tensors 47 params 24641536 bytes 49283072 +kind model.layers.*.mlp.shared_expert.gate_proj.weight tensors 47 params 98566144 bytes 197132288 +kind model.layers.*.mlp.shared_expert.up_proj.weight tensors 47 params 98566144 bytes 197132288 +kind model.layers.*.mlp.shared_expert.down_proj.weight tensors 47 params 98566144 bytes 197132288 +kind model.layers.*.mlp.experts.*.gate_proj.weight tensors 12032 params 12616466432 bytes 25232932864 +kind model.layers.*.mlp.experts.*.up_proj.weight tensors 12032 params 12616466432 bytes 25232932864 +kind model.layers.*.mlp.experts.*.down_proj.weight tensors 12032 params 12616466432 bytes 25232932864 +total tensors 36734 params 39785287456 routed 37849399296 bytes 79570574912 shards 15 ```