Files
Pavlo Ratushnyi da8c974f68 Drop the stale engine/strata paths and retired generator names from comments, doc strings and generated fixtures (STRA-407)
Rust comments that named scripts/offline/*, gen_goldens.py, oracle/gen_*.{sh,cpp,py}, build_oracle.sh and similar retired generators now say where the data
came from (the Original's code, Strata 41cf05a0) or drop the sentence. The path/generator text of seven generated fixtures (sampler_oracle.json, sampling_keys.json,
memory_plan_golden.json, rope_golden.json, cvec_oracle.json, stra161 fixtures.json, commentary-tool-prompt.json) is reworded; no test reads those fields and no pin
covers their bytes. cmd_time/doc.rs: the two path texts in the format string; its lines are re-broken so they stay within 120 columns (the string is unchanged
otherwise). Comment-only except those data/string spots; no behaviour change.
2026-11-23 22:37:17 +01:00

50 lines
2.4 KiB
Rust

//! Dequantization versus the pinned gguf-py (`quants.dequantize`, llama.cpp 3cf03257) and `tools/iq_fixture.py`.
//!
//! `tests/fixtures/offline/dequant_oracle.json` holds one seeded 256-value row of each of 23 block types and the
//! oracle's float32 bits (recorded from the Original's Python code, Strata 41cf05a0). The production
//! visitor (`gguf_f32_stream::visit`: independent Rust decoders where they
//! exist, the pinned ggml C bridge otherwise) must reproduce every float bit for bit. Q8_K has no gguf-py
//! dequantizer; its reference is `d * qs`.
use leleka_control_plane::{gguf, gguf_f32_stream};
use serde_json::Value;
use std::io::Cursor;
fn unhex(text: &str) -> Vec<u8> {
(0..text.len() / 2).map(|i| u8::from_str_radix(&text[i * 2..i * 2 + 2], 16).unwrap()).collect()
}
/// The production visitor's float32 bytes for `blocks` of the given `kind`.
fn visit_all(blocks: &[u8], kind: u32, geometry: (u64, u64), name: &str) -> Vec<u8> {
let (elements, bytes) = geometry;
let mut got = Vec::new();
gguf_f32_stream::visit(&mut Cursor::new(blocks.to_vec()), 0, kind, blocks.len() as u64, |raw, f32| {
assert_eq!(raw.len() as u64 / bytes * elements, f32.len() as u64 / 4);
got.extend_from_slice(f32);
Ok(())
})
.unwrap_or_else(|e| panic!("{name}: {e}"));
got
}
fn differing_floats(got: &[u8], want: &[u8]) -> usize {
got.as_chunks::<4>().0.iter().zip(want.as_chunks::<4>().0).filter(|(a, b)| a != b).count()
}
#[test]
fn every_block_type_decodes_bit_exactly_like_gguf_py() {
let golden: Value = serde_json::from_str(include_str!("fixtures/offline/dequant_oracle.json")).unwrap();
let types = golden["types"].as_array().unwrap();
assert_eq!(types.len(), 23);
for entry in types {
let name = entry["name"].as_str().unwrap();
let kind = entry["kind"].as_u64().unwrap() as u32;
let blocks = unhex(entry["blocks_hex"].as_str().unwrap());
let want = unhex(entry["f32_hex"].as_str().unwrap());
let (elements, bytes) = gguf::block_geometry(kind).unwrap_or_else(|| panic!("{name}: geometry"));
assert_eq!(blocks.len() as u64, golden["elements"].as_u64().unwrap() / elements * bytes, "{name}");
let got = visit_all(&blocks, kind, (elements, bytes), name);
let differing = differing_floats(&got, &want);
assert_eq!((got.len(), differing), (want.len(), 0), "{name} (kind {kind})");
}
}