Expand description
The Q5_K weight encoder: a transcription of llama.cpp b7650’s
quantize_row_q5_K_ref (ggml/src/ggml-quants.c:1467).
Q5_K is Q4_K’s super-block fit with two things changed and nothing else:
- the codes run
0..=31instead of0..=15, and the candidate grid handed tomake_qkx2_quantsis(-0.5, 0.1, 15)rather than(-1.0, 0.1, 20)– both of which are [Q5_K_FIT], passed to the SAME [super::fit::fit_qk_super_block] Q4_K uses; - the fifth bit of each code goes into a separate 32-byte
qhplane, which is the only packing this module writes out itself.
Two transcriptions of that shared fit is precisely the shape this repo has paid the most for: the copies agree the day they are written and drift the first time one of them is corrected. So the difference between Q4_K and Q5_K is four numbers in a struct, and if someone fixes the least-squares step it is fixed for both or for neither.
The qh bit assignment is worth stating because it is not the
obvious one: the 256 codes are walked in four groups of 64, and
within a group the first 32 codes’ high bits go to bit m1 of
qh[j] and the second 32’s to bit m2, where m1/m2 start at 1
and 2 and shift LEFT BY TWO per group. So qh[j] holds the high
bits of elements j, j+32, j+64, … in bit pairs, not one
contiguous run. dequant_q5_k in this crate reads it back with the
same u1 <<= 2 walk.
Functions§
- encode_
block_ q5_ k - Encodes one Q5_K super-block (exactly
Q5_K_BLOCK_ELEMSvalues) and appends itsQ5_K_BLOCK_BYTESbytes toout. - encode_
row_ q5_ k - Encodes a whole row (or any slice whose length is a multiple of
Q5_K_BLOCK_ELEMS) into Q5_K super-blocks, appending toout.