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#809 (code only)
Apply it
git checkout -b patch-6d9ab87aa9099453 85a185816307d435e89a77666de327c293c26961 curl -fsSL https://interplane.io/drakestapleton/aien-sovereign-core-mv/patches/6d9ab87aa9099453.patch | git am
Provenance
github-import 1
aien-dev/aien-sovereign-core-mv
809
96480acc8cc169be63a1ce8547fca122106dd726
{"kind":"github-import","owner":"aien-dev","repo":"aien-sovereign-core-mv","number":809,"url":"https://github.com/aien-dev/aien-sovereign-core-mv/pull/809","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:38:05Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/.crumb b/.crumb index a1d85d4c..1103602f 100644 --- a/.crumb +++ b/.crumb @@ -125,14 +125,14 @@ } ], "children_root": "sha256:05d34c0deec7c4a6cd3aa12640dca0c20bd8b2d4a4df809b234090822f422b4f", - "compiled_at": "2026-10-30T16:18:51Z", + "compiled_at": "2026-10-30T17:12:11Z", "compiler": "crumb-compile/1", - "digest": "sha256:af06cb85279b46470d7276e59a224e62adca55445ced89329d916e34a5374eda", + "digest": "sha256:355033a48d24542f3c57cd08b110c23667de8192838d9cab51f7fa7c4a0bbc61", "evidence_files": 3602, "evidence_root": "sha256:1b8069934a4cc67803874ebd2ad5de32671fae5ccce1a3ea70aeb532fe8ea86b", "files": 8110, - "generated_at_commit": "37c2d29a321eaf169288f2b32403eff2e37197b7", - "source_tree": "sha256:66f00cf6eeab30f6701a7ec8f8a42484bfd8c2125336c6cdf39e9804f90c7e46" + "generated_at_commit": "57f961e0292feba2becc2fe70e477affc885d80f", + "source_tree": "sha256:1c6687de20c97737d7de6cab8b8043a416b268ee3d6d631c839f041b311e7883" } }, "history": [], diff --git a/om/flint/README.md b/om/flint/README.md index 11687ac2..c6e1b3f8 100644 --- a/om/flint/README.md +++ b/om/flint/README.md @@ -216,13 +216,21 @@ 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 (95)` with real checkpoint inputs; wrong-token and skipped-final-normalization source mutants must fail the comparison. +`flint-ops decode` runs the same fixture as a KV-cache decode: one row per chunk, each layer +appends that row's K/V to a per-layer cache (49 layers x 8 positions x 512) and attention reads +every earlier position only from that cache. It must PASS the same reference within the same +budget and element count as the batch forward (a tolerance check, not a bitwise decode-vs-batch +comparison); the `kv-slot-overwrite` mutant (cache row written at slot 0) must fail. The cache +holds `FKVP` = 8 positions per layer and `fw_kv` refuses `P+n > FKVP` (`refused 7 kv-cache-bound`); +the gate rebuilds with `FKVP` 1 and requires that refusal. + 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. +paged/ring KV-cache beyond 8 positions, long-context batching or GPU/backend qualification is claimed. diff --git a/om/flint/check.sh b/om/flint/check.sh index 0c2b585a..463d5b7d 100755 --- a/om/flint/check.sh +++ b/om/flint/check.sh @@ -273,17 +273,31 @@ if [ "${FLINT_FORWARD:-0}" = 1 ]; then 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 + # KV-cache decode: one row per chunk, earlier K/V only from the cache, same fixture and budget + dline=$(timeout 900 "$b/ops" decode "$b/forward.fx" "$b/real.tsv" "$FLINT_SHARDS" 2>&1 < /dev/null) + rc=$? + dlast=${dline##*$'\n'}; de=${dlast##*elems }; fe=${line##*elems } + echo "$dlast" + if [ "$rc" = 0 ] && [[ $dlast == "flint-op decode layer 49 "* ]] && [[ $dlast == *" PASS" ]] && [ "${de%% *}" = "${fe%% *}" ]; then ok "KV-cache decode passes the same forward reference within budget, same element count"; else bad "decode rc $rc"; fi + # cache bound: with FKVP 1 the two-row decode must be refused (7), never overrun the next layer + [ "$(grep -c '^const FKVP ulong 8$' "$here/ops.om")" = 1 ] || bad "kv guard: FKVP site" + { s=$(cat "$here/ops.om"); printf '%s\n' "${s/const FKVP ulong 8/const FKVP ulong 1}"; } > "$b/kvg.om" + if build "$b/kvg" "$b/kvg.om"; then + gline=$(timeout 900 "$b/kvg" decode "$b/forward.fx" "$b/real.tsv" "$FLINT_SHARDS" 2>&1 < /dev/null); rc=$? + if [ "$rc" = 7 ] && [[ $gline == *"refused 7 kv-cache-bound"* ]]; then ok "KV cache bound refuses P+n > FKVP (rc 7)"; else bad "kv guard rc $rc: ${gline##*$'\n'}"; fi + else bad "kv guard compile"; fi s=$(cat "$here/ops.om") - while IFS='|' read -r name from to; do + while IFS='|' read -r name op 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) + line=$(timeout 900 "$b/fwdmut" "$op" "$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 + if [ "$rc" = 1 ] && [[ $line == *" FAIL" ]]; then ok "CAUGHT $op mutant $name: ${line##*$'\n'}"; else bad "$op 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 +wrong-token|forward|id = fx_w add 8 add get gfs 2 t|id = add fx_w add 8 add get gfs 2 t 1 +skip-final-norm|forward|put gfh o get gy i|put gfh o get gv i +kv-slot-overwrite|decode|c = mul add add mul L FKVP P j 512|c = mul add mul L FKVP j 512 FORWARD_MUTANTS fi else diff --git a/om/flint/ops.om b/om/flint/ops.om index 9c507be3..b07b0e35 100644 --- a/om/flint/ops.om +++ b/om/flint/ops.om @@ -3,7 +3,7 @@ note (aien-architecture-mv#353, aien-sovereign-core-mv#802, P0 forward lane). note note Usage: flint-ops OP FIXTURE INVENTORY SHARD_DIR note flint-ops selftest -note OP is rmsnorm, qkv, attn, router, shared, expert or moe. FIXTURE is written by +note OP is rmsnorm, qkv, attn, router, shared, expert, moe, forward or decode. FIXTURE is written by note test/opref.py from the pinned reference modules; INVENTORY is the TSV flint-manifest note printed for SHARD_DIR. Each operator recomputes the reference output in f64 from the note real BF16 shard weights and carries a first-order bound E on the error of the @@ -74,7 +74,13 @@ global gfa f64 4096 global gfq f64 8192 global gfo f64 8192 global gfs ulong 4 +note gkc/gvc: per-layer K and V cache, 49 layers x FKVP positions x 512 (4 kv heads x 128); +note the global size 200704 = 49 x FKVP x 512 must change with FKVP. fw_kv refuses P+n > FKVP. +const FKVP ulong 8 +global gkc f64 200704 +global gvc f64 200704 text tofwd "forward" +text todec "decode" text tembd "model.embed_tokens.weight" text tfnorm "model.norm.weight" text tlmhead "lm_head.weight" @@ -84,6 +90,7 @@ text tu "usage: flint-ops OP FIXTURE INVENTORY SHARD_DIR | flint-ops selftest" text tio "io" text tnreg "not-regular-file" text tfx "fixture" +text tkv "kv-cache-bound" text tnf "tensor-not-in-inventory" text tdt "tensor-dtype-or-shape" text tref "refused " @@ -1458,14 +1465,32 @@ note only token IDs are inputs; the fixture's intermediate tensors are compariso 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 +note gfs slots: 0 rows n in this chunk, 1 tensor index, 2 first position P, 3 mode (1 decode). +note A chunk computes rows P .. P+n only; attention reads earlier K/V from gkc/gvc. +note forward runs one chunk of T rows; decode runs T chunks of one row (KV-cache decode). +fn fw_cmpat o ulong n ulong to void 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 + +note fixture tensor s holds T rows of FHID after the header and IDs; rows P .. P+n are contiguous +fn fw_cmp n ulong to void +T = get gst 4 +o = add add 8 T mul add mul get gfs 1 T get gfs 2 FHID +fw_cmpat o n +put gfs 1 add get gfs 1 1 +end + +fn fw_rep to int +if eq get gfs 3 1 +r = report todec +ret r +end +r = report tofwd +ret r end fn fw_hidden to void @@ -1519,7 +1544,7 @@ put gve d 0.0f64 end rmsv 128 0 if rp -ropev t +ropev add get gfs 2 t end for d ulong 128 if eq nh 32 @@ -1563,8 +1588,8 @@ 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 +n = att_sc g add get gfs 2 t 0 +att_sm n get gsk h add get gfs 2 get gfs 0 put gacc 11 0.0f64 for d ulong 128 v = pv_d n add mul g 128 d @@ -1572,6 +1597,34 @@ put gfo add b d v end end +note fw_kv: append this chunk's K (gx2) and V (gx3) rows to layer L's cache at positions +note P .. P+n, then rebuild gx2/gx3 positions 0 .. P+n from the cache for attention +fn fw_kv L ulong to void +P = get gfs 2 +if gt add P get gfs 0 FKVP +op_die 7 tkv +end +n = get gfs 0 +for j ulong n +c = mul add add mul L FKVP P j 512 +for i ulong 512 +put gkc add c i get gx2 add mul j 512 i +put gvc add c i get gx3 add mul j 512 i +end +end +fw_kvr L add P n +end + +fn fw_kvr L ulong m ulong to void +for p ulong m +c = mul add mul L FKVP p 512 +for i ulong 512 +put gx2 add mul p 512 i get gkc add c i +put gx3 add mul p 512 i get gvc add c i +end +end +end + fn fw_att L ulong to void fw_qk L true fw_qk L false @@ -1582,6 +1635,7 @@ fw_proj 512 for i ulong mul get gfs 0 512 put gx3 i get gx1 i end +fw_kv L nm_lay L nm_tx tsnk ld_t 32 0 @@ -1651,7 +1705,7 @@ put gfh i add get gfh i get gfa i end fw_hidden put gst 3 L -r = report tofwd +r = fw_rep if ne r 0 exit 1 end @@ -1659,7 +1713,7 @@ end fn fw_embed to void for t ulong get gfs 0 -id = fx_w add 8 t +id = fx_w add 8 add get gfs 2 t if ge id 150144 op_die 7 tfx end @@ -1692,6 +1746,13 @@ end fw_cmp mul get gfs 0 FHID end +note fw_lgo: fixture offset of logit r of chunk row t, after the 247 hidden-size tensors +fn fw_lgo t ulong r ulong to ulong +T = get gst 4 +o = add add 8 T mul mul T FHID 247 +ret add o add mul add get gfs 2 t 150144 r +end + fn fw_logits to void for t ulong get gfs 0 for r ulong 150144 @@ -1710,11 +1771,23 @@ end end v = matdot rem r 2048 FHID put gfa 0 v -fw_cmp 1 +fw_cmpat fw_lgo t r 1 end end end +fn fw_chunk P ulong n ulong to void +put gfs 0 n +put gfs 1 0 +put gfs 2 P +fw_embed +for L ulong 49 +fw_layer L +end +fw_final +fw_logits +end + fn op_forward to int T = get gst 4 if or eq T 0 gt T 2 @@ -1722,16 +1795,15 @@ 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 +if eq get gfs 3 1 +for P ulong T +fw_chunk P 1 +end +else +fw_chunk 0 T end -fw_final -fw_logits put gst 3 49 -r = report tofwd +r = fw_rep ret r end @@ -1760,6 +1832,10 @@ end if op_argeq 1 tofwd ret 8 end +if op_argeq 1 todec +put gfs 3 1 +ret 8 +end op_die 2 tu ret 0 end