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/blob/main/docs/inference/LLAMA3-ENGINE-VERIFICATION.md # 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 branch `main` Branches Tags History `aien-sovereign-core-mv / docs / inference / LLAMA3-ENGINE-VERIFICATION.md` 235 lines ยท 11637 bytes Raw Blame History Rendered 1 # Llama 3.x engine cut: verification record 2 3 Date: 2026-10-06. Branch `next-phase/engine-llama3`, based on 4 `next-phase/compose-v5` (`1ac121d`). Machine: DGX Spark (GB10, sm_121). 5 6 Tags: **PROVEN** means measured here with the command shown. 7 **INFERRED** means it follows from code reading or from a related 8 measurement. **UNVERIFIED** means not checked. 9 10 ## What the cut does 11 12 1. `ModelConfig` and the tensor catalog come from the model's own 13 `config.json` (`aien_inference_abi::load_model_config`, 14 `checkpoint::llama_catalog`). Anything that is not 15 `LlamaForCausalLM`, uses an activation other than `silu`, has 16 attention or MLP bias, or uses a `rope_type` other than `default` or 17 `llama3` is refused with the field named. 18 2. Tied embeddings: when `tie_word_embeddings` is true the catalog has no 19 `lm_head.weight`, `TransformerWeights.lm_head` is `None`, and 20 `output_projection()` returns the embedding table itself. No copy is 21 made. Both the CPU reference and the Omega GPU backend read the output 22 projection through that one accessor. 23 3. llama3 rope scaling (`Llama3RopeScaling`, `RopeParams`) follows the 24 wavelength bands of the HF reference. Plain rope keeps the exact old 25 expression, so TinyLlama is bit identical. 26 4. `ChatTokenizer::from_model_dir` picks the chat template (Zephyr or 27 Llama 3 instruct) from `tokenizer_config.json` or `chat_template.jinja`, 28 the stop set from `generation_config.json` `eos_token_id` (falling back 29 to `config.json`), and the context length from 30 `max_position_embeddings`. The template text carries no BOS; the 31 tokenizer post-processor adds exactly one. 32 5. `COMPOSE_ASSISTANT_PREFIX` is now `"filename:"` (compose-v5 had 33 `"filename: "` with a trailing space). One constant, used by the 34 daemon proposer, the gate driver and the tests. 35 6. `finish_reason` reuses compose-v5's plumbing (commit `2af89bd`); this 36 cut only checks that it reaches the receipt (see below). 37 7. The daemon reads `config.json` when it sits next to the checkpoint 38 (`AIEN_MODEL_PATH` / `AIEN_MODEL_DIR`); with no such file it keeps the 39 built-in TinyLlama config. The default model is unchanged. 40 41 Side fix found on the way: the batched decode path had a hard-wired stop 42 set `{0, 1, 2}`. In the Llama 3 vocabulary those ids are `!`, `"` and `#`, 43 so a reply would have ended at the first `!`. The batch path now uses the 44 model's stop set (`ModelConfig::stop_token_ids`, legacy `{0,1,2}` only 45 when the config names none). 46 47 ## Inputs (sha256) 48 49 | model | file | sha256 | 50 |---|---|---| 51 | TinyLlama-1.1B-Chat-v1.0 | model.safetensors | `6e6001da2106d4757498752a021df6c2bdc332c650aae4bae6b0c004dcf14933` | 52 | | config.json | `486bedda3a6988332e60d9638a09ca4b260d34ebcf1b19e22cf3b140b63d8fe9` | 53 | | generation_config.json | `18046d04f5bd8b4998095ecabdd17a1bf0053d9acdccead4a05be4a3575f3c5c` | 54 | | tokenizer.json | `bcd04f0eadf90287bd26e1a183ac487d8a141b09b06aecb7725bbdd343640f2e` | 55 | unsloth/Llama-3.2-1B-Instruct (`5a8abab`) | model.safetensors | `1ff795ff6a07e6a68085d206fb84417da2f083f68391c2843cd2b8ac6df8538f` | 56 | | config.json | `dfb67fd8afe73a1c75245824ef9d64a6ba8983025447e3bf76aa1ea57ee46152` | 57 | | generation_config.json | `6d4f979915331212d7672c68b22a4ddad9e21ed8126cf2bd1ea6b2b88f595c1c` | 58 | | tokenizer.json | `6b9e4e7fb171f92fd137b777cc2714bf87d11576700a1dcd7a399e7bbe39537b` | 59 | | tokenizer_config.json | `9ddd255c19fe319c8d4e891163540382e9fbda99f394674f2a929efc47d57458` | 60 | | chat_template.jinja | `5816fce10444e03c2e9ee1ef8a4a1ea61ae7e69e438613f3b17b69d0426223a4` | 61 | unsloth/Llama-3.2-3B-Instruct (`006f5dc`) | model-00001-of-00002.safetensors | `13cbd6d16e927a0c5bad54102514e6e18b4a47b3a6eb911e39d678d328d19f55` | 62 | | model-00002-of-00002.safetensors | `7b770216613ac5c34d7c54bdff1fa616bc4e338a9d0b20af6303e48c295ee23c` | 63 | | model.safetensors.index.json | `0a57c30afc07c81610ae7fe013bea3b9d50365f9a8145ae98e8714220f3d7c7c` | 64 | | config.json | `eadff796b79b82cefa0537004668d70a1dd099fd4986b91ef88398ed91b26311` | 65 | | generation_config.json | `8bab06a398ca622f8b941eb0b5f425d71d007080436cfa4f37d6c03c23b756a9` | 66 | | tokenizer.json | `6b9e4e7fb171f92fd137b777cc2714bf87d11576700a1dcd7a399e7bbe39537b` | 67 | | tokenizer_config.json | `9ddd255c19fe319c8d4e891163540382e9fbda99f394674f2a929efc47d57458` | 68 69 GPU engine: prebuilt `libomega_gpu.a` from omega `62b6a28` (sha256 70 `ef80e431`...), linked with `AIEN_OMEGA_GPU_LIB`. 71 72 ## How the gates were run 73 74 The gate driver is a small scratch example kept out of the tree (it 75 hard-codes the three NEXT-PHASE-1 tasks). It follows the daemon path 76 exactly: `load_model_config` then `load_from_safetensors` (strict 77 catalog), the shared KV spine, `NativeTransformerBackend`, 78 `ChatTokenizer::from_model_dir`, one warm-up turn on `WARM_UP_TEXT`, then 79 for each task `proposal_prompt` -> `format_chat` + `"filename:"`, greedy, 80 96 tokens max, the model's stop set. 81 82 ``` 83 # CPU (reference backend) 84 AIEN_FORCE_CPU_STUB=1 cargo build --release --example llama3diag -p aien-runtime 85 llama3diag tasks 96 > l1b-cpu.json 86 # GPU (Omega backend), under the quiet lock 87 AIEN_OMEGA_GPU_LIB= cargo build --release --example llama3diag -p aien-runtime 88 quietlock hold --owner np1-engine --minutes 20 -- env DIAG_BACKEND=omega llama3diag tasks 96 89 ``` 90 91 The HF reference is `transformers` greedy decoding in float32 on the 92 exact prompt ids the Rust side produced (so tokenizer and model are 93 checked separately), run from a scratch script outside the repo. It also 94 records the smallest top-1 vs top-2 logit gap along each reply. 95 96 ## Gate A: tests and lint 97 98 - **PROVEN** `cargo clippy --workspace --all-targets -- -D warnings` 99 clean (CPU stub build). 100 - **PROVEN** `cargo test --workspace -- --test-threads=1`: every test target and all doc tests pass 101 (CPU stub build) except 3 tests. The 3 failures are machine checks in 102 `spark-adapters`, which does not depend on any crate this cut touches: 103 the branch name must start with `feat/` or `fix/` (this branch is 104 `next-phase/...` by instruction), a Forgejo git remote must exist, and 105 a live service on port 18095 answered 401 instead of 404. 106 - **PROVEN** new unit tests: TinyLlama `config.json` gives the built-in 107 `tinyllama_1_1b()` config (apart from the explicit stop set `[2]`) and 108 the same catalog as `tinyllama_catalog()`; the Llama 3.2 1B catalog 109 has no `lm_head` and the tie flag set; llama3 `inv_freq` for 110 head_dim 64 matches 32 values computed independently in f64 (and HF's 111 own f32 function to about 1e-8); refusals name the bad field; 112 the Llama 3 template renders the instruct layout; the Llama 3 113 tokenizer gives exactly one BOS (128000) at the start. 114 115 ## Gate B: CPU 116 117 **PROVEN** TinyLlama regression. Through the new `config.json` path 118 (Zephyr template, stop `[2]`) on the v4 attempt-1 prompt: the same 119 prompt ids, the same 48 output ids as v4, and the same warm-up token 120 (29956). 121 122 **PROVEN** Llama-3.2-1B, CPU reference, all three tasks token-for-token 123 equal to HF float32 greedy, all ending on `eos` (128009): 124 125 | task | prompt tokens | output tokens | stop | smallest logit gap | 126 |---|---|---|---|---| 127 | NOTES.md | 106 | 16 | eos | 0.349 | 128 | docs/HOURS.txt | 117 | 16 | eos | 2.918 | 129 | checklist.md | 113 | 18 | eos | 0.0058 | 130 131 Task 3 had a near tie (0.0058) and still matched. 132 133 Replies (prefix included): 134 135 ``` 136 filename: README.md 137 # Project Notes 138 This project keeps every change inside its workspace. 139 140 filename: docs/HOURS.txt 141 open 09:00 142 close 17:30 143 144 filename: checklist.md 145 lock: Locking system 146 key: Key management 147 lamp: Lighting system 148 ``` 149 150 The 1B model names the wrong file in task 1 (README.md) and decorates 151 task 3. That is the model's answer, matched by HF; it is not an engine 152 error. 153 154 **PROVEN** Llama-3.2-3B (two shard files, so this also exercises the 155 sharded loader), CPU reference, all three tasks token-for-token equal to 156 HF float32 greedy, all ending on `eos`. Weight load 33.4 s, warm-up 157 12.7 s (first id 2181). 158 159 | task | prompt tokens | output tokens | stop | smallest logit gap | prefill ms | decode tok/s | 160 |---|---|---|---|---|---|---| 161 | NOTES.md | 106 | 65 | eos | 0.131 | 11543 | 0.86 | 162 | docs/HOURS.txt | 117 | 16 | eos | 1.922 | 12785 | 0.82 | 163 | checklist.md | 113 | 41 | eos | 0.300 | 12498 | 0.85 | 164 165 The 3B model answers task 2 exactly. In task 1 it writes `docs/README.md` 166 and in task 3 it puts the full workspace path in the filename line. Both 167 are model answers that HF also gives. 168 169 170 ## Gate C: GPU (Omega backend, no CUDA) 171 172 **PROVEN** Llama-3.2-1B on the Omega GB10 backend: all ops native 173 (`rmsnorm, apply_rope, matmul_vec, matmul_batch, swiglu, gqa_attention, 174 paged_attention, paged_attention_batch, compute_logits`), no fallbacks. 175 All three replies token-for-token equal to the CPU run (and so to HF), 176 all ending on `eos`. 177 178 | task | prefill ms | decode tok/s | total ms | 179 |---|---|---|---| 180 | NOTES.md | 2061 | 5.15 | 4975 | 181 | docs/HOURS.txt | 2192 | 5.16 | 5097 | 182 | checklist.md | 2214 | 5.21 | 5479 | 183 184 Warm-up turn 9866 ms (124 prompt tokens, first id 40). Weight load 185 11.7 s. Load average was about 7.5 during the run because the workspace 186 test suite was running at the same time, so these times are an upper 187 bound, not a benchmark. 188 189 **PROVEN, BLOCKED** Llama-3.2-3B on the Omega backend does not run. The 190 omega attention kernel accepts only `head_dim == 64` (stated in 191 `aien-omega-gpu`, and returned as `TOO_LARGE` on the first decode 192 step); Llama 3.2 3B uses `head_dim` 128. The strict real-model guard 193 stopped the run instead of falling back to CPU, which is the intended 194 behavior. The gap is in the omega engine (pinned `62b6a28`), not in this 195 cut. Llama 3.2 1B (head_dim 64) and TinyLlama (64) are unaffected. 196 197 A first attempt failed earlier, at channel creation with "out of memory" 198 (`RM_ALLOC` status `NV_ERR_NO_MEMORY`), while the HF 3B reference run 199 was holding host memory. The retry passed that stage and hit the 200 head_dim limit above. **INFERRED** the first failure was memory 201 pressure from the concurrent run. 202 203 204 ## finish_reason reaches the receipt 205 206 - **PROVEN** (compose-v5 test `finish_reason_is_recorded_per_attempt`, 207 still passing here) the proposal attempt record carries 208 `finish_reason` per attempt, and `finish_reason_label` maps the 209 scheduler's reasons to `eos` / `max_tokens`. 210 - **INFERRED** (code path) daemon: scheduler `Finished { finish_reason }` 211 -> `generate_text` sets `Generation.finish_reason` -> `model_proposer` 212 keeps it -> `propose_with_retries` copies it into each 213 `ProposalAttempt` -> `ComposeRun.proposal_attempts` in the run JSON -> 214 `rows-v5.jq` reads `accepted_attempt.finish_reason` and 215 `make-receipt.sh` prints it. Not exercised end to end through a live 216 daemon in this cut. 217 - **PROVEN** the gate driver reports the same label from the same 218 function: `eos` for all Llama replies above, `max_tokens` for the 219 48-token TinyLlama regression. 220 221 ## Notes and limits 222 223 - The Llama 3 template here is the plain instruct layout. HF's shipped 224 Llama 3.2 template also inserts a system block with "Cutting Knowledge 225 Date" and today's date. That makes the prompt depend on the wall clock, 226 so it is left out on purpose. The HF comparison above uses the same 227 prompt ids as the Rust side, so it is not affected. 228 - A TinyLlama daemon that now reads `config.json` stops on `[2]` only 229 (the old backend set was `{0, 1, 2}`). The v4 regression output is 230 unchanged. **INFERRED** ids 0 and 1 are never produced by TinyLlama 231 greedy decoding in practice. 232 - The daemon's `model_sha256` hashes only the file it was pointed at; for 233 a sharded model that is one shard. **UNVERIFIED** whether any receipt 234 depends on it covering all shards. 235 - Only greedy decoding was checked. Sampling is not covered.