quant.cpp icon indicating copy to clipboard operation
quant.cpp copied to clipboard

Add Q3_K_M weight dequant support

Open unamedkr opened this issue 7 months ago • 1 comments

The GGUF weight loader (src/engine/tq_gguf_quants.c) handles Q2_K through Q6_K dequantization, but Q3_K_M (3-bit with medium grouping) needs testing and verification against the llama.cpp reference implementation.

What to do:

  • Verify that the dequantize_q3_K path correctly handles the Q3_K_M nibble ordering and scale layout.
  • Compare output against refs/llama.cpp/ggml-quants.c to ensure bit-level compatibility.
  • Add a unit test in tests/ that roundtrips a known vector through Q3_K_M and checks MSE.

Files to touch: src/engine/tq_gguf_quants.c, tests/ (new test file or add to existing).

unamedkr avatar Apr 03 '26 14:04 unamedkr

Q3_K weight dequantization and fused dot product are already implemented:

  • dequant_q3_k() — full Q3_K dequantization (src/engine/tq_gguf_quants.c:393)
  • fused_dot_q3_k() — fused dequant+dot for fast matmul (src/engine/tq_gguf_quants.c:1797)
  • Registered in matmul dispatch switch (line 2208)

Q3_K_M models should load and run correctly. The "M" in Q3_K_M refers to the quantization strategy used during model conversion (medium), but the runtime format is standard Q3_K which we fully support.

Tested: models with Q3_K tensors (e.g., Gemma 4 26B-A4B UD-Q3_K_M) load and produce correct output.

Closing as implemented.

unamedkr avatar Apr 05 '26 01:04 unamedkr