aefinityAIINC commited on
Commit
cef6fe9
·
verified ·
1 Parent(s): d23dd89

CIS-2 v0.3b: spec, op-level conformance vectors, expected digests, GPU result

Browse files
CIS2_SPEC_v0.3b.md CHANGED
@@ -62,20 +62,33 @@ This spec's primary pinned tuple is unchanged from v0.1: `HuggingFaceTB/SmolLM2-
62
  `"Once upon a time"`, 16 greedy-decoded tokens, fp32 compute, bf16-on-disk
63
  weights. §7's RoPE construction is now general (any `rope_theta`), so a
64
  second (model, prompt, decode-length) tuple — `Qwen/Qwen2.5-0.5B`,
65
- `rope_theta = 1_000_000` — is evidence-of-correctness (`docs/E15d_bc_RESULT.md`)
66
- but is **not** itself a pinned §13 test vector in this version; only the
67
- SmolLM2-135M tuple's digests are normative test vectors here. It does **not**
 
 
 
 
68
  claim:
69
 
70
- - General correctness of the pinned transcendental polynomials (`exp`,
71
- `sin`, `cos`, `ln`) outside the input ranges actually exercised by the
72
- decodes checked so far (§14.4, carried from v0.1, and §14.1 new-in-v0.2 for
73
- `ln_pinned`'s domain).
 
 
 
 
74
  - Cross-framework agreement (vs. PyTorch/`transformers`) as a conformance
75
- requirement — oracle comparisons (§13.3, `docs/E15b_m1p5_CORRECTNESS.md`,
76
- `docs/E15d_bc_RESULT.md`) are evidence of correctness, not a conformance
77
- requirement; CIS-2 conformance is defined relative to this document's own
78
- bits, not to any third-party framework's output.
 
 
 
 
 
79
  - Seeded/temperature sampling — decode is greedy-only (argmax every step),
80
  matching CIS-1's own non-goal (CIS-1 §10).
81
  - Anything about `verify/` or `cis2-verify2` (independently-written
@@ -126,6 +139,22 @@ arithmetic runs:**
126
  optimization barrier — e.g. Rust's `std::hint::black_box` — so the
127
  compiler cannot fold the arithmetic away and mask a broken pin.)
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  1.4. **No FMA contraction, anywhere, in the reference.** Every
130
  multiply-then-add in this spec is defined as **two separate, separately
131
  RNE-rounded operations**: compute the product, round to `f32`; then add,
@@ -147,7 +176,13 @@ any flag that licenses reassociating floating-point expressions, assuming
147
  no NaN/Inf, or substituting approximate reciprocal/rsqrt hardware
148
  instructions (e.g. `-ffast-math`, `-Ofast`, `-freciprocal-math`). This
149
  spec's reduction orders (§5) are only bit-determining if the compiler
150
- computes exactly the sequence of operations stated, in the stated order.
 
 
 
 
 
 
151
 
152
  1.6. **Division and sqrt**: ordinary IEEE-754 `/` and `sqrt` (both
153
  mandatory-correctly-rounded operations under IEEE-754), never a
@@ -359,6 +394,69 @@ so the "no matching vocab entry" branch is never taken for any input.
359
  U+010A `Ċ`). Decode uses the inverse map; both directions are
360
  computed once from this same construction, never independently
361
  hand-tuned per direction.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
362
  b. **Initial symbol sequence.** For each byte-remapped "word" string
363
  from §3.1.4.b: split it into individual Unicode characters (one
364
  character = one original input byte, by construction of 3.1.4.b/3.1.5.a);
@@ -834,11 +932,16 @@ values that matter for this spec's actual pinned models are
834
  `rope_theta = 100_000.0` (SmolLM2-135M, §13's pinned test vector) and
835
  `rope_theta = 1_000_000.0` (Qwen2.5-0.5B, §0's informative second-model
836
  evidence, `docs/E15d_bc_RESULT.md`); **both are conformant** under this
837
- tolerance. This spec does **not** claim `ln_pinned` is correctly rounded or
838
- bit-exact against any oracle for arbitrary `x` outside the tested set above
839
- — a clean-room implementer targeting a `rope_theta` not in that set should
840
- not assume accuracy without its own validation (carried-forward caution,
841
- same spirit as v0.1 §14.4 for `sin`/`cos`).
 
 
 
 
 
842
 
843
  #### 6.5.1 `frexp_exact(x)` — exact mantissa/exponent split
844
 
@@ -897,8 +1000,9 @@ not change); `sin_pinned`/`cos_pinned` are re-measured below, over the full
897
  | function | domain measured | max ULP vs. correctly-rounded fp32 | max relative error |
898
  |---|---|---|---|
899
  | `rsqrt_cr` | all finite x>0 | 0 (correctly rounded by construction) | 0 |
900
- | `exp_pinned` | x∈[-40,40] | 1 | 1.19e-7 |
901
- | `ln_pinned` | x = rope_theta only | 0 at the two pinned values (100000.0, 1000000.0); ≤1 over a padded scan | 0 / 7.85e-8 |
 
902
  | `sin_pinned` (v0.3, Taylor, informative/superseded) | RoPE angle, pos ∈ [0, 8192) | up to 2813.5 raw (486.5 filtered) | 2.37e-4 |
903
  | `sin_pinned` (v0.3b, minimax, NORMATIVE) | same | **≤1.5** | **1.2e-7** |
904
  | `cos_pinned` (v0.3, Taylor, informative/superseded) | same | up to 407 raw (144.5 filtered) | 3.14e-5 |
@@ -1300,6 +1404,12 @@ A second, independently-run oracle comparison against Qwen2.5-0.5B
1300
  diff ≈4.4e-6) is informative evidence for §7's theta-general RoPE, not a
1301
  §13.1 test vector.
1302
 
 
 
 
 
 
 
1303
  13.4. **Compiler-invariance matrix (NEW in v0.2, informative but
1304
  strongly evidential)**: the pinned SmolLM2-135M test vector's `CIS2_REF`
1305
  and `inv_freq_table_digest` reproduce bit-for-bit across a 20-cell matrix
@@ -1310,23 +1420,289 @@ Preregistered digest values and the full per-cell table are recorded in
1310
  same check (`docs/E15d_a_COMPILER_INVARIANCE.md`) targeted the old
1311
  `ba88708b...` digest and is superseded by the v0.2 rerun.
1312
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1313
  ## 14. Known gaps and internal inconsistencies (informative — read before treating this as complete)
1314
 
1315
  Renumbered from v0.1's §14; items resolved by v0.2 are marked **CLOSED**
1316
  and kept for history, per §16's changelog discipline.
1317
 
1318
- 14.1. **`ln_pinned`'s validated domain is a finite, explicitly-tested set
1319
- of `x` values (§6.5), not a general accuracy proof.** The two values that
1320
- matter for this spec's models (`100_000.0`, `1_000_000.0`) are both
1321
- tested to ≤2e-6 relative tolerance against host `f64::ln` cast to f32; a
1322
- `rope_theta` far outside the tested range (e.g. `< 0.001` or a value
1323
- requiring `frexp_exact`'s domain guard to reject NaN/negative inputs) is
1324
- unvalidated by this document. This is the direct successor to v0.1's
1325
- "§14.1: rope_theta=100000.0-only" gap — **PARTIALLY CLOSED**: the
1326
- literal-only restriction is gone, but "pinned for exactly one theta" has
1327
- been replaced by "validated for a finite tested set of thetas," which is
1328
- weaker than "proven general" but strictly broader than v0.1's single-value
1329
- pin.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1330
 
1331
  14.2. **Digest byte encoding for artifact hashes: CLOSED.** v0.1 fed the
1332
  64-character hex **string's** ASCII bytes into the witness hash, not the
@@ -1353,33 +1729,171 @@ a verifier wanting to localize a mismatch should still compare
1353
  five are still printed, §12.3), not rely on `CIS2_REF` alone to diagnose
1354
  *why* it differs.
1355
 
1356
- 14.4. **Trig polynomial accuracy is only validated for `|x| ≲ 14`** (unit
1357
- tests sweep `x = i * 0.7` for `i` in `-20..=20`). RoPE angles in this
1358
- spec's fixed 20-position decode stay small (`pos < 20`, `inv_freq ≤ 1.0`
1359
- for `rope_theta=100000`; for `rope_theta=1000000`, `inv_freq` values are
1360
- smaller still, since `inv_freq[i] = theta^(-2i/64)` shrinks faster for
1361
- larger theta at fixed `i`, so angles stay in-range there too), so this is
1362
- adequate for §13's test vectors, but the two-part-π reduction (§6.3) has
1363
- not been stress-tested at larger magnitudes where it could lose more
1364
- precision. A clean-room implementer targeting a longer sequence than this
1365
- spec's 20 positions should not assume this polynomial's accuracy holds
1366
- unchanged. **Unchanged from v0.1 (was §14.4 there too).**
1367
-
1368
- 14.5. **RMSNorm multiply order (§8) is pinned but its bit-level necessity
1369
- is unconfirmed.** `(x[i]*inv)*weight[i]` vs. `x[i]*(inv*weight[i])` are
1370
- not provably identical for arbitrary fp32 operands under rounding, but no
1371
- divergence between the two orders has actually been observed on either
1372
- model tested. **Unchanged from v0.1 (was §14.5 there too).**
1373
-
1374
- 14.6. **The oracle correctness checks (§13.3) are defensible spot-checks,
1375
- not exhaustive.** They confirm greedy token-id agreement and one step's
1376
- full-vocab logit agreement to ~4e-6 relative on two model families now
1377
- (SmolLM2-135M, Qwen2.5-0.5B) — neither checks every intermediate layer's
1378
- activations against the oracle, so a compensating pair of errors elsewhere
1379
- in the layer stack that happens to preserve step-0's output and all
1380
- argmax decisions cannot be completely ruled out by this evidence alone.
1381
- **Unchanged in kind from v0.1 (was §14.6 there); now covers two models
1382
- instead of one.**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1383
 
1384
  14.7. **This spec's own history.** Carried forward from v0.1: earlier
1385
  states of the reference computed `inv_freq` via unpinned host `f64::powf`,
@@ -1399,6 +1913,27 @@ time, the exact failure mode §14.3 (now closed) used to warn about: a
1399
  the digest without also comparing the finer-grained digests
