Files
leleka/docs/iq3-reference-parity.md
T
Pavlo Ratushnyi a498381cb7
Linux / keyless-cuda-gate (pull_request) Skipped
Linux / verify (pull_request) Successful in 5m16s
Linux / keyless-cuda (pull_request) Skipped
Linux / static-cuda-package (pull_request) Skipped
Linux / hosted-cuda-package (pull_request) Skipped
Linux / linux-cli-container (pull_request) Successful in 5m19s
Linux / linux-static-cli (pull_request) Failing after 7m35s
Linux / release-cli (pull_request) Skipped
refactor(model): extract independent Rust IQ3 decoding core
2026-10-07 20:53:25 +02:00

3.5 KiB

IQ3_S CPU reference parity

The Rust IQ3_S decoder uses the 256-value / 110-byte block layout and grid pinned to Strata d9ab8435f654c368c586340d490915f6addf56a3. Its offline C oracle is the vendored GGML decoder from llama.cpp 3cf03257f219afbe7334045ff7c6a06ac68c627d, recorded in GGML provenance. The existing control-plane bridge statically compiles that pinned CPU code. The independent Rust quantization crate does not depend on the C oracle or bridge. No upstream source or pin is changed for these tests.

The new bridge test exhausts all 63,488 finite FP16 scale encodings: both signed zeros, every positive/negative subnormal, every positive/negative normal, and the maximum finite scale of either sign. Each gets a deterministic generated 110-byte block with varied packed fields. An explicit byte bijection at each field position guarantees all 256 byte values over a complete low-pattern-byte sweep; high-pattern-byte and position mixing vary the joint block patterns. Coverage assertions require every 8-bit low-index, high-index and sign value at every corresponding field position, every scale nibble at every subblock, and all 512 combined grid indexes.

Every one of the 256 decoded values is compared with f32::to_bits() against the pinned C output: the tolerance is zero, including signed zero. This is 63,488 blocks / 16,252,928 element comparisons. It exhausts the FP16 scale domain and observes each packed field value; it does not exhaust all possible joint combinations of the 108 packed bytes. A separate 14-block contiguous batch checks the same exact-bit contract through both decode_into paths with a source pointer deliberately unaligned for the C bridge.

The Rust decoder's existing error for a NaN or infinity block scale is retained. All 2,048 nonfinite FP16 encodings are tested for refusal by both Rust entry points. They are outside the C numerical parity domain, and are never silently skipped as successful parity cases. The existing pinned block-size, original mixed IQ3_S block and known Q8_0/Q2_0 tests are retained.

Fixtures are generated synthetic packed bytes, not model weights or captures. These checks qualify CPU block decoding only. They do not establish real-model parity, inference quality, readiness, GPU behavior or a performance improvement. The eventual production engine must qualify its own load, arithmetic and model semantics independently.

Targeted gate

cargo test --locked -p strata-control --lib ggml_bridge::tests

Actual local CPU result, 2026-10-07

  • Rust: rustc 1.99.0 (b940084d7 2026-09-28).
  • Host target: aarch64-apple-darwin (Darwin arm64).
  • C compiler: Apple Clang 21.0.0 (clang-2100.1.1.101).
  • Command above: 6 passed, 0 failed (172 unrelated tests filtered).
  • Finite-scale element bits, every packed-field coverage assertion, unaligned batch parity and all nonfinite-scale refusals passed.
  • Vendored GGML manifest hashes were checked before the run. The production bridge body and the three original bridge tests remain unchanged.

The first draft generator passed every numerical comparison but failed its sign-byte coverage assertion. The generator was corrected to the explicit byte bijection described above; all exact-bit and coverage assertions were retained, and the complete targeted gate was rerun successfully. No decoder arithmetic or numerical tolerance was changed. Both private temporary build targets were cleaned. This result applies to this CPU/compiler configuration; Linux/GCC, real-model and GPU qualification remain separate.