pub fn encode_block_q8_0(block: &[f32; 32], out: &mut Vec<u8>)Expand description
Encodes one Q8_0 block (exactly Q8_0_BLOCK_ELEMS values) and
appends its Q8_0_BLOCK_BYTES bytes to out.
Every arithmetic choice here mirrors ggml-quants.c:
amaxis folded witha > b ? a : b, not Rust’sf32::max. They differ on NaN –f32::maxreturns the non-NaN operand, ggml’s macro propagates it – and a checkpoint with a NaN weight should produce llama.cpp’s bytes, not politely different ones.- The scale is applied as a multiply by
1/d, not a divide byd.v * (1.0/d)andv / ddiffer by an ulp for many inputs, and an ulp either side of.5is a differentroundfresult, so a divide here would disagree with llama.cpp on real weights. d == 0(an all-zero block) yields the reciprocal0.0, so the stored scale is+0.0and every quant is 0. The obvious alternative, storing a scale of 1.0, dequantizes identically and is therefore invisible to every test that checks values – and produces a file that differs from llama.cpp’s in bytes.