1400
  individually.
1401
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1402
  ## 15. Conformance (normative)
1403
 
1404
  An implementation is CIS-2 v0.2 conforming iff, from this document's text
 
62
  `"Once upon a time"`, 16 greedy-decoded tokens, fp32 compute, bf16-on-disk
63
  weights. §7's RoPE construction is now general (any `rope_theta`), so a
64
  second (model, prompt, decode-length) tuple — `Qwen/Qwen2.5-0.5B`,
65
+ `rope_theta = 1_000_000` — is evidence-of-correctness (`docs/E15d_bc_RESULT.md`,
66
+ `docs/E25_RMSNORM_ASSOCIATION.md` §4) but is **not** itself a pinned §13 test
67
+ vector in this version; only the SmolLM2-135M tuple's digests are normative
68
+ test vectors here. §14.8 (erratum E-3) records a further consequence: §3 pins
69
+ one exact `tokenizer.json` shape, which that second checkpoint does not have,
70
+ so a conforming implementation cannot drive it end-to-end at all — work on it
71
+ is confined to §4–§11 with the prompt token ids supplied from outside §3. It does **not**
72
  claim:
73
 
74
+ - Correct rounding of the pinned transcendental polynomials. Accuracy
75
+ itself is no longer a gap: §14.1 (erratum E-4) records an exhaustive
76
+ measurement of `exp`, `ln` and `silu` over **every** f32 bit pattern, and
77
+ §14.4 (erratum E-2) the same for `sin` and `cos` over every f32 argument
78
+ below `2^31`. What is not claimed is that any of them is *correctly
79
+ rounded*, and §14.1(a) records one deliberate, normative divergence from
80
+ mathematical `exp`: §6.2's `x > 88.0` guard clips 94,743 arguments whose
81
+ true `exp` is finite and representable.
82
  - Cross-framework agreement (vs. PyTorch/`transformers`) as a conformance
83
+ requirement — oracle comparisons (§13.3, §14.6, `docs/E15b_m1p5_CORRECTNESS.md`,
84
+ `docs/E15d_bc_RESULT.md`, `docs/E28_LAYER_ORACLE.md`) are evidence of
85
+ correctness, not a conformance requirement; CIS-2 conformance is defined
86
+ relative to this document's own bits, not to any third-party framework's
87
+ output. That evidence now covers every intermediate activation of both §0
88
+ models and not only the stack's output (§14.6, erratum E-5), but ~1e-5
89
+ relative agreement with `transformers` is what it shows and all it could
90
+ show: bit-exactness is claimed between conforming implementations of this
91
+ document, never against a third-party framework.
92
  - Seeded/temperature sampling — decode is greedy-only (argmax every step),
93
  matching CIS-1's own non-goal (CIS-1 §10).
94
  - Anything about `verify/` or `cis2-verify2` (independently-written
 
139
  optimization barrier — e.g. Rust's `std::hint::black_box` — so the
140
  compiler cannot fold the arithmetic away and mask a broken pin.)
141
 
142
+ **ERRATUM E-11 (2026-09-09).** The first half of that self-test, as
143
+ published, **cannot fail**. `f32::MIN_POSITIVE * 1.0e-10` is
144
+ `1.18e-48`, which is below *half* the smallest positive subnormal
145
+ (`7.0e-46`), so it rounds to `+0.0` under RNE whether or not FTZ is set.
146
+ Measured directly, in a build with the pin deliberately gutted and proven
147
+ gutted (`is_pinned() == false`): the probe still reads `0x00000000`. The
148
+ multiplier `1.0e-10` is therefore **REPLACED by `0.5`**:
149
+ `f32::MIN_POSITIVE * 0.5` is `5.88e-39`, a genuine subnormal, which reads
150
+ `0x00000000` when FTZ is pinned and `0x00400000` when it is not. The DAZ
151
+ half of the self-test (`0x00000001 + 0.0`) always did discriminate, and the
152
+ readback assertion above always did enforce the pin, so no digest anywhere
153
+ in this specification changes and no implementation whose pin is correct is
154
+ affected --- the corrected probe newly fails exactly those implementations
155
+ whose FTZ was in fact broken, which is what the self-test exists to catch.
156
+ See docs/E38_REACH_SWEEP.md §5.
157
+
158
  1.4. **No FMA contraction, anywhere, in the reference.** Every
159
  multiply-then-add in this spec is defined as **two separate, separately
160
  RNE-rounded operations**: compute the product, round to `f32`; then add,
 
176
  no NaN/Inf, or substituting approximate reciprocal/rsqrt hardware
177
  instructions (e.g. `-ffast-math`, `-Ofast`, `-freciprocal-math`). This
178
  spec's reduction orders (§5) are only bit-determining if the compiler
179
+ computes exactly the sequence of operations stated, in the stated order. This
180
+ is a prohibition on *licensing* reassociation, not a prohibition on
181
+ optimization: §13.5 measures that `--release -C target-cpu=native` emits
182
+ 8-wide AVX2 for the elementwise work and leaves every §5 reduction scalar,
183
+ with every intermediate activation bit-identical to a non-vectorized
184
+ build. An optimizer denied fast-math can only act where acting does not
185
+ move the bits.
186
 
187
  1.6. **Division and sqrt**: ordinary IEEE-754 `/` and `sqrt` (both
188
  mandatory-correctly-rounded operations under IEEE-754), never a
 
394
  U+010A `Ċ`). Decode uses the inverse map; both directions are
395
  computed once from this same construction, never independently
396
  hand-tuned per direction.
