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.
69 lines
3.1 KiB
Rust
69 lines
3.1 KiB
Rust
//! The control-vector loader against the Original's `load_control_vectors` compiled verbatim on the host
|
|
//! (fixture recorded from that build): same tables bit for bit, same error text.
|
|
|
|
use leleka_serving_policy::cvec::{Mode, Options, build_tables, parse_gguf};
|
|
use serde_json::Value;
|
|
|
|
fn unhex(text: &str) -> Vec<u8> {
|
|
(0..text.len() / 2).map(|i| u8::from_str_radix(&text[2 * i..2 * i + 2], 16).unwrap()).collect()
|
|
}
|
|
|
|
fn blobs_of(fixture: &Value) -> Vec<Vec<u8>> {
|
|
fixture["blobs"].as_array().unwrap().iter().map(|b| unhex(b.as_str().unwrap())).collect()
|
|
}
|
|
|
|
fn files_of(case: &Value, blobs: &[Vec<u8>]) -> Vec<(String, leleka_serving_policy::cvec::VectorFile, f32)> {
|
|
let name = case["name"].as_str().unwrap();
|
|
let mut files = Vec::new();
|
|
for entry in case["files"].as_array().unwrap() {
|
|
let blob = entry[0].as_u64().unwrap() as usize;
|
|
let scale = f32::from_bits(entry[1].as_u64().unwrap() as u32);
|
|
files.push((format!("FILE{blob}"), parse_gguf(&blobs[blob]).unwrap_or_else(|e| panic!("{name}: {e}")), scale));
|
|
}
|
|
files
|
|
}
|
|
|
|
fn options_of(case: &Value) -> Options {
|
|
Options {
|
|
first: case["first"].as_i64().unwrap() as i32,
|
|
last: case["last"].as_i64().unwrap() as i32,
|
|
mode: if case["mode"] == "project" { Mode::Project } else { Mode::Add },
|
|
single: case["single"].as_i64().unwrap() as i32,
|
|
}
|
|
}
|
|
|
|
fn assert_tables(name: &str, case: &Value, tables: &leleka_serving_policy::cvec::Tables) {
|
|
let bits = |values: &[f32]| -> Vec<u64> { values.iter().map(|v| u64::from(v.to_bits())).collect() };
|
|
let want =
|
|
|key: &str| -> Vec<u64> { case["up"][key].as_array().unwrap().iter().map(|v| v.as_u64().unwrap()).collect() };
|
|
assert_eq!(bits(&tables.dir), want("dir_bits"), "{name}: dir");
|
|
assert_eq!(bits(&tables.s), want("s_bits"), "{name}: s");
|
|
assert_eq!(tables.first as i64, case["up"]["first"].as_i64().unwrap(), "{name}");
|
|
assert_eq!(tables.last as i64, case["up"]["last"].as_i64().unwrap(), "{name}");
|
|
assert_eq!(tables.mode == Mode::Project, case["up"]["mode"].as_i64().unwrap() == 0, "{name}");
|
|
assert_eq!(tables.summary, case["summary"].as_str().unwrap(), "{name}");
|
|
}
|
|
|
|
#[test]
|
|
fn tables_and_errors_equal_the_engines_loader() {
|
|
let fixture: Value = serde_json::from_str(include_str!("fixtures/cvec_oracle.json")).unwrap();
|
|
let layers = fixture["n_layers"].as_u64().unwrap() as usize;
|
|
let width = fixture["n_embd"].as_u64().unwrap() as usize;
|
|
let blobs = blobs_of(&fixture);
|
|
let (mut loaded, mut refused) = (0, 0);
|
|
for case in fixture["cases"].as_array().unwrap() {
|
|
let name = case["name"].as_str().unwrap();
|
|
let files = files_of(case, &blobs);
|
|
let got = build_tables(&files, layers, width, options_of(case));
|
|
if case["ok"].as_bool().unwrap() {
|
|
let tables = got.unwrap_or_else(|e| panic!("{name}: unexpected error {e}"));
|
|
assert_tables(name, case, &tables);
|
|
loaded += 1;
|
|
} else {
|
|
assert_eq!(got.unwrap_err(), case["err"].as_str().unwrap(), "{name}");
|
|
refused += 1;
|
|
}
|
|
}
|
|
assert!(loaded >= 14 && refused >= 8, "{loaded} loaded, {refused} refused");
|
|
}
|