Files
leleka/control-plane/examples/scan-quant-blocks.rs
T
Pavlo Ratushnyi 4013e0c9bd
Desktop foundation / core (ubuntu-latest) (push) Failing after 28s
Desktop foundation / core (macos-latest) (push) Canceled after 0s
Desktop foundation / core (windows-latest) (push) Canceled after 0s
Linux / verify (push) Canceled after 0s
Linux / keyless-cuda (push) Canceled after 0s
Linux / static-cuda-package (push) Canceled after 0s
Linux / hosted-cuda-package (push) Canceled after 0s
Linux / linux-static-cli (push) Canceled after 0s
Linux / linux-cli-container (push) Canceled after 0s
Linux / release-cli (push) Canceled after 0s
Import tracked Strata Next source snapshot
2026-10-05 18:15:08 +02:00

54 lines
1.9 KiB
Rust

//! Decode the first real block of each quantized GGUF kind in one source shard.
//! This is an offline diagnostic; input weights remain outside Git.
use std::{collections::BTreeMap, env, fs::File, path::Path};
use sha2::{Digest, Sha256};
use strata_control::{gguf, gguf_f32_stream};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let path = env::args()
.nth(1)
.ok_or("usage: scan-quant-blocks FILE.gguf")?;
let path = Path::new(&path);
let index = gguf::tensor_index(path)?;
let mut first_by_kind = BTreeMap::new();
for tensor in &index.tensors {
first_by_kind.entry(tensor.kind).or_insert(tensor);
}
let mut source = File::open(path)?;
for (kind, tensor) in first_by_kind {
let (expected_elements, bytes) =
gguf::block_geometry(kind).ok_or_else(|| format!("unsupported source kind {kind}"))?;
let absolute = index
.summary
.data_start
.checked_add(tensor.offset)
.ok_or("GGUF tensor offset overflow")?;
let mut hasher = Sha256::new();
let decoded_bytes =
gguf_f32_stream::visit(&mut source, absolute, kind, bytes, |_, values| {
if values
.as_chunks::<4>()
.0
.iter()
.any(|word| !f32::from_le_bytes(*word).is_finite())
{
return Err(format!("{}: non-finite decoded value", tensor.name));
}
hasher.update(values);
Ok(())
})?;
if decoded_bytes != expected_elements * 4 {
return Err(format!("{}: decoded block length mismatch", tensor.name).into());
}
println!(
"kind {kind}: {} values from {} SHA-256 {}",
expected_elements,
tensor.name,
hex::encode(hasher.finalize())
);
}
Ok(())
}