397
+
398
+ **ERRATUM E-14 (2026-09-09).** "Decode uses the inverse map" is the
399
+ only sentence in v0.3b about turning ids back into text, and it is
400
+ about the *byte* map alone. The step before it --- token id to token
401
+ string --- is specified nowhere: §3.4's "Decode protocol" names greedy
402
+ generation, not detokenization, and §12 pins a decode to token **ids**,
403
+ never to characters. A conforming verifier therefore never has to
404
+ produce text, and two conforming implementations can disagree about
405
+ what a receipt *says* while agreeing on every digest in it.
406
+
407
+ E41 measured what that leaves open on the two checkpoints §0 names.
408
+ The inverse is well defined in both --- 0 ids carrying two strings, no
409
+ gaps below the largest id, the 256-entry byte table a bijection --- so
410
+ this is a gap in the specification, not a defect in the artifacts. Three
411
+ cases the text does not reach:
412
+
413
+ 1. **A codepoint can straddle a token boundary.** 313 of
414
+ `HuggingFaceTB/SmolLM2-135M`'s 49,152 vocabulary entries are not
415
+ valid UTF-8 on their own; they are fragments of one. An
416
+ implementation must concatenate the bytes of the whole id sequence
417
+ and validate once, never validate per token. Nothing in v0.3b says
418
+ so, and a per-token decoder is wrong on 0.64 % of this checkpoint's
419
+ vocabulary.
420
+ 2. **Not every emittable id has a string.** §12.1's argmax ranges over
421
+ `config.vocab_size` logits. On `Qwen/Qwen2.5-0.5B` that is 151,936,
422
+ against 151,643 `model.vocab` entries plus 22 `added_tokens` at
423
+ ids 151,643..=151,664 --- leaving **271 ids the decode can emit with
424
+ no string in either table**. Their embedding rows are not zero and
425
+ not distinguishable by norm from real tokens (all 271 within
426
+ `[3.009416e-1, 3.009682e-1]`, against a smallest sampled mapped-token
427
+ norm of `2.999703e-1`), so they cannot be excluded by inspecting the
428
+ weights. On §13.1's vector they never win: best rank 115,765 of
429
+ 151,936, the argmax logit ahead by 2.0655226e1. **Untriggered on
430
+ this vector, not shown impossible** --- the same standing E-12 and
431
+ E-13 record for FTZ/DAZ.
432
+ 3. **Decoding is not the inverse of encoding on special tokens.**
433
+ §3.3 pins `add_special_tokens = false`, so §3 never *produces* a
434
+ special-token id; but §11.2's argmax can emit one. All 17 of
435
+ SmolLM2's `added_tokens` are ids 0..=16, and each decodes to its own
436
+ literal text --- id 2 to the ten characters `<|im_end|>`. Re-encoding
437
+ that text gives `[44, 108, 306, 79, 486, 108, 46]`, never `[2]`. So
438
+ `encode(decode(ids)) == ids` fails on exactly these 17 ids, and once a
439
+ decode has been rendered to text **a model-emitted control token is
440
+ indistinguishable from ordinary generated text that spells it**. Any
441
+ consumer that re-reads generated text --- which is every agent loop ---
442
+ must keep the ids, not only the string. v0.3b neither says this nor
443
+ gives a rendering that would avoid it.
444
+
445
+ v0.4 should either specify the id → text direction --- which table is
446
+ inverted, byte-level concatenation before UTF-8 validation, a defined
447
+ result for an id with no string, and whether a special token renders as
448
+ its literal text or is reserved --- or state that CIS-2 conformance is
449
+ over token ids only and that text rendering is out of scope. Either
450
+ resolves the gap; leaving it open does not.
451
+
452
+ `cis2-verify` implements the first reading as a **documented extension,
453
+ not a conformance requirement**: `Tokenizer::decode` inverts
454
+ `model.vocab` alone (total on the one checkpoint §3 accepts, since
455
+ SmolLM2's 17 `added_tokens` all overlap it), concatenates bytes across
456
+ the whole id sequence before validating UTF-8, and returns an error
457
+ rather than a substitution for an id with no string. See
458
+ `docs/E41_DETOKENIZATION_IS_UNSPECIFIED.md`.
459
+
460
  b. **Initial symbol sequence.** For each byte-remapped "word" string
461
  from §3.1.4.b: split it into individual Unicode characters (one
462
  character = one original input byte, by construction of 3.1.4.b/3.1.5.a);
 
932
  `rope_theta = 100_000.0` (SmolLM2-135M, §13's pinned test vector) and
933
  `rope_theta = 1_000_000.0` (Qwen2.5-0.5B, §0's informative second-model
934
  evidence, `docs/E15d_bc_RESULT.md`); **both are conformant** under this
935
+ tolerance. This spec does **not** claim `ln_pinned` is correctly rounded.
936
+ It is, however, no longer restricted to the tested set above: `ln_pinned`
937
+ has since been evaluated at **every** f32 bit pattern and is within one ULP
938
+ of the f64 value narrowed to f32 at all 2,130,706,432 positive normals, and
939
+ **0 ULP** — not merely within 2e-6 — at both pinned `rope_theta` values. See
940
+ §14.1 erratum E-4 and `docs/E27_EXP_LN_RANGE.md`; the corresponding caution
941
+ for `sin`/`cos` was v0.1 §14.4 and was discharged the same way (erratum
942
+ E-2). A clean-room implementer targeting an arbitrary `rope_theta` should
943
+ still note that §6.5 returns `-Infinity` for every subnormal input under
944
+ §1.3's DAZ.
945
 
946
  #### 6.5.1 `frexp_exact(x)` — exact mantissa/exponent split
947
 
 
1000
  | function | domain measured | max ULP vs. correctly-rounded fp32 | max relative error |
1001
  |---|---|---|---|
1002
  | `rsqrt_cr` | all finite x>0 | 0 (correctly rounded by construction) | 0 |
1003
+ | `exp_pinned` | **all 2^32 f32** (E27) | **1** | **1.19e-7** (= 2^-23) |
1004
+ | `ln_pinned` | **all 2^32 f32** (E27) | **1** over all positive normals; **0** at both pinned thetas | **1.19e-7** / 0 at both thetas |
1005
+ | `silu_pinned` | **all 2^32 f32** (E27) | **2** off §6.2's clip band | **2.33e-7** |
1006
  | `sin_pinned` (v0.3, Taylor, informative/superseded) | RoPE angle, pos ∈ [0, 8192) | up to 2813.5 raw (486.5 filtered) | 2.37e-4 |
1007
  | `sin_pinned` (v0.3b, minimax, NORMATIVE) | same | **≤1.5** | **1.2e-7** |
1008
  | `cos_pinned` (v0.3, Taylor, informative/superseded) | same | up to 407 raw (144.5 filtered) | 3.14e-5 |
 
1404
  diff ≈4.4e-6) is informative evidence for §7's theta-general RoPE, not a
1405
  §13.1 test vector.
1406
 
1407
+ This clause compares only the *output* of the layer stack. §14.6 (erratum
1408
+ E-5) records the corresponding comparison of every *intermediate* activation
1409
+ — 7,467 tensors on the first model and 5,985 on the second, worst relative L2
1410
+ error 9.923e-5, with no layer diverging from or compensating for the oracle
1411
+ (`docs/E28_LAYER_ORACLE.md`).
1412
+
1413
  13.4. **Compiler-invariance matrix (NEW in v0.2, informative but
1414
  strongly evidential)**: the pinned SmolLM2-135M test vector's `CIS2_REF`
1415
  and `inv_freq_table_digest` reproduce bit-for-bit across a 20-cell matrix
 
1420
  same check (`docs/E15d_a_COMPILER_INVARIANCE.md`) targeted the old
1421
  `ba88708b...` digest and is superseded by the v0.2 rerun.
1422
 
1423
+ 13.5. **Optimizer-invariance at every intermediate (NEW in v0.3b,
1424
+ informative but strongly evidential).** §13.4 compares two digests across a
1425
+ compiler matrix. This clause compares *every intermediate activation*
1426
+ across code generation targets. Three binaries built from one source tree —
1427
+ a default `--release` build, a `-C target-cpu=native` build on an AVX2 part
1428
+ (397 `%ymm` instructions emitted), and a `-C target-cpu=native` build on a
1429
+ part without AVX2 (none) — produce, on both of §0's models, dumps that are
1430
+ identical byte for byte: 7,467 tensors / 51,750,154 B for SmolLM2-135M and
1431
+ 5,985 tensors / 103,942,814 B for Qwen2.5-0.5B, over eight runs on two
1432
+ microarchitectures. Zero FMA instructions in all three binaries (§1.4).
1433
+
1434
+ The same check then covers all ten `{opt-level 0,1,2,3,s} × {target-cpu
1435
+ generic, native}` cells of §13.4's matrix on x86_64: **ten distinct
1436
+ binaries, one dump**, every cell reproducing
1437
+ `5386d3b0e529d9817af86f2ba1381193c2b174b0f26d12e22a441616dafb2f64` and the
1438
+ pinned §13.1 digests, with zero FMA instructions throughout. The emitted
1439
+ AVX2 instruction count rises with optimization pressure — 286 at
1440
+ `opt-level s`, 344 at 1, 397 at 2, 529 at 3 — while `dot_seq`'s
1441
+ multiply/add stay scalar in every cell, varying only in unroll factor,
1442
+ which changes the instruction count without changing the order of the
1443
+ additions.
1444
+
1445
+ The mechanism is the point, and it is a property of this specification
1446
+ rather than of these builds. §5.1's `acc = acc + p` is a serial
1447
+ floating-point dependency, so an optimizer denied fast-math (§1.5) cannot
1448
+ vectorize the reduction: `matvec` is scalar in all three binaries,
1449
+ including the AVX2 one. §8's sum-of-squares splits into an elementwise map
1450
+ and §5.3's fold, and the AVX2 build vectorizes the map 8-wide while
1451
+ emitting the fold as a scalar `vaddss` chain. **This spec pins exactly
1452
+ those operations whose order changes the result and leaves free exactly
1453
+ those whose order does not**, so an optimizer can act only where acting is
1454
+ a no-op on the bits. A conforming implementation therefore need not ship an
1455
+ unoptimized build; `--release -C target-cpu=native` was measured to be
1456
+ conforming.
1457
+
1458
+ Two controls accompany the result, because an invariance claim is empty
1459
+ without them. (a) The AVX2 vector loop is on the executed path: replacing
1460
+ one of its `vmulps` instructions with `ud2` in a copy of the binary
1461
+ terminates the run with SIGILL. (b) The dump is sensitive: flipping one
1462
+ low-order mantissa bit of one weight in the 269 MB artifact moves 570 of
1463
+ the 7,467 tensors — entering at `L27.down_proj` in a single element,
1464
+ saturating L28 and L29, and moving all 19 `logits` vectors — while changing
1465
+ **no** argmax decision. That last observation is the measured form of
1466
+ §12.1's requirement to hash the full logit vector rather than the emitted
1467
+ token ids: the corruption was visible in 100 % of the logit vectors and 0 %
1468
+ of the decisions. Full method, disassembly and provenance in
1469
+ `docs/E29_OPTIMIZER_INVARIANCE.md`; the per-tensor comparison tool is
1470
+ `scripts/diff_dumps.py`.
1471
+
1472
+ The same comparison was then extended over *inputs*. Six prompt/length
1473
+ configurations (different lengths, a digit-heavy prompt, a code prompt, a
1474
+ single-token prompt with 32 generated tokens; all ASCII, so §3.1.4's open
1475
+ question could not confound the result) were each run four times — the
1476
+ generic binary on both hosts, plus each host's `target-cpu=native` build.
1477
+ The six configurations produce six *different* dumps, totalling 558,394,570
1478
+ bytes of intermediate activations, and within each configuration all four
1479
+ runs agree on every byte.
1480
+
1481
+ The remaining half of §13.4's matrix has since been closed, and closed as a
1482
+ standing gate rather than a measurement: the `intermediates` job in
1483
+ `.github/workflows/verify.yml` runs **all twenty cells** —
1484
+ `{x86_64, aarch64} × {opt-level 0,1,2,3,s} × {target-cpu generic, native}` —
1485
+ on GitHub-hosted runners of both ISAs, and fails the build if any cell's
1486
+ dump digest moves. Twenty distinct binaries, one dump. On aarch64 the
1487
+ identity does not rest on the code having stayed scalar: NEON is
1488
+ architecturally baseline there, and every cell, `-O0` included, emits
1489
+ 875–936 vector instructions. Zero FMA-family instructions in all twenty.
1490
+
1491
+ Scope limits, stated so this is not over-read: every cell ran the same
1492
+ `rustc`/LLVM, so this widens the ISA and code-generation axes and not the
1493
+ compiler axis (`verify3`'s four `{x86_64, aarch64} × {gcc, clang}` cells are
1494
+ the independent-compiler axis, and §0's four-implementation convergence is
1495
+ the independent-implementation axis, though neither compares
1496
+ intermediates); six ASCII prompts, at most 64 generated tokens, on two
1497
+ models; and of the remaining codegen flags, `lto=fat`, `lto=thin` and
1498
+ `codegen-units=1` have since been measured over eight further cells (same
1499
+ dump, same digests, zero FMA — thin LTO with `target-cpu=native` emits 1,539
1500
+ AVX2 instructions, 3.9× the plain native build, and computes the same bits),
1501
+ and profile-guided optimization over eight further cells (E33: instrumented
1502
+ `profile-generate` builds, `profile-use` at both `target-cpu` settings, and
1503
+ the same combined with thin and fat LTO — same dump, same digests, zero FMA,
1504
+ including cells whose profile was trained on a *different* prompt than the
1505
+ one verified, and where the profile names `ops::matvec` as 86 % of all
1506
+ counted activity). Every codegen flag named here is now measured; any flag
1507
+ outside `{opt-level, target-cpu, lto, codegen-units, profile-use}` remains
1508
+ untested, and only `opt-level` and `target-cpu` are continuously gated.
1509
+
1510
  ## 14. Known gaps and internal inconsistencies (informative — read before treating this as complete)
1511
 
1512
  Renumbered from v0.1's §14; items resolved by v0.2 are marked **CLOSED**
1513
  and kept for history, per §16's changelog discipline.
1514
 
1515
+ 14.1. **`exp_pinned` and `ln_pinned` accuracy is measured exhaustively, at
1516
+ every f32.** §6.2's `exp_pinned`, §6.5's `ln_pinned` and §6.4's `silu_pinned`
1517
+ have each been evaluated at *all 2^32 f32 bit patterns* under the §1.3 pinned
1518
+ environment against an f64 accuracy oracle. Outside §6.2's two guard bands,
1519
+ every one of the 3,257,925,634 comparable `exp_pinned` arguments and all
1520
+ 2,130,706,432 positive-normal `ln_pinned` arguments are within **one ULP** of
1521
+ the f64 value narrowed to f32, with no degradation across the argument range.
1522
+ Both functions are exactly monotone over the whole finite domain.
1523
+ `ln_pinned` is **0 ULP** at both pinned `rope_theta` values (`100_000.0`,
1524
+ `1_000_000.0`), superseding the "≤2e-6 relative tolerance" figure quoted in
1525
+ §6.5 and in v0.3b's §14.1. `silu_pinned` is within **two ULP** everywhere it
1526
+ is not sitting on §6.2's clip band.
1527
+
1528
+ Two deliberate divergences from mathematical `exp`, both pinned:
1529
+
1530
+ (a) §6.2 step 2 clips at `x > 88.0`, but `ln(f32::MAX) = 88.7228390520684`.
1531
+ Exactly **94,743** arguments in `[0x42B00001, 0x42B17217]` =
1532
+ [88.0000076, 88.7228317] therefore return `+Infinity` where the true value is
1533
+ finite and representable. §10's softmax cannot reach this band --- it
1534
+ evaluates `exp_pinned(v - max_v)` with `max_v` the maximum over the same
1535
+ vector, so its argument is always `≤ 0` --- but §6.4's SiLU can: an FFN
1536
+ intermediate `x ∈ [-88.7228317, -88.0000076]` makes `exp_pinned(-x)` land
1537
+ inside it. A read-only census of SmolLM2-135M decodes over six
1538
+ prompt/length configurations (the §13.1 reference decode
1539
+ `"Once upon a time"`/16 among them, plus a 43-character prompt, a
1540
+ digit-heavy prompt, a code prompt, `"Once upon a time"`/64 and `"A"`/32)
1541
+ records **0** of its **18,892,800** `silu_pinned` arguments in that band —
1542
+ the most negative argument seen anywhere is -31.406876, some 57 units short
1543
+ of the band — and **0** of its **2,355,480** softmax `exp_pinned` arguments
1544
+ below `-88.0`; the instrumented build reproduces each configuration's pinned
1545
+ digests exactly. So §13.1's digests do not depend on the clip. That is one
1546
+ model, six ASCII prompts and at most 64 generated tokens, and does not
1547
+ establish unreachability in general. This
1548
+ clip is **normative and MUST be reproduced**; a clean-room implementation
1549
+ that returns the finite value will not reproduce the pinned digests.
1550
+
1551
+ (b) §6.2 step 3 returns `0.0` for `x < -88.0`. Every value *this* guard
1552
+ destroys is subnormal and would be flushed by §1.3 in any case; the measured
1553
+ count of arguments where it returned zero and the oracle was nonzero is **0**.
1554
+ The visible discontinuity in §6.4 comes from (a), not from this guard:
1555
+ `silu_pinned(-88.0)` is `0x83354DDC` (≈ -5.328e-37) while
1556
+ `silu_pinned(-88.0000076)` is `-0.0`, because `exp_pinned(88.0000076)` is
1557
+ clipped to `+Infinity`. Note that `5.328e-37` is a **normal** f32 (about 45×
1558
+ `f32::MIN_POSITIVE`), so §1.3's FTZ does not flush it. The error is
1559
+ numerically negligible and, being produced identically by every conforming
1560
+ implementation, does not affect bit-exact agreement.
1561
+
1562
+ Under §1.3's DAZ, `ln_pinned` returns `-Infinity` for all 16,777,214
1563
+ subnormal inputs of both signs, because §6.5's `x == 0.0` guard is an SSE
1564
+ compare and DAZ makes a subnormal operand compare equal to zero. That is
1565
+ §1.3 acting on §6.5's guard, not a property of the polynomial;
1566
+ `frexp_exact` (§6.5.1) is bit manipulation and is unaffected.
1567
+
1568
+ Tier-1 op-level goldens pinning all of this -- 48 `(input_bits,
1569
+ output_bits)` pairs, with two structural mutation controls -- are in
1570
+ `cis2-verify/src/mathpin.rs`, `mod exp_ln_range`.
1571
+
1572
+ **ERRATUM E-4 (2026-09-09).** Through v0.3b as published, this clause read
1573
+ "`ln_pinned`'s validated domain is a finite, explicitly-tested set of `x`
1574
+ values (§6.5), not a general accuracy proof ... **PARTIALLY CLOSED**". That
1575
+ was accurate about what had been measured and wrong in three ways about what
1576
+ is true: the stated tolerance was two orders of magnitude looser than the
1577
+ truth; the clause cautioned about `ln_pinned`, which runs once per model
1578
+ load, while saying nothing about `exp_pinned`, which runs twice per decode
1579
+ step (§10 softmax and §6.4 SiLU); and it did not know that §6.2's high guard
1580
+ clips below the representable range. §6.2, §6.4 and §6.5 are unchanged; only
1581
+ this limitations note was. See CHANGELOG.md, "Errata against v0.3b", and
1582
+ docs/E27_EXP_LN_RANGE.md.
1583
+
1584
+ **ERRATUM E-10 (2026-09-09).** The reach census quoted in (a) and the
1585
+ zero count quoted in (b) were both taken on **one model, six ASCII prompts and
1586
+ at most 64 generated tokens**, and the clause said so. Extending the same
1587
+ instrument to **20 cells across both §0 models** --- ten per model, adding
1588
+ Japanese, Cyrillic, Arabic, emoji, accented-Latin and mathematical-symbol
1589
+ prompts, a 32-character repeat, a punctuation repeat, and a 256-token decode ---
1590
+ censused **145,385,472** `silu_pinned` arguments and **43,523,148** softmax
1591
+ `exp_pinned` arguments, against the 18,892,800 and 2,355,480 quoted above.
1592
+
1593
+ Two of the numbers above therefore need correcting, and one claim needs
1594
+ retracting:
1595
+
1596
+ * The SiLU side is **strengthened, not changed**: still **0** arguments in
1597
+ §6.2's clip band, on either model, in any of the 20 cells. The deepest
1598
+ `silu_pinned` argument seen anywhere is now **-32.173088** (SmolLM2, Japanese
1599
+ prompt) rather than -31.406876 --- still some 56 units short of the band.
1600
+ * "**0** of its 2,355,480 softmax `exp_pinned` arguments below `-88.0`" is
1601
+ **false in the wider scope.** Qwen2.5-0.5B decoding `"Once upon a time"` for
1602
+ 256 tokens produces a softmax argument of **-88.369385**, and **2** of that
1603
+ cell's 22,626,240 arguments fall below `-88.0` and so trip (b)'s LOW guard.
1604
+ It is a monotone trend in decode length on that one prompt and model, not a
1605
+ freak: 16 tokens reaches -55.623780, 128 reaches -80.235170, 192 reaches
1606
+ -82.705530, 256 reaches -88.369385.
1607
+ * (b)'s "the measured count of arguments where it returned zero and the oracle
1608
+ was nonzero is **0**" is likewise **now 2**. (b)'s *substance* is unaffected,
1609
+ though not for the reason given here: the true `exp(-88.369385)` is about
1610
+ 4.2e-39, a subnormal, and the guard destroys it --- but §1.3 never sees it.
1611
+ See erratum **E-12**.
1612
+
1613
+ A second counter, absent when this clause was written, records arguments in
1614
+ `[-88.0, -87.33654022216797)`, where no guard fires and `exp_pinned` is
1615
+ evaluated. The same Qwen cell puts **2** arguments there. E22's M01 mutant ---
1616
+ §1.3's pin gutted, and instrumented to prove the pin is really absent --- was
1617
+ re-run on that cell: the witness and argmax digests are **byte-identical to the
1618
+ pinned build**.
1619
+
1620
+ > **This paragraph originally called that band the FTZ-*dependent* window and
1621
+ > said "the result is a subnormal that §1.3 flushes", concluding that "a
1622
+ > denormal genuinely arises in a real decode". That is wrong and is withdrawn
1623
+ > by erratum E-12 below. The band and its count of 2 are real; the mechanism
1624
+ > attributed to them is not.**
1625
+
1626
+ Nothing normative changes. The clip in (a) and the guard in (b) are unaltered,
1627
+ and every digest in §13 is unaffected. What changes is the scope of the
1628
+ supporting measurement and the retraction of a count. The clause's own caveat
1629
+ --- "does not establish unreachability in general" --- was right to be there.
1630
+ See CHANGELOG.md and docs/E38_REACH_SWEEP.md.
1631
+
1632
+ **ERRATUM E-12 (2026-09-09).** (b) says every value §6.2's low guard destroys
1633
+ "would be flushed by §1.3 in any case", and erratum E-10 above extended that
1634
+ reading to the band `[-88.0, -87.33654022216797)`, calling it the window where
1635
+ §1.3's FTZ/DAZ pin is digest-relevant. **Both statements name the wrong
1636
+ mechanism, and `exp_pinned` cannot reach the state they describe.**
1637
+
1638
+ §6.2's final step is `ldexp_exact(result, k)`, which is bit manipulation, not a
1639
+ floating-point operation, and returns exactly `+0.0` whenever the reconstructed
1640
+ exponent field would be `<= 0`. `result` always carries exponent field 126 or
1641
+ 127, so `exp_pinned` returns either `+0.0` or a **normal** f32. Evaluating
1642
+ `exp_pinned` on **all 4,294,967,296** f32 bit patterns yields **0** subnormal
1643
+ outputs; the smallest nonzero magnitude it can produce anywhere is `0x00800026`
1644
+ (exponent field 1, at `x = 0xc2aeac4f`). **No FTZ decision is ever taken on
1645
+ `exp_pinned`'s output.** Direct measurement agrees: with the pin cleared and
1646
+ restored around each evaluation, every point in the band returns `0x00000000`
1647
+ both ways.
1648
+
1649
+ The consequences are confined to the stated reason:
1650
+
1651
+ * (b)'s conclusion --- the guard is harmless --- is **correct**. Its reason is
1652
+ not: the values are destroyed by `ldexp_exact`'s zero branch, before §1.3 is
1653
+ consulted. §1.3 does not participate.
1654
+ * The band counter measures arguments **whose true `exp` is subnormal**, not
1655
+ subnormals computed and flushed. It is FTZ-*independent*, like the guarded
1656
+ side it was introduced to contrast with.
1657
+ * "A denormal genuinely arises in a real decode" is **withdrawn**. Through
1658
+ §6.2, on the measured vector, none did.
1659
+ * E-10's *reach* result is untouched: the softmax argument really does reach
1660
+ -88.369385, and (a)'s and (b)'s counts really are 2.
1661
+ * No digest, coefficient, guard or required behaviour changes.
1662
+
1663
+ Where §1.3 **can** change bits in this pipeline is §10's elementwise division
1664
+ `w[i] = exp_i / denom`: `exp_pinned` yields a normal, `denom >= 1` because
1665
+ max-subtraction puts `exp(0) = 1` in the sum, and a smallest-normal numerator
1666
+ over a denominator above 1 is subnormal --- an SSE operation FTZ governs. That
1667
+ quantity had never been counted. Measured over the same Qwen cell,
1668
+ **22,626,240** softmax weights produced **0** subnormal quotients and **0**
1669
+ where FTZ would have changed the stored bits; the smallest nonzero weight is
1670
+ `1.5562307486661955e-38`, a factor of **1.32** above the subnormal boundary. So
1671
+ on this vector §1.3 is not digest-relevant through §10 --- which fully explains
1672
+ E-10's byte-identical M01 digests --- and it is **untriggered, not shown
1673
+ unnecessary**: a third of a binade more spread in one attention row would
1674
+ trigger it. §14's caveat that a SAME digest is weaker than "no denormal ever
1675
+ arose" therefore stands, now with the measurement that makes it precise. See
1676
+ CHANGELOG.md and docs/E39_FTZ_IS_NOT_WHERE_WE_SAID.md.
1677
+
1678
+ **ERRATUM E-13 (2026-09-09).** E-12 closed one operation (§10's division) and
1679
+ left the rest of the pipeline uncounted, so "untriggered, not shown unnecessary"
1680
+ was stated for §10 alone. The remaining operations have now been counted, and
1681
+ the scope of that sentence widens to the whole decode.
1682
+
1683
+ Every §5.1 product and partial sum, every §8 RMSNorm intermediate and every §10
1684
+ softmax weight of the §13.1 decode was classified exactly, on both §0
1685
+ checkpoints: **562,531,070,920** intermediates, **0** subnormal and **0** where
1686
+ FTZ would have changed the stored bits. Every §2.5 weight operand the decode
1687
+ reads was scanned first, since DAZ acts on inputs: **628,547,776** operands, **0**
1688
+ subnormal. The operations no counter reaches --- §11's residual adds, §7's RoPE
1689
+ rotations, §9.2's score scaling, §10's max-subtraction, and the polynomial
1690
+ internals of §6.2/§6.3 --- are covered instead by a differential: the §14.6 layer
1691
+ dump run twice, once with §1.3's FTZ and DAZ cleared for the whole decode, is
1692
+ **byte-identical** across all **7,467** named intermediate tensors of the
1693
+ normative vector (and 5,985 of the Qwen vector), and those dumps contain **0**
1694
+ stored subnormals and **0** exact zeros in 38,775,808 f32 values.
1695
+
1696
+ So on the normative vector **§1.3 is not digest-relevant anywhere**, not merely
1697
+ through §10. The requirement stands unchanged and for the unchanged reason:
1698
+ §1.3 exists so that the *platform* cannot answer the question, and a conforming
1699
+ implementation must pin FTZ/DAZ whether or not its inputs exercise the pin. What
1700
+ is now measured rather than assumed is the weaker and more useful statement a
1701
+ conformance tier can rely on: **no conforming implementation's digest is hostage
1702
+ to FTZ/DAZ on this vector.** The nearest approach is still E-12's factor of
1703
+ 1.32, so this remains untriggered rather than unnecessary. No digest,
1704
+ coefficient, guard or required behaviour changes. See CHANGELOG.md and
1705
+ docs/E40_MATVEC_RMSNORM_REACH.md.
1706
 
1707
  14.2. **Digest byte encoding for artifact hashes: CLOSED.** v0.1 fed the
1708
  64-character hex **string's** ASCII bytes into the witness hash, not the
 
1729
  five are still printed, §12.3), not rely on `CIS2_REF` alone to diagnose
1730
  *why* it differs.
1731
 
1732
+ 14.4. **Trig polynomial accuracy is measured, exhaustively, to `|x| <
1733
+ 2^31`.** §6.3's Cody-Waite reduction has been evaluated at *every* f32 bit
1734
+ pattern `x` with `0 <= x < 2^31` -- 1,325,400,064 arguments, subnormals
1735
+ included -- against an f64 accuracy oracle under the §1.3 pinned
1736
+ environment. The worst absolute error is **9.4218e-8 for `|x| < 2^20`** and
1737
+ **2.0925e-7 for `|x| < 2^31`**: 0.790 and 1.756 ULP at 1.0 respectively.
1738
+ Relative (ULP) error is much larger near the zeros of `sin` and `cos` --
1739
+ 2617 ULP at worst -- but there the absolute error is *smaller*, by four to
1740
+ five orders of magnitude, because the f32 grid is finer near zero; ULP is
1741
+ not a meaningful figure of merit for these functions and absolute error is.
1742
+
1743
+ Because §7.1 makes `inv_freq[0]` exactly `1.0` and every later entry
1744
+ smaller, the largest RoPE angle a decode evaluates is its sequence length.
1745
+ The `|x| < 2^20` figure therefore covers **every RoPE angle any context up
1746
+ to 1,048,576 positions can produce**, for any `rope_theta`. Direct
1747
+ enumeration of the angle multiset for both §0 models at `L = 131,072`
1748
+ agrees: max absolute error 9.3815e-8.
1749
+
1750
+ `sin_pinned` is exactly odd and `cos_pinned` exactly even *in value* over
1751
+ every f32 with `2^-126 <= |x| < 2^31`. Two exceptions are documented, and
1752
+ neither affects any reachable RoPE angle: on the zero/subnormal class
1753
+ §1.3's DAZ makes `sin_pinned` return `+0.0` for both signs, and at three
1754
+ arguments above `2^29` (620046660, 1175634300, 1240093300) the reduced
1755
+ argument underflows and only the sign of a zero result fails to mirror.
1756
+
1757
+ Tier-1 op-level goldens pinning this behaviour at the worst-case arguments
1758
+ are in `cis2-verify/src/mathpin.rs`, `mod large_angle`.
1759
+
1760
+ **ERRATUM E-2 (2026-09-09).** Through v0.3b as published, this clause read
1761
+ "Trig polynomial accuracy is only validated for `|x| ≲ 14` ... A clean-room
1762
+ implementer targeting a longer sequence than this spec's 20 positions
1763
+ should not assume this polynomial's accuracy holds unchanged," carried
1764
+ unchanged from v0.1. That was accurate about what had been measured and
1765
+ badly misleading about what is true: the reduction does not degrade at all
1766
+ across nine orders of magnitude of argument. §6.3 is unchanged; only this
1767
+ limitations note was. See CHANGELOG.md, "Errata against v0.3b", and
1768
+ docs/E26_TRIG_RANGE.md.
1769
+
1770
+ 14.5. **RMSNorm multiply order (§8) is pinned, and its bit-level necessity
1771
+ is measured.** `(x[i]*inv)*weight[i]` and `x[i]*(inv*weight[i])` are not
1772
+ provably identical for arbitrary fp32 operands under rounding, and they in
1773
+ fact differ by one ULP on about 35 % of the operand triples an actual decode
1774
+ produces — 231,014 of the 667,584 RMSNorm elements in the §13.1 vector.
1775
+ Substituting the other association changes the §13.1 witness digest from
1776
+ `d82743059d…` to `570c0bbb0d…`. It does **not** change the argmax digest or
1777
+ the generated token ids for this vector, so the violation is invisible to any
1778
+ check that hashes only the model's outputs — one of the reasons §12.1 hashes
1779
+ the full logit vector. The second model §0 names behaves the same way:
1780
+ `Qwen/Qwen2.5-0.5B` on the same prompt and decode length diverges on 287,859
1781
+ of its 834,176 RMSNorm elements (34.51 %), moves its witness
1782
+ digest from `c9dff099d9…` to `4df2b260ee…`, and leaves its argmax digest and
1783
+ all sixteen generated token ids unchanged. (That run supplies its prompt token
1784
+ ids rather than deriving them; see §14.8.) See
1785
+ `docs/E25_RMSNORM_ASSOCIATION.md`.
1786
+ **ERRATUM E-1 (2026-09-09).** Through v0.3b as published, this clause read
1787
+ "…its bit-level necessity is unconfirmed… no divergence between the two
1788
+ orders has actually been observed on either model tested," carried unchanged
1789
+ from v0.1. That was wrong: E22's M09 mutation is this exact reassociation and
1790
+ had already moved the digest. §8 is unchanged; only this limitations note was.
1791
+ See CHANGELOG.md, "Errata against v0.3b".
1792
+
1793
+ 14.6. **Every intermediate activation has been compared against the oracle,
1794
+ on both models. CLOSED.** §13.3's checks look only at the two ends of the
1795
+ pipe --- greedy token ids and one step's full-vocab logit vector. That left a
1796
+ compensating pair of errors inside the layer stack, one layer diverging and a
1797
+ later one bringing the result back, outside the reach of the evidence. It is
1798
+ now inside it.
1799
+
1800
+ Every named intermediate of the forward pass --- `embed`, and per layer
1801
+ `ln1`, `q_proj`, `k_proj`, `v_proj`, `attn_out`, `o_proj`, `resid_attn`,
1802
+ `ln2`, `gate_proj`, `up_proj`, `mlp_act`, `down_proj`, `resid_mlp`, and
1803
+ `final_norm`/`logits` --- has been dumped at every position of a full decode
1804
+ of **both** §0 models and compared against the same tensors taken from a
1805
+ `transformers` fp32 forward pass by module hook:
1806
+
1807
+ | | SmolLM2-135M | Qwen2.5-0.5B |
1808
+ |---|---|---|
1809
+ | tensors compared | 7,467 | 5,985 |
1810
+ | worst relative L2 error, any tensor | **2.228e-5** | **9.923e-5** |
1811
+ | `embed` agreement | exactly 0 | exactly 0 |
1812
+ | worst amplification of the carried-in error by any layer | **4.07x** | **3.22x** |
1813
+
1814
+ The last row is the one that closes the clause. A divergent layer shows its
1815
+ own tensors far above the error it was handed; a compensating layer shows the
1816
+ opposite. Measured, **every layer's first computed tensor is within
1817
+ 0.73-1.18x of the error handed to it**, on all 30 layers of the first model
1818
+ and all 24 of the second, with the worst whole-layer amplification bounded by
1819
+ 4.07x and uniform with depth. There is no divergent layer and no compensating
1820
+ layer.
1821
+
1822
+ The residual stream shows apparent spikes (8.79x at layer 9 of the first
1823
+ model) which are **cancellation, not divergence**: there the two addends have
1824
+ norms 486.5 and 414.1 and their sum has norm 105.6, so a 4.6x cancellation
1825
+ inflates the relative measure by 4.6x while every input to the add sits at
1826
+ 1-3e-6. Evidence and method: `docs/E28_LAYER_ORACLE.md`. Instrumentation:
1827
+ `cis2-verify` `--features layerdump`, plus `scripts/oracle_layers.py` and
1828
+ `scripts/compare_layers.py`.
1829
+
1830
+ Scope, unchanged by this: agreement with `transformers` is ~1e-5 relative and
1831
+ **must not** be bit-exact --- the oracle uses different kernels and a
1832
+ different summation order. CIS-2's bit-exactness claim is between conforming
1833
+ implementations of *this document*, not between this document and PyTorch.
1834
+ This is one prompt and 19 positions on each model, so a compensating pair
1835
+ that appears only at some other context length or activation pattern is not
1836
+ excluded; and the Qwen run supplies its prompt token ids from outside §3
1837
+ (§14.8), so it attests to §4-§11 only.
1838
+
1839
+ **ERRATUM E-5 (2026-09-09).** Through v0.3b as published, and unchanged in
1840
+ kind since v0.1, this clause read:
1841
+
1842
+ > The oracle correctness checks (§13.3) are defensible spot-checks, not
1843
+ > exhaustive. They confirm greedy token-id agreement and one step's
1844
+ > full-vocab logit agreement to ~4e-6 relative on two model families now
1845
+ > (SmolLM2-135M, Qwen2.5-0.5B) --- neither checks every intermediate layer's
1846
+ > activations against the oracle, so a compensating pair of errors elsewhere
1847
+ > in the layer stack that happens to preserve step-0's output and all argmax
1848
+ > decisions cannot be completely ruled out by this evidence alone.
1849
+ > **Unchanged in kind from v0.1 (was §14.6 there); now covers two models
1850
+ > instead of one.**
1851
+
1852
+ That statement was correct when written, and the measurement it asked for has
1853
+ now been made. Nothing normative changes: no digest, coefficient, or required
1854
+ behaviour is affected. What changes is the strength of the evidence behind
1855
+ §13.3, and the fact that this clause is no longer an open gap.
1856
+
1857
+ **ERRATUM E-9 (2026-09-09).** Three numbers above are **per-prompt maxima
1858
+ quoted as general bounds**. As published they read "every layer's first
1859
+ computed tensor is within **0.73-1.18x** of the error handed to it" and "the
1860
+ worst whole-layer amplification bounded by **4.07x**" (SmolLM2) / **3.22x**
1861
+ (Qwen). Each is the value measured on the single prompt E28 ran. Re-measuring
1862
+ the identical instrument over six prompt/length cells on each model
1863
+ (`docs/E36_ORACLE_PROMPT_SWEEP.md`, `docs/E37_QWEN_ORACLE_SWEEP.md`; 144,825
1864
+ tensors, 312 (cell, layer) ratio rows) gives:
1865
+
1866
+ | | as published | measured over six cells per model |
1867
+ |---|---|---|
1868
+ | first-computed-tensor / carried-in ratio | 0.73-1.18x | **0.51-1.70x** |
1869
+ | worst whole-layer amplification, SmolLM2 | 4.07x | **6.48x** |
1870
+ | worst whole-layer amplification, Qwen | 3.22x | **4.83x** |
1871
+
1872
+ E28's own cell reproduces 4.07x, 3.22x and the 0.73 low end exactly, so these
1873
+ are that prompt's values and not a transcription error. The table earlier in
1874
+ this clause is likewise per-prompt: SmolLM2's worst relative L2 error rises to
1875
+ **3.406e-5** across six prompts (E36), while Qwen's **9.923e-5** turns out to be
1876
+ the six-cell maximum already.
1877
+
1878
+ **The conclusion of this clause is unchanged, and now rests on a better test.**
1879
+ The width of the ratio interval was never the evidence; whether an extreme is a
1880
+ property of the *weights* is. A divergent or compensating layer must appear at
1881
+ the same layer, in the same direction, on every input. Measured, it does not:
1882
+ Qwen's layer 22 hands back 0.73x the error it was given on one prompt and 1.61x
1883
+ on another, and SmolLM2's layer 3 spans 0.68x to 1.48x — activation-dependent
1884
+ scatter in a ratio of two small relative errors, not a layer that creates or
1885
+ destroys error. The compensating pair is excluded instead by the residual-stream
1886
+ test, run on all 324 (cell, layer) rows of both sweeps: a compensating pair would
1887
+ show a residual spike larger than that layer's own-tensor error times its
1888
+ cancellation factor, and `max resid_l2 / (own_l2 x cancellation)` is **0.848**
1889
+ on SmolLM2 and **0.557** on Qwen — every row below 1, none unexplained. Read the
1890
+ row above as: *no layer's own tensors depart from the error handed to it by more
1891
+ than about 1.7x in either direction, and no layer's departure reproduces across
1892
+ inputs.* The "one prompt and 19 positions on each model" scope note below is
1893
+ correspondingly widened to six prompts and up to 67 fed positions on each; it is
1894
+ still not exhaustive, and the Qwen half still attests to §4-§11 only (§14.8).
1895
+ Nothing normative changes: no digest, coefficient, or required behaviour is
1896
+ affected. See CHANGELOG.md, "Errata against v0.3b".
1897
 
1898
  14.7. **This spec's own history.** Carried forward from v0.1: earlier
1899
  states of the reference computed `inv_freq` via unpinned host `f64::powf`,
 
1913
  the digest without also comparing the finer-grained digests
1914
  individually.
1915
 
1916
+ 14.8. **§3 admits exactly one `tokenizer.json`, and §0's second model is not
1917
+ it. ERRATUM E-3 (2026-09-09).** §3.1.3 pins `normalizer: null` and §3.1.4 pins
1918
+ the `pre_tokenizer` value `Sequence[Digits(individual_digits = true),
1919
+ ByteLevel(add_prefix_space = false, use_regex = true)]` — the shape
1920
+ `HuggingFaceTB/SmolLM2-135M` ships. `Qwen/Qwen2.5-0.5B`, which §0 names as the
1921
+ second model and `docs/E15d_bc_RESULT.md` uses as evidence of correctness,
1922
+ ships an NFC normalizer and `Sequence[Split(<GPT-4-style regex>, Isolated),
1923
+ ByteLevel(use_regex = false)]`. A conforming implementation of §3 therefore
1924
+ **must refuse that checkpoint's tokenizer**, and cannot run that model
1925
+ end-to-end from its artifacts. This was always true of the text; it was never
1926
+ written down, and a reader could reasonably have taken §0's second-model
1927
+ sentence to mean otherwise. The scope is unchanged — §13.1 was and is the only
1928
+ normative test vector, and §0 already said the Qwen tuple is not one — but the
1929
+ boundary is now stated. Work on such a checkpoint is confined to §4–§11 and
1930
+ must supply the prompt token ids from outside §3, saying so; a receipt produced
1931
+ that way attests to §4–§11 and nothing of §3. A future version that wants a
1932
+ second normative tuple has to generalize §3.1.3/§3.1.4 from a pinned literal to
1933
+ a small enumerated set, with the same "refuse rather than reinterpret"
1934
+ discipline for anything outside it. See `docs/E25_RMSNORM_ASSOCIATION.md` §4.1
1935
+ and CHANGELOG.md, "Errata against v0.3b".
1936
+
1937
  ## 15. Conformance (normative)
1938
 
1939
  An implementation is CIS-2 v0.2 conforming iff, from this document's text
EXPECTED_DIGESTS.md CHANGED
@@ -83,6 +83,42 @@ cross-ISA evidence, not §13.1 normative test vectors.
83
  | 3 | 19 | `ee1247798e49f766adf10b64fb9cce07ee9cf80a34394e5e38c47485939c6c01` |
84
  | 4 | 215 | `135f50b5850e9e7bf31ee4fd9b935a002c7627cce6e1b7260e665e726c2c450b` |
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  ## Informative: Qwen2.5-0.5B (theta-general RoPE exercise, `rope_theta=1000000`)
87
 
88
  Not a §13.1 test vector; exercises §7's general RoPE construction against
 
83
  | 3 | 19 | `ee1247798e49f766adf10b64fb9cce07ee9cf80a34394e5e38c47485939c6c01` |
84
  | 4 | 215 | `135f50b5850e9e7bf31ee4fd9b935a002c7627cce6e1b7260e665e726c2c450b` |
85
 
86
+ ## Informative: SmolLM2-360M (second-model-scale evidence, same family/tokenizer)
87
+
88
+ Not a §13.1 test vector (that role belongs to SmolLM2-135M above); exercises
89
+ the reference construction (`src/`, not the clean-rooms) against a second,
90
+ genuinely different checkpoint in the same model family — 32 layers vs. 9,
91
+ hidden_size 960 vs. 576, `rope_theta=100000` (same as 135M) — sharing only the
92
+ tokenizer with the primary vector. Confirmed bit-identical between an AVX2
93
+ x86_64 machine and a scalar (no AVX2/FMA) x86_64 machine on 2026-09-22.
94
+
95
+ ```
96
+ Model: HuggingFaceTB/SmolLM2-360M, prompt "Once upon a time", gen_toks=16, spec v0.3b, dtype=fp32
97
+
98
+ weights_sha256 = 7aaff6661428bed033abba9522bec81938678642cca3181fe752b6ca9e1e540f
99
+ config_sha256 = 34f7801487078de7e434e19162c497e5cc6ff397080e40e8586627cb68a5168a
100
+ tokenizer_sha256 = 9ca9acddb6525a194ec8ac7a87f24fbba7232a9a15ffa1af0c1224fcd888e47c
101
+ table_digest = 23c7bfaf5cef0095fd021af2eb1808abb4928bae4219756d86bdac670a06b35d
102
+ inv_freq_table_digest = da9f6dcfde0425588815509e874515cdcd3d6b8818b6d0136590052e7bbf6f12
103
+ argmax_digest = 90681903ebafdc4f8d8141be882e19b95b7a2c0f0761f16fa213df196db794a8
104
+ generated_token_ids = 28,281,253,1666,1869,2025,28,665,436,253,9077,1379,1217,260,476,61
105
+
106
+ CIS2_REF (witness digest) = 3d159b94fd7a241fcc380bb6bc158cf03a6b4c13c03f46325c8a91d75c477dad
107
+ ```
108
+
109
+ Reproduced via `src/` (`cis2_ref --weights-dir <dir>`, default `--gen-toks 16`)
110
+ on:
111
+ - x86_64, AVX2, `aefinity-box` (box1) — 23.9s wall.
112
+ - x86_64, scalar (no AVX2/FMA — Intel Celeron N4020), `aefinity-box2` (box2),
113
+ same commit, cross-machine replay — 43.2s wall.
114
+
115
+ Both machines produced the identical witness/argmax/table/inv_freq_table
116
+ digests above, byte-for-byte, in a single run per machine (not just the
117
+ in-process two-run check). `table_digest` and `inv_freq_table_digest` are
118
+ identical to the primary SmolLM2-135M vector, as expected — both are
119
+ independent of model weights (the transcendental-polynomial table is a
120
+ fixed constant, and `rope_theta=100000` is shared with 135M).
121
+
122
  ## Informative: Qwen2.5-0.5B (theta-general RoPE exercise, `rope_theta=1000000`)
123
 
124
  Not a §13.1 test vector; exercises §7's general RoPE construction against
README.md CHANGED
@@ -125,29 +125,24 @@ enough information for strangers to converge on identical bits — across an ISA
125
  boundary, a compiler boundary, a language boundary, and a CPU/GPU boundary,
126
  with no implementation consulting another.
127
 
128
- ## Falsification challenge
129
-
130
- Try to break it. Verified divergences and reproductions are credited by name in
131
- HALL-OF-DIVERGENCE.md:
132
- https://github.com/Aefinity-AI/alice-aegis/blob/main/CHALLENGE.md — write your
133
- own implementation from `CIS2_SPEC_v0.3b.md`, in any language for any device,
134
- and get a different digest. If the disagreement is because the spec text permits
135
- two readings, that is the most valuable finding: it means the document is not
136
- yet sufficient, which is the entire thing CIS-2 claims to be.
137
-
138
- ## Results: single-weight corruption detection (2026-09-13)
139
-
140
- Does a single flipped weight bit in a deployed model get noticed by text
141
- output, a cheaper top-k logit check, or the CIS witness digest? Of 247
142
- single-weight bitflips on a pruned BitNet-2B that changed the model's
143
- output, text/argmax replay missed 182 (74%, CI 68-79%), a top-k logit-set
144
- check missed 82 (33%, CI 28-39%), the CIS witness digest missed 0 (CI
145
- 0-1.5%). 43 other flips produced a bit-identical digest to baseline (no
146
- real effect); the digest correctly passed all of them. Limits: single
147
- prompt/model, no adversarial tampering, most embedding-row hits are
148
- integrity-only. Full report:
149
- https://github.com/Aefinity-AI/cis2-spec/blob/main/docs/results/2026-09-13-BITFLIP-HEADTOHEAD.md
150
 
151
  ---
152
 
153
  Aefinity AI Inc. · Justin Brian Thompson
 
 
 
 
 
 
 
125
  boundary, a compiler boundary, a language boundary, and a CPU/GPU boundary,
126
  with no implementation consulting another.
127
 
128
+ ## Try to break it
129
+
130
+ Write your own implementation from `CIS2_SPEC_v0.3b.md`, in any language for
131
+ any device, and see whether you get a different digest. Verified divergences
132
+ and verified reproductions are credited by name in the repository's
133
+ `HALL-OF-DIVERGENCE.md`. There is no cash offer attached to this: the reason
134
+ to do it is the finding itself, and the credit for it.
135
+
136
+ If two implementations disagree because the spec text permits two readings,
137
+ that is the most valuable outcome, not an embarrassing one: it means the
138
+ document is not yet sufficient, which is the entire property CIS-2 claims.
 
 
 
 
 
 
 
 
 
 
 
139
 
140
  ---
141
 
142
  Aefinity AI Inc. · Justin Brian Thompson
143
+
144
+ ## Acknowledgments
145
+
146
+ A special thank you to Charles Seaman and Linda Blanchard, whose contributions have helped Aefinity AI stay on track.
147
+
148
+ And a very special thank you to **Bonnie Rae Power**: an amazing woman, a great friend and neighbor, without whom Aefinity AI would have never had a chance to ever get started. Thank you, Bonnie, for your advice, care, encouragement, guidance, intuitive wisdom, and financial assistance.
vectors/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # CIS-2 third-party conformance suite (E21: RMSNorm, RoPE table, exp_pinned, attention block, matvec + CLI protocol)
2
 
3
  This directory lets someone with an independent CIS-2 implementation
4
  check individual normative primitives against pinned vectors, without
@@ -9,10 +9,11 @@ full forward pass): each vector here exercises exactly one primitive with
9
  a small, hand-sized input.
