Skip to content

[BUG] quantize: a dense load with an inference-only backend (backend=BACKEND.MARLIN / MarlinConfig() / EXLLAMA_V2) makes every later quantize() fail with "cannot pack quantized weights" (documented backend-selection example crashes) #6154

Done

Description

@Qubitium

Summary

Since #4375 (typed BackendConfig) and #4606 (enum inheritance, fix of #4582), quantize(backend=AUTO) inherits the backend given to the dense GPTQModel.load(..., quantize_config, backend=X) and uses it as the packing backend. When X is an inference-only kernel that has no pack API (Marlin, ExLlamaV2, AWQ Marlin; also Machete), quantize() now raises before calibration:

ValueError: Selected backend `BACKEND.MARLIN` with kernel `MarlinLinear` cannot pack quantized weights for format `FORMAT.GPTQ`.

This is exactly the example in docs/backend-selection.md (lines 19-24):

qcfg = QuantizeConfig(bits=4, runtime=RuntimeConfig(max_packers=2))
model = GPTQModel.load("org/unquantized-model", quantize_config=qcfg,
                      backend=MarlinConfig(fp32=False))
# model.quantize(CalibrationConfig(dataset=calibration_dataset)) retains that typed backend selection.

Running that quantize() line fails. The same happens for the plain enum spelling GPTQModel.load(src, GPTQConfig(...), backend=BACKEND.MARLIN) followed by model.quantize(CalibrationConfig(...)), which worked before #4606: as described in #4582, an enum load backend was then only used for device selection, so quantize() packed with its default packer. The only way out is to drop backend= from the load or pass an explicit packing backend to quantize().

Introduced by

e44bb70 (#4375, typed MarlinConfig case) and 50a5b9f (#4606, enum case). Present at HEAD a311c91.

Location

gptqmodel/models/base.py:3047, quantize():

        backend, _ = resolve_quantize_backend(backend, self.quantize_config, inherit=True)

gptqmodel/utils/backend_config.py:295-302 replaces AUTO with the retained _backend_config / _load_backend; the retained value then becomes preferred_backend and is validated with pack=True in gptqmodel/models/base.py:3258 -> gptqmodel/utils/importer.py:1836-1840:

    if pack:
        if not _supports_pack_api(qlinear):
            raise ValueError(
                f"Selected backend `{backend}` with kernel `{qlinear.__name__}` cannot pack quantized weights for format `{format}`."
            )

Reproduction (ran it, RTX 4090, Qwen/Qwen2.5-0.5B-Instruct, 8 wikitext calibration rows)

from gptqmodel import GPTQModel, CalibrationConfig, BACKEND
from gptqmodel.backend import MarlinConfig
from gptqmodel.quantization import GPTQConfig, AWQConfig

for b, q in [(BACKEND.MARLIN, GPTQConfig(bits=4, group_size=128)),
             (MarlinConfig(fp32=False), GPTQConfig(bits=4, group_size=128)),
             (BACKEND.EXLLAMA_V2, GPTQConfig(bits=4, group_size=128)),
             (BACKEND.TRITON, GPTQConfig(bits=4, group_size=128)),
             (BACKEND.MARLIN, AWQConfig(bits=4, group_size=128))]:
    m = GPTQModel.load("Qwen/Qwen2.5-0.5B-Instruct", q, backend=b)
    m.quantize(CalibrationConfig(dataset=texts))

Output:

MARLIN        FAIL ValueError('Selected backend `BACKEND.MARLIN` with kernel `MarlinLinear` cannot pack quantized weights for format `FORMAT.GPTQ`.')
MarlinConfig  FAIL ValueError('Selected backend `BACKEND.MARLIN` with kernel `MarlinLinear` cannot pack quantized weights for format `FORMAT.GPTQ`.')
EXLLAMA_V2    FAIL ValueError('Selected backend `BACKEND.GPTQ_EXLLAMA_V2` with kernel `ExllamaV2Linear` cannot pack quantized weights for format `FORMAT.GPTQ`.')
TRITON        OK   {'TritonV2Linear'}
MARLIN (AWQ)  FAIL ValueError('Selected backend `BACKEND.MARLIN` with kernel `AwqMarlinLinear` cannot pack quantized weights for format `FORMAT.GEMM`.')

Expected vs actual

Expected: the documented load(..., backend=MarlinConfig(...)) + quantize(...) flow quantizes. Marlin is the default inference kernel for these checkpoints, so asking for it at load time is a natural request.
Actual: quantize() raises before calibration for every inference-only backend.

Suggested fix

Only inherit a retained load backend as the packer when that kernel can pack (_supports_pack_api); otherwise pack with the method's default packer (as quantize(backend=AUTO) does without a retained selection) and keep the retained backend/typed options for the post-quantization in-session kernel. An explicit quantize(backend=BACKEND.MARLIN) can keep raising. Alternatively reject the combination at GPTQModel.load with a clear message and fix the docs/backend-selection.md example; add a test that runs the documented example.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions