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
aien-sovereign-core-mv / om / flint / README.md
| 1 | # flint: pinned checkpoint manifest reader (Core #802 P0) |
| 2 | |
| 3 | `manifest.om` is the first deliverable of Core #802 (aien-architecture-mv#353): a bounded |
| 4 | reader that admits the Flint BF16 checkpoint at one pinned revision and refuses everything |
| 5 | else. Memory, kernel, training and serving work read its output, the tensor inventory TSV, |
| 6 | instead of parsing safetensors themselves. It does not execute the model. |
| 7 | |
| 8 | Pinned source: `RecursiveSI/flint` revision `2a247be0c0aec895ccb0ac7ca92229ec6df37288`, |
| 9 | Apache-2.0 (see `THIRD_PARTY.md`). |
| 10 | |
| 11 | | File | sha256 | |
| 12 | |---|---| |
| 13 | | `config.json` (2451 bytes, copied to `test/config.json`) | `a57c33d11f725099105b657043c113149763066d204fd472d0b2ee399abc2ba7` | |
| 14 | | `model.safetensors.index.json` (3329405 bytes) | `e5e9c492685f84c8d2d8369f36c74674b03410715f23f6179313f6f1feb90311` | |
| 15 | | inventory TSV printed by the reader (36734 rows plus the header line) | `60ff4dbdaa1c3632c934c6935aa60ed5b2def4e15f0ca5083ddc7dd660f083f5` | |
| 16 | |
| 17 | Build with omega-mv `bf54b19fa590e8ae925c0e80815516dbf41e7326`, seeded omc sha256 |
| 18 | `62775d2a391cfef7cde64e387655caa9809a267093112910ec76bfa568f3712b`. `om/vendor/json.om` is |
| 19 | byte-identical to that revision's `seed/json/json.om` (sha256 `456254fc…e2d2`). This is a newer |
| 20 | compiler pin than `om/tur-ledger` (`6999fa9e`, omc `d6290c76…`). |
| 21 | |
| 22 | ```sh |
| 23 | { printf 'om2\n'; cat om/vendor/json.om om/flint/manifest.om; } | "$OMC" > flint-manifest && chmod +x flint-manifest |
| 24 | ./flint-manifest CONFIG INDEX SHARD_DIR > inventory.tsv |
| 25 | ``` |
| 26 | |
| 27 | On success the exit status is 0, stdout is the TSV and stderr is one line: |
| 28 | |
| 29 | ``` |
| 30 | flint-manifest ok tensors 36734 params 39785287456 routed 37849399296 shards 15 bytes 79570574912 |
| 31 | ``` |
| 32 | |
| 33 | TSV columns: `name shard dtype shape begin end`. Shards come in name order; within a shard, |
| 34 | rows follow the order of the header's entries. `begin`/`end` are byte offsets into the shard's data section, |
| 35 | which starts at `8 + header length`. `shape` is `d0xd1` or `d0`. |
| 36 | |
| 37 | ## What it checks |
| 38 | |
| 39 | - **Config.** Every key of the pinned `config.json` is recognised or the file is refused, and |
| 40 | so is a duplicate key. Every value that affects the forward path is pinned. Examples: |
| 41 | architecture `FlintForCausalLM`; 49 layers; hidden 2048, head_dim 128, 32 query and 4 KV |
| 42 | heads; 256 experts, top-6, `norm_topk_prob` true; `router_score_function` `sigmoid`; |
| 43 | `softmax_type` `learnable`; `sliding_window` 513; the full-attention set {0, 1, 5, 9, ..., 45, 48}, |
| 44 | which must equal `no_rope_layer_indices`; `mlp_only_layers` [0, 1]; untied embeddings; vocab |
| 45 | 150144; `rms_norm_eps` 1e-6 and `rope_theta` 10000, compared as exact decimals; `rope_scaling` |
| 46 | null. `attention_dropout`, `initializer_range`, `output_router_logits`, |
| 47 | `router_aux_loss_coef`, `use_cache` and `transformers_version` may be absent; when present |
| 48 | only their type is checked. |
| 49 | - **Index.** The index is read with a strict JSON subset scanner: ASCII without escapes and |
| 50 | unsigned integers only. The `weight_map` names must be exactly the layout's 36734 tensors, |
| 51 | each once. A shard name is 13 to 127 bytes of `[A-Za-z0-9._-]`, does not start with `.`, |
| 52 | and ends in `.safetensors`; at most 64 distinct shards. `total_size` must equal 2 bytes |
| 53 | times the parameter count derived from the config. |
| 54 | - **Shards.** Each file is opened with `O_RDONLY|O_CLOEXEC|O_NOFOLLOW` and must be a regular |
| 55 | file. The 8-byte little-endian header length is checked against the file size. Each header |
| 56 | entry needs dtype `BF16` and exactly the shape derived from the config for its slot. |
| 57 | `data_offsets` must satisfy `begin <= end` and `end - begin == 2 * prod(shape)` without |
| 58 | overflow. Within a shard the extents must tile `[0, data length)` exactly: no gap, no |
| 59 | overlap, no trailing bytes. Each tensor must sit in the shard the index names, and every |
| 60 | tensor the index assigns to a shard must be present in it. |
| 61 | - **Totals.** Parameters are 39785287456, of which 37849399296 are routed expert parameters. |
| 62 | Both match the issue and the WolframLanguageEvaluator reconciliation recorded with the |
| 63 | source capture. |
| 64 | |
| 65 | The reader reads headers with `pread`. It never maps or reads tensor data and keeps no |
| 66 | duplicate buffers. It does not hash shard payloads: the 15 shard sha256 values are pinned |
| 67 | separately (`shards.lfs-sha256` in the source capture) and checked by a separate step. |
| 68 | |
| 69 | ### Storage dtype versus compute contract |
| 70 | |
| 71 | Every tensor is stored as BF16, including the router `mlp.gate.weight` [256x2048]. The FP32 |
| 72 | sigmoid router is a compute contract of the forward path, not a storage dtype. Nothing in |
| 73 | the checkpoint is FP32. |
| 74 | |
| 75 | ### Canonical slot space |
| 76 | |
| 77 | Slot `0` is `model.embed_tokens.weight`, `1` is `model.norm.weight` and `2` is |
| 78 | `lm_head.weight`. Every other tensor is slot `3 + layer * 784 + kind`: |
| 79 | |
| 80 | | kind | tensor | layers | |
| 81 | |---|---|---| |
| 82 | | 0, 1 | `input_layernorm`, `post_attention_layernorm` | all | |
| 83 | | 2..5 | `q_proj`, `k_proj`, `v_proj`, `o_proj` | all | |
| 84 | | 6, 7 | `q_norm`, `k_norm` | all | |
| 85 | | 8 | `softmax_offset` (the learned sink) | all | |
| 86 | | 9..11 | dense `gate_proj`, `up_proj`, `down_proj` | 0, 1 | |
| 87 | | 12 | router `mlp.gate` | 2..48 | |
| 88 | | 13..15 | `shared_expert.{gate,up,down}_proj` | 2..48 | |
| 89 | | 16 + 3e + j | `experts.e.{gate,up,down}_proj` (j 0, 1, 2) | 2..48 | |
| 90 | |
| 91 | There is no `shared_expert_gate` tensor: the shared expert is ungated. |
| 92 | |
| 93 | ## Refusals |
| 94 | |
| 95 | On refusal nothing is written to stdout. stderr carries `refused N reason` and the exit |
| 96 | status is N. |
| 97 | |
| 98 | | Exit | Reason | Meaning | |
| 99 | |---|---|---| |
| 100 | | 2 | usage | not exactly three arguments | |
| 101 | | 3 | io | open, read or stat failed, or a shard is absent | |
| 102 | | 4 | not-regular-file | a symlink (`ELOOP` under `O_NOFOLLOW`), directory or other non-regular file | |
| 103 | | 10 | config-json | config is not one JSON object | |
| 104 | | 11 | config-field | unknown, duplicate, missing or wrong-valued config key | |
| 105 | | 20 | index-size | index over 4194304 bytes | |
| 106 | | 21 | index-syntax | index outside the strict subset | |
| 107 | | 22 | shard-name | shard name outside the allowed form, or more than 64 distinct shards | |
| 108 | | 23 | unknown-tensor | a name outside the layout, in the index or a header | |
| 109 | | 24 | index-duplicate | a name twice in `weight_map` | |
| 110 | | 25 | total-size | `total_size` differs from 2 bytes times the derived parameter count | |
| 111 | | 26 | index-missing-tensor | a layout tensor absent from `weight_map` | |
| 112 | | 30 | shard-short | shard shorter than 8 bytes | |
| 113 | | 31 | header-length | header length under 2, over 983040, or past the end of the file | |
| 114 | | 32 | header-json | header is not valid JSON | |
| 115 | | 33 | header-entry | header root or entry has the wrong shape | |
| 116 | | 34 | header-metadata | `__metadata__` present | |
| 117 | | 35 | dtype | dtype other than `BF16` | |
| 118 | | 36 | shape | rank or dimensions differ from the config-derived shape | |
| 119 | | 37 | data-offsets | `begin > end`, out of range or overflowing, a length that is not 2 x elements, or data truncated | |
| 120 | | 38 | data-tiling | extents overlap, leave a gap, or leave trailing bytes | |
| 121 | | 39 | header-duplicate | a tensor in two headers | |
| 122 | | 40 | shard-mismatch | tensor stored in a different shard than the index says | |
| 123 | | 41 | header-missing-tensor | a tensor the index assigns to a shard is absent from its header | |
| 124 | | 42 | shard-capacity | over 4096 tensors in one shard, or a header that fills the JSON tape | |
| 125 | | 43 | output-capacity | TSV over 8388608 bytes; a defensive guard that no admitted layout reaches (the full output is 4269125 bytes) | |
| 126 | |
| 127 | Hugging Face cache snapshots are directories of symlinks, so they are refused with 4. Point |
| 128 | `SHARD_DIR` at real files, for example after `huggingface-cli download --local-dir`. |
| 129 | `__metadata__` is refused because the pinned checkpoint has none. |
| 130 | |
| 131 | ## Gate: `check.sh` |
| 132 | |
| 133 | ```sh |
| 134 | OMC=/path/to/omega-mv/seed/out/omc bash om/flint/check.sh |
| 135 | ``` |
| 136 | |
| 137 | `test/gen.py` is the fixture referee. It derives the full tensor layout from `config.json` |
| 138 | alone and writes a sparse 15-shard checkpoint with the published shard boundaries. It also |
| 139 | writes the expected TSV and one mutant per refusal. The gate: |
| 140 | |
| 141 | 1. builds the reader with the pinned omc, refusing any other compiler hash; |
| 142 | 2. requires the synthetic checkpoint to load with a TSV byte-equal to the referee's and the |
| 143 | exact summary line, and requires usage exit 2 for 0, 1, 2 and 4 arguments; |
| 144 | 3. runs 38 refusal fixtures, each required to exit with its own code, print `refused <code>` |
| 145 | and write nothing to stdout; |
| 146 | 4. rebuilds the reader 25 times, each with one guard removed (every `fm_die N` for one code, |
| 147 | plus `O_NOFOLLOW` dropped from the open flags). Each mutant must stop producing its code on |
| 148 | that guard's fixture, which proves the refusal comes from the named guard. |
| 149 | |
| 150 | Optional arms, which print `NOT_RUN` when unset: |
| 151 | |
| 152 | - `FLINT_SRC=dir` is the pinned source capture (`config.json`, the index, `headers/<shard>.header.json` |
| 153 | and `shards.lfs-sha256`). The arm rebuilds sparse shards from the exact published header bytes |
| 154 | and sizes, and the TSV sha256 must equal `60ff4dbd…f5`. |
| 155 | - `FLINT_SHARDS=dir` is the 15 downloaded shards, with config and index from `FLINT_SRC`. The |
| 156 | same TSV sha256 is required. |
| 157 | - The forward-operator arm runs when both are set and the `FLINT_SHARDS` arm wrote its TSV. |
| 158 | `FLINT_PY` is the referee's interpreter (torch plus the transformers `a672eb5f` checkout, |
| 159 | e.g. `env PYTHONPATH=/tmp/tf-a672 ~/.venv/bin/python`); default `python3`. |
| 160 | |
| 161 | Measured 2026-10-29 on the Spark host CPU (`taskset -c 10-14`), reader sha256 |
| 162 | `d9caa2ab4ecf2580114cfdc8cedb30eb93e80f9f1fc0c0da1be1f31a8d381ae8`: `OM-FLINT-MANIFEST PASS (70)` |
| 163 | with both optional arms. On the downloaded checkpoint the reader took 0.27 s wall and |
| 164 | 9440 kB max RSS, with 0 major faults. Without the optional arms the result is |
| 165 | `PASS (68)` plus two `NOT_RUN` lines. With the operator arm the full gate is `PASS (89)`. |
| 166 | |
| 167 | ## Forward operators: `ops.om` |
| 168 | |
| 169 | ```sh |
| 170 | { printf 'om2\n'; cat om/vendor/json.om om/flint/ops.om; } | "$OMC" > flint-ops && chmod +x flint-ops |
| 171 | ./flint-ops selftest |
| 172 | ./flint-ops OP FIXTURE INVENTORY SHARD_DIR # OP: rmsnorm qkv attn router shared expert moe |
| 173 | ``` |
| 174 | |
| 175 | `test/opref.py` is the referee: it runs the pinned reference's own modules |
| 176 | (`modeling_flint.py` sha256 `f0540832…0c09` and `configuration_flint.py` sha256 |
| 177 | `849eee30…4d00`, transformers `a672eb5f`) in f32 on deterministic inputs built from the real |
| 178 | BF16 weights and writes one fixture per operator, with the torch version in header word 6. |
| 179 | `check.sh` requires the fixtures, concatenated in a fixed order, to hash to `FX_PIN` |
| 180 | (`2d838552…7b7a`, torch 2.14.0 on the Spark host CPU); any other torch, reference file or |
| 181 | CPU result fails that check. `ops.om` reads the |
| 182 | fixture, loads the named BF16 tensors from the shards through the inventory TSV, recomputes the |
| 183 | output in f64 and prints `flint-op OP layer L elems N worst_ppm P ties K PASS|FAIL` (exit 0, 1, |
| 184 | or 2 and up for a refusal). An element passes within twice a first-order bound on the |
| 185 | reference's own f32 error; `test/TOLERANCE.md` has the bound per operator, the gamma_n table, |
| 186 | the Wolfram queries and the detection floor (systematic errors below about 2 gamma_n of the |
| 187 | output's last accumulation always pass). The RoPE bound allows FULP = 4 ulps (`ops.om`) per |
| 188 | powf, cosf and sinf call of the reference; `opref.py` measures those calls against float64 and |
| 189 | refuses to write fixtures if any exceeds FULP (2026-10-29: worst 0.848 ulp, cosf). |
| 190 | |
| 191 | Fixtures: RMSNorm (layer 2); q/k/v with q/k norm and RoPE on sliding layer 2, and on full |
| 192 | layer 5 without RoPE; attention with sinks over 520 keys, the 513-key window and its edge on |
| 193 | layer 2, full attention on layer 5, through o_proj; the sigmoid top-6 renormalized router on |
| 194 | layer 24, plus a control with the reference top-6 swapped (must FAIL) and a near-tie control |
| 195 | (must PASS with ties above 0); the shared expert, routed expert 99 and the whole MoE block on |
| 196 | layer 24. |
| 197 | |
| 198 | Mutants, each required to turn its operator's line to FAIL with exit 1: softmax router |
| 199 | (`om_exp` in place of `om_sig`), shared expert gated by sigmoid(0), sink omitted, RoPE on every |
| 200 | layer, expert index permuted (255 - e), and window 514. |
| 201 | |
| 202 | ## Not covered (NOT_RUN for this unit) |
| 203 | |
| 204 | - bf16-activation parity: the referee runs in f32; |
| 205 | - generation, bf16 activations and long-context serving remain NOT_RUN; complete two-token |
| 206 | chained layer/intermediate/logit parity is now covered by the optional arm below; |
| 207 | - weight streaming and repacking, with peak allocation and residency measured during load; |
| 208 | - per-expert layout checks before fusing; |
| 209 | - tokenizer and control-token identity, and a load report. |
| 210 | |
| 211 | This unit has no GPU arm. A GGUF importer, if added, will be a separate optional unit. |
| 212 | |
| 213 | ## Complete bounded host forward |
| 214 | |
| 215 | `FLINT_FORWARD=1` adds a full 49-layer chained computation to the same check command. |
| 216 | It starts from two token IDs, loads real BF16 embedding rows and all selected expert weights, |
| 217 | and compares five intermediate tensors per layer, final normalization and every vocabulary logit. |
| 218 | The reference tensors are comparison targets, never teacher-forced inputs. |
| 219 | The full gate prints `OM-FLINT-MANIFEST PASS (92)` with real checkpoint inputs; wrong-token |
| 220 | and skipped-final-normalization source mutants must fail the comparison. |
| 221 | |
| 222 | See [PROFILE.md](PROFILE.md) for the frozen weight/runtime/tokenizer/template identities |
| 223 | and the architecture audit. In particular, this checkpoint has **no expert bias**, unlike |
| 224 | the requested selection-only bias description. [test/TOLERANCE.md](test/TOLERANCE.md) |
| 225 | declares the candidate integration budget separately from the tighter per-operator bounds. |
| 226 | Native f64 computation with BF16 storage is compared to reference f32 computation. |
| 227 | This is host-forward evidence only: no serving API, task completion, quantized model, |
| 228 | KV-cache, long-context batching or GPU/backend qualification is claimed. |