The vendored Strata tree engine/strata is removed for good (owner decision 2026-11-23): Leleka never builds or runs it, the vanilla
benchmark builds from its own checkout, the comparison measurements are finished and the CUDA ports are frozen. Everything below
compiled or read that tree, so it cannot run without it and is retired (the tree stays in git history, see third_party/strata/UPSTREAM.md).
Checked-in fixtures, golden JSON, sealed PTX, seal plans and MANIFEST hashes are untouched and keep being replayed by the cargo tests.
Drift guard
- crates/experimental-ref/tests/literal_port.rs: include_str! of the Original .cu files compared with the checked-in experimental ports.
Oracle generators and builders (they compile or extract from the Strata C++/Python sources; their outputs are the checked-in goldens)
- crates/experimental-ref/oracle/gen_{cvec,kv,remote,stream}_golden.{cpp,sh}, gen_seal_additions.py and the cuda_runtime stub they used
- crates/sampler-ref/oracle/build_oracle.sh, gen_fixtures.cpp, gen_sampling_keys.py, stub/ (run_port_host_tests.sh and the fixtures stay)
- crates/serving-policy/oracle/ (build_oracle.sh, gen_{host,cvec,vision}_fixtures.cpp)
- crates/context/tests/rope_plan_golden/gen_* (plan, rope, kv pool)
- crates/engine-core/src/conversation/golden/gen*.{sh,cpp} and stub/
- crates/cuda-driver/oracle/gen_prefill_ring_trace.py and drivers/prefill_ring_trace.cpp (extracted prefill.cpp), check_cu_syntax.sh
- crates/engine-qwen35-cuda/tests/stra161_reference/reference.py (fixtures.json and the Rust constants stay)
- control-plane/tests/golden/gen_goldens.py, scripts/offline/ (Python differentials and golden generators against the Strata Python tools)
Source-compiling CUDA oracles and builders
- scripts/build-cuda-{projection-family,q5,q6,qsa}-oracle.sh with scripts/cuda-{projection-family,q5,q6,qsa}-oracle/ (include the Original .cu; sha256 pins of them)
- scripts/build-original-verify-ptx.sh, scripts/q8/rebuild_quantizer_ptx.sh, scripts/decode-sm120/make_iq_prefix.py (needs engine/strata/include)
- scripts/cuda-stubs/ (check-cu.py and literal_diff.py need the strata headers and the Original sources; the stub headers served only them)
- tools/chain-probe/build.sh, tools/kernel-ab/{cpp,aa.sh,smoke.sh,time_smoke.sh} (the C++ comparator is built from the Strata CPU kernels; verify_manifest.py stays)
- scripts/e2e/codex/speed/verify-hc-down-kernel-microbench-vs-upstream/ (compiles the upstream kernel from the tree)
Engine builds and Python smokes that need the tree
- scripts/build-cpu.sh, scripts/build-static-cuda.sh, scripts/check-keyless-gpu.sh, scripts/test-static-cuda-profile.py (CMake of engine/strata)
- scripts/compare-real-tokenizer.py, scripts/smoke-mtp-pack.py (reads src/core/mtp.cpp and a bench manifest), scripts/prepare-keyless-routing.py and its test
- scripts/smoke-native-pack.py became scripts/native-pack-fixture.py: the synthetic GGUF fixtures the four other smokes import stay, the iq_pack.py oracle comparison goes
Gates and CI
- scripts/check-local.sh: no live Python oracle differentials, no literal_port note, no check-cu, no build-cpu, no retired test scripts
- .github/workflows/linux.yml: the keyless-cuda, static-cuda-package and hosted-cuda-package jobs (they built the engine from the tree) and their dispatch
inputs, and the two oracle smoke steps; .github/workflows/port.yml: the Python oracle environment and the llama.cpp fetch of port-oracles
(the sampler host shim still runs)
- limits.json and scripts/check_limits_test.py exclude third_party/strata/ instead of engine/strata/
Documentation and comments: README.md names third_party/strata and the pin; deploy/README.md marks the retired build and smoke commands; comments
in Rust, Python and Markdown that named engine/strata/... now name "Strata 41cf05a0, ..."; the gpu-bringup scratch-copy test no longer copies the
removed include directories. Stale engine/strata paths in sealed .cu, .ptx, seal-plan and MANIFEST files are left as they are (hashes may depend on the bytes).
145 lines
5.4 KiB
Rust
145 lines
5.4 KiB
Rust
//! Golden tests: the Rust references against fixtures produced by the Original's own host code
|
|
//! (`oracle/gen_kv_golden.sh`; the reference functions are extracted verbatim from Strata 41cf05a0).
|
|
|
|
use leleka_experimental_ref::{
|
|
fwht, kv_q8,
|
|
layout::{self, KvFormat, QsaShapes, StreamFormat},
|
|
q4_0::{self, BlockQ4_0, Contraction},
|
|
};
|
|
use serde_json::Value;
|
|
|
|
fn load(name: &str) -> Value {
|
|
let path = format!("{}/tests/fixtures/{name}", env!("CARGO_MANIFEST_DIR"));
|
|
serde_json::from_str(&std::fs::read_to_string(path).expect("fixture")).expect("json")
|
|
}
|
|
|
|
fn floats<const N: usize>(v: &Value) -> [f32; N] {
|
|
let a = v.as_array().expect("array");
|
|
assert_eq!(a.len(), N);
|
|
let mut out = [0.0; N];
|
|
for (o, x) in out.iter_mut().zip(a) {
|
|
*o = f32::from_bits(x.as_u64().expect("bits") as u32);
|
|
}
|
|
out
|
|
}
|
|
|
|
fn hex(s: &str) -> Vec<u8> {
|
|
(0..s.len()).step_by(2).map(|i| u8::from_str_radix(&s[i..i + 2], 16).unwrap()).collect()
|
|
}
|
|
|
|
/// Two elements of the largest magnitude with opposite sign: the Original's host reference and its CUDA
|
|
/// kernel resolve the tie differently (documented in `q4_0`).
|
|
fn has_opposite_sign_tie(x: &[f32; 32]) -> bool {
|
|
let amax = x.iter().fold(0.0f32, |m, v| m.max(v.abs()));
|
|
x.contains(&amax) && x.iter().any(|v| *v == -amax)
|
|
}
|
|
|
|
#[test]
|
|
fn fwht_rows_are_bit_identical_to_the_host_reference() {
|
|
let g = load("kv_golden_separate.json");
|
|
let rows = g["fwht"].as_array().unwrap();
|
|
assert_eq!(rows.len(), 24);
|
|
for (i, row) in rows.iter().enumerate() {
|
|
let input: [f32; 256] = floats(&row["in"]);
|
|
let want: [f32; 256] = floats(&row["out"]);
|
|
let mut host = input;
|
|
fwht::fwht256_host_reference(&mut host);
|
|
assert_eq!(host.map(f32::to_bits), want.map(f32::to_bits), "host order row {i}");
|
|
let mut kernel = [0.0; 256];
|
|
fwht::fwht256(&input, &mut kernel);
|
|
assert_eq!(kernel.map(f32::to_bits), want.map(f32::to_bits), "kernel order row {i}");
|
|
assert_eq!(
|
|
fwht::fwht256_warp_model(&input).map(f32::to_bits),
|
|
want.map(f32::to_bits),
|
|
"warp model row {i}"
|
|
);
|
|
}
|
|
}
|
|
|
|
fn check_q4(fixture: &str, c: Contraction) -> (usize, usize) {
|
|
let g = load(fixture);
|
|
let groups = g["q4"].as_array().unwrap();
|
|
assert_eq!(groups.len(), 576);
|
|
let (mut kernel_compared, mut ties) = (0, 0);
|
|
for (i, e) in groups.iter().enumerate() {
|
|
let x: [f32; 32] = floats(&e["x"]);
|
|
let want = BlockQ4_0::from_bytes(&hex(e["block"].as_str().unwrap()));
|
|
assert_eq!(q4_0::quantize_group_host_reference_with(&x, c), want, "host reference, group {i}");
|
|
if has_opposite_sign_tie(&x) {
|
|
ties += 1;
|
|
continue;
|
|
}
|
|
assert_eq!(q4_0::quantize_group(&x, c), want, "kernel semantics, group {i}");
|
|
kernel_compared += 1;
|
|
}
|
|
(kernel_compared, ties)
|
|
}
|
|
|
|
#[test]
|
|
fn q4_0_blocks_match_the_host_reference_separate_operations() {
|
|
let (compared, ties) = check_q4("kv_golden_separate.json", Contraction::Separate);
|
|
assert!(compared > 350 && ties > 0, "{compared} {ties}");
|
|
}
|
|
|
|
#[test]
|
|
fn q4_0_blocks_match_a_fused_multiply_add_build() {
|
|
let (compared, _) = check_q4("kv_golden_fused.json", Contraction::Fused);
|
|
assert!(compared > 350);
|
|
// the fused build really differs from the separate one on the boundary groups
|
|
let s = load("kv_golden_separate.json");
|
|
let f = load("kv_golden_fused.json");
|
|
let differ = s["q4"]
|
|
.as_array()
|
|
.unwrap()
|
|
.iter()
|
|
.zip(f["q4"].as_array().unwrap())
|
|
.filter(|(a, b)| a["block"] != b["block"])
|
|
.count();
|
|
assert!(differ > 40, "{differ}");
|
|
}
|
|
|
|
#[test]
|
|
fn int8_k_groups_match_the_hybrid_parity_host_reference() {
|
|
let g = load("kv_golden_separate.json");
|
|
let groups = g["q8"].as_array().unwrap();
|
|
assert_eq!(groups.len(), 96);
|
|
for (i, e) in groups.iter().enumerate() {
|
|
let x: [f32; 64] = floats(&e["x"]);
|
|
let (codes, scale) = kv_q8::quantize_group(&x);
|
|
assert_eq!(u64::from(scale), e["scale"].as_u64().unwrap(), "scale {i}");
|
|
let want: Vec<i8> = e["codes"].as_array().unwrap().iter().map(|c| c.as_i64().unwrap() as i8).collect();
|
|
assert_eq!(codes.to_vec(), want, "codes {i}");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn layout_sizes_match_the_original_functions() {
|
|
let g = load("kv_golden_separate.json");
|
|
let s = QsaShapes::real();
|
|
assert_eq!(g["per_cell"]["q8"].as_u64(), Some(kv_q8::bytes_per_cell(2, 256)));
|
|
assert_eq!(g["per_cell"]["q4"].as_u64(), Some(q4_0::bytes_per_cell(2, 256)));
|
|
for (key, fmt) in [
|
|
("f16", StreamFormat::F16),
|
|
("int8", StreamFormat::Int8),
|
|
("q4", StreamFormat::Q4),
|
|
("value_int8", StreamFormat::ValueInt8),
|
|
] {
|
|
assert_eq!(g["block_bytes"][key].as_u64(), Some(layout::kv_block_bytes(&s, fmt)), "{key}");
|
|
}
|
|
let mut checked = 0;
|
|
for e in g["pool_bytes"].as_array().unwrap() {
|
|
let fmt = match e["format"].as_str().unwrap() {
|
|
"fp16" => KvFormat::Fp16,
|
|
"int8" => KvFormat::Int8,
|
|
"q4_0" => KvFormat::Q4_0,
|
|
"k8v4" => KvFormat::K8V4,
|
|
"int8-keyless" => KvFormat::Int8Keyless,
|
|
other => panic!("{other}"),
|
|
};
|
|
let pages = e["pages"].as_u64().unwrap();
|
|
assert_eq!(layout::kv_pool_bytes(fmt, &s, pages), e["bytes"].as_u64().unwrap(), "{fmt:?} {pages}");
|
|
checked += 1;
|
|
}
|
|
assert_eq!(checked, 25);
|
|
}
|