10
 
11
  **Status.** RMSNorm (§8), RoPE table (§7), exp_pinned (§6.2 pinned exp()
12
- polynomial), one attention block (§9.2–§9.4), and one matvec (§5.2)
13
- vector exist, plus a `cis2-conformance` CLI wrapper implementing the
14
- stdin/stdout protocol documented in `PROTOCOL.md`. See "What's missing"
15
- at the bottom for what's still outstanding.
 
16
 
17
  ## Protocol
18
 
@@ -273,6 +274,100 @@ test in the same file is not part of the pinned suite; it exists only to
273
  regenerate the fixture if the reference math ever changes — run with
274
  `cargo test --test conformance_matvec print_bits -- --ignored --nocapture`.)
275
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
276
  ## The `cis2-conformance` CLI
277
 
278
  `src/bin/cis2_conformance.rs` implements the stdin/stdout protocol
 
1
+ # CIS-2 third-party conformance suite (E21: RMSNorm, RoPE table, exp_pinned, attention block, matvec, softmax, embed lookup + CLI protocol)
2
 
3
  This directory lets someone with an independent CIS-2 implementation
4
  check individual normative primitives against pinned vectors, without
 
9
  a small, hand-sized input.
10
 
11
  **Status.** RMSNorm (§8), RoPE table (§7), exp_pinned (§6.2 pinned exp()
12
+ polynomial), one attention block (§9.2–§9.4), one matvec (§5.2), softmax
13
+ (§9.3, standalone) and token-embedding lookup (§2.5) vectors exist, plus
14
+ a `cis2-conformance` CLI wrapper implementing the stdin/stdout protocol
15
+ documented in `PROTOCOL.md`. See "What's missing" at the bottom for
16
+ what's still outstanding.
17
 
