Skip to content

test(kernels): resolve the generic torch alias to GGUF_TORCH (#4059 regression) - #4064

Merged
Qubitium merged 1 commit into
mainfrom
fix/gguf-torch-backend
Nov 14, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/gguf-torch-backend

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes the #4059 regression in tests/kernels/test_selection.py::test_gguf_does_not_accept_generic_torch_backend (follow-up to #4053, items 4-8).

Option chosen: A — keep the mapping, rewrite the test around the real contract

I kept "gguf": {BACKEND.TORCH: BACKEND.GGUF_TORCH, BACKEND.TRITON: BACKEND.GGUF_TRITON} and rewrote the test to assert that the generic torch alias resolves to GGUFTorchLinear and not to the generic TorchLinear.

Why A:

  1. The safety property the old test protected is structural, not name-based. get_kernel_for_backend() (gptqmodel/utils/importer.py:496-508) filters candidates with quant_method not in cls.SUPPORTS_METHODS, and TorchLinear.SUPPORTS_METHODS == [METHOD.GPTQ] (gptqmodel/nn_modules/qlinear/torch.py:183). A METHOD.GGUF selection can therefore never return TorchLinear; the old assertion only pinned the pre-alias-table fact that torch was absent from _LEGACY_BACKEND_BY_METHOD, which is an implementation detail rather than a contract.
  2. It keeps torch uniform across methods. _LEGACY_BACKEND_BY_METHOD is the compat table that translates the legacy generic name into each method's canonical kernel (gptq, awq, fp8, exl3, vptq already did this). Leaving GGUF out made backend="torch" raise the exact misleading Unsupported backend: BACKEND.TORCH for METHOD.GGUF error that the [BUG] Checkpoint interop: AutoAWQ modules_to_not_convert loads as NaN, format-change re-save writes stale qzeros, HF save_pretrained writes kernel runtime layout, Marlin ignores g_idx, is_marlin_format:false rejected, export broken #4053 Minor bullet reported for QQQ/GGUF/BnB.
  3. It implements the requested fix instead of declining it. Option B would have left torch working for QQQ and BitsAndBytes but not GGUF, which is the inconsistency the issue asked to remove.
  4. The rewritten test is stronger, not weaker. It pins all three facts: METHOD.GGUF not in TorchLinear.SUPPORTS_METHODS, normalize_backend(TORCH, GGUF) is GGUF_TORCH, and select_quant_linear(...) is GGUFTorchLinear and is not TorchLinear. Removing the mapping still fails the test (verified below), so it is not vacuous.

Change

File Change
tests/kernels/test_selection.py Renamed test_gguf_does_not_accept_generic_torch_backend -> test_gguf_accepts_generic_torch_backend_as_gguf_torch_kernel; asserts alias resolution to GGUF_TORCH / GGUFTorchLinear, plus TorchLinear does not declare METHOD.GGUF.
gptqmodel/utils/backend.py Comment only (3 lines) recording why the GGUF aliases are safe and must not be reverted. No behavior change in this PR.

No control-flow change: the mapping already shipped in #4059; this PR aligns the test with it. No diagrams required.

Before / after

Before this PR After this PR
test_gguf_does_not_accept_generic_torch_backend Failed: DID NOT RAISE ValueError replaced
test_gguf_accepts_generic_torch_backend_as_gguf_torch_kernel n/a passes
normalize_backend(BACKEND.TORCH, quant_method=METHOD.GGUF) GGUF_TORCH (mapping from #4059) GGUF_TORCH, now asserted
GGUF served by generic TorchLinear impossible (SUPPORTS_METHODS) impossible, now asserted

Test commands and results

CUDA venv (/opt/venvs/cu130t/bin/python, PYTHONPATH=$PWD):

pytest -q tests/kernels/test_selection.py
  before: 1 failed, 134 passed, 39 skipped   (DID NOT RAISE ValueError)
  after:  135 passed, 39 skipped
pytest -q tests/test_backend_naming.py tests/test_awq_bitblas.py
  -> 19 passed, 6 skipped
ruff check gptqmodel docs/eora tests setup.py
  -> All checks passed

ROCm venv (/opt/venvs/rocm101t/bin/python, HIP_VISIBLE_DEVICES=2):

pytest -q tests/kernels/test_selection.py
  -> 118 passed, 56 skipped

Fail-before check for the rewritten test (mapping removed in-memory, no file edit):

normalize -> BACKEND.TORCH
fail-before confirmed: Unsupported backend: `BACKEND.TORCH` for `METHOD.GGUF` with format `FO...

QQQ and BitsAndBytes double-check

Untouched in this PR. tests/kernels/test_selection.py covers the whole file (135 passed on CUDA, 118 passed / 56 skipped on ROCm), including test_qqq_rejects_native_kernel_on_rocm. The only other Unsupported backend assertion in the test tree is tests/test_awq_bitblas.py::test_awq_bitblas_kernel_mapping_rejects_gptq_bitblas_backend (AWQ + GPTQ_BITBLAS), which passes and is unrelated to these aliases. No test asserted that QQQ or BitsAndBytes reject the generic torch name.

Hardware

  • NVIDIA RTX 4090, GPU-d458708b-c760-bbf1-08fb-8b8803a2157d (never the RTX 5090).
  • AMD R9700, HIP_VISIBLE_DEVICES=2.

@Qubitium
Qubitium merged commit ad0525c into main Nov 14, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/gguf-torch-backend branch November 14, 2026 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant