interplane.Get Omega
Read in your language

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

GitHub aien-dev/aien-sovereign-core-mv#780 (code only)

closed derived 4d38a25fe2b81481 #780

Imported from GitHub aien-dev/aien-sovereign-core-mv#780 (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 d38411c38f94b02d9e87beea440d01b42cfc5bd8 · Head 59d126e8886799b9cd7bc6b23b882b24130e8ce5

Fetch it

A git bundle of the pull request's head, 8025 bytes.

curl -fsSL https://interplane.io/drakestapleton/aien-sovereign-core-mv/patches/4d38a25fe2b81481.bundle -o 4d38a25fe2b81481.bundle
git fetch 4d38a25fe2b81481.bundle refs/pull/780/head

Raw bundle · 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
780
59d126e8886799b9cd7bc6b23b882b24130e8ce5
{"kind":"github-import","owner":"aien-dev","repo":"aien-sovereign-core-mv","number":780,"url":"https://github.com/aien-dev/aien-sovereign-core-mv/pull/780","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:37:59Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/om/README.md b/om/README.md
index 8319b7b7..55b3b03d 100644
--- a/om/README.md
+++ b/om/README.md
@@ -19,6 +19,7 @@ aien-architecture-mv#300).
 | `expert-bytes/expert-bytes.om` | Per-expert byte check for Qwen3.6-35B-A3B-FP8 (DRA-63, #855): reads only the safetensors headers and requires, for layers 0-39, FP8 E4M3 weights gate/up [512, 2048] and down [2048, 512] (3,145,728 B) plus BF16 block-128 scales [4, 16] / [16, 4] (384 B), 3,146,112 B per expert. Omc pinned in `expert-bytes/omega.pin` (omega-mv `474197e4`). | Host gate SC-EXPERT-BYTES (`expert-bytes/gate.sh`, `tests/gates/run.sh expert-bytes`): PASS on the checkpoint, controls width 768, FP32 scales and an input-side shape mutant FAIL as required; receipt `evidence/motor-chip-20261021/expert-bytes-check.log`. |
 | `crumb-coverage/crumb-coverage.om` | `.crumb` coverage of this repository (DRA-95): from `git ls-files -z` it counts tracked directories (the root plus every ancestor directory of a tracked path), directories with a `.crumb`, and crumb directories with at least one invariant whose `Check: ...` resolves to an existing test function (`cargo test -p X --test T -- --exact NAME`, `--lib -- --exact M::tests::NAME`) or a repository script; it lists the invariants whose check does not resolve. Omc pinned in `crumb-coverage/omega.pin` (omega-mv `b3346c2e`). | Host: `AIEN_OMC=<seed omc> bash om/crumb-coverage/run.sh` prints the report; `run.sh --self-test` runs fixture repositories (all four check forms resolve; a wrong test name, module or crate, no `Check:`, a missing script, an absolute path and a symlinked test file are reported unresolved with exit 1; bad JSON, non-array invariants and unsorted input are refused with exit 4). Advisory: no gate runs it. A resolved check names a real function; it does not prove that the function tests the claim. |
 | `residency/residency.om` | MoE expert residency simulator (sc#630 question, sc#633 hints): replays a recorded router trace against a per-layer expert cache, and (when L*E <= 65536) one cache shared by all layers in serving order, and counts hits and misses for LRU and Belady OPT at 25-90 % resident. An optional hint section (H <= 16 predicted experts per step and layer) adds two shared-LRU replays with prefetches that count demand misses and prefetches used and wasted: hlru (a hint marks its expert used) and hcold (a hint only protects its expert for the step; a fetched one enters at the LRU end). Reads up to T*L = 1000000 rows. | Host only. Matches the Wolfram LRU/OPT/hinted-LRU oracle (`residency/fixtures/oracle.wl`) on a real 35B trace slice and a synthetic trace with and without hints; 15 refusals, 3 boundary checks, 2 hint-line gates, 4 hint invariants and 10 mutants checked (`OMEGA_OMC=<seed omc> bash om/residency/run.sh`). Not wired into the pager. |
+| `dsv4/fp4dq.om` | DeepSeek-V4-Flash routed-expert decoder: packed 4-bit e2m1 codes (low nibble first) times the E8M0 scale of each 32 weights, emitted as exact float32 bit patterns with integers only. | Host only. Bit-identical to DeepSeek's own decoder (`inference/convert.py` FP4_TABLE x torch E8M0) on all 16 x 256 code/scale pairs and on six real layer-5 expert matrices; 7 refusals, 3 mutants caught (`OMEGA_OMC=<seed omc> [DSV4_SHARD7=<shard>] bash om/dsv4/run.sh`). Not wired into the engine. |
 
 Run: `OMEGA_OMC=<path to seed omc> bash om/effects/run.sh` (needs the offline cargo cache for the Rust
 reference, `crates/aien-runtime/examples/om_world_reference.rs`).
diff --git a/om/dsv4/fixtures/edge.in b/om/dsv4/fixtures/edge.in
new file mode 100644
index 00000000..be05931e
Binary files /dev/null and b/om/dsv4/fixtures/edge.in differ
diff --git a/om/dsv4/fixtures/shard7.txt b/om/dsv4/fixtures/shard7.txt
new file mode 100644
index 00000000..db96fd00
--- /dev/null
+++ b/om/dsv4/fixtures/shard7.txt
@@ -0,0 +1,6 @@
+e0.w1 2048 4096 347370840 351565144 13922136 14184280 a3b804d6536f5afb2d16a661f5bbe7701ff6f2504c2d943230bcc74e229f373a
+e0.w2 4096 2048 351565144 355759448 14184280 14446424 f82daff5e505d36cf82a81d1786a3faa6d4a66ac95455e126129e8153372261b
+e0.w3 2048 4096 355759448 359953752 14446424 14708568 1acb8328107d50132203f6c99cf31a9cec941601363a2c02ebe9700c2dc66243
+e255.w1 2048 4096 2536797528 2540991832 150761304 151023448 c033e099a2f967311d65d8f688b64658a14943561ef39ee133d4fc622bcd7594
+e255.w2 4096 2048 2540991832 2545186136 151023448 151285592 955e77d915a37902ef571fe0a394dbdf26e14c4955358ec1cb5af32643e66bb8
+e255.w3 2048 4096 2545186136 2549380440 151285592 151547736 930bb8ccbbb80259e8fcf2dfbeb3fbe2059694b150a2e049d6d544bc48a5bc3f
diff --git a/om/dsv4/fp4dq.om b/om/dsv4/fp4dq.om
new file mode 100644
index 00000000..76d2ca46
--- /dev/null
+++ b/om/dsv4/fp4dq.om
@@ -0,0 +1,163 @@
+note SPDX-License-Identifier: Apache-2.0
+note DeepSeek-V4-Flash routed-expert weight decoder in seeded Omega (host only).
+note The checkpoint stores each routed expert matrix as packed 4-bit e2m1 codes (dtype I8,
+note shape [rows, cols/2], element 2j in the low nibble, 2j+1 in the high nibble) and one
+note E8M0 scale byte per 32 elements along a row (dtype F8_E8M0, shape [rows, cols/32]).
+note DeepSeek's decoder (inference/convert.py FP4_TABLE, then times scale.float()) gives
+note   value = table[code] * 2^(s-127), table = 0 .5 1 1.5 2 3 4 6, 0 -.5 -1 -1.5 -2 -3 -4 -6.
+note Code 8 is +0 in that table, not -0. Scale byte 255 is NaN; torch's float8_e8m0fnu.float()
+note gives the bits 0x7fc00001 for it, and the NaN propagates through the product, whatever the code.
+note This unit emits that float32 product as its exact IEEE-754 bit pattern, computed with
+note integers only, rounding to nearest even where the product is subnormal.
+note Input on stdin: rows (8 bytes little-endian), cols (8 bytes little-endian), then
+note rows*cols/2 packed weight bytes, then rows*cols/32 scale bytes; at most 16 MiB in total.
+note Output on stdout: rows*cols float32 values, little-endian, row-major.
+note Exit: 0 ok, 2 read error, 3 input over 16 MiB, 4 bad shape, 5 length mismatch, 9 write error.
+global inb uchar 16777216
+note hd: 0 rows, 1 cols, 2 input length, 3 scale offset.
+global hd ulong 4
+global ob uchar 16384
+global ow ulong 1
+
+note slurp: read all of stdin into inb; 64 outer passes cover the 16777216-byte buffer.
+fn slurp to int
+n = ulong 0
+for r ulong 64
+while lt n len inb bound 999999
+k = read 0 inb n sub len inb n
+if lt k 0
+ret 2
+end
+if eq k 0
+put hd 2 n
+ret 0
+end
+n = add n ulong k
+end
+end
+ret 3
+end
+
+note le8: little-endian 64-bit number at byte offset p.
+fn le8 p ulong to ulong
+v = ulong 0
+for i ulong 8
+v = or v shl ulong get inb add p i mul i 8
+end
+ret v
+end
+
+note flush: write ob to stdout, looping over partial writes, then empty it.
+fn flush to int
+o = ulong 0
+w = get ow 0
+while lt o w bound 16385
+k = write 1 ob o sub w o
+if le k 0
+ret 9
+end
+o = add o ulong k
+end
+put ow 0 0
+ret 0
+end
+
+note emit: append the 4 little-endian bytes of b, flushing when ob is full.
+fn emit b ulong to void
+w = get ow 0
+if ge w len ob
+if ne flush 0
+exit 9
+end
+w = ulong 0
+end
+for i ulong 4
+put ob add w i uchar and shr b mul i 8 255
+end
+put ow 0 add w 4
+end
+
+note rne: sig shifted right by sh (1..63), rounded to nearest, ties to even.
+fn rne sig ulong sh ulong to ulong
+if gt sh 40
+ret 0
+end
+q = shr sig sh
+r = and sig sub shl ulong 1 sh 1
+h = shl ulong 1 sub sh 1
+if or gt r h and eq r h eq and q 1 1
+q = add q 1
+end
+ret q
+end
+
+note bits: float32 bit pattern of table[c] * 2^(s-127).
+note Magnitude code m = 1..7 is (1 + f/2) * 2^e with (e, f) = (-1,0) (0,0) (0,1) (1,0) (1,1) (2,0) (2,1),
+note so the biased exponent of the product is e + s.
+fn bits c ulong s ulong to ulong
+if eq s 255
+ret 2143289345
+end
+m = and c 7
+if eq m 0
+ret 0
+end
+sg = shl and shr c 3 1 31
+note bp is the biased exponent plus one, so it never goes below zero: e + 1 = m/2 for m >= 2, 0 for m = 1.
+f = ulong 0
+bp = s
+if ge m 2
+f = and m 1
+bp = add s div m 2
+end
+if ge bp 256
+ret or sg 2139095040
+end
+if ge bp 2
+ret or or sg shl sub bp 1 23 shl f 22
+end
+sig = or shl ulong 1 23 shl f 22
+ret or sg rne sig sub 2 bp
+end
+
+note row: decode row r.
+fn row r ulong to void
+cols = get hd 1
+wb = add 16 mul r div cols 2
+sb = add get hd 3 mul r div cols 32
+for j ulong cols
+x = ulong get inb add wb div j 2
+c = and shr x mul and j 1 4 15
+s = ulong get inb add sb div j 32
+emit bits c s
+end
+end
+
+fn main to int
+e = slurp
+if ne e 0
+ret e
+end
+if lt get hd 2 16
+ret 5
+end
+rows = le8 0
+cols = le8 8
+if or or lt rows 1 lt cols 32 ne rem cols 32 0
+ret 4
+end
+if or gt rows 16777216 gt cols 16777216
+ret 4
+end
+so = add 16 div mul rows cols 2
+put hd 0 rows
+put hd 1 cols
+put hd 3 so
+if ne get hd 2 add so div mul rows cols 32
+ret 5
+end
+for r ulong rows
+row r
+end
+ret flush
+end
diff --git a/om/dsv4/run.sh b/om/dsv4/run.sh
new file mode 100755
index 00000000..110ff75b
--- /dev/null
+++ b/om/dsv4/run.sh
@@ -0,0 +1,74 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: Apache-2.0
+# Checks om/dsv4/fp4dq.om, the DeepSeek-V4-Flash routed-expert decoder, against reference outputs
+# made by DeepSeek's own decoder (inference/convert.py FP4_TABLE x torch float8_e8m0fnu scale,
+# checkpoint revision 60d8d70770c6776ff598c94bb586a859a38244f1, torch 2.14.1+cpu).
+# The reference outputs are recorded as sha256 values below; torch is not needed to run this.
+#   edge:  every one of the 16 codes under every one of the 256 scale bytes (subnormal, NaN, overflow).
+#   shard: six real expert matrices of layer 5 cut from model-00007-of-00046.safetensors, if
+#          DSV4_SHARD7 points at that file (sha256 2d782c46d6d2...); otherwise NOT_RUN.
+# Also: refusal exit codes and three mutants that must change the output.
+# Usage: OMEGA_OMC=<seed omc> [DSV4_SHARD7=<path>] bash om/dsv4/run.sh
+set -u
+ROOT=$(cd "$(dirname "$0")/../.." && pwd)
+PIN=2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f
+OMC=${OMEGA_OMC:?set OMEGA_OMC to the seed compiler (omega-mv seed/out/omc)}
+D=$ROOT/om/dsv4
+O=$ROOT/target/om-dsv4
+got=$(sha256sum < "$OMC" | cut -d' ' -f1)
+[ "$got" = "$PIN" ] || { echo "FAIL omc sha256 $got, pinned $PIN"; exit 1; }
+rm -rf "$O"; mkdir -p "$O"
+fails=0
+pass() { echo "PASS $1"; }
+fail() { echo "FAIL $1"; fails=$((fails + 1)); }
+build() { "$OMC" < "$1" > "$2" && chmod +x "$2"; }
+build "$D/fp4dq.om" "$O/fp4dq" || { echo "FAIL build fp4dq.om"; exit 1; }
+H() { sha256sum | cut -d' ' -f1; }
+EDGE=6a35e83e299a76416e32c650443e490806ec5658e0c75df657f6b38e4b76076d
+
+# edge: all 4096 (code, scale) pairs
+g=$("$O/fp4dq" < "$D/fixtures/edge.in" | H)
+[ "$g" = "$EDGE" ] && pass "edge 16 codes x 256 scales" || fail "edge (got $g)"
+
+# refusals
+le8() { local v=$1 i; for i in 0 1 2 3 4 5 6 7; do printf "\\x$(printf %02x $(( (v >> (8*i)) & 255 )))"; done; }
+refuse() {  # label want-exit
+    "$O/fp4dq" < "$O/case" > /dev/null 2>&1; r=$?
+    [ $r = "$2" ] && pass "refuse $1 (exit $r)" || fail "refuse $1 (want $2, got $r)"
+}
+: > "$O/case"; refuse "empty input" 5
+head -c 15 "$D/fixtures/edge.in" > "$O/case"; refuse "short header" 5
+{ le8 1; le8 31; } > "$O/case"; refuse "cols not a multiple of 32" 4
+{ le8 0; le8 32; } > "$O/case"; refuse "zero rows" 4
+{ le8 1; le8 32; head -c 16 /dev/zero; } > "$O/case"; refuse "missing scale byte" 5
+{ le8 1; le8 32; head -c 18 /dev/zero; } > "$O/case"; refuse "trailing byte" 5
+head -c 16777217 /dev/zero > "$O/case"; refuse "input over 16 MiB" 3
+
+# mutants: each must change the edge output
+mutant() {  # label sed-expression
+    sed "$2" "$D/fp4dq.om" > "$O/m.om"
+    cmp -s "$O/m.om" "$D/fp4dq.om" && { fail "mutant $1 (sed matched nothing)"; return; }
+    build "$O/m.om" "$O/m" || { fail "mutant $1 (does not build)"; return; }
+    g=$("$O/m" < "$D/fixtures/edge.in" | H)
+    [ "$g" != "$EDGE" ] && pass "mutant $1 caught" || fail "mutant $1 survived"
+}
+mutant "high nibble first" 's/^c = and shr x mul and j 1 4 15$/c = and shr x mul sub 1 and j 1 4 15/'
+mutant "code 8 as -0" '/^if eq m 0$/{n;s/^ret 0$/ret shl and shr c 3 1 31/}'
+mutant "NaN bits 0x7fc00000" 's/^ret 2143289345$/ret 2143289344/'
+
+# shard: real layer-5 expert matrices, base = 8 + header length 172656
+if [ -n "${DSV4_SHARD7:-}" ] && [ -r "$DSV4_SHARD7" ]; then
+    B=172664
+    while read -r name rows cols w0 w1 s0 s1 want; do
+        { le8 "$rows"; le8 "$cols"
+          tail -c +$((B + w0 + 1)) "$DSV4_SHARD7" | head -c $((w1 - w0))
+          tail -c +$((B + s0 + 1)) "$DSV4_SHARD7" | head -c $((s1 - s0)); } > "$O/case"
+        g=$("$O/fp4dq" < "$O/case" | H)
+        [ "$g" = "$want" ] && pass "shard7 $name identical to reference" || fail "shard7 $name (got $g)"
+    done < "$D/fixtures/shard7.txt"
+else
+    echo "NOT_RUN shard7 (set DSV4_SHARD7 to model-00007-of-00046.safetensors)"
+fi
+
+[ $fails = 0 ] && echo "ALL PASS" || echo "$fails FAILED"
+exit $fails