//! 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> { 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(()) }