Expand description
WeightMatrix: a weight matrix that may live either as plain f32
(small dims, embeddings, synthetic test weights) or as raw
Q8_0/Q4_0 block bytes loaded straight from a GGUF file, with no f32
expansion at load time. This is what lets ferrox load a
multi-billion-parameter checkpoint without first blowing it up 4x
in RAM: the loader (ferrox-models) hands tensors over still
quantized, and every matmul call here dispatches to the fused
dequant+dot kernels in ferrox-quant.
Enums§
- Batch
Acts - A batch of activations quantized once for reuse across several
WeightMatrix::apply_batch_with_actscalls that read the same input (q/k/v on one normed batch; gate/up on another). Build withWeightMatrix::quantize_batch_acts. Q8_0/Q4_0 matrices consumeBatchActs::Q8; the K-quants consumeBatchActs::Q8K. - Quant
Kind - Weight
Bytes - Backing storage for a quantized weight matrix’s raw bytes: either an
owned buffer (synthetic/test weights, or any tensor that had to be
copied for some other reason) or a zero-copy view into a shared
memory-mapped GGUF file. This is the fix for the “loader read
everything into a fresh Vec
” inefficiency: a real checkpoint’s resident memory should be the mmap itself, not a second copy of it, which is how llama.cpp’s mmap-based loader both avoid doubling a multi-hundred-gigabyte checkpoint’s memory footprint. - Weight
Matrix
Functions§
- active_
backend - The backend dense matmuls will actually use in this process, decided
by the same cached env/probe reads dispatch uses. CUDA wins when both
are compiled in, matching [
WeightMatrix::apply_gpu]’s order. - cpu_
int_ dot_ enabled - Whether CPU Q8_0 / Q4_0 / Q4_K / Q5_K / Q6_K matvec should quantize the
activation to int8 and use the integer
vec_dotpath. Q4_K additionally lazy-repacks into interleavedblock_q4_Kx8for 8-wide GEMV; Q8_0 intoblock_q8_0x4and Q4_0 intoblock_q4_0x4for 4-wide GEMV. - cpu_
int_ dot_ kind_ supported - Which quant kinds take the CPU integer
vec_dotpath (activation quantized to Q8/Q8_K, int8xint8 dots) rather than the much slower f32 dequant-dot.colsmatters: the K-quant kernels need a whole number of 256-element super-blocks, the legacy ones 32-element blocks. - cuda_
matvec_ kind_ supported - Which quant kinds have a CUDA matvec kernel.
- default_
cpu_ ⚠int_ dot_ on - Sets
FERROX_CPU_INT_DOT=1unless the caller already expressed a preference. Call from a binary’s startup, before any worker threads exist. Seecpu_int_dot_enabledfor why the default lives here rather than in the getter. - metal_
matvec_ kind_ name - Which quant kinds have a Metal matvec kernel, as the kernel name
[
ferrox_metal::gpu::matvec_launch_meta] resolves. - metal_
mul_ mm_ kind_ supported - Which quant kinds have a Metal batched simdgroup GEMM
(
*_mul_mm_sg), the prefill path. A kind with a matvec but no GEMM still runs on Metal — asbatchseparate matvecs over the same weights, which is the 13.7x shape. - quant_
kind_ for - Maps a GGUF tensor’s on-disk dtype to the
QuantKindaWeightMatrixuses to pick a fused dequant+dot kernel, orNonefor a dtype with no quantized kernel (F32, or one not implemented at all).