aefinityAIINC commited on
Commit
909e920
·
verified ·
1 Parent(s): c66ab86

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

Browse files
CIS2_SPEC_v0.3b.md ADDED
@@ -0,0 +1,1683 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CIS-2 — Canonical Floating-Point Semantics for fp32 Transformer Inference, v0.3b
2
+
3
+ **Status: DRAFT, not frozen.** Private research (Aefinity-AI/cis2-fp). HELD —
4
+ not for publication without Justin's explicit decision (2026-08-28 publish
5
+ policy). This document is normative for the scope stated below: a
6
+ conforming, from-spec-text-only clean-room implementation MUST reproduce
7
+ `CIS2_REF` (§12) and the `inv_freq table_digest` (§7.2) bit-for-bit on the
8
+ pinned test vectors of §13, on both x86-64 and aarch64.
9
+
10
+ This is v0.3b of the spec, drafted as v0.1 (`docs/CIS2_SPEC_v0.1.md`), then
11
+ v0.2 (`docs/CIS2_SPEC_v0.2.md`), then an intermediate v0.3 (superseded,
12
+ kept only in §16's changelog and §6.3/§6.7's history notes). **v0.3b closes
13
+ CIS-2's one remaining stated technical limitation** (v0.2 §6.7,
14
+ `docs/H2_TRANSCENDENTAL_RIGOR.md`): `sin_pinned`/`cos_pinned` now use an
15
+ octant range reduction (`r ∈ [-π/4, π/4]`, quadrant index, §6.3),
16
+ f64-staged same as v0.3's attempt, PLUS separate degree-7/8 minimax
17
+ polynomials (replacing the degree-10 Taylor series both v0.2 and v0.3
18
+ used). v0.3 alone (f64-staged reduction, unchanged Taylor polynomial) fixed
19
+ the reduction's catastrophic cancellation but left the *fixed Taylor
20
+ polynomial's own truncation error* dominant (up to ~2813 ULP even after the
21
+ reduction fix) — a PARTIAL result, documented in `docs/E15m_RESULT.md`.
22
+ v0.3b's minimax-polynomial-on-a-smaller-octant approach reaches **≤2 ULP**
23
+ vs. a correctly-rounded fp32 oracle across the full RoPE position domain
24
+ (`pos ∈ [0, 8192)`), closing the bar v0.3 missed. This changes **only**
25
+ §6.3 and §6.6 (`table_digest`, which now hashes one f64 octant-reduction
26
+ constant plus 6 minimax coefficients in place of the prior reduction
27
+ constant(s) and Taylor tables); RoPE's `inv_freq` construction (§7.1,
28
+ `ln_pinned`/`exp_pinned`) and `inv_freq_table_digest` (§7.2) are
29
+ **unaffected** by anything in this task. `CIS2_REF` and `table_digest`
30
+ **both changed at each step** (v0.2→v0.3→v0.3b; §16 has the full changelog
31
+ and all digest values); `inv_freq_table_digest` does **not** change at any
32
+ step. Full design rationale, determinism justification, and honest
33
+ gate-by-gate results (including v0.3's partial miss): `docs/E15m_PREREG.md`
34
+ (pre-registered before implementation) and `docs/E15m_RESULT.md`
35
+ (post-implementation gate results for both v0.3 and v0.3b). This
36
+ document's body is, as with v0.1/v0.2, written to be implementable
37
+ **without** access to `src/` — Appendix A cites exact `file:line`s only so
38
+ a reviewer can audit that this spec did not silently diverge from what the
39
+ reference actually computes.
40
+
41
+ **What conformance buys:** bit-identical fp32 decode of
42
+ `HuggingFaceTB/SmolLM2-135M` given the pinned prompt (§13), reproducible by
43
+ an independent from-spec-text implementation, on any ISA that supports
44
+ IEEE-754 binary32 arithmetic with FTZ/DAZ control (x86-64 MXCSR, aarch64
45
+ FPCR.FZ). Unlike v0.1, this version's RoPE construction (§7) is
46
+ **theta-general**: it is defined for any `rope_theta` value read from
47
+ `config.json`, not just `100000.0`, and has been exercised against a second
48
+ model family (`Qwen/Qwen2.5-0.5B`, `rope_theta = 1000000`) under an
49
+ independent oracle (`docs/E15d_bc_RESULT.md`). This is still deliberately
50
+ narrower than CIS-1 (§1 of `docs/CIS-1_SPEC_v1.0.md` in the public `Aefinity-AI/alice-aegis` repository, https://github.com/Aefinity-AI/alice-aegis):
51
+ floating-point addition is not associative, so this spec does not claim "any
52
+ reduction order is safe" — it claims exactly one pinned reduction order, one
53
+ pinned transcendental route (now including a pinned general `ln`), and one
54
+ pinned digest encoding are collectively sufficient for bit-identity, and
55
+ states each of them exactly.
56
+
57
+ ---
58
+
59
+ ## 0. Scope and non-goals (normative)
60
+
61
+ This spec's primary pinned tuple is unchanged from v0.1: `HuggingFaceTB/SmolLM2-135M`, prompt
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
82
+ clean-room implementations built by *not* reading `src/`, used only to
83
+ find gaps in earlier drafts of this document — evidence this spec was
84
+ tested against, not itself normative). A clean-room re-verification of
85
+ this exact v0.2 document against `cis2-verify2` is tracked separately
86
+ (`docs/E15h_verify2_v0.2` lineage) and is not required for this document's
87
+ own normative status.
88
+
89
+ ## 1. Floating-point environment (normative)
90
+
91
+ **Unchanged from v0.1.** Reproduced verbatim (renumbered where v0.1 section
92
+ numbers shifted below, otherwise identical text and identical pinned
93
+ values):
94
+
95
+ 1.1. **Format**: IEEE-754 binary32 (`f32`) for all decode-path compute.
96
+ Weights are stored on disk as `bfloat16` and widened to `f32` per §4.2
97
+ before any arithmetic.
98
+
99
+ 1.2. **Rounding mode**: round-to-nearest-even (RNE), the IEEE-754 default,
100
+ for every basic operation (`+`, `-`, `*`, `/`, `sqrt`). No other rounding
101
+ mode is set at any point in the decode path. Nothing in this spec changes
102
+ the FPU/SIMD rounding-mode control bits from their IEEE-754 default.
103
+
104
+ 1.3. **FTZ/DAZ MUST be pinned on, on every ISA, before any decode-path fp32
105
+ arithmetic runs:**
106
+ - x86-64: MXCSR bit 15 (FTZ) and bit 6 (DAZ) both set to 1, via direct
107
+ read-modify-write of the MXCSR register (not the deprecated
108
+ `_MM_SET_*` wrapper macros). A conforming implementation MUST assert
109
+ (readback, not just "we called the setter") that both bits are 1
110
+ before proceeding.
111
+ - aarch64: FPCR bit 24 (FZ) set to 1, via `mrs`/`msr fpcr`. aarch64 has
112
+ no separate DAZ control; FZ alone flushes both denormal inputs and
113
+ denormal outputs for scalar and Advanced SIMD binary32/binary64
114
+ arithmetic. FPCR bit 19 (FZ16, half-precision flush-to-zero) is left
115
+ at its architectural default (this reference never uses fp16) — do
116
+ not set it. A conforming implementation MUST assert (readback) that
117
+ FZ is 1 before proceeding.
118
+ - Any other ISA: undefined by this version of the spec; a conforming
119
+ implementation MUST refuse to run (hard compile-time or run-time
120
+ error) rather than silently proceed without an equivalent control.
121
+ - **Adversarial self-test (MUST run and pass before decode)**: with
122
+ FTZ/DAZ pinned, `f32::MIN_POSITIVE (2^-126) * 1.0e-10` MUST equal
123
+ exactly `+0.0` (not a subnormal), and the smallest positive subnormal
124
+ bit pattern `0x00000001` added to `+0.0` MUST also equal exactly
125
+ `+0.0`. (This must be checked with the operands passed through an
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,
132
+ round to `f32` again. A single fused `a*b+c` with one rounding step is
133
+ **non-conforming** even though it may be "more accurate" — it produces
134
+ different bits. In Rust terms: never call `f32::mul_add`; write `a*b + c`
135
+ as two statements/expressions, which LLVM does not auto-fuse absent an
136
+ explicit fast-math flag Rust does not provide. A conforming implementation
137
+ in any language MUST mechanically verify (e.g., disassemble the release
138
+ binary and grep for `vfmadd*`/`vfnmadd*`/`vfmsub*`/`vfnmsub*`/`fmadd`/
139
+ `fmsub` on the target ISA) that the emitted machine code contains zero
140
+ fused multiply-add instructions on the decode path. This has now been
141
+ mechanically verified across 20 compiler configurations (opt-level ×
142
+ target-cpu × ISA) with a reproducing pre-registered digest — see §13.4,
143
+ new in v0.2.
144
+
145
+ 1.5. **No fast-math, no reassociation.** The compiler MUST NOT be given
146
+ 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
154
+ reciprocal-approximation instruction (x86 `rcpps`/`rsqrtps`, ARM
155
+ `frecpe`/`frsqrte`) and never a library "fast inverse sqrt" trick. Any
156
+ conformant IEEE-754 binary32 `sqrt`/`/` implementation on any ISA produces
157
+ identical bits for identical inputs, by the standard itself — this is the
158
+ one part of the arithmetic this spec does not need to additionally pin.
159
+
160
+ ## 2. Model artifact (normative)
161
+
162
+ **Unchanged from v0.1** (verbatim, all pinned values identical):
163
+
164
+ 2.1. **Source**: Hugging Face repo `HuggingFaceTB/SmolLM2-135M`, files
165
+ fetched from the public `resolve/main/` URLs (no authentication required,
166
+ repo is public). No git revision/commit hash is pinned beyond content —
167
+ the artifact is identified **only** by the sha256 hashes below, which is
168
+ strictly stronger than a mutable branch ref:
169
+
170
+ | file | sha256 |
171
+ |---|---|
172
+ | `model.safetensors` | `80521b40281d6ce74e35c9282c22539e75aa0ac8578892b2a59955ef78d55da1` |
173
+ | `config.json` | `1d556eab73b69c7f11f64c557a2f9c6f440bd4c6b89bb2584a6b498c92603843` |
174
+ | `tokenizer.json` | `9ca9acddb6525a194ec8ac7a87f24fbba7232a9a15ffa1af0c1224fcd888e47c` |
175
+
176
+ A conforming implementation MUST verify all three sha256 hashes before use
177
+ and MUST fail loudly (not silently proceed) on mismatch.
178
+
179
+ 2.2. **Architecture parameters**, taken from `config.json` (a conforming
180
+ implementation MUST read these from the file, not hardcode them, but their
181
+ pinned values for this artifact are, for the reader's convenience):
182
+
183
+ | field | value |
184
+ |---|---|
185
+ | `hidden_size` | 576 |
186
+ | `intermediate_size` | 1536 |
187
+ | `num_hidden_layers` | 30 |
188
+ | `num_attention_heads` | 9 |
189
+ | `num_key_value_heads` | 3 |
190
+ | `hidden_act` | `silu` |
191
+ | `rms_norm_eps` | `1e-05` (f64 in JSON; §2.3 pins its f32 cast) |
192
+ | `rope_theta` | `100000` (`100000.0`) |
193
+ | `rope_interleaved` | `false` |
194
+ | `max_position_embeddings` | 8192 |
195
+ | `tie_word_embeddings` | `true` |
196
+ | `torch_dtype` | `bfloat16` |
197
+ | `vocab_size` | 49152 |
198
+
199
+ Derived: `head_dim = hidden_size / num_attention_heads = 576/9 = 64`
200
+ (exact integer division); `group = num_attention_heads / num_key_value_heads
201
+ = 9/3 = 3` (GQA group size); `half = head_dim/2 = 32`.
202
+
203
+ 2.3. **`rms_norm_eps` f32 cast**: the JSON value `1e-05` is parsed as an
204
+ IEEE-754 `f64` (`1.0e-5`), then cast to `f32` via a single RNE rounding
205
+ (Rust `as f32`, equivalent to any IEEE-754-conformant `f64`→`f32`
206
+ narrowing conversion). Pinned bit pattern:
207
+
208
+ ```
209
+ EPS_F32 = 0x3727C5AC (== (1.0e-5f64) as f32)
210
+ ```
211
+
212
+ 2.4. **`rope_theta` restriction — REMOVED in v0.2** (v0.1's §2.4 required
213
+ `rope_theta == 100000.0` exactly and refused to run otherwise; §7's
214
+ theta-general construction removes this restriction, closing v0.1 §14.1 —
215
+ see §7 and §16).
216
+
217
+ 2.5. **Tensor names and shapes** (row-major, `[out_features, in_features]`
218
+ for every linear layer, matching PyTorch's `nn.Linear.weight` layout — a
219
+ matvec is `y[o] = Σ_i w[o,i]·x[i]`, §5.1):
220
+
221
+ ```
222
+ model.embed_tokens.weight [vocab, hidden]
223
+ model.layers.{i}.input_layernorm.weight [hidden] for i in 0..30
224
+ model.layers.{i}.post_attention_layernorm.weight [hidden]
225
+ model.layers.{i}.self_attn.q_proj.weight [hidden, hidden]
226
+ model.layers.{i}.self_attn.k_proj.weight [n_kv_heads*head_dim, hidden]
227
+ model.layers.{i}.self_attn.v_proj.weight [n_kv_heads*head_dim, hidden]
228
+ model.layers.{i}.self_attn.o_proj.weight [hidden, hidden]
229
+ model.layers.{i}.mlp.gate_proj.weight [inter, hidden]
230
+ model.layers.{i}.mlp.up_proj.weight [inter, hidden]
231
+ model.layers.{i}.mlp.down_proj.weight [hidden, inter]
232
+ model.norm.weight [hidden]
233
+ ```
234
+
235
+ There is **no** separate `lm_head.weight` tensor in this checkpoint
236
+ (confirmed by safetensors header inspection: 272 tensors total, all
237
+ `BF16`, no `lm_head.*` name present) — this matches
238
+ `tie_word_embeddings: true`. The LM head matmul (§11) reuses
239
+ `model.embed_tokens.weight` directly as the `[vocab, hidden]` output
240
+ projection matrix; no separate weight is loaded or derived for it.
241
+
242
+ Every tensor's on-disk dtype is `BF16` (2 bytes/element, little-endian
243
+ 16-bit pattern per element, raw `safetensors` payload bytes taken two at a
244
+ time as `u16::from_le_bytes`). Every tensor MUST be widened per §4.2
245
+ before use; no tensor is used in bf16 form at compute time.
246
+
247
+ **Informative, v0.2**: a second model family, `Qwen/Qwen2.5-0.5B`
248
+ (different `rope_theta`, GQA shape, `attention_bias=true` on q/k/v
249
+ projections, optionally untied `lm_head.weight`), has been run through the
250
+ same reference code path unmodified beyond config-driven parameters
251
+ (`docs/E15d_bc_RESULT.md`). This is evidence the reference's architecture
252
+ handling generalizes; it is not a second pinned §13 test vector in this
253
+ version.
254
+
255
+ ## 3. Tokenizer, prompt, and decode protocol (normative)
256
+
257
+ 3.1. **Tokenizer.** **v0.2.1 (H4, this section): fully re-specified,
258
+ closing H3 BLOCKER-2** (`docs/H3_SPEC_AUDIT.md`; carried forward from
259
+ `verify3/SPEC_GAPS_v0.2.md` items 1–2). v0.1/v0.2's text ("loaded as a
260
+ complete, self-contained HuggingFace `tokenizers`-format tokenizer
261
+ (BPE-family; the exact merge/vocab table is entirely contained in this one
262
+ file — no external vocab/merges files, no additional special-token config
263
+ beyond what `tokenizer.json` itself specifies)") is retained but is no
264
+ longer the full normative surface: it is necessary but not sufficient, since
265
+ it does not define the BPE algorithm, the pretokenizer, the byte-level
266
+ mapping, or the merge tie-break rule. Those are pinned below.
267
+
268
+ 3.1.1. **Artifact.** The `tokenizer.json` file shipped with the checkpoint,
269
+ bound by content hash: `sha256(tokenizer.json) =
270
+ 9ca9acddb6525a194ec8ac7a87f24fbba7232a9a15ffa1af0c1224fcd888e47c` (§2.1's
271
+ table, repeated here for locality). A conforming implementation MUST verify
272
+ this hash before use. This one file is self-contained: it embeds the full
273
+ vocab (49152 entries), the full ordered merge-rank list (48900 pairs), the
274
+ pre-tokenizer config, and the 17 special/added tokens (§3.1.6) — no external
275
+ vocab.json/merges.txt/tokenizer_config.json is consulted.
276
+
277
+ 3.1.2. **Reference library binding (normative fallback).** The reference
278
+ implementation calls the Rust `tokenizers` crate, version **0.23.1**
279
+ (`Cargo.lock`; upstream source
280
+ `https://crates.io/crates/tokenizers/0.23.1`), specifically
281
+ `tokenizers::Tokenizer::from_file(&tokenizer_path)` then
282
+ `.encode(prompt, false)` (`src/main.rs:487-488,536`). Per this spec's
283
+ preference for algorithm over library citation: §3.1.3–3.1.6 below give the
284
+ byte-level BPE algorithm in full, transcribed from that crate's source
285
+ (`src/pre_tokenizers/byte_level.rs`, `src/pre_tokenizers/digits.rs`,
286
+ `src/models/bpe/word.rs`, `src/models/bpe/model.rs`, all at tag `v0.23.1`)
287
+ and independently verified in this audit to reproduce §3.3's pinned
288
+ token ids using the Python `tokenizers` binding (same crate, same version
289
+ family) loading the actual downloaded `tokenizer.json`. If any future
290
+ implementer finds an algorithmic edge case this section under-specifies,
291
+ `tokenizers` crate v0.23.1's published source is the normative
292
+ tie-breaker — this citation, not just the informal "HuggingFace
293
+ `tokenizers`-format" phrase, is part of the normative surface (the same
294
+ pattern this spec already uses for `sha256` as an external cited standard,
295
+ §2.1).
296
+
297
+ 3.1.3. **Pipeline, in order:** normalizer (none — `tokenizer.json`'s
298
+ `normalizer` field is `null`) → pre-tokenizer (§3.1.4, splits the input
299
+ string into a sequence of "words") → per-word byte-level BPE encode
300
+ (§3.1.5) → no post-processor (`tokenizer.json`'s `post_processor` field is
301
+ `null`; this is what makes `add_special_tokens=false`, §3.3, produce zero
302
+ inserted tokens rather than a template).
303
+
304
+ 3.1.4. **Pre-tokenizer.** `tokenizer.json`'s `pre_tokenizer` field is
305
+ `{"type": "Sequence", "pretokenizers": [
306
+ {"type": "Digits", "individual_digits": true},
307
+ {"type": "ByteLevel", "add_prefix_space": false, "trim_offsets": true,
308
+ "use_regex": true}]}`. Applied in list order to the raw Unicode input
309
+ string:
310
+ a. **Digits** (`individual_digits=true`): split the string at every
311
+ maximal run of Unicode-numeric characters (`char::is_numeric`),
312
+ *isolating* each individual digit as its own one-character segment
313
+ (contrast with `individual_digits=false`, which would keep a digit
314
+ run together — not used here). Non-digit segments pass through
315
+ unsplit. (No digits occur in the pinned prompt `"Once upon a time"`,
316
+ so this stage is a no-op on the §13.1 test vector but MUST still be
317
+ applied for other inputs.)
318
+ b. **ByteLevel** (`add_prefix_space=false`, `use_regex=true`): for each
319
+ segment from (a), do NOT prepend a space (this checkpoint's config
320
+ differs from the GPT-2 default of `add_prefix_space=true`); then
321
+ split it further using the literal GPT-2 pre-tokenizer regex,
322
+ applied with Unicode property classes, isolated-delimiter semantics
323
+ (each match becomes its own segment, unlike the ordinary
324
+ split/no-delimiter mode):
325
+ ```
326
+ 's|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+
327
+ ```
328
+ (verbatim from `tokenizers` crate `src/pre_tokenizers/byte_level.rs`,
329
+ itself citing `https://github.com/openai/gpt-2/blob/master/src/encoder.py#L98`).
330
+ Then, for every resulting segment, remap **every UTF-8 byte** of that
331
+ segment's text through the byte→unicode table of §3.1.5.a, producing
332
+ a string of the same byte-count length (each input byte becomes
333
+ exactly one output Unicode codepoint). This byte-remapped string is
334
+ the final "word" handed to the BPE model (§3.1.5).
335
+
336
+ 3.1.5. **Byte-level BPE model** (`tokenizer.json`'s `model` field: `type =
337
+ "BPE"`, `dropout = null`, `unk_token = null`, `continuing_subword_prefix =
338
+ null`, `end_of_word_suffix = null`, `fuse_unk = false`,
339
+ `byte_fallback = false`, `ignore_merges = false`). `dropout = null` means
340
+ the merge process below is fully deterministic (no probabilistic merge
341
+ skipping); `unk_token = null` and `byte_fallback = false` are moot because
342
+ the byte-level remap of 3.1.4.b guarantees every input byte already maps to
343
+ some single-character token that is a base entry in `vocab` (step a below),
344
+ so the "no matching vocab entry" branch is never taken for any input.
345
+ a. **Byte→unicode map construction** (verbatim from
346
+ `tokenizers` crate `bytes_char()`, itself following
347
+ `https://github.com/openai/gpt-2/blob/master/src/encoder.py#L9`):
348
+ starting from the empty list, let `bs` = the 188 byte values in the
349
+ three ranges `0x21..=0x7E` (`!`..`~`), `0xA1..=0xAC`, `0xAE..=0xFF`,
350
+ each mapped to itself as a Unicode codepoint (`char::from_u32(b as
351
+ u32)`); then, in ascending byte order `0..=255`, for every byte `b`
352
+ NOT already in `bs`, append `b` to `bs` and map it to codepoint
353
+ `256 + n` where `n` is a counter starting at 0 and incremented after
354
+ each such assignment. This produces a total bijection over all 256
355
+ byte values (188 map to themselves as printable-ASCII/Latin-1
356
+ codepoints, the remaining 68 — control chars, space, DEL, and the
357
+ `0x7F..=0xA0`/`0xAD` gap — map to codepoints `256..323`, e.g. byte
358
+ `0x20` (space) maps to U+0120 `Ġ`, byte `0x0A` (newline) maps to
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);
365
+ look each single character up in `vocab` (the base single-byte
366
+ vocabulary entries, ids 18–273 in this tokenizer's vocab, are exactly
367
+ the 256 codepoints of 3.1.5.a, so this lookup always succeeds — see
368
+ the `unk`/`byte_fallback` note above); the resulting list of
369
+ `(vocab_id, byte_length=1)` pairs, in original left-to-right order, is
370
+ the word's initial symbol sequence.
371
+ c. **Merge loop (deterministic, rank-ordered, leftmost-tie-break).**
372
+ `tokenizer.json`'s `model.merges` is an ordered list of 48900 symbol
373
+ pairs; its list position IS the pair's merge rank (rank 0 = highest
374
+ priority, applied first; rank 48899 = lowest). Given the initial
375
+ symbol sequence from (b):
376
+ i. Build a priority queue seeded with every adjacent pair in the
377
+ current symbol sequence that appears in `model.merges`, each
378
+ keyed `(rank, position)`.
379
+ ii. Repeatedly pop the queue entry with the **lowest rank**; if two
380
+ queued entries have equal rank (impossible here since merge
381
+ ranks are a total order over distinct pairs, but stated for
382
+ completeness as the crate's own tie-break), the entry with the
383
+ **lower (leftmost) position** wins.
384
+ iii. Before applying a popped entry, re-validate it still describes
385
+ an adjacent, unmerged pair at that position (earlier merges may
386
+ have invalidated it); if stale, discard and continue.
387
+ iv. Apply the merge: replace the two symbols with one symbol whose
388
+ vocab id is `model.merges[rank]`'s resulting token id (from
389
+ `tokenizer.json`'s corresponding `model.vocab` entry for the
390
+ concatenated string) and whose byte-length is the sum of the
391
+ two merged symbols'; enqueue any newly-adjacent mergeable pairs
392
+ this creates (with the previous and/or next symbol) at their
393
+ own rank.
394
+ v. Repeat ii–iv until the queue is empty. The final symbol sequence
395
+ (in order) is that word's token id sequence.
396
+ d. **Concatenation.** The prompt's full token id sequence is the
397
+ concatenation, in original left-to-right order, of every word's token
398
+ id sequence from (c), across all words produced by §3.1.4.
399
+
400
+ 3.1.6. **Special/added tokens.** `tokenizer.json`'s `added_tokens` array
401
+ pins 17 special tokens, ids 0–16 (`<|endoftext|>`, `<|im_start|>`,
402
+ `<|im_end|>`, `<repo_name>`, `<reponame>`, `<file_sep>`, `<filename>`,
403
+ `<gh_stars>`, `<issue_start>`, `<issue_comment>`, `<issue_closed>`,
404
+ `<jupyter_start>`, `<jupyter_text>`, `<jupyter_code>`, `<jupyter_output>`,
405
+ `<empty_output>`), each with `special: true`. Per §3.3,
406
+ `add_special_tokens = false` means **none** of these are inserted for the
407
+ pinned prompt — no BOS (`<|endoftext|>`, id 0, is this tokenizer's only
408
+ BOS/EOS-like token and is never emitted for this prompt), no EOS, no
409
+ chat-template tokens. This is why the pinned `prompt_token_ids` (§3.3) has
410
+ exactly 4 entries, not 5 or more.
411
+
412
+ 3.1.7. **Worked example — self-check before running the model.** Applying
413
+ §3.1.3–3.1.6 to the pinned prompt `"Once upon a time"` (§3.2):
414
+ - No digits (§3.1.4.a is a no-op).
415
+ - ByteLevel regex (§3.1.4.b) with `add_prefix_space=false` splits the
416
+ ASCII string into 4 words: `"Once"`, `" upon"`, `" a"`, `" time"`
417
+ (each of the latter three carries its leading space per the ` ?\p{L}+`
418
+ alternative). Byte-remapping (§3.1.5.a) maps each literal space byte
419
+ `0x20` to `Ġ` (U+0120) and leaves all other ASCII letters unchanged
420
+ (they are in the `0x21..=0x7E` self-mapped range), giving the 4
421
+ byte-remapped words `"Once"`, `"Ġupon"`, `"Ġa"`, `"Ġtime"`.
422
+ - Per-word BPE merge (§3.1.5.b–d) on this tokenizer's `vocab`/`merges`
423
+ reduces each word to exactly **one** token each (each whole word is
424
+ itself a `vocab` entry reachable by the merge sequence — a property of
425
+ this particular checkpoint's trained merge table for these four common
426
+ words, not a general guarantee): `"Once"` → id `6403`, `"Ġupon"` → id
427
+ `1980`, `"Ġa"` → id `253`, `"Ġtime"` → id `655`.
428
+ - Concatenation (§3.1.5.d) with no special tokens (§3.1.6, §3.3) gives
429
+ ```
430
+ prompt_token_ids = [6403, 1980, 253, 655]
431
+ ```
432
+ — bit-for-bit the pinned value already stated in §3.3 and reproduced
433
+ in §13.1. An implementer can check their own tokenizer stage against
434
+ this worked example (word segmentation, byte remap, and final ids)
435
+ *before* running any model math, isolating tokenizer bugs from
436
+ numeric-core bugs.
437
+
438
+ 3.1.8. **Cross-check performed for this section (informative, not itself
439
+ part of the normative text).** The exact `tokenizer.json` cited by §3.1.1's
440
+ hash was fetched from `https://huggingface.co/HuggingFaceTB/SmolLM2-135M/
441
+ resolve/main/tokenizer.json`; its sha256 was confirmed to equal
442
+ `9ca9acddb6...` (§3.1.1) byte-for-byte; loading it with the Python
443
+ `tokenizers` library (`Tokenizer.from_file(...).encode("Once upon a time",
444
+ add_special_tokens=False)`) reproduced `[6403, 1980, 253, 655]` exactly,
445
+ confirming both this section's transcription of the algorithm and its
446
+ worked example (§3.1.7) against a live run of the actual pinned artifact —
447
+ not merely against source-code reading.
448
+
449
+ 3.2. **Prompt**: the literal ASCII string `Once upon a time` (no
450
+ leading/trailing whitespace beyond what is written here, no chat template
451
+ applied, no system prompt, no BOS/EOS token added or implied by any
452
+ wrapper). This is raw next-token completion, not chat-formatted.
453
+
454
+ 3.3. **BOS/special-token handling**: tokenization MUST be performed with
455
+ `add_special_tokens = false` (i.e. the tokenizer's raw BPE encode of the
456
+ prompt string only — no BOS, no EOS, no any other special token
457
+ prepended/appended). Pinned result:
458
+
459
+ ```
460
+ prompt_token_ids = [6403, 1980, 253, 655] (4 tokens, u32)
461
+ ```
462
+
463
+ 3.4. **Decode protocol**: greedy only (argmax every step, §11.2), no
464
+ sampling, no temperature, no top-k/top-p. Exactly **16** tokens are
465
+ generated after the 4-token prompt, unconditionally — **EOS is not
466
+ checked and does not stop generation early** (matching CIS-1's own Tier-3
467
+ "EOS ignored" precedent, CIS-1 spec §8). Position indices are
468
+ `0, 1, 2, 3` for the 4 prompt tokens (prefill) and `4, 5, ..., 19` for the
469
+ 16 generated tokens, assigned strictly in generation order (prompt
470
+ positions first, generated positions immediately following, no gaps, no
471
+ re-indexing).
472
+
473
+ 3.5. **KV-cache equivalence (informative, not itself a conformance
474
+ requirement)**: the reference recomputes attention incrementally with a
475
+ KV cache that stores exactly the post-RoPE K/V vectors a from-scratch
476
+ full-recompute-per-step forward pass would produce (pure memoization, not
477
+ a reduction-order change). §14.5 (v0.1 numbering) independently confirms
478
+ the cached and oracle (full-recompute, no cache) paths agree. A conforming
479
+ implementation MAY use a KV cache or MAY recompute from scratch each
480
+ step; both are conformant iff they produce bit-identical logits — this
481
+ spec pins the *math*, not the caching strategy.
482
+
483
+ ## 4. bf16 → fp32 widening (normative)
484
+
485
+ **Unchanged from v0.1** (verbatim):
486
+
487
+ 4.1. **Formula**: exact, lossless bit-shift, not a rounding conversion.
488
+ For a bf16 value with raw 16-bit pattern `b` (as loaded via
489
+ `u16::from_le_bytes` on the 2 little-endian bytes of that element in the
490
+ safetensors payload):
491
+
492
+ ```
493
+ f32_bits = (b as u32) << 16
494
+ widened = f32::from_bits(f32_bits)
495
+ ```
496
+
497
+ This is exact because bf16's sign(1)/exponent(8)/mantissa(7) layout is
498
+ identical to fp32's top 16 bits with the low 16 mantissa bits defined as
499
+ zero — bf16's exponent field has the same width and bias as fp32's, so
500
+ there is no exponent range issue and no rounding decision to make. This
501
+ MUST be implemented as the literal bit operation above, not as a call
502
+ through any "convert" library routine that might round or normalize
503
+ differently.
504
+
505
+ 4.2. Every tensor listed in §2.5 is widened element-wise via §4.1 at load
506
+ time before any arithmetic touches it. No tensor is used in bf16 form.
507
+
508
+ ## 5. Numeric reduction primitives (normative)
509
+
510
+ **Unchanged from v0.1** (verbatim):
511
+
512
+ 5.1. **Sequential dot product.** For vectors `a`, `b` of equal length `n`:
513
+
514
+ ```
515
+ acc = 0.0_f32
516
+ for i in 0..n:
517
+ p = a[i] * b[i] # separate multiply, RNE-rounded to f32
518
+ acc = acc + p # separate add, RNE-rounded to f32
519
+ return acc
520
+ ```
521
+
522
+ Strictly left-to-right, index order `0, 1, ..., n-1`. No pairwise tree, no
523
+ chunking, no reordering by magnitude. This is the **only** conforming
524
+ reduction order for every dot product and every "sum of products" loop in
525
+ this spec (matvec rows §5.2, attention score dot §9.2, V-mix §9.4).
526
+ `dot_seq` is order-sensitive by design: dotting `[1e8, 1.0, -1e8]` against
527
+ `[1.0, 1.0, 1.0]` in this order gives exactly `0.0_f32` (the `1.0` term is
528
+ lost to rounding against the `1e8` partial sum) — any other order gives a
529
+ different, nonzero answer; a conforming implementation MUST reproduce
530
+ `0.0_f32` on this specific input as a regression check.
531
+
532
+ 5.2. **Matvec.** `y[o] = dot_seq(w[o, :], x)` for `o = 0..out_features`,
533
+ where `w[o, :]` is row `o` of the row-major `[out_features, in_features]`
534
+ weight tensor (§2.5). Each output element is one independent §5.1 dot
535
+ product; rows may be computed in any order or in parallel relative to
536
+ each other (row order does not affect any single row's bits), but each
537
+ row's own reduction MUST use §5.1's exact order.
538
+
539
+ 5.3. **Sequential sum.** For a vector `a` of length `n` (used for
540
+ sum-of-squares in RMSNorm §8 and the softmax denominator §10):
541
+
542
+ ```
543
+ acc = 0.0_f32
544
+ for i in 0..n:
545
+ acc = acc + a[i] # separate add, RNE-rounded to f32
546
+ return acc
547
+ ```
548
+
549
+ Same left-to-right, no-reassociation rule as §5.1.
550
+
551
+ 5.4. **Elementwise add** (residual connections, §9.5/§10.3, and optional
552
+ QKV bias, §9.1 new-in-v0.2): plain `out[i] = a[i] + b[i]` for every `i`,
553
+ one IEEE-754 add each, no reduction involved.
554
+
555
+ ## 6. Transcendental functions (normative)
556
+
557
+ There are now **three** routes (v0.1 had two); this spec pins all three
558
+ exactly. §6.1/§6.2/§6.3 are unchanged from v0.1; §6.5 is new in v0.2.
559
+
560
+ ### 6.1 rsqrt — route (a), correctly-rounded, no table
561
+
562
+ ```
563
+ rsqrt(x) = 1.0_f32 / x.sqrt()
564
+ ```
565
+
566
+ Composed from two IEEE-754-mandatory correctly-rounded operations
567
+ (`sqrt`, then `/`). Because both are mandatory-correctly-rounded under the
568
+ standard, **any** conformant IEEE-754 binary32 implementation on any ISA
569
+ produces identical bits for identical `x` — no coefficient table, no
570
+ digest, no pinning needed beyond "use the standard's `sqrt` and `/`, not
571
+ an approximate hardware reciprocal-sqrt instruction" (already stated in
572
+ §1.6). `rsqrt(64.0) == 0.125` exactly (`0x3E000000`) is a conformance
573
+ check.
574
+
575
+ ### 6.2 exp — route (b), pinned Cephes-pattern polynomial
576
+
577
+ For `x` a finite `f32`:
578
+
579
+ 1. If `x` is NaN, return NaN.
580
+ 2. If `x > 88.0`, return `+Infinity`.
581
+ 3. If `x < -88.0`, return `0.0`.
582
+ 4. Range reduction: find integer `k` and remainder `r` such that
583
+ `x ≈ k·ln(2) + r`, `|r|` small, via:
584
+ ```
585
+ t = x * EXP_LOG2E # x / ln(2), separate mul
586
+ z0 = t + 0.5
587
+ k = floor(z0) # k as f32, truncated toward -inf at z0
588
+ kc1 = k * EXP_C1
589
+ r0 = x - kc1
590
+ kc2 = k * EXP_C2
591
+ r = r0 - kc2 # two-part ln(2) split, Cephes pattern
592
+ ```
593
+ 5. Polynomial evaluation (Horner, strict left-to-right, descending
594
+ coefficient index, no FMA):
595
+ ```
596
+ r2 = r * r
597
+ poly = EXP_P[0]
598
+ for i in 1..=5:
599
+ poly = poly * r + EXP_P[i]
600
+ m1 = poly * r2
601
+ poly2 = m1 + r
602
+ result = poly2 + 1.0
603
+ ```
604
+ (This computes `exp(r) ≈ 1 + r + r²·P(r)` with `P` the degree-5
605
+ polynomial `EXP_P[0]·r⁵ + EXP_P[1]·r⁴ + ... + EXP_P[5]`.)
606
+ 6. Reconstruct `exp(x) = 2^k · result` via **exact bit manipulation** of
607
+ the `f32` exponent field (`ldexp_exact`, §6.2.1) — not a library
608
+ `ldexp`/multiply-by-power-of-2-computed-as-a-float call.
609
+
610
+ Pinned coefficients (`f32` bit patterns, hex, big-endian digit order of
611
+ the 32-bit pattern as conventionally written — i.e. `0xSEEEEEEE MMMMMMM`
612
+ read as one `u32`):
613
+
614
+ ```
615
+ EXP_LOG2E = 0x3FB8AA3B (1/ln2)
616
+ EXP_C1 = 0x3F318000 (ln2 hi)
617
+ EXP_C2 = 0xB95E8083 (ln2 lo, negative)
618
+ EXP_P[0] = 0x39506967
619
+ EXP_P[1] = 0x3AB743CE
620
+ EXP_P[2] = 0x3C088908
621
+ EXP_P[3] = 0x3D2AA9C1
622
+ EXP_P[4] = 0x3E2AAAAA
623
+ EXP_P[5] = 0x3F000000 (== 0.5 exactly)
624
+ ```
625
+
626
+ #### 6.2.1 `ldexp_exact(x, k)` — exact scale-by-power-of-2
627
+
628
+ ```
629
+ if x == 0.0: return x
630
+ bits = x.to_bits()
631
+ exp_bits = (bits >> 23) & 0xFF # 8-bit biased exponent field
632
+ new_exp = exp_bits + k # k is a signed integer
633
+ if new_exp <= 0: return 0.0 # underflow — FTZ/DAZ (§1.3) governs anyway
634
+ if new_exp >= 0xFF: return (x.is_sign_negative() ? -Infinity : +Infinity)
635
+ new_bits = (bits & !(0xFF << 23)) | (new_exp << 23) # replace exponent field only
636
+ return f32::from_bits(new_bits)
637
+ ```
638
+ Sign and mantissa bits are untouched; only the 8-bit exponent field is
639
+ replaced. This is exact (no rounding) whenever the result stays in the
640
+ normal-or-flush range, which the `exp()` domain clamp (steps 2–3) and the
641
+ saturation branches above guarantee.
642
+
643
+ ### 6.3 sin/cos — route (b), octant reduction + SEPARATE minimax polynomials (CHANGED in v0.3b — supersedes v0.3, closes v0.2 §6.7's finding)
644
+
645
+ **History (repeated here for §16's changelog):**
646
+ - **v0.2's construction** (no longer normative): a two-part-π split
647
+ (`TWO_PI_HI`/`TWO_PI_LO`) done entirely in `f32`. Found
648
+ (`docs/H2_TRANSCENDENTAL_RIGOR.md`, v0.2 §6.7) to suffer catastrophic
649
+ cancellation growing with the RoPE angle's magnitude, up to 1104 ULP /
650
+ 1e-4 relative error by decode position 19, and ~0.58 relative
651
+ (unusable) toward `max_position_embeddings = 8192` — an accuracy
652
+ defect, not a determinism defect.
653
+ - **v0.3's construction** (no longer normative, superseded by v0.3b
654
+ below): fixed the reduction by staging it through `f64` (exact widen,
655
+ correctly-rounded f64 div/round/mul/sub, correctly-rounded narrow back
656
+ to f32) while keeping v0.2's degree-10 Taylor polynomials on the
657
+ resulting `r ∈ [-π, π]` unchanged. This closed the *reduction's*
658
+ accuracy defect (reduced remainder now accurate to a few ULP of f64,
659
+ utterly negligible next to f32's own ULP) but left the *fixed Taylor
660
+ polynomial's own truncation error* as the dominant remaining term,
661
+ worst near `|r| ≈ π` and near `sin(r)`/`cos(r)` zero crossings — up to
662
+ ~2813 raw ULP / 486 ULP filtered away from zero crossings even after
663
+ the reduction fix, missing this spec family's pre-registered ≤2-ULP
664
+ accuracy bar (`docs/E15m_PREREG.md`, `docs/E15m_RESULT.md`'s v0.3
665
+ section — reported honestly as a partial result, not silently narrowed).
666
+
667
+ **v0.3b's construction (normative).** Reducing to a *quarter*-period
668
+ octant (`r ∈ [-π/4, π/4]`, quadrant index `k mod 4`) instead of a full
669
+ period (`r ∈ [-π, π]`) lets a much lower-degree **minimax** polynomial
670
+ (fit to minimize worst-case error over the whole reduced interval, rather
671
+ than a Taylor series truncated at an arbitrary degree) reach far better
672
+ accuracy across that smaller domain. Still f64-staged (same determinism
673
+ argument as v0.3), still no FMA, still no fast-math/reassociation (§1.4/
674
+ §1.5):
675
+
676
+ **Reduction** (Cody–Waite pattern, f64-staged, strict left-to-right):
677
+
678
+ ```
679
+ xd = x as f64 # exact widening cast, f32 -> f64, zero rounding error
680
+ k = round(xd / PI_2_F64) # f64 division (correctly rounded), then round-to-
681
+ # nearest-integer, ties away from zero (f64::round()
682
+ # semantics: pure function of the input bit pattern,
683
+ # no ISA-dependent instruction selection, §1.5)
684
+ khi = k * PI_2_F64 # f64 multiply (correctly rounded)
685
+ r64 = xd - khi # f64 subtract (correctly rounded)
686
+ r = r64 as f32 # single correctly-rounded f64 -> f32 narrowing cast
687
+ quadrant = ((k as i64) % 4 + 4) % 4 # k is exact (small integer in f64), cast to i64 losslessly
688
+ ```
689
+
690
+ ```
691
+ PI_2_F64 = 0x3FF921FB54442D18 (f64 bit pattern; == 1.5707963267948966, the
692
+ correctly-rounded f64 value of pi/2)
693
+ ```
694
+
695
+ **Why f64-staging suffices instead of full Payne-Hanek**: unchanged
696
+ argument from v0.3 (`docs/E15m_PREREG.md`) — the RoPE angle is bounded,
697
+ `|x| = |pos · inv_freq[i]| < max_position_embeddings = 8192` (§2.2, §7.1),
698
+ which leaves ample f64 mantissa headroom regardless of whether the modulus
699
+ is `2π` or `π/2`.
700
+
701
+ **Polynomials** (Cephes `sinf`/`cosf`'s minimax coefficients — long
702
+ public-domain algorithm shape, coefficients independently pinned as
703
+ literal f32 bit patterns per this spec's own convention, §6.2's preamble):
704
+ for `r ∈ [-π/4, π/4]`, strict left-to-right, no FMA:
705
+
706
+ ```
707
+ # sin(r) = r + r^3 * (SIN_C0 + r^2 * (SIN_C1 + r^2 * SIN_C2))
708
+ r2 = r * r
709
+ inner = SIN_C2
710
+ inner = inner * r2 + SIN_C1
711
+ inner = inner * r2 + SIN_C0
712
+ r3 = r2 * r
713
+ term = inner * r3
714
+ sin_r = r + term
715
+
716
+ # cos(r) = 1 - r^2/2 + r^4 * (COS_C0 + r^2 * (COS_C1 + r^2 * COS_C2))
717
+ r2 = r * r
718
+ inner = COS_C2
719
+ inner = inner * r2 + COS_C1
720
+ inner = inner * r2 + COS_C0
721
+ r4 = r2 * r2
722
+ term = inner * r4
723
+ half_r2 = 0.5 * r2
724
+ step1 = 1.0 - half_r2
725
+ cos_r = step1 + term
726
+ ```
727
+
728
+ ```
729
+ SIN_C0 = 0xBE2AAAA3 (== -0.16666655242443085, r^3 coefficient)
730
+ SIN_C1 = 0x3C08839E (== 0.008332161232829094, r^5 coefficient)
731
+ SIN_C2 = 0xB94CA1F9 (== -0.00019515295571181923, r^7 coefficient)
732
+
733
+ COS_C0 = 0x3D2AAAA5 (== 0.04166664555668831, r^4 coefficient)
734
+ COS_C1 = 0xBAB6061A (== -0.0013887316454201937, r^6 coefficient)
735
+ COS_C2 = 0x37CCF5CE (== 2.44331567955669e-05, r^8 coefficient)
736
+ ```
737
+
738
+ **Quadrant sign/swap** (standard `sin(k·π/2 + r)`/`cos(k·π/2 + r)`
739
+ identities for `k mod 4 ∈ {0,1,2,3}`):
740
+
741
+ ```
742
+ quadrant = 0: sin(x) = sin_r cos(x) = cos_r
743
+ quadrant = 1: sin(x) = cos_r cos(x) = -sin_r
744
+ quadrant = 2: sin(x) = -sin_r cos(x) = -cos_r
745
+ quadrant = 3: sin(x) = -cos_r cos(x) = sin_r
746
+ ```
747
+
748
+ **Determinism**: identical argument to v0.3's (§6.3 history above,
749
+ `docs/E15m_PREREG.md`) — every reduction op is an exact widening cast, an
750
+ IEEE-754-mandatory correctly-rounded f64 arithmetic operation,
751
+ `f64::round()` (deterministic bit-pattern function), or a single
752
+ correctly-rounded narrowing cast; the polynomial evaluation is ordinary
753
+ strict-left-to-right f32 arithmetic, no FMA, no reassociation.
754
+
755
+ **Accuracy** (§6.7's re-measurement): max ULP vs. a correctly-rounded fp32
756
+ oracle over the full RoPE position domain (`pos ∈ [0, 8192)`, both pinned
757
+ `rope_theta` values) is now **≤2 ULP** (measured max 1.5 ULP on a dense
758
+ grid, `scripts/h2m_accuracy_harness.py`), closing the accuracy bar this
759
+ task pre-registered and v0.3 (Taylor-polynomial-only fix) missed.
760
+
761
+ ### 6.4 SiLU
762
+
763
+ ```
764
+ silu(x) = x / (1.0 + exp_pinned(-x))
765
+ ```
766
+ i.e.: `neg = -x`; `e = exp_pinned(neg)`; `denom = 1.0 + e` (separate add);
767
+ `return x / denom` (one IEEE-754-mandatory-correctly-rounded division, not
768
+ a reciprocal-multiply).
769
+
770
+ ### 6.5 ln — route (b), pinned Cephes-pattern polynomial (NEW in v0.2, closes v0.1 §14.1)
771
+
772
+ For `x` a finite `f32`, `x >= 0`:
773
+
774
+ 1. If `x` is NaN or `x < 0.0`, return NaN.
775
+ 2. If `x == 0.0`, return `-Infinity`.
776
+ 3. **Exact frexp** (`frexp_exact`, §6.5.1): split `x = m · 2^e`, `m ∈
777
+ [0.5, 1.0)`, via bit manipulation only (no rounding, no library call).
778
+ 4. Mantissa range fix-up (strict, no FMA):
779
+ ```
780
+ if m < LOG_SQRTHF: # m < sqrt(0.5)
781
+ e = e - 1
782
+ m = m + m - 1.0 # m := 2m - 1
783
+ else:
784
+ m = m - 1.0
785
+ ```
786
+ 5. Polynomial evaluation (Horner, strict left-to-right, ascending-then-
787
+ folded per the Cephes logf structure, no FMA):
788
+ ```
789
+ z = m * m
790
+ poly = LOG_P[0]
791
+ for i in 1..=8:
792
+ poly = poly * m + LOG_P[i]
793
+ y = poly * m # y := poly(m) * m
794
+ y = y * z
795
+ fe = e as f32 # exact integer->f32 cast (e is small, always exact)
796
+ t1 = fe * LOG_Q1
797
+ y = y + t1
798
+ half_z = 0.5 * z
799
+ y = y - half_z
800
+ result = m + y
801
+ t2 = fe * LOG_Q2
802
+ result = result + t2
803
+ ```
804
+ (This computes `ln(x) = ln(m) + e·ln(2)`, with `ln(m)` via the degree-9
805
+ Cephes polynomial `m + m·z·P(m) - z/2` and `e·ln(2)` split as
806
+ `e·LOG_Q1 + e·LOG_Q2` — the same two-part-ln(2) split pattern as
807
+ `EXP_C1`/`EXP_C2`, deliberately reusing identical bit patterns: `LOG_Q1
808
+ == EXP_C2`, `LOG_Q2 == EXP_C1`.)
809
+
810
+ Pinned coefficients (`f32` bit patterns, hex):
811
+
812
+ ```
813
+ LOG_SQRTHF = 0x3F3504F3 (sqrt(0.5))
814
+ LOG_Q1 = 0xB95E8083 (ln2 lo, negative — identical bits to EXP_C2)
815
+ LOG_Q2 = 0x3F318000 (ln2 hi — identical bits to EXP_C1)
816
+ LOG_P[0] = 0x3D9021BB
817
+ LOG_P[1] = 0xBDEBD1B8
818
+ LOG_P[2] = 0x3DEF251B
819
+ LOG_P[3] = 0xBDFE5D4F
820
+ LOG_P[4] = 0x3E11E9BF
821
+ LOG_P[5] = 0xBE2AAE50
822
+ LOG_P[6] = 0x3E4CCEAD
823
+ LOG_P[7] = 0xBE7FFFFC
824
+ LOG_P[8] = 0x3EAAAAAA
825
+ ```
826
+
827
+ **Which `rope_theta` values are conformant.** This construction is used
828
+ exactly once per model load, on exactly one input (`ln_pinned(rope_theta as
829
+ f32)`, §7.1) — it is not a per-decode-step hot path. It has been validated
830
+ (unit test, ≤2e-6 relative tolerance against host `f64::ln` cast down, §6.5
831
+ citing `src/math.rs` `ln_matches_std_within_tolerance`) at `x ∈ {0.001, 0.1,
832
+ 0.5, 0.999, 1.0, 1.5, 2.0, 10.0, 100.0, 100_000.0, 1_000_000.0}`. The two
833
+ 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
+
845
+ ```
846
+ bits = x.to_bits()
847
+ exp_bits = (bits >> 23) & 0xFF # 8-bit biased exponent field, as i32
848
+ mantissa_bits = (bits & 0x807FFFFF) | (126 << 23) # force exponent field to 126 (bias 127-1)
849
+ mantissa = f32::from_bits(mantissa_bits) # in [0.5, 1.0)
850
+ exponent = exp_bits - 126
851
+ return (mantissa, exponent)
852
+ ```
853
+ Exact (bit reinterpretation only, no rounding), matching §6.2.1's
854
+ `ldexp_exact` in spirit (the inverse bit-field operation). Precondition:
855
+ `x > 0.0` and finite (checked by the domain guard in step 1–2 above before
856
+ this is called).
857
+
858
+ ### 6.6 Table digest (NOW BOUND into the witness chain — see §12.1, closes v0.1 §14.3; CHANGED in v0.3b)
859
+
860
+ SHA-256 over the LE bytes of every pinned coefficient above, in this exact
861
+ declared order — `[EXP_LOG2E, EXP_C1, EXP_C2]`, then `EXP_P[0..6]`, then
862
+ **(changed in v0.3b)** `PI_2_F64` (8 little-endian bytes of the `f64` bit
863
+ pattern, replacing v0.3's `TWO_PI_F64` and, before that, v0.2's two 4-byte
864
+ `f32` half-constants `[TWO_PI_HI, TWO_PI_LO]`), then `SIN_C0`, `SIN_C1`,
865
+ `SIN_C2` (replacing v0.2/v0.3's `SIN_COEF[0..11]`), then `COS_C0`,
866
+ `COS_C1`, `COS_C2` (replacing `COS_COEF[0..11]`), then `LOG_SQRTHF`, then
867
+ `LOG_Q1`, then `LOG_Q2`, then `LOG_P[0..9]` (all `f32`, 4 little-endian
868
+ bytes each), concatenated, one continuous SHA-256 stream:
869
+
870
+ ```
871
+ table_digest = 23c7bfaf5cef0095fd021af2eb1808abb4928bae4219756d86bdac670a06b35d
872
+ ```
873
+
874
+ **v0.3 vs v0.3b**: the *set* of constants hashed changed (one 8-byte
875
+ `PI_2_F64` plus 6 minimax coefficients replace `TWO_PI_F64` plus the two
876
+ 11-entry Taylor tables), so this digest differs from v0.3's
877
+ `986abc500e...` (and v0.2's `465d358ccd...`) for that reason alone. This
878
+ digest remains one of the raw 32-byte inputs folded directly into
879
+ `CIS2_REF` — see §12.1 (unchanged from v0.2's binding).
880
+
881
+ ### 6.7 Accuracy characterization (informative; v0.2 addendum, UPDATED in v0.3 then v0.3b — closes the H2 finding)
882
+
883
+ §6.2–§6.5 pin exact coefficients; §6.2's addendum (originally added in
884
+ v0.2) quantifies their error vs. a correctly-rounded fp32 reference. **v0.3
885
+ re-ran this characterization after §6.3's f64-staged reduction fix and
886
+ found the fixed degree-10 Taylor polynomial's own truncation error now
887
+ dominant (up to ~2813 raw ULP / 486 ULP filtered away from zero
888
+ crossings) — a PARTIAL result, missing this task's pre-registered ≤2-ULP
889
+ bar. v0.3b (octant reduction + separate minimax polynomials, §6.3) closes
890
+ that gap.** Full method, oracle, and domain derivation in
891
+ `docs/H2_TRANSCENDENTAL_RIGOR.md` (v0.2 finding) and
892
+ `docs/E15m_RESULT.md` (v0.3 partial result + v0.3b resolution).
893
+ `exp_pinned`/`ln_pinned`/`rsqrt_cr` are unchanged from v0.2 (their code did
894
+ not change); `sin_pinned`/`cos_pinned` are re-measured below, over the full
895
+ `pos ∈ [0, 8192)` domain (v0.2's table only covered `pos ≤ 19`):
896
+
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 |
905
+ | `cos_pinned` (v0.3b, minimax, NORMATIVE) | same | **≤1.5** | **1.2e-7** |
906
+
907
+ **Resolution**: `docs/E15m_PREREG.md`/`docs/E15m_RESULT.md` document both
908
+ the f64-staging fix (v0.3, partial) and the octant-reduction +
909
+ minimax-polynomial fix (v0.3b, closes the bar) and their shared
910
+ cross-ISA determinism justification (both stages are f64-staged
911
+ identically; only the reduction period and the polynomial degree/domain
912
+ differ). `table_digest` (§6.6) changed at each step; `inv_freq_table_digest`
913
+ (§7.2) never changed (RoPE's `inv_freq` construction only calls
914
+ `ln_pinned`/`exp_pinned`, neither of which changed at any point in this
915
+ task). This closes the "if decode length were ever extended toward
916
+ `max_position_embeddings = 8192`" caveat v0.2 §6.7 flagged for future
917
+ work — v0.3b measures that full range directly and meets a ≤2-ULP bar
918
+ across it, rather than extrapolating from `pos ≤ 19`.
919
+
920
+ ## 7. RoPE (normative, now theta-general — closes v0.1 §14.1)
921
+
922
+ 7.1. **`inv_freq` construction.** For `i = 0..head_dim/2` (32 values for
923
+ SmolLM2-135M's `head_dim = 64`; a different `head_dim` scales this
924
+ identically):
925
+
926
+ ```
927
+ ln_theta = ln_pinned(rope_theta as f32) # §6.5, NEW: general, not a literal
928
+ for i in 0..head_dim/2:
929
+ frac = (2*i as f32) / (head_dim as f32) # e.g. i=0 -> 0.0, i=1 -> 2/64
930
+ neg_arg = -(frac * ln_theta) # separate mul, then negate
931
+ inv_freq[i] = exp_pinned(neg_arg) # §6.2, the SAME pinned exp
932
+ ```
933
+
934
+ **v0.1 vs v0.2**: v0.1 pinned `LN_THETA` as a bare literal f32 bit pattern
935
+ (`0x413834F1`) valid **only** for `rope_theta == 100000.0`, and mandated the
936
+ loader assert this exact value and refuse to run otherwise (v0.1 §2.4).
937
+ v0.2 **removes that restriction**: `ln_theta` is computed at load time from
938
+ whatever `rope_theta` is present in `config.json`, via the pinned `ln`
939
+ polynomial (§6.5) — not any host `pow`/`powf`/`ln` call. For
940
+ `rope_theta = 100000.0` specifically, `ln_pinned(100_000.0)` MUST agree with
941
+ the old v0.1 literal `0x413834F1` to within the same ≤2e-6 relative
942
+ tolerance used elsewhere in this spec (it is not required to be bit-
943
+ identical to the old hardcoded literal, since the literal was the
944
+ RNE-nearest f32 to the true `ln(100000)` while `ln_pinned` is a polynomial
945
+ approximation — the two need not collide at the last bit; what matters is
946
+ that `inv_freq_table_digest`, §7.2, still reproduces bit-for-bit run-to-run
947
+ and cross-ISA, which it does, §13.1).
948
+
949
+ Mathematically this is still `inv_freq[i] = theta^(-2i/head_dim) =
950
+ exp(-(2i/head_dim)·ln(theta))`, evaluated with the pinned `exp_pinned`
951
+ polynomial (§6.2) and now also the pinned `ln_pinned` polynomial (§6.5)
952
+ rather than any host `pow`/`powf`/`ln` call — this is a deliberate, pinned
953
+ choice (superseding both the v0.1 literal draft and an earlier,
954
+ non-normative pre-v0.1 draft that used host `f64::powf`; see Appendix A for
955
+ the exact history).
956
+
957
+ 7.2. **`inv_freq` table digest.** SHA-256 over the LE bytes of each of the
958
+ `head_dim/2` `inv_freq` values, `f32.to_le_bytes()`, in index order, one
959
+ continuous stream. **Unchanged construction from v0.1** (this digest was
960
+ already raw bytes, not hex-ASCII, in v0.1 — see §14.2 (v0.1 numbering) /
961
+ Appendix B item 3). For SmolLM2-135M (`head_dim=64`, `rope_theta=100000.0`,
962
+ 32 values):
963
+
964
+ ```
965
+ inv_freq_table_digest = da9f6dcfde0425588815509e874515cdcd3d6b8818b6d0136590052e7bbf6f12
966
+ ```
967
+
968
+ Identical bit-for-bit to v0.1's value for this same model — evidence that
969
+ switching from the bare `LN_THETA` literal to the general `ln_pinned(rope_theta)`
970
+ call did not change SmolLM2-135M's `inv_freq` table at all (§16 changelog
971
+ note). **Now bound into `CIS2_REF`** (§12.1) — v0.1 computed and printed
972
+ this digest but never fed it into the witness chain (v0.1 §14.3); v0.2
973
+ closes that gap.
974
+
975
+ 7.3. **Per-position cos/sin table.** For a query/key head being rotated
976
+ at sequence position `pos` (a `usize`, cast to `f32` exactly — `pos` never
977
+ exceeds 19 in this spec's fixed 20-position decode, well within `f32`'s
978
+ exact-integer range):
979
+
980
+ ```
981
+ for i in 0..half (half = head_dim/2 = 32):
982
+ angle = (pos as f32) * inv_freq[i]
983
+ cos_v[i] = cos_pinned(angle) # §6.3
984
+ sin_v[i] = sin_pinned(angle) # §6.3
985
+ ```
986
+
987
+ 7.4. **Rotation (rotate-half convention, `rope_interleaved = false`).**
988
+ Given a `head_dim`-length slice `head[0..head_dim]` for one attention
989
+ head, with `half = head_dim/2`:
990
+
991
+ ```
992
+ for i in 0..half:
993
+ x1 = head[i]
994
+ x2 = head[i + half]
995
+ t1 = x1 * cos_v[i]
996
+ t2 = (-x2) * sin_v[i]
997
+ out[i] = t1 + t2
998
+ t3 = x2 * cos_v[i]
999
+ t4 = x1 * sin_v[i]
1000
+ out[i + half] = t3 + t4
1001
+ head[0..head_dim] = out[0..head_dim] # in place, after computing all `out`
1002
+ ```
1003
+
1004
+ This is applied to **every** query head (9 heads, each `head_dim=64`
1005
+ slice of the 576-wide `q` vector) and **every** key head (3 heads, each
1006
+ `head_dim=64` slice of the 192-wide `k` vector) independently, once per
1007
+ decode step, at that step's `pos`. Values are never rotated more than
1008
+ once (the KV cache stores post-RoPE `k`; §3.5).
1009
+
1010
+ ## 8. RMSNorm (normative)
1011
+
1012
+ **Unchanged from v0.1** (verbatim):
1013
+
1014
+ For input vector `x` of length `n = hidden = 576`, gain vector `weight`
1015
+ of the same length, and `eps` = `EPS_F32` (§2.3):
1016
+
1017
+ ```
1018
+ for i in 0..n: sq[i] = x[i] * x[i]
1019
+ ss = sum_seq(sq) # §5.3, strict left-to-right
1020
+ mean = ss / (n as f32) # one IEEE-754 division
1021
+ inv = rsqrt(mean + eps) # §6.1: 1.0 / (mean+eps).sqrt()
1022
+ for i in 0..n:
1023
+ scaled = x[i] * inv
1024
+ out[i] = scaled * weight[i] # (x[i]*inv)*weight[i] — THIS association, not x[i]*(inv*weight[i])
1025
+ ```
1026
+
1027
+ The multiply order `(x[i] * inv) * weight[i]` (not `x[i] * (inv *
1028
+ weight[i])`) is pinned explicitly: floating-point multiplication is not
1029
+ associative under rounding, so these two orders can differ in the low bit
1030
+ in general, even though no divergence from this specific reordering has
1031
+ been observed on this model/prompt.
1032
+
1033
+ Applied twice per layer (`input_layernorm` before attention, in §2.5's
1034
+ naming `post_attention_layernorm` before the MLP) and once after the final
1035
+ layer (`model.norm.weight`), all using the same procedure and the same
1036
+ `eps`.
1037
+
1038
+ ## 9. Attention (GQA, causal, per decode step) (normative)
1039
+
1040
+ Let `qh` range over `n_heads = 9` query heads, `kv_head = qh /
1041
+ group` (`group = 3`) map each query head to its shared KV head (integer
1042
+ division), `head_dim = 64`.
1043
+
1044
+ 9.1. **Projections.** `q = matvec(q_proj, ln1, 576, 576)`; `k =
1045
+ matvec(k_proj, ln1, 192, 576)`; `v = matvec(v_proj, ln1, 192, 576)`
1046
+ (§5.2), where `ln1` is this layer's post-RMSNorm hidden state (§8).
1047
+ **New in v0.2 (informative for SmolLM2-135M, normative for any checkpoint
1048
+ that carries these tensors)**: if the checkpoint provides
1049
+ `self_attn.{q,k,v}_proj.bias` tensors (Qwen2-family
1050
+ `attention_bias=true`), each is added elementwise (§5.4) to the
1051
+ corresponding projection immediately after the matvec, before RoPE; if the
1052
+ checkpoint has no such tensors (Llama-family, including SmolLM2-135M),
1053
+ this step is a no-op and the pinned §13 test vector is unaffected. RoPE
1054
+ (§7) is then applied in place to each of the 9 query-head slices of `q`
1055
+ and each of the 3 key-head slices of `k`, at the current step's `pos`. `v`
1056
+ is never rotated.
1057
+
1058
+ 9.2. **Score.** For query head `qh` at position `pos`, against every
1059
+ cached key position `j = 0..=pos` (causal: only positions ≤ current,
1060
+ enforced by the KV cache containing exactly those positions, not by an
1061
+ explicit mask value):
1062
+
1063
+ ```
1064
+ scale = rsqrt(head_dim as f32) # computed once: rsqrt(64.0) == 0.125 exactly
1065
+ d = dot_seq(q_head, k_j) # §5.1, over the 64-dim head slice
1066
+ scores[j] = d * scale # separate multiply, applied AFTER the dot
1067
+ ```
1068
+
1069
+ 9.3. **Softmax** (`softmax_seq`, in place over `scores[0..=pos]`):
1070
+
1071
+ ```
1072
+ max_v = scores[0]
1073
+ for v in scores[1..]:
1074
+ if v > max_v: max_v = v # strict >, so the FIRST occurrence of the max wins ties
1075
+ for v in scores: v = exp_pinned(v - max_v) # §6.2
1076
+ denom = sum_seq(scores) # §5.3
1077
+ for v in scores: v = v / denom # elementwise division, NOT multiply-by-reciprocal
1078
+ ```
1079
+
1080
+ 9.4. **V-mix.** For each output dimension `d = 0..head_dim`:
1081
+
1082
+ ```
1083
+ acc = 0.0_f32
1084
+ for j in 0..=pos:
1085
+ p = scores[j] * v_cache[j][kv_head][d]
1086
+ acc = acc + p # separate mul, separate add — same
1087
+ # left-to-right order as §5.1, written
1088
+ # as an explicit loop rather than a
1089
+ # dot_seq call, but semantically identical
1090
+ out_head[d] = acc
1091
+ ```
1092
+
1093
+ 9.5. **Output projection and residual.** Concatenate all 9 `out_head`
1094
+ slices into a 576-wide `attn_out`; `o = matvec(o_proj, attn_out, 576,
1095
+ 576)`; `h = elementwise_add(h, o)` (§5.4).
1096
+
1097
+ ## 10. MLP / SwiGLU (normative)
1098
+
1099
+ **Unchanged from v0.1** (verbatim):
1100
+
1101
+ Given this layer's post-`post_attention_layernorm` hidden state `ln2`
1102
+ (576-wide):
1103
+
1104
+ ```
1105
+ gate = matvec(gate_proj, ln2, 1536, 576) # §5.2
1106
+ up = matvec(up_proj, ln2, 1536, 576)
1107
+ for i in 0..1536:
1108
+ hid[i] = silu_pinned(gate[i]) * up[i] # §6.4, then one separate multiply
1109
+ down = matvec(down_proj, hid, 576, 1536)
1110
+ h = elementwise_add(h, down) # §5.4
1111
+ ```
1112
+
1113
+ ## 11. LM head and argmax (normative)
1114
+
1115
+ 11.1. After the final layer, `hn = rmsnorm(h, model.norm.weight, eps)`
1116
+ (§8). `logits = matvec(lm_head_weights, hn, vocab, hidden)` (§5.2). For
1117
+ SmolLM2-135M (`tie_word_embeddings=true`), `lm_head_weights` is the tied
1118
+ `embed_tokens.weight` matrix directly (§2.5) — no separate weight, no
1119
+ transpose (the embedding table is already `[vocab, hidden]`, the exact
1120
+ shape a `matvec` row-dot needs). **New in v0.2 (informative for
1121
+ SmolLM2-135M, normative for any checkpoint with
1122
+ `tie_word_embeddings=false`)**: if the checkpoint config sets
1123
+ `tie_word_embeddings=false` and provides a separate `lm_head.weight`
1124
+ tensor (`[vocab, hidden]`), that tensor is used instead of `embed_tokens`;
1125
+ this branch is untested by this version's pinned §13 test vector
1126
+ (SmolLM2-135M is tied) but is exercised by the informative Qwen2.5-0.5B
1127
+ evidence (§0), which is itself tied (`tie_word_embeddings=true` for the
1128
+ base, non-Instruct checkpoint) — so even that evidence does not exercise
1129
+ the untied branch end-to-end; a clean-room implementer targeting an
1130
+ untied checkpoint should treat this branch as spec-described but
1131
+ less-validated than the tied path.
1132
+
1133
+ 11.2. **Argmax**, strict left-to-right scan, first-occurrence-wins on
1134
+ exact ties:
1135
+
1136
+ ```
1137
+ best_idx = 0
1138
+ best_val = logits[0]
1139
+ for idx, v in enumerate(logits):
1140
+ if v > best_val: # strict >, never >=
1141
+ best_val = v
1142
+ best_idx = idx
1143
+ next_token_id = best_idx as u32
1144
+ ```
1145
+
1146
+ ## 12. Digest / receipt format (normative)
1147
+
1148
+ All digests are SHA-256 (32 raw bytes), rendered as lowercase hex (64
1149
+ ASCII characters) **only for display/printing** — the witness chain itself
1150
+ consumes raw bytes, not the hex rendering (§12.1, this is the v0.2 change
1151
+ from v0.1). There are **three separate, independently computed** digests;
1152
+ none of them contains any of the others as a sub-input except where
1153
+ explicitly stated.
1154
+
1155
+ 12.1. **Witness chain / `CIS2_REF` digest.** One continuous
1156
+ `Sha256::update()` stream (not a step-wise re-hash of
1157
+ `running_digest || new_data` — this is a single hash object updated
1158
+ repeatedly, then finalized once), fed in exactly this order:
1159
+
1160
+ 1. `weights_sha256` — the **raw 32-byte SHA-256 digest** of
1161
+ `model.safetensors` (§2.1). **CHANGED in v0.2**: v0.1 fed the
1162
+ **64-character lowercase hex ASCII string** (the digest's UTF-8/ASCII
1163
+ bytes, 64 bytes) instead of these 32 raw bytes; this closes v0.1 §14.2.
1164
+ 2. `tokenizer_sha256` — same raw-32-byte encoding, `tokenizer.json`'s
1165
+ digest.
1166
+ 3. `config_sha256` — same raw-32-byte encoding, `config.json`'s digest.
1167
+ 4. `table_digest` — the **raw 32 bytes** of §6.6's pinned
1168
+ exp/sin/cos/ln coefficient-table digest. **NEW in v0.2** (closes v0.1
1169
+ §14.3): v0.1 computed and printed this value but never fed it into the
1170
+ witness chain.
1171
+ 5. `inv_freq_table_digest` — the **raw 32 bytes** of §7.2's RoPE
1172
+ `inv_freq` table digest. **NEW in v0.2** (closes v0.1 §14.3, same gap
1173
+ as item 1).
1174
+
1175
+ **E15k correction (this pass):** this doc previously listed items
1176
+ 1-5 in the order table_digest, inv_freq_table_digest, weights,
1177
+ tokenizer, config. That prose never matched the actual reference
1178
+ implementation (`src/main.rs`, which is the source of the pinned
1179
+ `CIS2_REF=a0c563ef...` value below) — the reference feeds
1180
+ weights/tokenizer/config first, then table/inv_freq, as corrected
1181
+ above. A from-spec-text-only clean-room (`verify3/`, E15j) followed
1182
+ the old (wrong) prose exactly and reproduced every other digest
1183
+ bit-for-bit (`table_digest`, `inv_freq_table_digest`, `argmax_digest`,
1184
+ all 16 `generated_token_ids`) but got a different `CIS2_REF`
1185
+ (`a532d4a4...`) purely from this item-order mismatch — see
1186
+ `docs/E15k_DIVERGENCE_LOCALIZATION.md`. Fixed here; `verify3/model.c`
1187
+ corrected to match and reconfirmed bit-exact on all 4 CI cells
1188
+ (x86_64/aarch64 × gcc/clang).
1189
+ 6. Every prompt token id, in order, each as **`u32` little-endian, 4
1190
+ bytes** (`t.to_le_bytes()`) — 4 tokens × 4 bytes = 16 bytes total for
1191
+ this prompt. **Unchanged from v0.1.**
1192
+ 7. For each of the `gen_toks` decode steps (16 for the pinned §13 test
1193
+ vector), in step order (`step = 0..gen_toks`):
1194
+ a. The **full fp32 logit vector for this step** (49152 entries for
1195
+ SmolLM2-135M, in vocab-index order), each entry's raw bit pattern as
1196
+ `u32` little-endian (`v.to_bits().to_le_bytes()`), concatenated —
1197
+ 49152 × 4 = 196608 bytes per step for this vocab size. This is the
1198
+ logit vector **before** this step's argmax pick (i.e., the vector
1199
+ argmax was just computed against), not the vector for the *next*
1200
+ position. **Unchanged from v0.1.**
1201
+ b. The chosen `next_token_id` for this step, as **`u32` little-endian,
1202
+ 4 bytes**. **Unchanged from v0.1.**
1203
+
1204
+ Finalize once after all steps; the resulting 32-byte digest, hex encoded,
1205
+ is `CIS2_REF`. For the pinned SmolLM2-135M / `"Once upon a time"` /
1206
+ 16-token test vector:
1207
+
1208
+ ```
1209
+ CIS2_REF = d82743059d1db929e710236fe4ec37f89e6f932524801345a006980f7c3cc9df
1210
+ ```
1211
+
1212
+ printed as `CIS2_REF digest=d8274305... prompt_idx=0 prompt_toks=4
1213
+ gen_toks=16 dtype=fp32`. **This digest is not backward-compatible with
1214
+ v0.3's `90f7484e...`, v0.2's `a0c563ef...`, or v0.1's `ba88708bf4...`** —
1215
+ v0.3b changed `table_digest` (§6.6, the octant-reduction constant plus 6
1216
+ minimax coefficients replacing v0.3's single f64 reduction constant plus
1217
+ the two Taylor tables), which feeds directly into this witness chain (item
1218
+ 4 below); v0.2→v0.3 separately changed `table_digest`'s constant set (f64
1219
+ reduction constant replacing two f32 halves); the v0.1→v0.2 transition
1220
+ changed the item order and the item 3–5 encoding (raw bytes, not
1221
+ hex-ASCII); see §16 for the full breakdown of which change contributed
1222
+ how. `generated_token_ids` and `argmax_digest` for this 16-token pinned
1223
+ test vector are **unchanged from v0.1/v0.2/v0.3** (none of this task's
1224
+ `sin`/`cos` accuracy fixes are large enough at `pos ≤ 19` to flip any of
1225
+ the 16 greedy argmax decisions — see `docs/E15m_RESULT.md`).
1226
+
1227
+ 12.2. **Argmax-token digest.** **Unchanged construction and unchanged
1228
+ value from v0.1** (this digest was never affected by either v0.2 change —
1229
+ it does not touch `table_digest`, `inv_freq_table_digest`, or any artifact
1230
+ hash). A **separate** `Sha256` instance (not derived from or continuing
1231
+ the witness chain above), fed the LE `u32` bytes of every token id in
1232
+ `prompt_token_ids ++ [16 generated token ids]` (20 tokens total, in that
1233
+ order, prompt first), one continuous stream, finalized once:
1234
+
1235
+ ```
1236
+ argmax_digest = 0b9c8f3ac90d0b9cd5f1719ac327dca1fc639fd87468305fccebbe3d56f67aff
1237
+ ```
1238
+
1239
+ 12.3. **Table digests** (§6.6, §7.2) are now **inputs to** `CIS2_REF`
1240
+ (§12.1 items 1–2, new in v0.2) but remain independent of, and not inputs
1241
+ to, the argmax-token digest (§12.2) — printed separately as before, in
1242
+ addition to being folded into the witness chain.
1243
+
1244
+ 12.4. **Determinism check (MUST).** The reference computes the entire
1245
+ decode (§3.4) **twice** in the same process (`run1`, `run2`) and MUST
1246
+ assert all three of: `witness_digest_run1 == witness_digest_run2`,
1247
+ `argmax_digest_run1 == argmax_digest_run2`, and
1248
+ `token_ids_run1 == token_ids_run2`, before printing any result — this is
1249
+ the same-host determinism bar, a precondition for the stronger cross-ISA
1250
+ claim (§13.2), not itself the interesting claim. **Unchanged from v0.1.**
1251
+
1252
+ ## 13. Test vectors (normative)
1253
+
1254
+ 13.1. **Full run, prompt `"Once upon a time"`, 16 greedy tokens:**
1255
+
1256
+ ```
1257
+ weights_sha256 = 80521b40281d6ce74e35c9282c22539e75aa0ac8578892b2a59955ef78d55da1
1258
+ config_sha256 = 1d556eab73b69c7f11f64c557a2f9c6f440bd4c6b89bb2584a6b498c92603843
1259
+ tokenizer_sha256 = 9ca9acddb6525a194ec8ac7a87f24fbba7232a9a15ffa1af0c1224fcd888e47c
1260
+ prompt_token_ids = [6403, 1980, 253, 655]
1261
+ generated_token_ids (16, in order) =
1262
+ [28, 665, 436, 253, 1838, 8180, 3365, 14176, 30, 2306, 4161, 281, 253, 2066, 2291, 351]
1263
+ table_digest = 23c7bfaf5cef0095fd021af2eb1808abb4928bae4219756d86bdac670a06b35d
1264
+ inv_freq_table_digest = da9f6dcfde0425588815509e874515cdcd3d6b8818b6d0136590052e7bbf6f12
1265
+ argmax_digest = 0b9c8f3ac90d0b9cd5f1719ac327dca1fc639fd87468305fccebbe3d56f67aff
1266
+ CIS2_REF (witness_digest) = d82743059d1db929e710236fe4ec37f89e6f932524801345a006980f7c3cc9df
1267
+ ```
1268
+
1269
+ Note `generated_token_ids` and `argmax_digest` are **unchanged from v0.3,
1270
+ v0.2, and v0.1** — none of v0.2's, v0.3's, or v0.3b's changes altered the actual
1271
+ computed logits or greedy decisions at this 16-token/pos≤19 length, only
1272
+ the receipt's hashing (v0.2, §16) or the reduction's accuracy at longer
1273
+ positions than this pinned vector exercises (v0.3, §6.3/§6.7).
1274
+
1275
+ 13.2. **Cross-run/cross-ISA conformance bar.** All of §13.1's values MUST
1276
+ reproduce bit-for-bit: (a) across two sequential runs in the same process
1277
+ (§12.4); (b) across two separate OS process invocations on the same host;
1278
+ (c) across x86-64 and aarch64, same source, unmodified, both with §1.3's
1279
+ FTZ/DAZ pin actually in effect (verified by the adversarial self-test,
1280
+ §1.3) and §1.4's zero-FMA gate passing (disassembly check). **Unchanged
1281
+ requirement from v0.1**, now additionally exercised by §13.4's 20-cell
1282
+ compiler-invariance matrix.
1283
+
1284
+ 13.3. **Step-0 full-logit-vector spot check (informative, not part of
1285
+ `CIS2_REF`)**: an independent oracle comparison
1286
+ (`docs/E15b_m1p5_CORRECTNESS.md`) against `torch`/`transformers` fp32
1287
+ forward pass of the same checkpoint found, at generation step 0 (right
1288
+ after prefill, before the first generated token), across all 49152
1289
+ logits: `max_abs_diff ≈ 8.965e-05` (vocab index 40082: this reference
1290
+ `5.486028671264648`, oracle `5.486118316650391`), `max|logit| ≈
1291
+ 22.531156539916992`, relative diff `≈ 3.98e-06` — evidence of
1292
+ *correctness* (this is a valid forward pass), not evidence of bit-identity
1293
+ with `torch` (which this spec never claims; `torch` uses its own BLAS
1294
+ reduction order and libm, out of scope). This spec does not define a
1295
+ `--dump-step0` flag as part of its normative surface; the debug env-var
1296
+ hook (`CIS2_DUMP_STEP0_LOGITS`, Appendix A) that produced this comparison
1297
+ is informative tooling, not part of conformance. **Unchanged from v0.1.**
1298
+ A second, independently-run oracle comparison against Qwen2.5-0.5B
1299
+ (`docs/E15d_bc_RESULT.md`, greedy 16/16 token match, logit relative
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
1306
+ of `{x86_64, aarch64} × {opt-level 0,1,2,3,s} × {target-cpu generic,
1307
+ native}`, with zero FMA instructions in every cell's disassembly (§1.4).
1308
+ Preregistered digest values and the full per-cell table are recorded in
1309
+ `docs/E15d_v0.2_DIGESTS.md` (this branch); the v0.1-era version of this
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
1333
+ 32 raw digest bytes — an ambiguity only recoverable by reading
1334
+ `src/main.rs`'s `sha256_file` return type. v0.2's `sha256_file` now
1335
+ returns `[u8; 32]` directly (Appendix A), and the witness chain (§12.1)
1336
+ consumes those raw bytes; hex encoding is applied only at print time via a
1337
+ local `hex::encode` helper. Closed by construction, not by convention —
1338
+ there is no longer a hex `String` in the artifact-hash code path for the
1339
+ witness chain to accidentally consume.
1340
+
1341
+ 14.3. **Table digests not bound into `CIS2_REF`: CLOSED.** v0.1's
1342
+ `table_digest` and `inv_freq_table_digest` were computed and printed
1343
+ entirely independently of the witness chain — a receipt holder could not
1344
+ detect, from `CIS2_REF` alone, whether a verifier used the exact pinned
1345
+ polynomial/RoPE-table coefficients of §6/§7 or some other transcendental
1346
+ implementation producing the same logits. v0.2 folds both digests into
1347
+ the witness chain's seed (§12.1 items 1–2), ahead of the artifact hashes.
1348
+ **Residual caveat**: this closes the "not bound at all" gap, but a
1349
+ `CIS2_REF` mismatch still does not, by itself, tell a verifier *which* of
1350
+ the now-five seed inputs (2 table digests + 3 artifact hashes) diverged —
1351
+ a verifier wanting to localize a mismatch should still compare
1352
+ `table_digest`/`inv_freq_table_digest`/artifact hashes individually (all
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`,
1386
+ producing a *different* `CIS2_REF`
1387
+ (`830d972dbfb0b5598015f33571d08623d2b05d8e239b8d0288562d9ac9786907`) than
1388
+ v0.1's `ba88708b...` (produced after switching to `exp_pinned`-based
1389
+ `inv_freq`). v0.2 adds a third data point:
1390
+ `a0c563ef804f50413b7fb6619ae4afe9b51b1ffa7655e944221393e85d6261da`
1391
+ (§13.1, this document), produced after (a) generalizing `inv_freq` to any
1392
+ `rope_theta` via `ln_pinned` and (b) the two receipt-format changes
1393
+ (§12.1). The `argmax_digest` (`0b9c8f3a...`) has been unchanged across
1394
+ *all three* `CIS2_REF` states — the greedy token ids have never flipped
1395
+ across any of these reference-internal changes, only the full logit/receipt
1396
+ bit patterns did. This is recorded here because it demonstrates, a second
1397
+ time, the exact failure mode §14.3 (now closed) used to warn about: a
1398
+ `CIS2_REF`-only comparison cannot localize *which* internal change moved
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
1405
+ alone (no access to `src/`):
1406
+
1407
+ 1. It reproduces every value in §13.1 bit-for-bit, on x86-64.
1408
+ 2. It reproduces every value in §13.1 bit-for-bit, on aarch64, unmodified
1409
+ source, with the ISA-specific FTZ/DAZ leg of §1.3 actually exercised
1410
+ (not a no-op stub).
1411
+ 3. Its release binary contains zero FMA instructions on the decode path
1412
+ (§1.4, disassembly-verified).
1413
+ 4. Its self-test (§1.3's adversarial denormal check) passes.
1414
+ 5. It passes §12.4's same-process two-run determinism check.
1415
+
1416
+ This is a narrower and more mechanical bar than CIS-1's three-tier scheme
1417
+ (CIS-1 §8) because CIS-2 has exactly one pinned (model, prompt, length)
1418
+ tuple as its normative §13.1 test vector, rather than CIS-1's
1419
+ op-goldens/selftest/token-digest split; a future version should factor out
1420
+ op-level goldens (individual
1421
+ `exp_pinned`/`sin_pinned`/`cos_pinned`/`ln_pinned`/`rsqrt`/`dot_seq` unit
1422
+ vectors) as their own tier, independent of the full 30-layer decode, the
1423
+ way CIS-1's Tier 1/Tier 2 do — not done in this version. **Unchanged
1424
+ structure from v0.1**, item list identical; only the referenced §13.1
1425
+ values changed underneath it.
1426
+
1427
+ ## 16. Version history
1428
+
1429
+ - **v0.3 (2026-08-29, PARTIAL — superseded by v0.3b below)** — attempted
1430
+ to close CIS-2's one remaining stated technical limitation (v0.2 §6.7 /
1431
+ `docs/H2_TRANSCENDENTAL_RIGOR.md`): `sin_pinned`/
1432
+ `cos_pinned`'s §6.3 range reduction is now staged through `f64` instead
1433
+ of two `f32` half-constants, fixing catastrophic-cancellation accuracy
1434
+ loss that grew with RoPE position (up to 1104 ULP / 1e-4 relative by
1435
+ position 19 in v0.2; ~0.58 relative, unusable, toward position 8192).
1436
+ Design pre-registered before implementation in `docs/E15m_PREREG.md`;
1437
+ gate results (determinism, accuracy, oracle-correctness) in
1438
+ `docs/E15m_RESULT.md`.
1439
+
1440
+ **What changed**: §6.3 (reduction only, not the degree-10 Taylor
1441
+ polynomials); §6.6 (`table_digest` now hashes one 8-byte `TWO_PI_F64`
1442
+ constant in place of v0.2's two 4-byte `TWO_PI_HI`/`TWO_PI_LO`
1443
+ constants); §6.7 (accuracy table re-measured over the full
1444
+ `pos ∈ [0, 8192)` domain instead of v0.2's `pos ≤ 19`).
1445
+
1446
+ **What did not change**: §7 (RoPE `inv_freq` construction —
1447
+ `ln_pinned`/`exp_pinned` untouched), `inv_freq_table_digest`
1448
+ (`da9f6dcfde...`, bit-identical to v0.1/v0.2), `argmax_digest`
1449
+ (`0b9c8f3a...`) and `generated_token_ids` for the 16-token/pos≤19 pinned
1450
+ test vector (the f64-staged fix is far more accurate at short range but
1451
+ not different enough from v0.2's already-adequate short-range values to
1452
+ flip any of the 16 greedy decisions at this length).
1453
+
1454
+ **Net effect on test vectors (§13.1)**: `CIS2_REF` changed
1455
+ (`a0c563ef80...` → `90f7484e4c...`); `table_digest` changed
1456
+ (`465d358ccd...` → `986abc500e...`); `inv_freq_table_digest`,
1457
+ `argmax_digest`, `generated_token_ids` unchanged from v0.2.
1458
+
1459
+ Also in this branch: `.github/workflows/e15d-compiler-invariance.yml`
1460
+ and `.github/workflows/e15c-cross-isa.yml` `TARGET_DIGEST` updated to
1461
+ `90f7484e4c...` (`TARGET_INVFREQ_DIGEST` unchanged); `verify2/` and
1462
+ `verify3/` clean-rooms updated from this spec's §6.3 text only (not by
1463
+ reading `src/math.rs`), logged in each crate's own `CLEANROOM_LOG.md`;
1464
+ new `scripts/h2m_accuracy_harness.py` (mpmath oracle, pos up to 8192);
1465
+ `scripts/oracle_compare.py`/`scripts/oracle_compare_qwen.py` extended to
1466
+ a 2048-token horizon.
1467
+
1468
+ **PARTIAL result (gate 2 missed)**: the accuracy harness
1469
+ (`scripts/h2m_accuracy_harness.py`) found max relative error improved
1470
+ ~55-70x (1.30e-2 -> 2.37e-4 sin, 1.36e-2 -> 3.14e-5 cos) but max ULP was
1471
+ still up to 2813 (486 filtered away from zero crossings) — the
1472
+ pre-registered <=2 ULP bar was NOT met. Root cause: the reduction itself
1473
+ became ~exact (matches an arbitrary-precision reduction to ~1 ULP of the
1474
+ reduced argument `r`); the *fixed degree-10 Taylor polynomial's own
1475
+ truncation error*, worst near `|r| ~ pi` and at sin/cos zero crossings,
1476
+ became the dominant term. Reported honestly rather than narrowing the
1477
+ claim; superseded by v0.3b below per coordinator directive.
1478
+
1479
+ - **v0.3b (2026-08-29)** — closes CIS-2's one remaining stated technical
1480
+ limitation, meeting the pre-registered accuracy bar v0.3 missed. Same
1481
+ pre-registration (`docs/E15m_PREREG.md`), refined mechanism: §6.3 now
1482
+ reduces to an octant (`r ∈ [-pi/4, pi/4]`, quadrant index `k mod 4`,
1483
+ still f64-staged, same Cody-Waite pattern and determinism argument as
1484
+ v0.3, just mod `pi/2` instead of mod `2*pi`), then evaluates sin(r)/
1485
+ cos(r) with SEPARATE degree-7/8 Cephes `sinf`/`cosf` minimax polynomials
1486
+ (not Taylor truncations), then selects/signs the result by quadrant.
1487
+
1488
+ **What changed**: §6.3 (reduction period and polynomial, both); §6.6
1489
+ (`table_digest` now hashes one 8-byte `PI_2_F64` constant plus 6 pinned
1490
+ f32 minimax coefficients — `SIN_C0/C1/C2`, `COS_C0/C1/C2` — in place of
1491
+ v0.3's `TWO_PI_F64` plus the two 11-entry Taylor tables); §6.7 (accuracy
1492
+ table adds the v0.3b row, marked NORMATIVE, alongside v0.3's superseded
1493
+ row for comparison).
1494
+
1495
+ **What did not change**: §7 (RoPE `inv_freq` construction), everything
1496
+ else in v0.3's "what did not change" list; `argmax_digest`/
1497
+ `generated_token_ids` for the 16-token pinned test vector remain
1498
+ unchanged across v0.1/v0.2/v0.3/v0.3b.
1499
+
1500
+ **Net effect on test vectors (§13.1)**: `CIS2_REF` changed
1501
+ (`90f7484e4c...` -> `d82743059d...`); `table_digest` changed
1502
+ (`986abc500e...` -> `23c7bfaf5c...`); `inv_freq_table_digest`,
1503
+ `argmax_digest`, `generated_token_ids` unchanged from v0.3/v0.2/v0.1.
1504
+
1505
+ **Gate (2) result**: `scripts/h2m_accuracy_harness.py` re-run to
1506
+ position 8192 on both pinned `rope_theta` values (SmolLM2-135M 1e5,
1507
+ Qwen2.5-0.5B 1e6) measures max **1.5 ULP** (both sin and cos, both
1508
+ models), max relative error ~1.2e-7 — meets the <=2 ULP bar.
1509
+
1510
+ Also in this branch: `.github/workflows/e15d-compiler-invariance.yml`
1511
+ and `.github/workflows/e15c-cross-isa.yml` `TARGET_DIGEST` updated to
1512
+ `d82743059d...`; `verify2/`/`verify3/` clean-rooms updated a second time
1513
+ from this spec's v0.3b §6.3 text only, logged in each crate's own
1514
+ `CLEANROOM_LOG.md`; all three implementations (`cis2_ref`, `verify2`,
1515
+ `verify3`) confirmed bit-for-bit matching locally on x86_64
1516
+ (`d82743059d...`) — see `docs/E15m_RESULT.md`'s v0.3b section for CI
1517
+ run ids (cross-ISA confirmation pending in CI).
1518
+
1519
+ - **v0.1 (2026-08-28)** — first draft. Closes every item in
1520
+ `verify/SPEC_GAPS.md` (digest byte encoding, transcendental route and
1521
+ exact coefficients, RoPE `inv_freq` construction and digest, RMSNorm
1522
+ elementwise order) against the actual reference implementation at the
1523
+ commit cited in v0.1's Appendix A. Known-incomplete: v0.1 §14's items,
1524
+ especially 14.1 (theta-general RoPE) and 14.3 (table digests not bound
1525
+ into the receipt), left open for v0.2.
1526
+
1527
+ - **v0.2 (2026-08-28)** — three changes, all against `origin/cm/e15h-ref-fixes`
1528
+ (Appendix A):
1529
+ 1. **Table digests folded into `CIS2_REF`** (closes v0.1 §14.3). §12.1
1530
+ items 1–2 (new), §6.6/§7.2 (both digests now witness-chain inputs,
1531
+ appended AFTER the three artifact hashes: the seeding order is
1532
+ weights, tokenizer, config, then table_digest, then
1533
+ inv_freq_table_digest — see §12.1 and src/main.rs:555-559.
1534
+ [E15k/H3 correction: an earlier draft of this line said "table
1535
+ digest first"; that was wrong and never matched the reference.]).
1536
+ 2. **RoPE `inv_freq` is now theta-general** (closes v0.1 §14.1). New
1537
+ §6.5 pinned `ln_pinned` polynomial (Cephes-pattern logf, exact
1538
+ `frexp_exact` bit-split, degree-9 Horner in the reduced mantissa);
1539
+ §7.1's `LN_THETA` bare literal removed, replaced by
1540
+ `ln_pinned(rope_theta as f32)`; §2.4's `rope_theta==100000.0`-only
1541
+ assert removed. Validated on SmolLM2-135M (`rope_theta=100000`,
1542
+ `inv_freq_table_digest` bit-identical to v0.1) and, informatively,
1543
+ Qwen2.5-0.5B (`rope_theta=1000000`, `docs/E15d_bc_RESULT.md`).
1544
+ 3. **Witness header now feeds raw 32-byte digest bytes, not 64-char
1545
+ hex-ASCII strings** (closes v0.1 §14.2/§12.1). `sha256_file()` now
1546
+ returns `[u8; 32]`; hex encoding moved to a display-only helper.
1547
+
1548
+ **Net effect on test vectors (§13.1)**: `CIS2_REF` changed
1549
+ (`ba88708bf4...` → `a0c563ef80...`); `table_digest` changed
1550
+ (`0bf9257bc5...` → `465d358ccd...`, because the coefficient set it
1551
+ covers grew to include the new `ln` table — not because of the raw-bytes
1552
+ change, which affects `CIS2_REF`'s artifact-hash inputs, not
1553
+ `table_digest`'s own internal computation); `inv_freq_table_digest`
1554
+ **unchanged** (`da9f6dcfde...`, both because its own construction was
1555
+ already raw-bytes in v0.1 and because `ln_pinned(100000.0)` reproduces
1556
+ the same `inv_freq` values `LN_THETA`'s literal did, to the precision
1557
+ that matters); `argmax_digest` and `generated_token_ids` **unchanged**
1558
+ (`0b9c8f3a...`; none of the three v0.2 changes touch what the model
1559
+ actually computes, only how the receipt hashes it).
1560
+
1561
+ Also in this branch (not spec content, but shipped alongside v0.2):
1562
+ the E15d(a) compiler-invariance workflow's pre-registered target updated
1563
+ from v0.1's `ba88708b...` to v0.2's `a0c563ef...`
1564
+ (`.github/workflows/e15d-compiler-invariance.yml`); a fresh
1565
+ 20-cell-matrix rerun and the E15d(b)/E15d(c) cross-ISA reruns against
1566
+ this v0.2 reference are recorded in `docs/E15d_v0.2_DIGESTS.md`.
1567
+
1568
+ - **v0.2.1 (2026-08-28, H4)** — doc-only, no digest change. Closes H3
1569
+ BLOCKER-2 (`docs/H3_SPEC_AUDIT.md`; carried forward from
1570
+ `verify3/SPEC_GAPS_v0.2.md` items 1–2): §3.1 is fully rewritten from a
1571
+ one-paragraph "HuggingFace `tokenizers`-format, BPE-family" pointer into
1572
+ a self-contained byte-level BPE specification — exact byte→unicode map
1573
+ construction, the literal GPT-2/ByteLevel pretokenizer regex plus the
1574
+ `Digits(individual_digits=true)` pre-split this checkpoint's
1575
+ `tokenizer.json` actually configures, the rank-ordered/leftmost-tie-break
1576
+ merge algorithm, special/added-token handling under
1577
+ `add_special_tokens=false`, and a worked example deriving
1578
+ `prompt_token_ids = [6403, 1980, 253, 655]` from the literal prompt
1579
+ string. §3.1.2 pins the reference library as a normative fallback
1580
+ (`tokenizers` crate v0.23.1) for any edge case the algorithm text does
1581
+ not resolve, per this spec's existing pattern of citing external
1582
+ standards (`sha256`, §2.1). No test-vector value in §13 changed; this
1583
+ entry only makes an already-correct, already-pinned token-id list
1584
+ reproducible from spec text alone. Verified by re-fetching the exact
1585
+ `tokenizer.json` (hash-checked against §2.1/§3.1.1) and confirming the
1586
+ Python `tokenizers` binding reproduces the pinned ids.
1587
+
1588
+ ---
1589
+
1590
+ ## Appendix A — source citations (informative; not required to implement this spec)
1591
+
1592
+ Every normative choice above is taken from this repo's `src/` at the
1593
+ commit checked out on branch `cm/e15i-spec-v0.2-doc` (based on
1594
+ `origin/cm/e15h-ref-fixes`, commit `98f541f`). Reference implementation
1595
+ state: post-E15h refactor (`docs/E15h_REFACTOR_v0.2_RESULT.md`), i.e. raw-
1596
+ byte digest hashing, table-digest binding, and theta-general `ln_pinned`
1597
+ all present. Citations below cover only what changed or is new versus
1598
+ v0.1's Appendix A; unlisted sections (§1, §2.1–2.3/2.5, §3, §4, §5, §6.1–
1599
+ 6.4, §8, §9.2–9.4, §10, §11.2) are unchanged from v0.1 and cite the same
1600
+ `file:line`s v0.1's own Appendix A already gives.
1601
+
1602
+ - §2.4 (removed restriction): v0.1's `rope_theta==100000.0` assert is gone
1603
+ from `src/main.rs`; `rope_theta` is read at `src/main.rs:331` and passed
1604
+ directly to `math::ln_pinned` at `src/main.rs:345`, with no equality
1605
+ assertion in between.
1606
+ - §6.5 `ln_pinned`: `src/math.rs:272-303` (`ln_pinned`), coefficient
1607
+ consts `src/math.rs:240-254` (`LOG_SQRTHF`, `LOG_Q1`, `LOG_Q2`,
1608
+ `LOG_P[0..9]`), unit test `src/math.rs:404-428`
1609
+ (`ln_matches_std_within_tolerance`, the tested-`x` set cited in §6.5).
1610
+ - §6.5.1 `frexp_exact`: `src/math.rs:256-267`.
1611
+ - §6.6 table digest (extended): `src/math.rs:337-367` (`table_digest`,
1612
+ the three new `h.update(...)` lines for `LOG_SQRTHF`/`LOG_Q1`/`LOG_Q2`/
1613
+ `LOG_P` are `src/math.rs:360-365`).
1614
+ - §7.1 `inv_freq` construction (generalized): `src/main.rs:334-354`
1615
+ (comment block explaining the E15d(c) generalization, then `let
1616
+ ln_theta = math::ln_pinned(rope_theta as f32);` at `src/main.rs:345`,
1617
+ the `inv_freq` loop at `:346-354`).
1618
+ - §7.2 `inv_freq_table_digest` (now bound into witness, still same
1619
+ construction): `src/main.rs:358-365` (digest computation, unchanged
1620
+ from v0.1's own Appendix A citation), `src/main.rs:516`
1621
+ (`witness.update(inv_freq_table_digest)`, new call site).
1622
+ - §9.1 QKV bias (new, informative for SmolLM2-135M which has none):
1623
+ `src/main.rs:90-97` (`add_bias_opt`), call sites `src/main.rs:155,157,159`.
1624
+ `LayerWeights.{q,k,v}_bias: Option<Vec<f32>>` fields `src/main.rs:35-37`;
1625
+ loader `src/main.rs:376-380` (`load_bias_opt`), populated
1626
+ `src/main.rs:407-409`.
1627
+ - §11.1 untied LM head (new, informative for SmolLM2-135M which is tied):
1628
+ `Model.lm_head: Option<Vec<f32>>` field `src/main.rs:56`; load-time
1629
+ branch on `tie_word_embeddings` `src/main.rs:415-423`; consumption at
1630
+ forward time `src/main.rs:219-220`.
1631
+ - §12.1 raw-byte witness header: `sha256_file` now returns `[u8; 32]`,
1632
+ `src/main.rs:245-250` (doc comment explicitly citing "CIS-2 v0.2 §12.1"
1633
+ at `:241-244`); witness seeding order `src/main.rs:555-561`
1634
+ (three artifact hashes first — weights, tokenizer, config — then
1635
+ `table_digest`, then `inv_freq_table_digest`, then prompt tokens); display-only hex helper `src/main.rs:252-261`
1636
+ (local `mod hex`).
1637
+ - §13.1 test vector values: `docs/E15h_REFACTOR_v0.2_RESULT.md` (full
1638
+ run transcript, `runs_identical = true`, this branch's commit
1639
+ `f227b43`+`36b5a0f`).
1640
+ - §13.4 compiler-invariance matrix: `.github/workflows/e15d-compiler-invariance.yml`
1641
+ (`TARGET_DIGEST` updated to `a0c563ef...` on `cm/e15i-spec-v0.2-doc`,
1642
+ superseding the v0.1-targeted value recorded in
1643
+ `docs/E15d_a_COMPILER_INVARIANCE.md`); results in
1644
+ `docs/E15d_v0.2_DIGESTS.md` (this branch).
1645
+ - Everything else (§1 FTZ/DAZ, §2.1/2.2/2.5 artifact+config+tensors, §3
1646
+ tokenizer/prompt/decode, §4 bf16 widening, §5 reductions, §6.1–6.4
1647
+ rsqrt/exp/sin/cos, §8 RMSNorm, §9.2–9.4 attention score/softmax/V-mix,
1648
+ §10 MLP, §11.2 argmax): unchanged `file:line`s from v0.1's own Appendix
1649
+ A, reproduced there in full and not re-cited here to avoid drift between
1650
+ two documents describing the same unchanged lines.
1651
+
1652
+ ## Appendix B — where this spec found the reference itself inconsistent or unpinned
1653
+
1654
+ (Every item cross-referenced to its §14 discussion above; v0.1's four
1655
+ items are carried forward with their resolution status noted; no new
1656
+ items were found during the v0.2 refactor beyond what v0.1 already
1657
+ flagged.)
1658
+
1659
+ 1. **RoPE `inv_freq` is theta-specific by construction: CLOSED in v0.2.**
1660
+ v0.1 flagged that `LN_THETA` was a bare literal despite surrounding code
1661
+ describing the implementation as "architecture-general... driven
1662
+ entirely from `config.json`". v0.2's `ln_pinned(rope_theta)` closes
1663
+ this specific inconsistency — the RoPE leg is now actually
1664
+ config-driven, matching the surrounding claim. Residual caveat: "closed"
1665
+ here means "no longer hardcoded to one value," not "proven correct for
1666
+ all values" — see §14.1's narrower, honest restatement. §14.1.
1667
+ 2. **Table digests not folded into `CIS2_REF`: CLOSED in v0.2.** §12.1
1668
+ items 1-2 now bind both digests. Residual caveat noted in §14.3: a
1669
+ `CIS2_REF` mismatch alone still does not localize *which* input
1670
+ diverged. §14.3.
1671
+ 3. **Digest byte encoding (hex-ASCII vs. raw bytes): CLOSED in v0.2.**
1672
+ `sha256_file` now returns `[u8; 32]`; there is no longer a hex `String`
1673
+ for the witness-chain call site to consume, so this can no longer
1674
+ silently regress to the v0.1 behavior without changing the function's
1675
+ own return type (a much harder mistake to make silently than v0.1's
1676
+ "call site happened to pick `.as_bytes()` on a hex `String`"). §14.2.
1677
+ 4. **`rsqrt`/`sqrt`/`/` remain the only operations in this whole spec that
1678
+ are unconditionally, provably cross-ISA-identical by the IEEE-754
1679
+ standard itself** — unchanged by v0.2; `exp`, `sin`, `cos`, and now
1680
+ `ln` are all pinned "by fiat" and have no such guarantee outside this
1681
+ document's specific coefficients. Carried forward verbatim as a
1682
+ standing caution, now covering one more transcendental (`ln`) than
1683
+ v0.1's version of this item.
EXPECTED_DIGESTS.md ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Expected digests
2
+
3
+ All digests below are SHA-256, lowercase hex. These are the pinned values
4
+ a conforming clean-room implementation of `docs/CIS2_SPEC_v0.3b.md` (current)
5
+ MUST reproduce bit-for-bit. No timing numbers are recorded anywhere in this
6
+ repository by policy. Historical v0.2 digests are kept below for reference.
7
+
8
+ ## Primary normative test vector (§13.1, spec v0.3b): SmolLM2-135M, `gen_toks=16`
9
+
10
+ Model: `HuggingFaceTB/SmolLM2-135M`, prompt `"Once upon a time"`, 16
11
+ greedy-decoded tokens, fp32 compute. Only `table_digest` and `CIS2_REF`
12
+ changed from v0.2 (RoPE range-reduction fix, see CHANGELOG.md v0.3/v0.3b);
13
+ `inv_freq_table_digest`, `argmax_digest`, and `generated_token_ids` are
14
+ unchanged from v0.1/v0.2.
15
+
16
+ ```
17
+ weights_sha256 = 80521b40281d6ce74e35c9282c22539e75aa0ac8578892b2a59955ef78d55da1
18
+ config_sha256 = 1d556eab73b69c7f11f64c557a2f9c6f440bd4c6b89bb2584a6b498c92603843
19
+ tokenizer_sha256 = 9ca9acddb6525a194ec8ac7a87f24fbba7232a9a15ffa1af0c1224fcd888e47c
20
+ table_digest = 23c7bfaf5cef0095fd021af2eb1808abb4928bae4219756d86bdac670a06b35d
21
+ inv_freq_table_digest = da9f6dcfde0425588815509e874515cdcd3d6b8818b6d0136590052e7bbf6f12
22
+ argmax_digest = 0b9c8f3ac90d0b9cd5f1719ac327dca1fc639fd87468305fccebbe3d56f67aff
23
+ generated_token_ids = 28,665,436,253,1838,8180,3365,14176,30,2306,4161,281,253,2066,2291,351
24
+
25
+ CIS2_REF (witness digest) = d82743059d1db929e710236fe4ec37f89e6f932524801345a006980f7c3cc9df
26
+ ```
27
+
28
+ This is the value `scripts/self_check.sh` builds `verify3/` and compares
29
+ against.
30
+
31
+ ## Historical: spec v0.2 primary test vector (superseded)
32
+
33
+ Model: `HuggingFaceTB/SmolLM2-135M`, prompt `"Once upon a time"`, 16
34
+ greedy-decoded tokens, fp32 compute.
35
+
36
+ ```
37
+ weights_sha256 = 80521b40281d6ce74e35c9282c22539e75aa0ac8578892b2a59955ef78d55da1
38
+ config_sha256 = 1d556eab73b69c7f11f64c557a2f9c6f440bd4c6b89bb2584a6b498c92603843
39
+ tokenizer_sha256 = 9ca9acddb6525a194ec8ac7a87f24fbba7232a9a15ffa1af0c1224fcd888e47c
40
+ table_digest = 465d358ccd63721256dbd2abbc77ad5de755adf3230635f95b12b1727dfa1ea3
41
+ inv_freq_table_digest = da9f6dcfde0425588815509e874515cdcd3d6b8818b6d0136590052e7bbf6f12
42
+ argmax_digest = 0b9c8f3ac90d0b9cd5f1719ac327dca1fc639fd87468305fccebbe3d56f67aff
43
+ generated_token_ids = 28,665,436,253,1838,8180,3365,14176,30,2306,4161,281,253,2066,2291,351
44
+
45
+ CIS2_REF (witness digest) = a0c563ef804f50413b7fb6619ae4afe9b51b1ffa7655e944221393e85d6261da
46
+ ```
47
+
48
+ Superseded by the v0.3b vector above; `scripts/self_check.sh` now targets
49
+ v0.3b's `CIS2_REF`.
50
+
51
+ **Note:** the informative 128-token, Qwen2.5-0.5B, and scale/horizon
52
+ vectors below were generated and confirmed against spec v0.2 only; they
53
+ have not been re-run against v0.3b as part of this port.
54
+
55
+ ## GPU confirmation of the §13.1 normative vector
56
+
57
+ The `CIS2_REF` value above was reproduced bit-for-bit by an independent CUDA
58
+ implementation on an NVIDIA Tesla P100 (sm_60) on 2026-09-08, alongside a
59
+ byte-identical per-step trace. Full result, scope limits and provenance:
60
+ `docs/GPU_RESULT.md`. One further informative vector was pinned by that run —
61
+ the same model and prompt at a longer horizon:
62
+
63
+ ```
64
+ SmolLM2-135M, "Once upon a time", gen_toks=128, spec v0.3b
65
+ CIS2_REF = 22f69ad87a615d66a77efaca8b1172d22bdfb4bd5092ceffd302e35669a050f6
66
+ ```
67
+
68
+ Two further digests from that run belong to a **candidate** pinned-tree
69
+ reduction order that is not part of v0.3b and is not normative; they are
70
+ recorded in `docs/GPU_RESULT.md` only.
71
+
72
+ ## Informative: 128-token prompt set (SmolLM2-135M, spec v0.2)
73
+
74
+ Five prompts of varying length, `gen_toks=128` each, confirmed identical
75
+ between x86_64 and aarch64 CI runners. These are informative
76
+ cross-ISA evidence, not §13.1 normative test vectors.
77
+
78
+ | prompt_idx | prompt_toks | `CIS2_REF` digest (`gen_toks=128`) |
79
+ |---|---|---|
80
+ | 0 | 4 | `e8d4f83fe623c329e2a56acb0efb0aa11614eda168e009ffcd014da110d5ac7d` |
81
+ | 1 | 11 | `e805baec6a932ff74d933ff0b51df045a75603f5409536a5325e46ab5a7ccc05` |
82
+ | 2 | 11 | `cf1ef40e0fda59fc72218e8f7daa9935e3f15083a1d92c4cde9729d8b015b803` |
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
89
+ a second model family with a different `rope_theta` and vocab size.
90
+
91
+ | gen_toks | `CIS2_REF` digest |
92
+ |---|---|
93
+ | 16 | `2c9f623589520aba9cc557edf53185808086f5f6f81cab5e78ee136d0375344c` |
94
+ | 128 | `dccd55e68a44eae3d62e36092295b40f980a07e1be72aadf37fe14ca306b20e7` |
95
+
96
+ ## Scale/horizon evidence: Qwen2.5-1.5B and SmolLM2-135M at longer horizons
97
+
98
+ A later hardening pass confirmed x86_64/aarch64 digest equality (not
99
+ listed here as literal hex — the source report records pass/fail
100
+ assertions, not the raw digest values) for:
101
+
102
+ - Qwen2.5-1.5B (~1.5B parameters) at `gen_toks` = 16, 128, and 512, plus a
103
+ PyTorch fp32 oracle comparison at 16 and 512 tokens.
104
+ - SmolLM2-135M at `gen_toks=512`.
105
+
106
+ These are cited here as evidence of scale- and horizon-robustness, not as
107
+ reproducible literal digests in this document; a reproducer wanting exact
108
+ hex values for these cases should regenerate them by running the
109
+ reference construction at the stated (model, `gen_toks`) pairs and
110
+ checking x86_64 vs. aarch64 equality directly, per §13.2 of the spec.
111
+
112
+ ## Sources
113
+
114
+ - Reference-implementation CI results and hardware logs (private
115
+ repository, not included here — see README "Scope").
116
+ - `docs/E15j_CLEANROOM_C_RESULT.md`-equivalent CI run (C clean-room,
117
+ `verify3/`), CI run id `33200155942` (post-§12.1-fix, 4/4 bit-exact on
118
+ x86_64/aarch64 x gcc/clang).
119
+ - Rust clean-room (`verify2/`) CI run id `33194049057` (spec v0.2, both
120
+ ISAs).
121
+ - Cross-ISA/compiler-invariance matrix CI run id `33195649908` (20/20
122
+ cells).
123
+ - Longer-horizon/scale hardening CI run id `33214545380` (9/9 jobs).
GPU_RESULT.md ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # GPU result — the §13.1 digest reproduced on an NVIDIA GPU
2
+
3
+ **Status: PASS. Run of 2026-09-08 12:07 UTC, NVIDIA Tesla P100-PCIE-16GB
4
+ (sm_60, Pascal), CUDA 12.8.**
5
+
6
+ An independent CUDA implementation of `docs/CIS2_SPEC_v0.3b.md` reproduces the
7
+ **primary normative `CIS2_REF` digest of this repository, bit-for-bit, on a
8
+ GPU** — the same value `scripts/self_check.sh` checks `verify3/` against on a
9
+ CPU.
10
+
11
+ ```
12
+ CIS2_REF, SmolLM2-135M, "Once upon a time", gen_toks=16, spec v0.3b
13
+
14
+ CPU reference (Rust, x86_64 and aarch64) d82743059d1db929e710236fe4ec37f89e6f932524801345a006980f7c3cc9df
15
+ CPU host build (g++, x86_64) d82743059d1db929e710236fe4ec37f89e6f932524801345a006980f7c3cc9df
16
+ GPU (nvcc, Tesla P100, sm_60) d82743059d1db929e710236fe4ec37f89e6f932524801345a006980f7c3cc9df
17
+ ```
18
+
19
+ ## All four vectors
20
+
21
+ | mode | `gen_toks` | `CIS2_REF` | CPU | GPU |
22
+ |---|---|---|---|---|
23
+ | sequential (v0.3b normative) | 16 | `d82743059d1db929e710236fe4ec37f89e6f932524801345a006980f7c3cc9df` | PASS | PASS |
24
+ | sequential (v0.3b normative) | 128 | `22f69ad87a615d66a77efaca8b1172d22bdfb4bd5092ceffd302e35669a050f6` | PASS | PASS |
25
+ | pinned tree (v0.4 **candidate**, not normative) | 16 | `3f3b1ffceca02e8e0e78d5c653963480ea988ef41a378acc5393006ad378e1b3` | PASS | PASS |
26
+ | pinned tree (v0.4 **candidate**, not normative) | 128 | `112661fbfcb11440ae7d27c43e45135f8a6ff9f6bc01189d756c76dac96a0fdf` | PASS | PASS |
27
+
28
+ The 16-token sequential digest is the §13.1 normative vector recorded in
29
+ `EXPECTED_DIGESTS.md`. The other three are **informative**: the 128-token
30
+ sequential digest extends the same prompt to a longer horizon, and the two
31
+ tree-mode digests belong to a *candidate* reduction order that is **not part of
32
+ v0.3b** and may or may not become v0.4.
33
+
34
+ The expected values and the CPU reference traces were generated on x86-64
35
+ (g++ and clang++) and frozen on 2026-09-03, five days before the GPU run.
36
+
37
+ ## Identity is byte-level, not only digest-level
38
+
39
+ The per-step trace — every intermediate the spec pins, not just the final
40
+ witness — is the same file on CPU and GPU:
41
+
42
+ ```
43
+ sha256(GPU 16-tok trace) = 9a559a9e284c5e5b2a78b29c0dbab0e2bb2ce0c2e48069dd6bac20331cad46b6
44
+ sha256(CPU 16-tok trace) = 9a559a9e284c5e5b2a78b29c0dbab0e2bb2ce0c2e48069dd6bac20331cad46b6
45
+
46
+ sha256(GPU tree trace) = 40c931cd080da04f8e926f84e7f6f5605eada74cd8f858baa4be0d6ae955f0bf
47
+ sha256(CPU tree trace) = 40c931cd080da04f8e926f84e7f6f5605eada74cd8f858baa4be0d6ae955f0bf
48
+ ```
49
+
50
+ The two modes hash differently from each other, which is the control that the
51
+ comparison discriminates.
52
+
53
+ ## How device execution was established
54
+
55
+ A GPU claim is only as good as the evidence that the code ran on the GPU.
56
+ Two independent checks, both machine-recorded:
57
+
58
+ 1. **`cuobjdump --dump-sass` on the shipped binaries** (not on a probe built
59
+ for the occasion) finds 13 kernel instantiations covering the whole forward
60
+ pass — embed, RMSNorm, matvec, RoPE, scores, softmax, weighted sum, KV
61
+ store, SiLU-multiply, add, add-bias. There is no host fallback path in the
62
+ nvcc build.
63
+ 2. **`nvidia-smi` sampled once per second** during the 128-token runs: mean GPU
64
+ utilization 58.2 % (max 87 %) sequential and 61.6 % (max 89 %) tree, across
65
+ 10 and 11 samples.
66
+
67
+ This is occupancy evidence for *where the code ran*. It is not a performance
68
+ measurement, and no timing number is claimed here or anywhere in this
69
+ repository.
70
+
71
+ ## The FMA gate, on the real binaries
72
+
73
+ The spec forbids FMA contraction in the pinned reductions. Compiled with
74
+ `-fmad=false -ftz=true -prec-div=true -prec-sqrt=true`, the shipped binaries
75
+ contain 63 `FFMA` instructions each, and none of them are in a reduction:
76
+
77
+ | kernel | FFMA | MUFU |
78
+ |---|---|---|
79
+ | matvec, scores, attention weighted-sum | **0** | — |
80
+ | embed, add, add-bias, KV store | **0** | — |
81
+ | RMSNorm (2 of 3 instantiations) | **0** | — |
82
+ | SiLU-multiply | 12 | 3 |
83
+ | softmax | 32 | 7 |
84
+ | RoPE | 1 | 3 |
85
+ | RMSNorm (1 instantiation) | 18 | 8 |
86
+
87
+ Every kernel that contains `FFMA` also contains `MUFU` — the reciprocal and
88
+ reciprocal-square-root seed instructions whose Newton–Raphson refinement steps
89
+ `-prec-div=true -prec-sqrt=true` emit for `/` and `sqrt`. Those refinements are
90
+ correctly rounded by construction; the bit-identical digest and the
91
+ byte-identical trace are the empirical evidence that they are, in this build,
92
+ on this device.
93
+
94
+ ## Scope — what this does and does not show
95
+
96
+ **Shows.** A specification written and audited for CPU fp32 — pinned reduction
97
+ order, no FMA contraction, no flush-to-zero, correctly rounded division and
98
+ square root, pinned transcendental polynomials, pinned RoPE tables — is
99
+ *sufficient* for an implementation on a fundamentally different execution model
100
+ to reproduce the CPU receipt bit-for-bit.
101
+
102
+ **Does not show.** Anything about performance; the run was correctness-only.
103
+ Anything about Ampere, Hopper or Blackwell; this is one Pascal device.
104
+ Anything about tensor-core paths; this port uses none. Anything about batched,
105
+ multi-stream, or multi-GPU execution. Anything about any model other than
106
+ SmolLM2-135M, or any horizon beyond 128 tokens.
107
+
108
+ One GPU generation, one driver and compiler version, one model, one prompt.
109
+
110
+ ## Prior art, and the wording of the claim
111
+
112
+ Reproducible and deterministic GPU inference is prior-occupied ground. Gensyn's
113
+ `repops` demonstrates a hash-matched CPU↔CUDA fp32 forward pass; Microsoft's
114
+ RepDL provides reproducible linear-algebra operators with CPU and CUDA
115
+ backends; vLLM and SGLang both ship batch-invariant determinism modes. This
116
+ repository makes **no "first" and no "only" claim** about deterministic GPU
117
+ inference, and none should be inferred from this document.
118
+
119
+ The narrower claim being made is about the *specification*: the artifact a
120
+ third party implements against here is a written document, and that document
121
+ turned out to carry enough information to cross an ISA boundary, a compiler
122
+ boundary, a language boundary, and now a CPU/GPU boundary without any of the
123
+ implementations consulting each other.
124
+
125
+ ## Availability of the GPU implementation
126
+
127
+ The CUDA port is **not included in this repository** and is not published.
128
+ What is published is what a third party needs to check the claim: the
129
+ specification, the CPU reference, two clean-room CPU implementations, and the
130
+ digests above. Anyone can write their own CUDA implementation from
131
+ `docs/CIS2_SPEC_v0.3b.md` and compare against `d82743059d1db929…`; that is the
132
+ intended way to falsify or confirm this result, and a matching independent GPU
133
+ implementation is exactly the contribution described in
134
+ "How to submit your own clean-room implementation" in the README.
135
+
136
+ ## Run provenance
137
+
138
+ - Kaggle kernel `aefinityaiinc/e18b-gpu`, GPU enabled, **internet disabled**,
139
+ finished 2026-09-08 12:07:11 UTC; container image pinned by digest
140
+ `sha256:37c64f7dd9c54116ecd1bcc88817c5469b88387388fade02bfa8bf3fc647d461`.
141
+ - Machine-readable verdicts (`nofma_cuda_pass`, `sequential_pass`,
142
+ `tree_candidate_pass`, all four digest comparisons, both `nvidia-smi`
143
+ summaries) were emitted by the run itself, not transcribed by hand.
144
+ - Earlier attempts v6 and v7 were **false positives** and are withdrawn: the
145
+ link step was missing `-x cu`, so the "GPU" binary was compiled as host C++
146
+ and executed on the CPU. v8 adds `-x cu`, gates the real binaries rather than
147
+ a standalone probe, and adds the utilization sampling. Do not cite v6 or v7.
148
+ - The earlier v5 run (2026-09-06, same device) reached the same four digests
149
+ but established device execution from source structure alone; its adversarial
150
+ review recorded that gap, and v8 closes it.
LICENSE ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the
44
+ purposes of this License, Derivative Works shall not include works
45
+ that remain separable from, or merely link (or bind by name) to the
46
+ interfaces of, the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including the
49
+ original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing
141
+ the origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Aefinity AI Inc.
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
PROTOCOL.md ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # `cis2-conformance` stdin/stdout protocol
2
+
3
+ This documents the exact wire contract a third-party binary must implement
4
+ to be checked by `cis2-conformance` (source: `src/bin/cis2_conformance.rs`
5
+ in this repo — reading that source is NOT required to implement a
6
+ conforming binary; this document is the full contract). No knowledge of
7
+ this repo's Rust code, `src/math.rs`, or `src/main.rs` is required either;
8
+ only this document and `tests/conformance/README.md` (which documents the
9
+ per-`op` field layout of each vector file).
10
+
11
+ ## Running the checker
12
+
13
+ ```
14
+ cargo run --release --bin cis2-conformance -- /path/to/your-binary
15
+ ```
16
+
17
+ or, against an already-built `cis2-conformance`:
18
+
19
+ ```
20
+ cis2-conformance /path/to/your-binary
21
+ ```
22
+
23
+ This runs **every** `tests/conformance/vectors/*.txt` / `*.expected` pair
24
+ against `your-binary`, invoking `your-binary` once per vector, and prints a
25
+ PASS/FAIL line per vector plus a final summary. Exit code is `0` if every
26
+ vector passed, `1` otherwise (including if `your-binary` fails to launch,
27
+ times out, or produces unparseable output on any vector).
28
+
29
+ ## Per-vector invocation
30
+
31
+ For each `<name>.txt` file under `tests/conformance/vectors/`:
32
+
33
+ 1. `cis2-conformance` spawns `your-binary` with **one argument**: the
34
+ vector's `op=` value (e.g. `your-binary rmsnorm`, `your-binary
35
+ attention_block`). This lets an implementation dispatch without having
36
+ to inspect the input first, but is redundant with the `op=` line inside
37
+ the input itself (both are provided; a conforming binary MUST accept
38
+ either identically-valued source, or ignore argv and parse `op=` from
39
+ stdin — both are conformant, since they are guaranteed to agree).
40
+ 2. `cis2-conformance` writes the **entire raw byte content** of
41
+ `<name>.txt` to `your-binary`'s stdin, unmodified (same `key=value`
42
+ text format documented in `tests/conformance/README.md`), then closes
43
+ stdin (EOF).
44
+ 3. `your-binary` MUST:
45
+ - Parse the `key=value` lines per `tests/conformance/README.md`'s
46
+ general format and the specific field layout documented there for
47
+ that vector's `op=` value.
48
+ - Compute the primitive named by `op=`, per the cited `spec_ref=`
49
+ section of `docs/CIS2_SPEC_v0.2.md`, exactly (bit-for-bit — no
50
+ tolerance, no "close enough": every operation in the cited section
51
+ must be reproduced in the exact order and association specified,
52
+ including strict left-to-right reduction (§5.1/§5.3), no
53
+ fused-multiply-add, and the pinned transcendental routes (§6)).
54
+ - Write to stdout, before exiting, **exactly one line** of the form:
55
+ ```
56
+ out_sha256=<64 lowercase hex chars>
57
+ ```
58
+ computed as SHA-256 over the concatenation of each output element's
59
+ 4 raw IEEE-754 binary32 bytes, **little-endian**, in index order —
60
+ the same convention `tests/conformance/README.md` and
61
+ `src/math.rs::table_digest` use (`out_sha256` in each `.expected`
62
+ file is exactly this digest).
63
+ - Optionally also write a second line `out_bits=<comma-separated
64
+ 0x-prefixed 32-bit hex>` (same convention as `.expected`'s
65
+ `out_bits`) — `cis2-conformance` will report it in diagnostic output
66
+ on a mismatch if present, but only `out_sha256` is checked for
67
+ pass/fail.
68
+ - Exit with status `0` on success. Any nonzero exit status is treated
69
+ as a FAIL for that vector regardless of stdout content.
70
+ 4. `your-binary` MUST NOT read any file from disk, make any network call,
71
+ or depend on any state outside its own stdin — every input the
72
+ computation needs is in the `.txt` content on stdin. This is what makes
73
+ the suite runnable against an arbitrary black-box binary with no shared
74
+ filesystem layout assumptions.
75
+ 5. `cis2-conformance` compares `your-binary`'s `out_sha256=` line (trimmed,
76
+ case-insensitively) against the pinned `out_sha256=` field of
77
+ `<name>.expected`. Match is PASS; anything else (missing line, mismatch,
78
+ nonzero exit, timeout, unparseable stdout) is FAIL, with a diagnostic
79
+ printed to `cis2-conformance`'s own stdout.
80
+
81
+ ## Example: one full stdin blob
82
+
83
+ For `rmsnorm_v1`, `your-binary rmsnorm` receives on stdin exactly the byte
84
+ content of `tests/conformance/vectors/rmsnorm_v1.txt` (see that file), and
85
+ must write to stdout:
86
+
87
+ ```
88
+ out_sha256=f712eda3e8b49d3d84639db584c134fe265f7994a21dede9f401d7be9bc5e60c
89
+ ```
90
+
91
+ (optionally preceded or followed by an `out_bits=...` line), then exit 0.
92
+
93
+ ## Timeouts
94
+
95
+ `cis2-conformance` allows each vector invocation up to 10 seconds
96
+ wall-clock before treating it as a FAIL (`timeout`). Every vector in this
97
+ suite is small (hand-sized inputs, no model weights), so a conforming
98
+ implementation should return in well under a second; the timeout exists
99
+ only to keep a hung or blocking candidate binary from stalling the whole
100
+ run.
101
+
102
+ ## What this does NOT cover
103
+
104
+ This protocol checks individual normative primitives in isolation (one
105
+ `RMSNorm` call, one RoPE table, one `exp_pinned` evaluation, one attention
106
+ block, one matvec) — it is deliberately narrower than the full
107
+ end-to-end §13.1 witness digest in `EXPECTED_DIGESTS.md`, which requires
108
+ loading the actual SmolLM2-135M weights and running a full forward pass.
109
+ Passing every vector here is necessary but not sufficient evidence of
110
+ full-model conformance.
README.md ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ pretty_name: CIS-2 — conformance vectors for bit-identical fp32 transformer inference
4
+ language:
5
+ - en
6
+ tags:
7
+ - reproducibility
8
+ - determinism
9
+ - verification
10
+ - inference
11
+ - floating-point
12
+ - specification
13
+ - conformance
14
+ size_categories:
15
+ - n<1K
16
+ ---
17
+
18
+ # CIS-2 — conformance vectors for bit-identical fp32 transformer inference
19
+
20
+ Floating-point transformer inference is usually treated as unavoidably
21
+ nondeterministic across hardware. Reduction order, FMA contraction, denormal
22
+ handling and platform math libraries all differ between x86_64 and aarch64, and
23
+ between compilers, so "the same model on the same input" in practice means
24
+ "agrees to within a tolerance", not bit-for-bit.
25
+
26
+ **CIS-2 is a written specification that removes those degrees of freedom**, and
27
+ this repository holds the artifacts a third party needs to check whether their
28
+ own implementation conforms: the spec text, five op-level conformance vectors
29
+ with pinned expected outputs, the expected end-to-end digests, and the GPU
30
+ result.
31
+
32
+ Everything here is Apache-2.0. Source of truth and CI:
33
+ **https://github.com/Aefinity-AI/cis2-spec**
34
+
35
+ ## The claim
36
+
37
+ ```
38
+ CIS2_REF, SmolLM2-135M, prompt "Once upon a time", 16 greedy tokens, spec v0.3b
39
+ d82743059d1db929e710236fe4ec37f89e6f932524801345a006980f7c3cc9df
40
+ ```
41
+
42
+ That digest is a SHA-256 witness chain folded over the **complete fp32 logit
43
+ vector at every decode step** — not the argmax token, the whole vector. It is
44
+ currently reproduced by:
45
+
46
+ | implementation | written from | platforms |
47
+ |---|---|---|
48
+ | Rust reference | — | x86_64, aarch64 (native runners) |
49
+ | Rust clean-room `verify2/` | the spec text alone | x86_64, aarch64 |
50
+ | C11 clean-room `verify3/` | the spec text alone | x86_64, aarch64 · gcc and clang |
51
+ | CUDA port (not published) | the spec text alone | NVIDIA Tesla P100, sm_60, CUDA 12.8 |
52
+
53
+ The two clean-room implementations were written without access to the reference
54
+ source or to each other. Public CI re-checks all of the CPU rows on every push.
55
+ The GPU row is documented in `GPU_RESULT.md`; on that run the per-step trace was
56
+ **byte-identical** to the CPU trace, not merely equal at the final digest.
57
+
58
+ ## What is pinned
59
+
60
+ - Reduction order — strictly left-to-right, sequential.
61
+ - FMA contraction — forbidden, and gated by `objdump` in CI.
62
+ - Denormals — FTZ/DAZ on, pinned via MXCSR (x86) and FPCR.FZ (aarch64).
63
+ - Transcendentals — `sin`/`cos` by octant reduction plus separate Cephes-pattern
64
+ minimax polynomials; `exp` and `ln` by pinned Cephes-pattern polynomials;
65
+ `rsqrt` correctly rounded with no table. Every coefficient is pinned as an f32
66
+ hex literal and hashed into the witness chain.
67
+ - RoPE `inv_freq` — pinned table, theta-general.
68
+ - Tokenization — byte-level BPE pinned at the byte level.
69
+
70
+ Full normative text: `CIS2_SPEC_v0.3b.md` (§13.1 carries the pinned vector).
71
+
72
+ ## Files
73
+
74
+ | file | what it is |
75
+ |---|---|
76
+ | `CIS2_SPEC_v0.3b.md` | the normative specification |
77
+ | `EXPECTED_DIGESTS.md` | pinned end-to-end digests, including the GPU confirmation |
78
+ | `GPU_RESULT.md` | the 2026-09-08 NVIDIA Tesla P100 run, with its scope limits |
79
+ | `PROTOCOL.md` | the stdin/stdout wire contract a third-party binary implements |
80
+ | `vectors/README.md` | per-op field layout of each vector file |
81
+ | `vectors/*.txt` | five op-level input vectors: matvec, rmsnorm, rope, exp_pinned, attention_block |
82
+ | `vectors/*.expected` | the pinned expected output for each |
83
+
84
+ The vectors are plain text `key=value` files with float fields given as exact
85
+ hex bit patterns, so parsing introduces no rounding of its own. They exist so an
86
+ implementation can be checked **op by op** — you find out *which* operation
87
+ diverges, instead of only that a 64-character digest came out wrong.
88
+
89
+ ## How to check your own implementation
90
+
91
+ ```bash
92
+ git clone https://github.com/Aefinity-AI/cis2-spec
93
+ cd cis2-spec
94
+ cargo run --release --bin cis2-conformance -- /path/to/your-binary
95
+ ```
96
+
97
+ `PROTOCOL.md` is the complete contract; you do not need to read any of this
98
+ project's Rust to implement against it.
99
+
100
+ ## Scope, stated plainly
101
+
102
+ fp32 scalar reference semantics, not a fast kernel. Greedy decoding. Models
103
+ checked up to 1.5B parameters. The GPU leg is one Pascal device, one toolchain,
104
+ correctness only — no tensor cores, no batching, no timing number is claimed
105
+ anywhere in this project. The CUDA port itself is deliberately not published, so
106
+ a second GPU implementation written from the spec would be a genuine independent
107
+ check rather than a re-run of ours; that is the contribution we are asking for.
108
+
109
+ ## Prior art
110
+
111
+ Reproducible and deterministic inference is prior-occupied ground. Gensyn's
112
+ `repops` demonstrates a hash-matched CPU/CUDA fp32 forward pass; Microsoft's
113
+ RepDL provides reproducible linear-algebra operators with CPU and CUDA backends;
114
+ vLLM and SGLang both ship batch-invariant determinism modes; and
115
+ arXiv:2606.00279 verifies bit-exact GPU inference by emulating vendor silicon
116
+ tables. **No "first" and no "only" claim is made here**, and none should be
117
+ inferred.
118
+
119
+ The narrower thing CIS-2 is testing is whether a *written document* can carry
120
+ enough information for strangers to converge on identical bits — across an ISA
121
+ boundary, a compiler boundary, a language boundary, and a CPU/GPU boundary,
122
+ with no implementation consulting another.
123
+
124
+ ## Falsification bounty
125
+
126
+ There is a standing $50-per-distinct-root-cause bounty for breaking this:
127
+ https://github.com/Aefinity-AI/alice-aegis/blob/main/CHALLENGE.md — write your
128
+ own implementation from `CIS2_SPEC_v0.3b.md`, in any language for any device,
129
+ and get a different digest. If the disagreement is because the spec text permits
130
+ two readings, that is the finding most worth paying for: it means the document
131
+ is not yet sufficient, which is the entire thing CIS-2 claims to be.
132
+
133
+ ---
134
+
135
+ Aefinity AI Inc. · Justin Brian Thompson
vectors/README.md ADDED
@@ -0,0 +1,304 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
5
+ building or reading this repo's `src/`, `verify2/`, or `verify3/`. It is
6
+ narrower and more granular than the full end-to-end §13.1 witness digest
7
+ in `EXPECTED_DIGESTS.md` (which requires the SmolLM2-135M weights and a
8
+ 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
+
19
+ Each vector is a pair of files under `vectors/`:
20
+
21
+ - `<name>.txt` — the input. `key=value` lines. Vector-valued fields
22
+ (suffixed `_bits`) are comma-separated `0x`-prefixed 32-bit hex
23
+ strings, each the raw IEEE-754 binary32 bit pattern of one element (not
24
+ a decimal literal — this avoids any ambiguity from a language's
25
+ string-to-float parser rounding differently than another's). Scalar
26
+ fields follow the same `_bits` convention.
27
+ - `<name>.expected` — the pinned output: `out_bits` (same comma-separated
28
+ hex-bit-pattern convention, one element per output value, in index
29
+ order) and `out_sha256` (lowercase hex SHA-256 of the concatenation of
30
+ each output element's 4 raw bytes, **little-endian**, in index order —
31
+ the same "feed_f32_le" convention `src/math.rs::table_digest` already
32
+ uses in this repo).
33
+
34
+ A conforming implementation reproduces `out_bits` exactly (bit-for-bit,
35
+ not "close") and therefore also `out_sha256`. The digest is provided as a
36
+ convenience for a one-line pass/fail check; the bit patterns are the
37
+ normative artifact.
38
+
39
+ A `cis2-conformance <your-binary>` CLI wrapper exists (`src/bin/cis2_conformance.rs`,
40
+ run via `cargo run --release --bin cis2-conformance -- /path/to/your-binary`)
41
+ that drives every vector below against an arbitrary black-box binary over
42
+ stdin/stdout and reports PASS/FAIL per vector — see `PROTOCOL.md` for the
43
+ exact wire contract. An implementer may use that wrapper directly, or
44
+ hand-roll the same steps against these files without it:
45
+
46
+ 1. Parses `<name>.txt`.
47
+ 2. Runs the algorithm cited by `spec_ref=` in that file, on that input,
48
+ in fp32, following every rule in the cited section (reduction order,
49
+ no FMA, association order, etc. — see `docs/CIS2_SPEC_v0.2.md` §§1–3
50
+ for the general rules that apply throughout, not just the cited
51
+ section).
52
+ 3. Compares the output bit patterns against `<name>.expected`'s
53
+ `out_bits`.
54
+
55
+ ## Vectors
56
+
57
+ ### `rmsnorm_v1` (§8 RMSNorm)
58
+
59
+ - Spec reference: `docs/CIS2_SPEC_v0.2.md` §8 (RMSNorm), which in turn
60
+ depends on §5.3 (strict left-to-right sequential sum) and §6.1 (`rsqrt`
61
+ = `1.0f32 / x.sqrt()`, both IEEE-754-mandatory correctly-rounded ops).
62
+ - `n=8` (deliberately small and hand-checkable; the real model uses
63
+ `hidden=576`, but the algorithm is length-independent).
64
+ - Algorithm (verbatim from spec §8):
65
+ ```
66
+ for i in 0..n: sq[i] = x[i] * x[i]
67
+ ss = sum_seq(sq) # §5.3, strict left-to-right
68
+ mean = ss / (n as f32)
69
+ inv = rsqrt(mean + eps) # §6.1: 1.0 / (mean+eps).sqrt()
70
+ for i in 0..n:
71
+ scaled = x[i] * inv
72
+ out[i] = scaled * weight[i] # THIS association, not x[i]*(inv*weight[i])
73
+ ```
74
+ - `eps_bits=0x3727C5AC` is CIS-2's pinned `EPS_F32` (§2.3: `1.0e-5f64` cast
75
+ to f32), used everywhere in the spec, not a value specific to this
76
+ vector.
77
+ - Input `x` and `gamma` were chosen to be exactly representable in f32
78
+ (halves/quarters of small integers), so there is no ambiguity in how
79
+ `<name>.txt` itself was produced, only in how the RMSNorm arithmetic is
80
+ carried out.
81
+
82
+ **How this vector was derived** (so it is provably correct, not just
83
+ asserted): `tests/conformance_rmsnorm.rs` includes `src/math.rs` by path
84
+ (`sum_seq`, `rsqrt_cr` — the same functions `src/main.rs::rmsnorm` calls
85
+ for the full-model §13.1 witness digest) and reimplements the §8 loop
86
+ above verbatim, computes the SHA-256 digest per the convention above, and
87
+ asserts both the bit patterns and the digest match
88
+ `vectors/rmsnorm_v1.expected`. Run it with:
89
+
90
+ ```
91
+ cargo test --test conformance_rmsnorm
92
+ ```
93
+
94
+ This was run once while authoring the vector (see `LOG.md`/commit
95
+ message for the exact `cargo test` output) to derive `rmsnorm_v1.expected`
96
+ from the reference implementation; the test now exists as a standing
97
+ self-check that the fixture stays correct across any future edit to
98
+ `src/math.rs`.
99
+
100
+ ### `rope_v1` (§7 RoPE table: `inv_freq` + per-position cos/sin)
101
+
102
+ - Spec reference: `docs/CIS2_SPEC_v0.2.md` §7 (RoPE), specifically §7.1
103
+ (`inv_freq` construction via the general, theta-general
104
+ `ln_pinned(rope_theta)` / `exp_pinned` route — not v0.1's hardcoded
105
+ literal), §7.2 (`inv_freq_table_digest`), and §7.3 (per-position
106
+ cos/sin table). §7.4 (rotate-half application to a query/key head) is
107
+ NOT covered by this vector — it is pure elementwise arithmetic given a
108
+ cos/sin table and is deferred to a future attention-block vector (see
109
+ "What's missing").
110
+ - `head_dim=8` (so `half = head_dim/2 = 4`; deliberately small and
111
+ hand-checkable, same rationale as `rmsnorm_v1`'s `n=8` — the real model
112
+ uses `head_dim=64`, but the construction is length-independent).
113
+ - `rope_theta=10000.0` (`0x461C4000`) — deliberately **not** one of the
114
+ two model-pinned values (`100000.0` SmolLM2, `1000000.0` Qwen2.5-0.5B)
115
+ cited in spec §7's "which `rope_theta` values are conformant" note, to
116
+ exercise the theta-general `ln_pinned` path at an arbitrary value rather
117
+ than only the two values the spec's own worked examples use.
118
+ - `positions=0,3` — two hand-sized sequence positions (§7.3's `pos`,
119
+ cast to f32 exactly), to exercise both the degenerate `pos=0` case
120
+ (`angle=0` for every `i`, so `cos_v` is all `1.0` and `sin_v` is all
121
+ `0.0` bit-exactly — a useful sanity check that range reduction doesn't
122
+ perturb the zero case) and a nonzero case.
123
+ - `out_bits` layout (20 values, index order): `inv_freq[0..4)`, then
124
+ `cos_v[0..4)`/`sin_v[0..4)` at `pos=0`, then `cos_v[0..4)`/`sin_v[0..4)`
125
+ at `pos=3` — see the header comment in `rope_v1.expected` for the exact
126
+ slice boundaries.
127
+ - Two digests are pinned: `out_sha256` (this suite's general convention,
128
+ full output, same as `rmsnorm_v1`) and `inv_freq_table_digest` (raw
129
+ SHA-256 over only the `inv_freq` values, index order — the same
130
+ construction as spec §7.2 and `src/main.rs`'s own
131
+ `inv_freq_table_digest` variable, so this vector can also be checked
132
+ directly against that specific spec definition).
133
+
134
+ **How this vector was derived**: `tests/conformance_rope.rs` includes
135
+ `src/math.rs` by path (`ln_pinned`, `exp_pinned`, `cos_pinned`,
136
+ `sin_pinned` — the same functions `src/main.rs` calls for the full-model
137
+ inv_freq/cos/sin construction) and reimplements §7.1/§7.2/§7.3 verbatim,
138
+ then asserts both the per-element bit patterns and both digests match
139
+ `vectors/rope_v1.expected`. Run it with:
140
+
141
+ ```
142
+ cargo test --test conformance_rope
143
+ ```
144
+
145
+ This was run once while authoring the vector to derive `rope_v1.expected`
146
+ from the reference implementation; the test now exists as a standing
147
+ self-check that the fixture stays correct across any future edit to
148
+ `src/math.rs`. (An `#[ignore]`d `print_bits_for_generation` test in the
149
+ same file is not part of the pinned suite; it exists only to
150
+ regenerate the fixture if the reference math ever changes — run with
151
+ `cargo test --test conformance_rope print_bits -- --ignored --nocapture`.)
152
+
153
+ ### `exp_pinned_v1` (§6.2 pinned exp(x) polynomial)
154
+
155
+ - Spec reference: `docs/CIS2_SPEC_v0.2.md` §6.2 (the pinned exp(x) route
156
+ (b) fallback described normatively in `src/math.rs::exp_pinned`'s module
157
+ doc comment) — the same function used by §7.1's RoPE `inv_freq`
158
+ construction (already exercised indirectly by `rope_v1` above), §9's
159
+ softmax, and SiLU's gate.
160
+ - `n=8` (deliberately small and hand-sized, same rationale as
161
+ `rmsnorm_v1`'s `n=8` / `rope_v1`'s `head_dim=8`).
162
+ - Inputs span §6.2's documented accuracy domain `x in [-40,40]` (softmax
163
+ post-max-sub args <= 0, SiLU gate args, RoPE inv_freq exponents): the two
164
+ domain endpoints (`-40.0`, `40.0`), mid-range values on each side
165
+ (`-10.0`, `-1.0`, `10.0`), the two special values `0.0` and `1.0`
166
+ (`exp(0)=1` exactly is a useful bit-exact sanity check that range
167
+ reduction doesn't perturb the zero case), and `0.5` for a non-integer,
168
+ non-zero small positive value.
169
+ - `out_bits` layout: 8 values, index order matching `x_bits`.
170
+ - Only the general `out_sha256` convention is pinned here (no
171
+ table-specific digest, unlike `rope_v1`'s `inv_freq_table_digest`) —
172
+ `src/math.rs::table_digest()` already covers the exp/sin/cos/ln
173
+ coefficient tables as a whole (see `EXPECTED_DIGESTS.md`); this vector
174
+ is about the *function's output* on specific inputs, not the
175
+ coefficients themselves.
176
+
177
+ **How this vector was derived**: `tests/conformance_exp_pinned.rs`
178
+ includes `src/math.rs` by path (`exp_pinned` — the same function
179
+ `src/main.rs`/`src/math.rs::silu_pinned`/`src/math.rs::softmax_seq` call)
180
+ and evaluates it directly on each `x_bits` input, computes the SHA-256
181
+ digest per the convention above, and asserts both the bit patterns and
182
+ the digest match `vectors/exp_pinned_v1.expected`. Run it with:
183
+
184
+ ```
185
+ cargo test --test conformance_exp_pinned
186
+ ```
187
+
188
+ This was run once while authoring the vector (see `LOG.md`/commit
189
+ message for the exact `cargo test` output) to derive
190
+ `exp_pinned_v1.expected` from the reference implementation; the test now
191
+ exists as a standing self-check that the fixture stays correct across any
192
+ future edit to `src/math.rs`. (An `#[ignore]`d `print_bits_for_generation`
193
+ test in the same file is not part of the pinned suite; it exists only to
194
+ regenerate the fixture if the reference math ever changes — run with
195
+ `cargo test --test conformance_exp_pinned print_bits -- --ignored --nocapture`.)
196
+
197
+ ### `attention_block_v1` (§9.2 Score, §9.3 Softmax, §9.4 V-mix)
198
+
199
+ - Spec reference: `docs/CIS2_SPEC_v0.2.md` §9.2 (score: `dot_seq(q_head,
200
+ k_j) * rsqrt(head_dim)`, the multiply by scale applied *after* the dot,
201
+ as a separate op), §9.3 (softmax, in place), §9.4 (V-mix: for each
202
+ output dim, a strict left-to-right accumulation of `scores[j] *
203
+ v[j][d]`). RoPE (§7, already covered by `rope_v1` above) is assumed
204
+ already applied to the `q_head`/`k_bits` inputs, per §9.1's ordering
205
+ (RoPE happens before scoring) — this vector starts from already-rotated
206
+ q/k, as the spec's own §9.2 step does.
207
+ - `head_dim=8`, `seq_len=3` (deliberately small and hand-sized, same
208
+ rationale as the other vectors above; the real model uses `head_dim=64`
209
+ and a much longer causal cache, but the algorithm is length-independent).
210
+ Every cached position `j = 0..=pos` (`pos = seq_len - 1`) is attended
211
+ (causal, current step).
212
+ - GQA's `kv_head = qh / group` head-to-KV-head mapping (§9's opening
213
+ paragraph) is a pure indexing detail on top of this same per-head
214
+ arithmetic, not additional numeric behavior, so this vector covers
215
+ exactly one query head against its already-selected KV cache and does
216
+ not separately exercise the mapping.
217
+ - `out_bits` layout: `head_dim=8` values, `out_head[0..head_dim)`, index
218
+ order.
219
+
220
+ **How this vector was derived**: `tests/conformance_attention_block.rs`
221
+ includes `src/math.rs` by path (`dot_seq`, `rsqrt_cr`, `softmax_seq` — the
222
+ same functions `src/main.rs`'s per-layer attention loop calls) and
223
+ reimplements the §9.2/§9.3/§9.4 pipeline above verbatim, computes the
224
+ SHA-256 digest per the convention above, and asserts both the bit
225
+ patterns and the digest match `vectors/attention_block_v1.expected`. Run
226
+ it with:
227
+
228
+ ```
229
+ cargo test --test conformance_attention_block
230
+ ```
231
+
232
+ This was run once while authoring the vector to derive
233
+ `attention_block_v1.expected` from the reference implementation; the test
234
+ now exists as a standing self-check that the fixture stays correct across
235
+ any future edit to `src/math.rs`. (An `#[ignore]`d
236
+ `print_bits_for_generation` test in the same file is not part of the
237
+ pinned suite; it exists only to regenerate the fixture if the reference
238
+ math ever changes — run with `cargo test --test conformance_attention_block
239
+ print_bits -- --ignored --nocapture`.)
240
+
241
+ ### `matvec_v1` (§5.2 Matvec)
242
+
243
+ - Spec reference: `docs/CIS2_SPEC_v0.2.md` §5.2 (matvec: `y[o] =
244
+ dot_seq(w[o,:], x)` for each output row `o`), which in turn depends on
245
+ §5.1 (strict left-to-right sequential dot product).
246
+ - `out_features=3`, `in_features=3` (deliberately small and hand-sized,
247
+ same rationale as the other vectors above).
248
+ - Row 0 of `w` is §5.1's own worked order-sensitivity example verbatim
249
+ (`[1e8, 1.0, -1e8]` dotted against `x = [1,1,1]`), which must give
250
+ exactly `0.0_f32` (the `1.0` term is lost to rounding against the `1e8`
251
+ partial sum) — a conforming implementation MUST reproduce this exact
252
+ cancellation, not just "close". Rows 1 and 2 use small
253
+ exactly-representable values.
254
+ - `out_bits` layout: 3 values, `y[0]` (the §5.1 example, must be exactly
255
+ `0x00000000`), `y[1]`, `y[2]`.
256
+
257
+ **How this vector was derived**: `tests/conformance_matvec.rs` includes
258
+ `src/math.rs` by path (`dot_seq` — the same function `src/main.rs`'s
259
+ per-layer projections/MLP/lm_head calls use) and reimplements §5.2's
260
+ per-row matvec verbatim, computes the SHA-256 digest per the convention
261
+ above, and asserts both the bit patterns and the digest match
262
+ `vectors/matvec_v1.expected`. Run it with:
263
+
264
+ ```
265
+ cargo test --test conformance_matvec
266
+ ```
267
+
268
+ This was run once while authoring the vector to derive
269
+ `matvec_v1.expected` from the reference implementation; the test now
270
+ exists as a standing self-check that the fixture stays correct across any
271
+ future edit to `src/math.rs`. (An `#[ignore]`d `print_bits_for_generation`
272
+ 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
279
+ documented in `PROTOCOL.md`: given a path to a third-party binary, it
280
+ runs every vector above against that binary (one invocation per vector,
281
+ vector's `op=` value as argv, `.txt` content on stdin, `out_sha256=...`
282
+ expected on stdout) and reports PASS/FAIL per vector plus a summary. See
283
+ `PROTOCOL.md` for the full wire contract. `src/bin/cis2_conformance_reference_candidate.rs`
284
+ is a reference candidate binary (reusing `src/math.rs` directly, unlike a
285
+ real third-party candidate) that exists only to smoke-test
286
+ `cis2-conformance` itself against a known-good implementation; it is not
287
+ part of the advertised protocol surface.
288
+
289
+ ```
290
+ cargo run --release --bin cis2-conformance -- /path/to/your-binary
291
+ ```
292
+
293
+ ## What's missing (next pass, E21 continues)
294
+
295
+ Not yet done:
296
+
297
+ - RoPE §7.4 rotation vector (apply a pinned cos/sin table to a hand-sized
298
+ query/key head slice — pure elementwise arithmetic, not covered by
299
+ `rope_v1` above; `attention_block_v1` above assumes RoPE already
300
+ applied rather than exercising the rotation step itself).
301
+ - A dual-ISA (x86_64/aarch64) CI job that runs this suite against the
302
+ in-repo reference implementation on both ISAs, the same way
303
+ `scripts/self_check.sh` / CI already does for the full §13.1 vector
304
+ (explicitly out of scope for this pass).
vectors/attention_block_v1.expected ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Pinned expected output for attention_block_v1.txt, computed by running
2
+ # the reference implementation's §9.2/§9.3/§9.4 attention pipeline
3
+ # (src/math.rs::dot_seq/rsqrt_cr/softmax_seq, the same functions
4
+ # src/main.rs's per-layer attention loop calls) via
5
+ # `cargo test --test conformance_attention_block` (see
6
+ # tests/conformance_attention_block.rs and
7
+ # tests/conformance/README.md "How this vector was derived").
8
+ #
9
+ # out_bits layout (8 values, index order): out_head[0..head_dim).
10
+ out_bits=0x3EE07710,0x3F0FC478,0x3F5F2076,0xBEB2D98A,0x3E429008,0x3F4F5BFE,0x3D7C477E,0x3F5F2076
11
+ out_sha256=65aecf9371ddb897b2075931594b6ff7bce93f33546089f0d733f1698a7ebfd9
vectors/attention_block_v1.txt ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CIS-2 conformance vector: attention_block_v1
2
+ # op=attention_block, spec ref: docs/CIS2_SPEC_v0.2.md §9.2 (Score), §9.3
3
+ # (Softmax), §9.4 (V-mix) -- one query head's full score/softmax/V-mix
4
+ # pipeline against a small causal KV cache. Deliberately covers ONE head
5
+ # only: GQA's `kv_head = qh / group` head-mapping (§9, opening paragraph)
6
+ # is a pure indexing detail on top of this same per-head arithmetic, not
7
+ # additional numeric behavior, so it is not separately vectored here.
8
+ # RoPE (§7, already covered by rope_v1) is assumed already applied to
9
+ # `q_head`/`k_j` inputs below, per §9.1's ordering (RoPE happens before
10
+ # scoring) -- this vector starts from already-rotated q/k, as the spec's
11
+ # §9.2 step itself does.
12
+ #
13
+ # Fields are `key=value`. `head_dim`/`seq_len` are plain decimal integers.
14
+ # `q_head_bits` is head_dim values (the current step's query head, already
15
+ # RoPE-rotated). `k_bits`/`v_bits` are `seq_len * head_dim` values,
16
+ # ROW-MAJOR (cached key/value at position 0's head_dim entries, then
17
+ # position 1, ... up to and including the current step `pos = seq_len -
18
+ # 1`, causal -- every cached position is attended, per §9.2's `j =
19
+ # 0..=pos`). All comma-separated `0x`-prefixed 32-bit hex IEEE-754 binary32
20
+ # bit patterns, per tests/conformance/README.md's general convention.
21
+ op=attention_block
22
+ spec_ref=docs/CIS2_SPEC_v0.2.md#9-attention-gqa-causal-per-decode-step-normative
23
+ head_dim=8
24
+ seq_len=3
25
+ q_head_bits=0x3F800000,0x3F000000,0xBF000000,0x40000000,0xBF800000,0x3E800000,0x3F400000,0xC0000000
26
+ k_bits=0x3F000000,0x3F800000,0x3F800000,0xBF800000,0x3F000000,0x3F000000,0xBF000000,0x3F800000,0x3F800000,0xBF800000,0x3F000000,0x3F000000,0x3F800000,0xBF000000,0x3F000000,0x3F000000,0xBF000000,0x3F000000,0x3F800000,0x3F800000,0xBF800000,0x3F800000,0x3F000000,0xBF000000
27
+ v_bits=0x3F800000,0x00000000,0x00000000,0x3F800000,0x3F000000,0x3F000000,0xBF000000,0x00000000,0x00000000,0x3F800000,0x3F000000,0x00000000,0x3F800000,0x00000000,0x3F000000,0x3F000000,0x3F000000,0x3F000000,0x3F800000,0xBF000000,0x00000000,0x3F800000,0x00000000,0x3F800000
vectors/exp_pinned_v1.expected ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ # Pinned expected output for exp_pinned_v1.txt, computed by running the
2
+ # reference implementation's pinned exp(x) (src/math.rs::exp_pinned) via
3
+ # `cargo test --test conformance_exp_pinned` (see
4
+ # tests/conformance_exp_pinned.rs and tests/conformance/README.md "How
5
+ # this vector was derived").
6
+ out_bits=0x229CBC92,0x383E6BCE,0x3EBC5AB2,0x3F800000,0x3FD3094C,0x402DF854,0x46AC14EE,0x5C51106A
7
+ out_sha256=36c626b5cc5513b5297314fcb22f428891ad5713d39f0d45b9d27f229cd42bff
vectors/exp_pinned_v1.txt ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CIS-2 conformance vector: exp_pinned_v1
2
+ # op=exp_pinned, spec ref: docs/CIS2_SPEC_v0.2.md §6.2 (pinned exp(x)
3
+ # polynomial, route (b) fallback described in src/math.rs::exp_pinned).
4
+ #
5
+ # Fields are `key=value`. x_bits is a comma-separated list of
6
+ # `0x`-prefixed 32-bit hex strings, each the raw IEEE-754 binary32 bit
7
+ # pattern of one input element, in index order (index 0 first).
8
+ #
9
+ # n=8, deliberately small and hand-sized (same rationale as rmsnorm_v1's
10
+ # n=8 / rope_v1's head_dim=8), spanning §6.2's documented accuracy domain
11
+ # `x in [-40,40]` (softmax post-max-sub args <= 0, SiLU gate args, RoPE
12
+ # inv_freq exponents): the two domain endpoints (-40, 40), a couple of
13
+ # mid-range values on each side (-10, -1, 10), the two special values
14
+ # 0.0 and 1.0 (exp(0)=1 exactly is a useful bit-exact sanity check), and
15
+ # 0.5 to exercise a non-integer, non-zero small positive value.
16
+ op=exp_pinned
17
+ spec_ref=docs/CIS2_SPEC_v0.2.md#62-pinned-transcendentals
18
+ n=8
19
+ x_bits=0xC2200000,0xC1200000,0xBF800000,0x00000000,0x3F000000,0x3F800000,0x41200000,0x42200000
vectors/matvec_v1.expected ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # Pinned expected output for matvec_v1.txt, computed by running the
2
+ # reference implementation's matvec (src/math.rs::dot_seq, the same
3
+ # function src/main.rs's per-layer projections/MLP/lm_head calls) via
4
+ # `cargo test --test conformance_matvec` (see tests/conformance_matvec.rs
5
+ # and tests/conformance/README.md "How this vector was derived").
6
+ #
7
+ # out_bits layout (3 values, index order): y[0] (the §5.1 order-sensitivity
8
+ # worked example, must be exactly 0.0), y[1], y[2].
9
+ out_bits=0x00000000,0x40C00000,0x40400000
10
+ out_sha256=482ae30571ed4c04bcca4c5365b233b1a159d8e653692fa41c0aca3c563c6bbe
vectors/matvec_v1.txt ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CIS-2 conformance vector: matvec_v1
2
+ # op=matvec, spec ref: docs/CIS2_SPEC_v0.2.md §5.2 (Matvec), which in turn
3
+ # depends on §5.1 (strict left-to-right sequential dot product, `dot_seq`).
4
+ #
5
+ # Fields are `key=value`. `out_features`/`in_features` are plain decimal
6
+ # integers (small config constants, no float-parsing ambiguity).
7
+ # `w_bits` is `out_features * in_features` values, ROW-MAJOR (row `o`'s
8
+ # `in_features` entries first, then row `o+1`, ...), each a
9
+ # comma-separated `0x`-prefixed 32-bit hex IEEE-754 binary32 bit pattern
10
+ # (per tests/conformance/README.md's general convention). `x_bits` is
11
+ # `in_features` values, the shared input vector.
12
+ op=matvec
13
+ spec_ref=docs/CIS2_SPEC_v0.2.md#52-matvec-normative
14
+ out_features=3
15
+ in_features=3
16
+ # Row 0 is §5.1's own worked example, verbatim: w[0,:] = [1e8, 1.0, -1e8]
17
+ # dotted against x = [1,1,1] MUST give exactly 0.0_f32 (the `1.0` term is
18
+ # lost to rounding against the 1e8 partial sum) -- a conforming
19
+ # implementation MUST reproduce this exact cancellation, not just "close".
20
+ # Row 1 and row 2 use small exactly-representable values (no order
21
+ # sensitivity) as a plain-arithmetic sanity check alongside the
22
+ # order-sensitive row 0.
23
+ w_bits=0x4CBEBC20,0x3F800000,0xCCBEBC20,0x3F800000,0x40000000,0x40400000,0x3F000000,0xBFC00000,0x40800000
24
+ x_bits=0x3F800000,0x3F800000,0x3F800000
vectors/rmsnorm_v1.expected ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ # Pinned expected output for rmsnorm_v1.txt, computed by running the
2
+ # reference implementation's RMSNorm (src/math.rs::sum_seq/rsqrt_cr) via
3
+ # `cargo test --test conformance_rmsnorm` (see tests/conformance_rmsnorm.rs
4
+ # and tests/conformance/README.md "How this vector was derived").
5
+ out_bits=0x3E6B80D1,0xBFB0A09D,0x3FB0A09D,0x3EEB80D1,0xBD6B80D1,0x3FEB80D1,0xC0047876,0x3F46B4B1
6
+ out_sha256=f712eda3e8b49d3d84639db584c134fe265f7994a21dede9f401d7be9bc5e60c
vectors/rmsnorm_v1.txt ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CIS-2 conformance vector: rmsnorm_v1
2
+ # op=rmsnorm, spec ref: docs/CIS2_SPEC_v0.2.md §8
3
+ #
4
+ # Fields are `key=value`. Vector fields (x_bits, gamma_bits) are
5
+ # comma-separated lists of `0x`-prefixed 32-bit hex, each the raw IEEE-754
6
+ # binary32 bit pattern of one element, in index order (index 0 first).
7
+ # eps_bits is the single f32 bit pattern for CIS-2 EPS_F32 (§2.3).
8
+ op=rmsnorm
9
+ spec_ref=docs/CIS2_SPEC_v0.2.md#8-rmsnorm-normative
10
+ n=8
11
+ eps_bits=0x3727C5AC
12
+ x_bits=0x3F800000,0xC0000000,0x40400000,0x3F000000,0xBF000000,0x40800000,0xBFC00000,0x40100000
13
+ gamma_bits=0x3F000000,0x3FC00000,0x3F800000,0x40000000,0x3E800000,0x3F800000,0x40400000,0x3F400000
vectors/rope_v1.expected ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Pinned expected output for rope_v1.txt, computed by running the
2
+ # reference implementation's RoPE table construction
3
+ # (src/math.rs::ln_pinned/exp_pinned/cos_pinned/sin_pinned, same functions
4
+ # src/main.rs uses for inv_freq / inv_freq_table_digest / the §7.3
5
+ # cos/sin loop) via `cargo test --test conformance_rope` (see
6
+ # tests/conformance_rope.rs and tests/conformance/README.md "How this
7
+ # vector was derived").
8
+ #
9
+ # out_bits layout (20 values, index order):
10
+ # [0..4) inv_freq[0..half) (§7.1, half=4)
11
+ # [4..8) cos_v[0..half) at pos=0 (§7.3)
12
+ # [8..12) sin_v[0..half) at pos=0 (§7.3)
13
+ # [12..16) cos_v[0..half) at pos=3 (§7.3)
14
+ # [16..20) sin_v[0..half) at pos=3 (§7.3)
15
+ out_bits=0x3F800000,0x3DCCCCCC,0x3C23D70A,0x3A83126E,0x3F800000,0x3F800000,0x3F800000,0x3F800000,0x00000000,0x00000000,0x00000000,0x00000000,0xBF7D7026,0x3F7490EE,0x3F7FE283,0x3F7FFFB5,0x3E1081C3,0x3E974E6C,0x3CF5B91F,0x3B449B92
16
+ out_sha256=67f519d23d8097775248acce28347667411d3b034b69f2a14c232ddc44ac14f8
17
+ # §7.2-specific digest: raw-bytes SHA-256 over only the inv_freq[0..half)
18
+ # values (LE bytes, index order) -- the same construction as the spec's
19
+ # own `inv_freq_table_digest` (§7.2) and `src/main.rs`'s
20
+ # `inv_freq_table_digest` variable, so this vector can be checked directly
21
+ # against that definition, not just this suite's general out_sha256
22
+ # convention.
23
+ inv_freq_table_digest=dfed0e89b6a1a7fcc1eca52713c491c0d0be5472e34c2c4682bda2c8266e0077
vectors/rope_v1.txt ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CIS-2 conformance vector: rope_v1
2
+ # op=rope_table, spec ref: docs/CIS2_SPEC_v0.2.md §7 (RoPE)
3
+ #
4
+ # Fields are `key=value`. head_dim and positions are plain decimal
5
+ # integers (no ambiguity: head_dim is a small config constant, and
6
+ # `positions` values are sequence positions, cast to f32 *exactly* per
7
+ # §7.3 -- both are exact integers well within f32's exact-integer range,
8
+ # so there is no float-parsing-rounding ambiguity to route around here,
9
+ # unlike genuinely fractional float inputs). rope_theta_bits is the single
10
+ # f32 bit pattern of rope_theta (comma-separated 0x-prefixed 32-bit hex
11
+ # convention, per tests/conformance/README.md, applied to a length-1 list).
12
+ op=rope_table
13
+ spec_ref=docs/CIS2_SPEC_v0.2.md#7-rope-normative
14
+ head_dim=8
15
+ rope_theta_bits=0x461C4000
16
+ positions=0,3