18
  ## Protocol
19
 
 
274
  regenerate the fixture if the reference math ever changes — run with
275
  `cargo test --test conformance_matvec print_bits -- --ignored --nocapture`.)
276
 
277
+ ### `softmax_v1` (§9.3 Softmax, standalone)
278
+
279
+ - Spec reference: `docs/CIS2_SPEC_v0.2.md` §9.3 (`softmax_seq`, in
280
+ place: strict-sequential max-scan with first-occurrence-wins tie
281
+ break, pinned-exp max-subtract per §6.2, §5.3 sequential-sum
282
+ denominator, elementwise divide — NOT multiply-by-reciprocal).
283
+ `attention_block_v1` above already exercises `softmax_seq` as one step
284
+ of the larger score/softmax/V-mix pipeline, but with input scores
285
+ produced by a dot product; this vector exercises `softmax_seq` on its
286
+ own, directly, with a hand-picked `scores` vector.
287
+ - `n=6` (deliberately small and hand-sized, same rationale as the other
288
+ vectors' small dimensions).
289
+ - Values `1.5, -0.5, 0.5, 1.5, -3.0, 0.0` deliberately include an EXACT
290
+ tie for the maximum at indices 0 and 3 (both `1.5`), to exercise §9.3's
291
+ "strict `>`, so the FIRST occurrence of the max wins ties" max-scan
292
+ rule explicitly (the tie happens to be invisible in the output bits
293
+ here, since the two tied values are themselves bit-identical, but the
294
+ vector still documents that a conforming max-scan must use strict `>`
295
+ and must not, e.g., pick the LAST occurrence or use an unstable
296
+ comparator — a real divergence would only show up with NaN-adjacent or
297
+ reordering-sensitive inputs, out of scope for this hand-sized vector).
298
+ `-3.0` exercises the post-max-sub `exp_pinned` route further from
299
+ zero than `attention_block_v1`'s scores do.
300
+ - `out_bits` layout: 6 values, index order matching `scores_bits`.
301
+
302
+ **How this vector was derived**: `tests/conformance_softmax.rs` includes
303
+ `src/math.rs` by path (`softmax_seq` — the same function
304
+ `src/main.rs`'s attention loop and `cis2_conformance_reference_candidate.rs`'s
305
+ `op_attention_block` call) and runs it directly on `scores_bits`,
306
+ computes the SHA-256 digest per the convention above, and asserts both
307
+ the bit patterns and the digest match `vectors/softmax_v1.expected`. Run
308
+ it with:
309
+
310
+ ```
311
+ cargo test --test conformance_softmax
312
+ ```
313
+
314
+ This was run once while authoring the vector to derive
315
+ `softmax_v1.expected` from the reference implementation; the test now
316
+ exists as a standing self-check that the fixture stays correct across
317
+ any future edit to `src/math.rs`. (An `#[ignore]`d
318
+ `print_bits_for_generation` test in the same file is not part of the
319
+ pinned suite; it exists only to regenerate the fixture if the reference
320
+ math ever changes — run with `cargo test --test conformance_softmax
321
+ print_bits -- --ignored --nocapture`.)
322
+
323
+ ### `embed_lookup_v1` (§2.5 `model.embed_tokens.weight` row-major lookup)
324
+
325
+ - Spec reference: `docs/CIS2_SPEC_v0.2.md` §2.5 (tensor shapes:
326
+ `model.embed_tokens.weight` is `[vocab, hidden]`, row-major), as
327
+ consumed by the token-embedding lookup step in `src/main.rs`'s
328
+ per-decode-step forward pass, immediately before the layer loop / §9
329
+ attention: `let start = token_id as usize * hidden; h =
330
+ model.embed_tokens[start..start + hidden].to_vec();`. This lookup is
331
+ pure indexing/copy of already-widened fp32 table rows — no
332
+ floating-point arithmetic is performed — so it is bit-exact by
333
+ construction; the vector pins the row-major `start = token_id *
334
+ hidden` indexing convention itself, not any numeric computation.
335
+ - `vocab=4`, `hidden=6` (deliberately small and hand-sized, same
336
+ rationale as the other vectors' small dimensions).
337
+ - `token_ids=0,3,1` bundles three lookups into one vector (same
338
+ rationale as `matvec_v1`'s several output rows / `attention_block_v1`'s
339
+ several cached KV positions), deliberately in a non-monotonic order
340
+ and including the LAST valid row (`(vocab-1)*hidden`, the largest
341
+ valid start offset) to catch an off-by-one or wrong-stride indexing
342
+ bug a monotonic `0,1,2` order could hide. Row values are `token*10 +
343
+ d` for `d in 0..hidden`, small exactly-representable integers chosen
344
+ so a mis-indexed row is trivially visible in the output, not to model
345
+ any real embedding table.
346
+ - `out_bits` layout: `18` values (`token_ids.len() * hidden`), the
347
+ `hidden`-wide row for `token_ids[0]`, then `token_ids[1]`, then
348
+ `token_ids[2]`, concatenated in that order.
349
+
350
+ **How this vector was derived**: `tests/conformance_embed_lookup.rs`
351
+ reimplements the `start = token_id * hidden` / slice expression above
352
+ verbatim (it does not include `src/math.rs` by path, unlike the other
353
+ `conformance_*.rs` files, since there is no floating-point routine to
354
+ share — the lookup is pure indexing) and runs it on `embed_bits` /
355
+ `token_ids`, computes the SHA-256 digest per the convention above, and
356
+ asserts both the bit patterns and the digest match
357
+ `vectors/embed_lookup_v1.expected`. Run it with:
358
+
359
+ ```
360
+ cargo test --test conformance_embed_lookup
361
+ ```
362
+
363
+ This was run once while authoring the vector to derive
364
+ `embed_lookup_v1.expected`; the test now exists as a standing self-check
365
+ that the fixture stays correct if `src/main.rs`'s lookup expression ever
366
+ changes. (An `#[ignore]`d `print_bits_for_generation` test in the same
367
+ file is not part of the pinned suite; it exists only to regenerate the
368
+ fixture if the reference indexing ever changes — run with `cargo test
369
+ --test conformance_embed_lookup print_bits -- --ignored --nocapture`.)
370
+
371
  ## The `cis2-conformance` CLI
372
 
373
  `src/bin/cis2_conformance.rs` implements the stdin/stdout protocol
vectors/embed_lookup_v1.expected ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Pinned expected output for embed_lookup_v1.txt, computed by reproducing
2
+ # the §2.5 row-major token-embedding lookup (`start = token_id * hidden`,
3
+ # `embed[start..start+hidden]`, verbatim from `src/main.rs`'s
4
+ # forward_step) via `cargo test --test conformance_embed_lookup` (see
5
+ # tests/conformance_embed_lookup.rs and tests/conformance/README.md "How
6
+ # this vector was derived").
7
+ #
8
+ # out_bits layout (18 values, index order): the hidden=6-wide row for
9
+ # token_ids[0]=0, then token_ids[1]=3, then token_ids[2]=1, concatenated
10
+ # in that order.
11
+ out_bits=0x00000000,0x3F800000,0x40000000,0x40400000,0x40800000,0x40A00000,0x41F00000,0x41F80000,0x42000000,0x42040000,0x42080000,0x420C0000,0x41200000,0x41300000,0x41400000,0x41500000,0x41600000,0x41700000
12
+ out_sha256=3d359de9bb9189ae245b65dd68fe129eb945198c13e2dda0abcec7efcfaf8b65
vectors/embed_lookup_v1.txt ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CIS-2 conformance vector: embed_lookup_v1
2
+ # op=embed_lookup, spec ref: docs/CIS2_SPEC_v0.2.md §2.5 (`model.embed_tokens.weight`
3
+ # tensor, shape [vocab, hidden], row-major) as consumed by the per-decode-step
4
+ # token-embedding lookup in `src/main.rs`'s forward pass (the step
5
+ # immediately preceding §9's attention block: `let start = token_id as
6
+ # usize * hidden; h = model.embed_tokens[start..start+hidden].to_vec();`).
7
+ # This lookup is pure indexing/copy of already-widened fp32 table rows --
8
+ # no floating-point arithmetic is performed -- so it is bit-exact by
9
+ # construction; the vector exists to pin the row-major indexing
10
+ # convention itself (`start = token_id * hidden`, contiguous slice of
11
+ # length `hidden`), not any numeric computation.
12
+ #
13
+ # Fields are `key=value`. `vocab`/`hidden` are plain decimal integers.
14
+ # `embed_bits` is `vocab * hidden` values, row-major (row 0 = token 0's
15
+ # hidden-wide embedding, then row 1, ...), comma-separated `0x`-prefixed
16
+ # 32-bit hex IEEE-754 binary32 bit patterns, per
17
+ # tests/conformance/README.md's general convention. `token_ids` is a
18
+ # comma-separated list of plain decimal u32 token ids to look up, in
19
+ # order -- a conforming implementation performs one lookup per id and
20
+ # concatenates the results in that same order (bundling several lookups
21
+ # into one vector, same rationale as matvec_v1's several output rows /
22
+ # attention_block_v1's several cached KV positions in a single call).
23
+ #
24
+ # vocab=4, hidden=6 (deliberately small and hand-sized, same rationale as
25
+ # the other vectors' small dimensions). token_ids=0,3,1 deliberately
26
+ # exercises the first row (offset 0), the LAST row (offset =
27
+ # (vocab-1)*hidden, the largest valid start index), and a middle row, in
28
+ # a non-monotonic order, to catch an off-by-one or wrong-stride indexing
29
+ # bug that a monotonic 0,1,2 order could hide. Row values are
30
+ # `token*10 + d` for d in 0..hidden, small exactly-representable
31
+ # integers chosen purely so a mis-indexed row is trivially visible in
32
+ # the output, not to model any real embedding.
33
+ op=embed_lookup
34
+ spec_ref=docs/CIS2_SPEC_v0.2.md#25-tensor-names-and-shapes-normative
35
+ vocab=4
36
+ hidden=6
37
+ embed_bits=0x00000000,0x3F800000,0x40000000,0x40400000,0x40800000,0x40A00000,0x41200000,0x41300000,0x41400000,0x41500000,0x41600000,0x41700000,0x41A00000,0x41A80000,0x41B00000,0x41B80000,0x41C00000,0x41C80000,0x41F00000,0x41F80000,0x42000000,0x42040000,0x42080000,0x420C0000
38
+ token_ids=0,3,1
vectors/softmax_v1.expected ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ # Pinned expected output for softmax_v1.txt, computed by running the
2
+ # reference implementation's §9.3 softmax_seq (src/math.rs::softmax_seq)
3
+ # via `cargo test --test conformance_softmax` (see
4
+ # tests/conformance_softmax.rs and tests/conformance/README.md "How this
5
+ # vector was derived").
6
+ out_bits=0x3EBB08FC,0x3D4A7FE4,0x3E099CDC,0x3EBB08FC,0x3B84FA38,0x3DA6EEC5
7
+ out_sha256=3458472526c61ca0b1c817e29cb7e1900a28ef84ffffe019770c74f6e9c858ed
vectors/softmax_v1.txt ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CIS-2 conformance vector: softmax_v1
2
+ # op=softmax, spec ref: docs/CIS2_SPEC_v0.2.md §9.3 (Softmax,
3
+ # `softmax_seq`, in place: strict-sequential max-scan, pinned-exp
4
+ # max-subtract, §5.3 sequential-sum denominator, elementwise divide).
5
+ # This vector exercises softmax_seq directly as its own primitive
6
+ # (unlike attention_block_v1, which exercises it as one step of a larger
7
+ # score/softmax/V-mix pipeline where the input scores come from a dot
8
+ # product) -- so the input here is a hand-sized `scores` vector, not
9
+ # derived from any dot product.
10
+ #
11
+ # Fields are `key=value`. `n` is a plain decimal integer. `scores_bits`
12
+ # is a comma-separated list of `0x`-prefixed 32-bit hex IEEE-754 binary32
13
+ # bit patterns, one per input logit, in index order (index 0 first),
14
+ # per tests/conformance/README.md's general convention.
15
+ #
16
+ # n=6. Values: 1.5, -0.5, 0.5, 1.5, -3.0, 0.0 -- deliberately includes an
17
+ # EXACT tie for the maximum at indices 0 and 3 (both 1.5), to exercise
18
+ # §9.3's "strict >, so the FIRST occurrence of the max wins ties"
19
+ # max-scan rule explicitly (the tie is invisible in the final output
20
+ # bits here, since both tied values are bit-identical, but the vector
21
+ # still documents that softmax_v1's max-scan must use strict `>` and
22
+ # must not, e.g., use the LAST occurrence or an unstable comparison).
23
+ # Also includes a large negative outlier (-3.0) to exercise the
24
+ # post-max-sub `exp_pinned` route at a value further from zero, and 0.0
25
+ # as a mid-range plain value.
26
+ op=softmax
27
+ spec_ref=docs/CIS2_SPEC_v0.2.md#93-softmax-softmax_seq-in-place-over-scores0pos
28
+ n=6
29
+ scores_bits=0x3FC00000,0xBF000000,0x3F000000,0x3FC00000,0xC0400000,0x00000000