Skip to main content

quantize_q8_0

Function quantize_q8_0 

Source
pub fn quantize_q8_0(src: &[f32]) -> Vec<u8> 
Expand description

Quantize an f32 slice into Q8_0 blocks, zero-padding a partial trailing block. Used by test fixtures and by the CPU reference “quantize activations for a symmetric int8 matmul” path, where the vector length is not guaranteed to be a whole number of blocks.

The per-block arithmetic is encode::encode_block_q8_0, not a second spelling of it: this function used to have its own, which divided by the scale where llama.cpp multiplies by its reciprocal and stored a scale of 1.0 for an all-zero block where llama.cpp stores 0.0. Both differences are invisible to a value comparison and both produce different bytes, which is exactly the kind of silent divergence a second copy of a code path creates. The tail padding is the ONLY thing this adds.

A weight encoder wants encode::encode_row_q8_0 instead, which refuses a ragged length rather than padding it: padding a weight row writes more elements than its shape declares.