Skip to content

fix: make exact GGUF_CPP CPU matmul selectable and correct accuracy docs (#4316) - #4341

Merged
Qubitium merged 1 commit into
mainfrom
pr/4316
Nov 16, 2026
Merged

Qubitium merged 1 commit into
mainfrom
pr/4316

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

_use_ggml_cpu_matmul became unconditional in 77930e3, so the GGUF_CPP CPU path always runs ggml's Q8 activation quantization while the docs still presented 2e-2 as a bound. That bound was measured only on Gaussian activations. ggml quantizes activations in 256-element blocks, so one large channel raises the scale for its whole block: the #4316 repro (16 of 4096 channels x100) reaches 3.3e-2 .. 3.8e-2 relative and 7.6e-2 .. 8.4e-2 worst row, over 4x the claimed bound. The exact path was reachable only through an env var or by switching the whole engine to GGUF_TORCH.

What Changed

  • GGUFCppKernel.__init__ accepts exact_matmul: Optional[bool] = None. True selects the exact torch/dequantize path (GGUF_TORCH numerics), False requests native ggml, and None (default) keeps the existing capability-based native choice. The constructor argument wins over the process-wide GPTQMODEL_GGUF_CPP_NATIVE_MATMUL env var; callers that pass nothing see no behaviour change.
  • GGML_NATIVE_MATMUL_ERROR_BOUND (2e-2) is retained as the Gaussian envelope the native path is validated against, and is no longer described as a universal bound. Added GGML_NATIVE_MATMUL_OUTLIER_ERROR_ENVELOPE = 1e-1, the recorded worst-row envelope for the outlier repro (not a universal bound).
  • docs/gguf-cpp-activation-quantization.md: separates Gaussian from outlier measurements, adds the [BUG] GGUF_CPP's documented 2e-2 activation-quantization bound is exceeded 2–4× with outlier channels, and the CPU path now always uses the lossy native matmul (incomplete fix of #4219) #4316 repro and its numbers, explains why the Q8_K 256-element block layout has no activation-independent bound, and documents the three ways to force the exact path.
  • Added tests/test_gguf_cpp_matmul_accuracy_4316.py.

Tests

$ export GPTQ_BYPASS_SAFETY_CHECKS=1 PYTHONPATH=$PWD CUDA_VISIBLE_DEVICES=
$ python3 -m pytest tests/test_gguf_cpp_matmul_accuracy_4316.py -q
4 passed

$ python3 -m pytest tests/kernels/test_gguf_cpp.py \
    tests/kernels/test_gguf_cpp_activation_quantization.py \
    tests/kernels/test_gguf_cpp_bias_epilogue.py \
    tests/kernels/test_gguf_cpp_path_selection.py \
    tests/kernels/test_gguf_torch_cpu.py tests/test_internal_gguf.py -q
117 passed, 37 skipped   # CUDA unavailable in this container

$ python3 -m pytest tests/test_gguf_all_formats.py -q
10 failed, 261 passed, 429 skipped

The 10 test_gguf_all_formats.py failures are pre-existing on pristine origin/main: they are bf16 rtol=2e-3 tolerance failures in the dense/fused paths, reproduced from a git archive HEAD of the parent commit before this change. They are unrelated to the CPU path selector.

ruff check passes on both changed Python files.

CUDA C++ extensions are not built in this container, so the CUDA-specific cases skip; the issue repro and all new tests are CPU-only.

Model Support / Module Plan

N/A — no new model types or registry entries.

Fixes #4316

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant