This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

Notebooks · lib/gguf/quants

Reading a GGUF file, part 3, ggml's quantized number formats

A quantized tensor is a run of blocks. Each block holds a few numbers in full or half precision (a scale, sometimes a minimum) and a small integer per weight; a weight is the integer times the scale, plus the minimum. The formats differ in the block size, the bits per integer and how the scales are packed. This module turns blocks back into numbers, one def per format: a rewrite of dequantize_row_* in ggml's src/ggml-quants.c, with the block structs of src/ggml-common.h (ggml at commit 3612c0af93f2, MIT, The ggml authors). The tests hold every def to gguf-py 0.19.0's gguf.quants.dequantize, the NumPy version of the same code, number for number.

ggml computes in single precision. Where a step rounds there, the code here rounds with fround; a product of a half and a small integer is exact in both, so most steps need nothing.

Used with from gguf.quants import tensor_rows (and the other names here).

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.

[1]lines 23–281