diff --git a/.crumb b/.crumb index 2a25f565..f1657082 100644 --- a/.crumb +++ b/.crumb @@ -27,33 +27,33 @@ "purpose": "Directory crates. Purpose not yet described by a human." }, { - "digest": "a3bf1a650bb24f9e0775776636e96bc14adb92b8c3c772d7ce0dfc976253e847", - "last_commit": "3f79153", + "digest": "3ee624a79df42f92ed58adfd80a511bc2f68dad065fd2cd8b8ce97176879fda0", + "last_commit": "b40d23f", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, { "digest": "e6450fb9b838f64fcc90113926436887241ae8a12ceb5523954818b3d986b281", - "last_commit": "3f79153", + "last_commit": "863bef8", "name": "native", "purpose": "Directory native. Purpose not yet described by a human." }, { "digest": "768f7a9a329815979e95b540161c74912dddd8615f44f45c44f97db5d49fdd93", - "last_commit": "3f79153", + "last_commit": "863bef8", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." } ], - "children_root": "sha256:c66c398981f077e8a76f9488c64ea8979e278a165d22ad0f7d3bcb6640cdd81d", - "compiled_at": "2026-10-11T01:27:19Z", + "children_root": "sha256:eb85eae85331edd701f4123676822a283f17968b79937a88acc0fb6a6887102f", + "compiled_at": "2026-10-11T14:02:56Z", "compiler": "crumb-compile/1", - "digest": "sha256:cb9a75f3db21a1ed249779b3ae4ea36e86b10d9aade776c115b7a428544e5fc3", + "digest": "sha256:de899ad3e8ef3e1edb3c0ff1fd40d38bdc82970b79bbe0051015ff2fe5ef435e", "evidence_files": 155, "evidence_root": "sha256:d59c0cef4e7dd5172923754a95b411ca54b01f35baca4587f792f1b259f1eaf7", - "files": 3037, - "generated_at_commit": "3f791539d41d852b2b6fd36fdebaebb9f76dc2a0", - "source_tree": "sha256:37585777b81353c7c3a9edbddd9a935cba4aaa2ca956ca19225e8deaab28d4ce" + "files": 3039, + "generated_at_commit": "b40d23ffe805b2044cb3cd1da6f79e03db3d7517", + "source_tree": "sha256:4da7de6f9224c5a9ab966ecf68b3526bc113b5e2a1fc58f9e1dfaf933895be96" }, "owner_lane": "", "provenance": { diff --git a/docs/.crumb b/docs/.crumb index 74752458..7760fd16 100644 --- a/docs/.crumb +++ b/docs/.crumb @@ -30,14 +30,14 @@ } ], "children_root": "sha256:55bcc89f5282eb2e3f4e86d882abdfb5f4ea39e427ef97ef620b2267e5701eb1", - "compiled_at": "2026-10-11T01:27:19Z", + "compiled_at": "2026-10-11T14:02:56Z", "compiler": "crumb-compile/1", - "digest": "sha256:a3bf1a650bb24f9e0775776636e96bc14adb92b8c3c772d7ce0dfc976253e847", + "digest": "sha256:3ee624a79df42f92ed58adfd80a511bc2f68dad065fd2cd8b8ce97176879fda0", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 66, - "generated_at_commit": "3f791539d41d852b2b6fd36fdebaebb9f76dc2a0", - "source_tree": "sha256:5477120ed4c490caa4486ca483711d971262e73e40fec1aa0910b102db7b01ad" + "files": 68, + "generated_at_commit": "b40d23ffe805b2044cb3cd1da6f79e03db3d7517", + "source_tree": "sha256:12a74d0bb0b2c660b299e25565483847252d5409d70cbe31ed1944a994287680" }, "owner_lane": "", "provenance": { diff --git a/docs/campaigns/B7B-PHYSICAL-BOOT-PREP.md b/docs/campaigns/B7B-PHYSICAL-BOOT-PREP.md new file mode 100644 index 00000000..d3baa22e --- /dev/null +++ b/docs/campaigns/B7B-PHYSICAL-BOOT-PREP.md @@ -0,0 +1,155 @@ +# B7B-PHYSICAL-BOOT-PREP: the attended B7b hardware boot, on paper only + +Status: PREPARATION DOCUMENT (2026-10-11). **None of this is executed without Drake's attended, explicitly approved +window.** Writing this page changed nothing on the machine: no reboot, no firmware staging, no boot-entry change, no +root command. Every PASS cited for the probe image is QEMU only, not physical. + +Owner issue: aien-dev/aienos#286 (native GB10, cut B7b). Authority: Drake's ruling of 2026-10-10 (aien-architecture#190, +item 5) authorizes B7b *preparation*, not a boot; the boot needs "a first operator-confirmed, two-hour attended window +after the recovery media, rollback, trust and preflight checks pass" (`docs/GB10_IORT_DECODE.md` section 10). +Related, read first: `docs/native/PREFLIGHT-AND-RECOVERY.md`, `docs/NATIVE_BOOT_ONE_TIME.md`, +`docs/NATIVE_BOOT_ROLLBACK_CONTRACT.md`, `docs/RECOVERY_MEDIA_MACHINE1.md`. + +## 1. What B7b is, and what is already built + +Goal in plain words: boot a special test build of the AIENOS kernel once, let it switch on the second memory-protection +chip ("SMMUv3 B", at 0x13000000) for one made-up device slot, read two read-only identity registers of that chip, switch +the slot off again, print one summary line, and return to Linux. No device is allowed to move data; the GPU is not +touched. + +Built and tested without hardware (PR #302, squash `863bef83`, issue #286 comment): + +- Probe image: `make [full] CK_B7B_PROBE=1` (output directory `target/native-kernel-b7b-probe`, allowed with + `CK_HARDWARE_STAGING`); code in `native/kernel/core/smmu_svc.c` (`ck_b7b_probe`). Default images are unchanged and + the link refuses a default image that carries the probe. +- QEMU gate: `scripts/qemu_ck_b7b_probe_test.sh`. Default mode: the Spark-target image refuses fail-closed on QEMU + (route none, `rc=-3 nostream`, nothing confined). `--positive`: TEST-ONLY segment-0 image confines one page, reads + IDR0/IDR1, unconfines. `--self-test`: 19 canned logs and 4 Makefile refusals. Local runs recorded in the PR: all PASS. +- Expected Spark output: `docs/GB10_IORT_DECODE.md` section 10, labelled *expected, not observed*. + +Not built, and therefore a blocker (section 4, G7): a probe variant of the one-time staging script +(`scripts/stage_one_time_boot_ck.sh` / `_full.sh`); it touches the boot-entry staging path and is left for this campaign. + +## 2. People and things required (all physical, all Drake's) + +| need | detail | +|---|---| +| Drake present for the whole window | at the machine, display and keyboard attached; a fresh go-ahead for this boot, given in this window (a past approval does not carry over) | +| Window | two hours, written down in advance with start time; nothing else uses the machine in it | +| Recovery stick | `AIENOSRECOV` plugged in, listed as `Boot0004`, verified (section 3) | +| Camera | one phone or camera on the screen for the whole boot; the screen is the only observation channel | +| Witness | a second person (or Drake plus a time-stamped recording) who reads the screen aloud and keeps the clock | +| Notes | paper or a laptop for times and the exact words on screen | + +## 3. Recovery preflight: read-only checklist + +Run on the Spark in Linux, as the normal user, before the window opens. **Every command below only reads or builds +into `target/`.** None needs sudo, none writes a boot variable, stages, mounts read-write or reboots. Stop at the first +failure. + +| step | command | PASS looks like | +|---|---|---| +| P1 | `git -C status --porcelain` | prints nothing (clean tree) | +| P2 | `git -C rev-parse HEAD` | the commit the probe image is built from; write it down | +| P3 | `quietlock check` | clear (no other session holds the machine quiet) | +| P4 | `efibootmgr` (no arguments) | lists `Boot0004` with `AIENOSRECOV`; `BootOrder` starts `0001`; no `BootNext`; `BootCurrent: 0001` | +| P5 | `lsblk -f` | the recovery stick is visible; the internal drive layout matches `docs/RECOVERY_MEDIA_MACHINE1.md` (root ext4 `d27bfd26-ff30-400e-9eca-9cdf73de9406`, ESP vfat `9DA2-3597`) | +| P6 | `bash scripts/verify_recovery_tools.sh` | `PASS` (static check of the recovery initrd; `NOT_RUN` is not a pass) | +| P7 | `bash scripts/qemu_verify_recovery_media.sh` | the recovery environment boots in QEMU with zero hard disks | +| P8 | `bash scripts/qemu_ck_rollback_test.sh` and `bash scripts/qemu_native_rollback_test.sh` | the rollback gates pass for this commit | +| P9 | `bash scripts/qemu_ck_b7b_probe_test.sh --self-test`, then with no flag, then `--positive` | `AIENOS_CK_B7B_PROBE_SELF_TEST: PASS`, `AIENOS_CK_B7B_PROBE: PASS`, `AIENOS_CK_B7B_PROBE_POSITIVE: PASS` | +| P10 | `bash scripts/ck_repro_build.sh full` (builds twice, compares) and the probe build `make -C native/kernel full CK_B7B_PROBE=1 CK_HARDWARE_STAGING=1 CK_OWNER_PUBKEYS= CK_MACHINE_ID=` | two equal digests; the probe image digest written down. UNVERIFIED that `ck_repro_build.sh` accepts the probe flag; read its help first | +| P11 | `bash scripts/native_boot_preflight.sh --image --expect-sha256 ` | last line `NATIVE_PREFLIGHT: READY`; the `ASK` lines are Drake's and are answered in person | +| P12 | `bash scripts/stage_one_time_boot_ck.sh --dry-run` (or the probe variant's dry run, once it exists) | prints every command, touches nothing; Drake reads it | +| P13 | the recovery stick, tested in person: booted once in an earlier attended window per `docs/RECOVERY_MEDIA_MACHINE1.md`, evidence kept | the evidence file from that boot is on hand. UNVERIFIED whether a current one exists; no script checks this | + +Secure Boot is recorded, never changed. As of 2026-10-01 it is OFF for development by owner decision +(`docs/native/PREFLIGHT-AND-RECOVERY.md` item 3); `native_boot_preflight.sh` records the state and stops if it is ON. +Whether the physical-boot block described in `docs/NATIVE_BOOT_ONE_TIME.md` section 1 (trust chain) still applies is +UNVERIFIED here and is part of Drake's go/no-go. + +## 4. Go / no-go + +**GO requires all of these, decided by Drake at the start of the window:** + +- G1 P1 to P12 passed within the last 24 hours on the commit being staged, outputs saved. +- G2 P13: a recovery-stick evidence record exists and Drake saw the stick boot. +- G3 Drake, camera and witness are present; the window is open; no other job needs the machine. +- G4 The image digest printed by the stage script equals the digest from P10 (and later the digest the kernel prints + on screen). +- G5 `BootNext` unset, `BootOrder` unchanged (P4), Linux is the running system. +- G6 Everyone can state the abort rule (section 7) from memory. +- G7 A reviewed probe variant of the staging script exists and its dry run (P12) was read by Drake. **Today this is + false; therefore today the answer is NO-GO.** +- G8 Drake says "go" out loud in the window, and the witness writes the time. + +**NO-GO (any one):** any preflight STOP line; a dirty tree; the stick missing; an unexpected `BootNext`; a digest +mismatch; anyone unsure; less than the full window left; an open question about the SMMU B side effect (section 8) +that Drake wants answered first. + +## 5. Boot steps (only after GO; Drake or the witness reads each step aloud) + +1. Start the camera and the notes. Write the commit and digest at the top. +2. In Linux, capture the "before" state (needs sudo; Drake runs it): + `sudo scripts/verify_native_rollback.sh --capture-pre evidence/pre_boot_capture.json`. + The staging script does this itself; do not capture twice. +3. Stage once: the probe variant of the stage script with `--apply` (needs sudo; it writes only the staging directory + `\EFI\AIENOS` on the ESP and sets `BootNext` once; it never reboots and never changes `BootOrder`). Read its + output aloud; it must end with `BootNext` set and `Boot0004 AIENOSRECOV` still listed. +4. Reboot by Drake's hand (`sudo reboot`). Start the clock. +5. Watch the screen only. Firmware consumes `BootNext` and loads the probe image. Expected lines, in order, as in + `docs/GB10_IORT_DECODE.md` section 10 (expected, not observed): `kernel: alive`; + `b7b_probe: start segment=15 rid=0x100 ...`; `b7b_probe: route instance=1 base=0x13000000 stream=0x100 ...`; + `smmu: instance 1 up base=0x13000000`; the reserved-range line; `b7b_probe: confined ...`; + `b7b_probe: instance=1 idr0=0x........ idr1=0x........ st_level=. sidsize=..`; `b7b_probe: unconfine rc=0 (ok)`; + `AIENOS_B7B_PROBE: CONFINED_AND_RELEASED`. +6. The image holds the console for its hold time (120 s on the infer image; UNVERIFIED for the probe image) and then + resets. Do not touch anything. The next start is Linux because `BootNext` is already consumed. +7. Back in Linux: `sudo scripts/verify_native_rollback.sh --capture-post evidence/post_boot_capture.json`, then + `--pre ... --post ... --verify` (ten invariants). Read the verdict aloud. + +## 6. Observation points + +| when | what to read | meaning | +|---|---|---| +| after the reboot, before any AIENOS text | firmware messages | `Secure Boot Violation` means the image was refused: a STOP condition, do not bypass; the machine falls back to Linux | +| `kernel: alive` | banner, memory map | the probe image started; the probe runs only after this line | +| `route ...` line | instance, base, stream | must read instance 1, base 0x13000000, stream 0x100. Anything else is a finding about the IORT decode (`GB10_IORT_DECODE.md` section 3), not a reason to retry | +| IDR0/IDR1 line | two register values | record verbatim; SIDSIZE must cover 0x100 | +| summary line | `CONFINED_AND_RELEASED`, `REFUSED` or `FAIL` | any other summary is a finding: `REFUSED` names a reason (`nostream`, `failed`), `FAIL` means unconfine failed or no live instance matched | +| after the summary | any extra line, panic, freeze, blank screen | write the time and the exact words | + +## 7. Abort and rollback + +- **Abort rule.** If the screen shows a panic, shows nothing new for 60 seconds, or anyone says "stop": touch nothing + until the 60 seconds are over, then hold the chassis power button until the machine is off, wait ten seconds, press + it again. `BootNext` was consumed before the image started, so the machine boots `BootOrder` (Linux, `0001`). +- **If Linux does not come up:** firmware boot-menu key (F11 or the firmware's own), pick `AIENOSRECOV` (`Boot0004`). + Mount root and ESP **read-only** and run the collector exactly as in `docs/RECOVERY_MEDIA_MACHINE1.md` ("Inspect + internal storage read-only", "Capture the recovery evidence"). +- **Repair** (removing `\EFI\AIENOS`, touching `BootOrder`) needs a new, separate go-ahead from Drake at that moment. +- **Never**: change Secure Boot, change firmware settings, run `--apply` a second time, retry a failed probe in the + same window without a fresh go, or "fix" anything on the machine during the window. +- Rehearsed so far only in QEMU (`scripts/qemu_ck_rollback_test.sh`, gate M0_ROLLBACK); not on the Spark. + +## 8. Known unknowns (carried from #302) + +- UNKNOWN whether the GB10 or the HDA0 audio device attempts DMA while no OS drives them, after SMMUv3 B is left + enabled with every stream aborting until the next reset. An abort there is recorded as an event, not acted on. +- UNVERIFIED that the Spark's real IORT routes segment 15 rid 0x100 to instance 1; this is the expectation from + decoded tables (`GB10_IORT_DECODE.md` sections 3 and 9), and the first thing the window tests. +- UNVERIFIED hold time and reset behavior of the probe image on the real console. + +## 9. Evidence to collect + +Camera recording of the whole boot; the witness's time-stamped notes; photographs of the summary screen; the stage +script output; `pre_boot_capture.json`, `post_boot_capture.json` and the verifier verdict; the preflight outputs P1 to +P12 saved with the commit and digests; `efibootmgr` output before and after; and a short result note that quotes the +summary line verbatim and lists every deviation from section 6. The result is posted on aienos#286 as observed facts +with limits; a physical PASS is claimed only for what was seen. + +## 10. Statement of non-execution + +This page prepares a boot. It is not an authorization. No command in sections 3 or 5 has been run for this campaign +beyond the host-side QEMU gates already recorded in PR #302, and nothing in it will run on the Spark until Drake has +opened an attended window and said "go" in it. diff --git a/docs/qualification/INT8-ACTIVATION-QUAL-v1.md b/docs/qualification/INT8-ACTIVATION-QUAL-v1.md new file mode 100644 index 00000000..d5b4d41d --- /dev/null +++ b/docs/qualification/INT8-ACTIVATION-QUAL-v1.md @@ -0,0 +1,229 @@ +# INT8-ACTIVATION-QUAL-v1: prospective numerical qualification of the int8 activation path + +Status: SPECIFICATION, written before any run (2026-10-11). Nothing in this document has been measured. +Owner issue: aien-dev/aienos#34 (L6-B). Draft implementation: PR #300 (branch `l6b-int8-dot`). +Authority: Drake's ruling of 2026-10-11 (aien-architecture#190, comment 6109731585; aienos#34, comment 6109732149). +Kernel default stays **f32** until a run of this specification records PASS and a separate, reviewed change flips it. + +Every threshold below is marked PREREGISTERED: fixed here, before measuring, never edited after a run. Changing +one means writing `INT8-ACTIVATION-QUAL-v2` and applying it only to runs made after it is merged. + +## 1. Purpose + +Decide, with numbers fixed in advance, whether the int8 activation path (activations rounded to ggml's Q8_K grid, +integer block dots, `usdot` on cores that have it) is an acceptable replacement for f32 activations on the +supported GB10 hardware. The test must tell two things apart: + +- **Expected quantization difference.** Rounding activations to 8 bits changes every logit a little. This is + allowed, and it can flip a greedy choice only where the f32 model itself is almost undecided. +- **Implementation error.** A wrong scale, a wrong sub-block index, a missing term, an overflow, a wrong fallback. + This is never allowed. Because the integer part of the int8 path is exact arithmetic, most implementation errors + can be caught by exact comparison, not by a tolerance (section 5). + +## 2. What the earlier FAIL established (aienos#300) + +Sources: `docs/l6b-int8-qualification.md`, `docs/l6b-int8-divergence-diagnosis.md`, +`evidence/l6_host_3f5a22426976_l6b_parity.json`, `evidence/l6b_int8_divergence_3f5a22426976.json` (all on branch +`l6b-int8-dot` / PR #300, not on `main`). + +- The registered rule was "identical 64 token ids". Observed: ids 0 to 11 identical, split at index 12 (f32 4897, + int8 53692). That verdict is **FAIL and stays FAIL**. This specification does not change it retroactively. +- Index 12 is the first token of an unprompted second assistant turn. The golden reply ends at index 7 (end-of-turn, + id 128009); the harness `l6_host` deliberately ignores end-of-turn for that run, and the kernel loop + (`aienos-infer-kernel`, `EOT = 128009`) stops at it. So the split sits in a region the kernel never decodes + (INFERRED from the sources, high confidence). +- At index 12 the f32 top1-top2 gap was 0.349 (4.97 to 14.40 at indexes 0 to 11), int8-vs-f32 logit noise was + 0.43 to 1.29 at every index, and llama.cpp 4a89937 on the same history picked the int8 token (gap 0.091). + Diagnosis: Q8_K rounding noise against a near-tie, no int8 defect found (mechanism INFERRED, about 85 percent per + the diagnosis). Limits: one model, one prompt, one history, one machine. +- Lesson built into this document: an "identical N tokens" rule conflates a near-tie with a defect. This + specification keeps token agreement as a gate, but excuses a split only when the f32 margin proves it was a + near-tie, and adds exact checks that cannot be excused. + +## 3. Reference: how the independent quantized reference is produced + +The int8 path under test is the crate's own code (`quantize_q8k`, `Q4_K`/`Q6_K` block dots shaped for `usdot`). +A check that reuses that code proves nothing, so three references are used and none shares source with it. + +**R-A, scalar integer reference (exact tier).** A new stand-alone C program, `crates/aienos-infer/tests/ref/q8ref.c` +(to be written by the implementation round; it does not exist yet), built with plain `cc -O0` and no vector flags. +It is written from the published ggml block layouts (`block_q4_K` 144 bytes, `block_q6_K` 210 bytes, `block_q8_K`) +and the Q8_K rule, not from the crate: scale `iscale = -127 / max` where `max` is the signed value of largest +magnitude in the 256-value block, `q = min(127, nearest_int(iscale * x))` with ties-to-even, `d = 1 / iscale`, +plus the 16 group sums. The implementer must quote the governing lines of `ggml-quants.c` at commit 4a89937 in the +`docs-read` record before writing it (UNVERIFIED here: the rule above is from memory of ggml and from the crate's +own tests, not re-read for this document). It unpacks the 4-bit and 6-bit weights with its own shifts and masks and +accumulates every product in `int64_t`. +Why it is independent: different language and compiler path, no shared code, no lane structure and no dot-product +instruction, wider accumulators. It shares only the published format. Where it and the crate agree bit for bit on +integers, a shared mistake would have to be a mistake in the format itself, which R-B below also tests. + +**R-B, llama.cpp 4a89937, CPU, 1 thread (cross-implementation tier).** Already used by #300 (`llama_ref.c`, +`llama_ref_hist.c`, fixtures `tests/fixtures/ref_*.txt`). It quantizes activations to Q8_K for these weight types too, +but with its own float order, so it is compared with tolerances, never bitwise. It is the tiebreaker for near-ties. + +**R-C, the crate's own f32 path at the base commit (baseline tier).** Defines the f32 logits, the f32 margins and +the rollback target. Its logits are recorded (SHA-256 of the little-endian f32 bytes per step) before any int8 change +lands, in the same evidence file. + +## 4. Prompts + +All prompts use the chat template of the frozen model (Llama-3.2-1B-Instruct-Q4_K_M, sha256 +`3f5a22426976ab26cfe84dba63c1d08391717abb1af893e10f1b2968d862dcc1`), greedy decoding, no system prompt beyond the +template's default. Host budget: at most 64 new tokens. Every run must end at id 128009 inside the budget (section 5, +T1). Texts are verbatim; `\n` is a newline. + +| id | text | source | +|---|---|---| +| P1 | `What is the capital of France?` | existing (`fr`; golden reply ids 791 6864 315 9822 374 12366 13 128009) | +| P2 | `Explain copy-on-write in one sentence.` | existing (`cow`) | +| P3 | `Say hi in 3 languages: café, 日本語, 😀 (it's 100% fine).\n\n Thanks!` | existing (`uni`) | +| P4 | `List the three primary colors, separated by commas.` | new | +| P5 | `What is 17 plus 25? Answer with just the number.` | new | +| P6 | `Write one short sentence about the ocean.` | new | + +Reserves, used in this order only if an earlier prompt fails the admission rule: R1 `Name one planet in the solar system.` +then R2 `Spell the word "cat" backwards.` + +Admission rule (PREREGISTERED): a prompt is admitted only if the **f32** path itself ends at 128009 within 64 new +tokens. Whether P4 to P6 satisfy it is UNVERIFIED (not run). A rejected prompt is replaced by the next reserve and +the swap is recorded; the f32 outcome is the only thing consulted, never the int8 outcome. Minimum for a valid run: +6 admitted prompts. + +Native leg: the kernel image today carries one fixed prompt (P1, `MAX_NEW = 16`, `KV_CAPACITY = 64`). The native +leg therefore checks P1 only, until the kernel takes other prompts; that limit is stated in the verdict. + +## 5. Metrics, bounds and failure signals + +Two groups. Group X is exact: any miss is an implementation error. Group N is numerical: bounds on expected noise. + +### Group X, exact (no tolerance) + +| id | check | bound | why | +|---|---|---|---| +| X1 | Quantizer: for every activation vector fed to a matvec during the teacher-forced runs, the crate's Q8_K output (`qs`, `d`, group sums) equals R-A's | 0 differing values; `d` bit-identical | Rounding is deterministic IEEE arithmetic with ties-to-even; there is no legitimate difference. PREREGISTERED | +| X2 | Integer block dots: for every block of every matvec (every layer and class, every prompt, every step), the crate's i32 accumulators (`sumi`, `mins` for Q4_K; `isum` for Q6_K) equal R-A's int64 results | 0 mismatches | Both are integer sums over identical inputs; order cannot matter. This includes the `usdot` build and the portable build. PREREGISTERED | +| X3 | Scaled row result: crate's f32 row output vs R-A's f64 recomputation from the same integers | abs diff <= 1e-6 x max abs of that row's reference | #300 measured 6.6e-7 absolute on rows of size about 5.4 (about 1.2e-7 relative); 1e-6 relative leaves roughly 8x headroom and still catches a wrong scale. PREREGISTERED | +| X4 | Overflow guard: every i32 accumulator stays below 2^31 and no Q8_K value leaves [-127, 127] | 0 violations | The diagnosis derived the bounds on paper; the run asserts them. PREREGISTERED | +| X5 | Determinism: each path run twice gives bit-identical logits for every step | 0 differing bits | Negative control for the harness; also separates noise from nondeterminism. PREREGISTERED | +| X6 | No non-finite value (NaN or inf) in any hidden state or logit vector, any path | 0 | A non-finite value is never quantization noise. PREREGISTERED | + +### Group N, numerical (teacher-forced along the f32 token history unless stated) + +Teacher forcing: both paths are fed the same f32 history, so one flipped choice cannot contaminate later steps. + +| id | metric | bound | why | +|---|---|---|---| +| N1 | Per-layer: for every layer and step, `max abs(h_int8 - h_f32) / max abs(h_f32)` of that layer's output hidden state | <= 0.05 | A priori only: Q8_K rounds each value by at most half a step, about 0.4 percent of the block maximum, and 16 layers compound it; 5 percent is a loose ceiling meant to catch gross errors, not to bound noise tightly. No measurement was used. PREREGISTERED (basis weak, confidence low; X1/X2 carry the weight) | +| N2 | Per-step max abs logit difference, int8 vs f32, over the whole vocabulary, every step of every prompt | <= 2.0 | #300 measured 0.43 to 1.29 over 13 steps (largest 1.288); 2.0 leaves about 55 percent headroom over the largest value seen. PREREGISTERED | +| N3 | Per-step max abs logit difference, int8 vs llama.cpp (R-B), same history | <= 2.0 | #300 measured 1.304 at index 12 and 0.567 at the first position; same reasoning as N2. PREREGISTERED | +| N4 | First decode position of P1, int8 vs llama.cpp max abs logit difference | <= 1.0 | The bound #300 already used (observed 0.567). PREREGISTERED | +| N5 | Logit margin: record f32 top1-top2 margin at every step (reported always, used by N6 and N7) | reported | The margin is what makes a flip excusable or not. | +| N6 | Divergence rule: a step where int8 top-1 differs from f32 top-1 is excused only if the f32 margin at that step is < T = **1.5** | T = 1.5 logits | T is above the largest single-logit error seen (1.288) and far above the one observed flip (margin 0.349). It is deliberately stricter than the theoretical maximum (two opposite errors could flip a margin up to 2 x N2); a false FAIL costs a re-specification, a false PASS ships a defect. PREREGISTERED | +| N7 | Top-1 agreement rate over all teacher-forced steps of all admitted prompts | >= 0.98, and 1.00 over steps whose f32 margin >= T | With about 100 or more steps, 2 percent allows a couple of true near-ties; the per-step rule N6 is the real gate, this is a floor against many small flips. PREREGISTERED | +| N8 | Free run (each path decoding its own tokens): token sequences of int8 and f32 are identical, or the first split is at a step excused by N6 | identical or excused | Free run shows what a user sees. After an excused split the runs may differ; they must still terminate (T1). PREREGISTERED | + +### Termination, required + +| id | check | bound | +|---|---|---| +| T1 | f32, int8 and llama.cpp free runs each emit 128009 (`<|eot_id|>`) within the budget, and decoding stops there | all admitted prompts; no token is decoded after 128009. PREREGISTERED | +| T2 | Comparisons stop at the first 128009. Positions after it (the unprompted second turn that #300 index 12 sat in) are excluded from every bound and rate | by construction | + +### Failure signals (any one means the whole run is FAIL) + +1. Any X1 to X6 miss. +2. Any step where int8 top-1 differs from f32 top-1 and the f32 margin is >= 1.5 (N6). +3. Any NaN or inf (X6). +4. Any run that does not reach 128009 inside the budget (T1), including an int8 run that loops or never stops. +5. Any N bound exceeded, or N7 below 0.98. +6. The usdot path and the portable integer path disagree with R-A at all (X2), since both are integer math. +7. A mutant that is not caught (section 8, negative controls). + +A run with any leg skipped is **NOT_RUN**, never PASS. + +## 6. CPU-feature checks and the fallback + +What is needed: `usdot` is Armv8.6 FEAT_I8MM; the signed `sdot` form needs FEAT_DotProd. The #300 design selects int8 +automatically only when both are present (`Features { dotprod, i8mm }`, `DotPath::select`). + +- **Detection, host.** Read `AT_HWCAP` bit 20 (`HWCAP_ASIMDDP`) and `AT_HWCAP2` bit 13 (`HWCAP2_I8MM`) from + `/proc/self/auxv`, as #300 does. Record the result and the CPU part number (`0xd85` X925, `0xd87` A725) in the + evidence file. +- **Detection, kernel.** Read `ID_AA64ISAR0_EL1.DP` and `ID_AA64ISAR1_EL1.I8MM` at boot, once per core, and print + one line with the result (`dotprod=.. i8mm=..`). The exact bit positions must be quoted from the Arm Architecture + Reference Manual in the implementer's `docs-read` record; they are not restated here (UNVERIFIED by this document). + The path is chosen from the weakest core, because inference may run on the A725 cores as well as the X925 cores. +- **Fallback.** No features: f32 path. Features present but int8 not requested or promotion off: f32 path. The + selector matrix (all 4 feature sets x requested x promotion, 16 rows, #300 `select_matrix_all_combinations`) is + re-run and must reproduce the same table. +- **No stray instructions.** Building the crate with `+dotprod,+i8mm` lets the compiler use those instructions + anywhere, not just in the int8 functions. On a core lacking them that is an illegal-instruction fault, not a + fallback. Requirement (PREREGISTERED): either the f32 image is a separate build without those features, or the + int8 code sits behind runtime dispatch; and `objdump -d` of the f32 image shows **zero** `sdot`, `udot`, `usdot`, + `smmla`, `ummla`, `usmmla` instructions, while the int8 image shows them only inside the designated int8 functions. +- **Both paths tested.** Legs: (L1) host X925, features present, int8 with `usdot`; (L2) host A725 core, same build; + (L3) portable integer build with no dot features (`cargo` without `-C target-feature`) run on the same host, forced + int8; (L4) QEMU `-cpu max` kernel image with features (the leg records the feature line it actually saw); + (L5) QEMU with a CPU model that lacks the features (candidate `cortex-a72`, to be confirmed by the recorded feature + line), which must select f32 and print the feature line showing why. L1 to L3 must satisfy every X and N check. + L3 supports qualifying the portable path, but production auto-selection still requires both features. + +## 7. Rollback + +- **Default.** `INT8_PROMOTION_DEFAULT = false` (`dotpath.rs`). Until this specification records PASS and a separate + reviewed change flips it, the shipped default is f32. +- **Switch.** Host: `AIENOS_DOT=f32` forces f32 regardless of features and constant; `AIENOS_DOT=int8` forces int8; + unset is `auto`. Kernel: the build constant, plus a boot-time forcing flag that must exist before promotion + (to be added by the implementing change; not designed here). +- **Proof, required (R1 to R3, all PREREGISTERED):** + - R1: with all features present and promotion forced true, setting `f32` yields logits whose per-step SHA-256 equals + the base-commit f32 record (section 3, R-C) for every admitted prompt. Bit-identical, not tolerance. + - R2: flipping the constant back to `false` and rebuilding yields the same hashes (the rollback is a one-line change). + - R3: native: the QEMU kernel image with f32 forced (feature-rich CPU model) prints the golden P1 ids + `791 6864 315 9822 374 12366 13 128009` and the boot is otherwise unchanged. +- "Reliable" means R1 to R3 pass on every release candidate, not only once. + +## 8. Procedure + +Order matters: the harness goes red before it goes green. + +1. Freeze: commit this document. The harness reads the bounds from the table below and refuses to run if a constant + in code differs; the evidence file stores this document's SHA-256. +2. Base record: run the f32 path at the base commit; store per-step logit hashes, margins, token ids (R-C). +3. Negative controls (must FAIL, each one recorded): (a) truncate instead of round in the Q8_K quantizer; + (b) off-by-one in a sub-block scale index; (c) drop the Q4_K mins term; (d) swap a Q6_K scale sign. If a mutant + passes, the harness is blind and the run is invalid. Also run f32 twice (X5) and f32-vs-f32 through the N rules + (must give zero difference). +4. Host legs L1 to L3 for all admitted prompts: teacher-forced pass (X, N1 to N7), free-run pass (N8, T1), llama.cpp + comparison (N3, N4). Release build, pinned to one core, `quietlock check` clear first, one thread. +5. Native legs L4, L5, R3 on QEMU (no hardware). A physical-Spark native leg is a separate decision and needs its own + attended window; it is not part of v1. +6. Write `evidence/int8_qual_v1_.json`: commit, doc hash, model hash, feature lines, per-prompt tables, every + metric against its bound, every mutant result, verdict. Verdict is PASS only if every row passes and no leg was + skipped; FAIL on any failure signal; NOT_RUN otherwise. Nothing is re-tuned after a FAIL; the FAIL is recorded. +7. After PASS: a separate PR proposes flipping the default, cites the evidence, and waits for Drake's decision. + +### BOUNDS-v1 (machine-readable, PREREGISTERED) + +```text +X3_REL=1e-6 N1_REL=0.05 N2_ABS=2.0 N3_ABS=2.0 N4_ABS=1.0 TIE_T=1.5 N7_AGREE=0.98 +MAX_NEW_HOST=64 MIN_PROMPTS=6 EOT=128009 ZERO_EXACT=X1,X2,X4,X5,X6 +``` + +## 9. Non-goals + +- No change to the #300 FAIL, to its rule, or to any recorded evidence. +- No kernel, Rust or Mojo change in this round; no default change; no new model. +- No performance claim (speed receipts are separate) and no claim about other models or other quantization types. +- No physical-hardware run, no GPU path, no multi-thread numerics. +- Does not decide whether int8 should ship; it defines what evidence would justify asking. + +## 10. Limits and UNVERIFIED items + +- All bounds are PREREGISTERED judgments anchored to one prior run (13 steps, one prompt); N1 has no data behind it. +- R-A does not exist yet; the Q8_K rule text is from memory of ggml and must be quoted from source at implementation. +- Whether P4 to P6 end at 128009 under f32 inside 64 tokens is untested. +- QEMU `-cpu max` exposing both features and `cortex-a72` lacking them are expectations, confirmed only by the + feature line a leg prints. +- The #300 sources cited here live on a draft branch, not on `main`.