Skip to content

fix(quantize): do not pack with an inherited inference-only backend (#6154) - #6162

Merged
Qubitium merged 2 commits into
mainfrom
fix/6154-inherited-pack-backend
Nov 28, 2026
Merged

Qubitium merged 2 commits into
mainfrom
fix/6154-inherited-pack-backend

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

quantize(backend=AUTO) inherits the backend given to the dense
GPTQModel.load(...). Marlin, ExLlamaV2 and AWQ-Marlin are inference-only: they
have no pack API. The inherited selection therefore failed the pack validation
before calibration:

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

That is exactly the documented example in docs/backend-selection.md
(load(..., backend=MarlinConfig(fp32=False)) + quantize()), and the plain
enum spelling regressed the same way in #4606.

Fixes #6154

What Changed

  • gptqmodel/utils/backend_config.py: inherited_quantize_backend(qcfg, backend)
    is now the single owner of the "would this call inherit the load's backend?"
    rule; resolve_quantize_backend uses it, so callers cannot disagree.
  • gptqmodel/models/base.py:
    • _backend_can_pack selects the backend's kernel without pack=True and asks
      _supports_pack_api, instead of provoking the validation error.
    • resolve_pack_backend keeps a retained selection that can pack and falls
      back to BACKEND.AUTO (the method default, exactly as an un-retained AUTO
      request) with one warning when it cannot.
    • quantize() uses it before the AUTO/device branch, so the packed modules and
      self.quantize_backend see the packable choice.
  • Tests added to the existing tests/test_backend_config.py family.

Behaviour change: a retained inference-only load backend no longer becomes the
packing backend; it is used only for the dense load (device selection), which is
the pre-#4606 behaviour. An explicit quantize(backend=BACKEND.MARLIN) is not
inherited, so it still raises - as the issue allows. Out of scope: making Marlin
itself packable ("marlin padding"), and the docs/backend-selection.md wording,
which remains accurate.

Tests

  • Unit tests have been executed and passed.
  • I added a new simple/fast unit test for this change.

Red - end-to-end, HEAD source, documented flow on a cached tiny model:

GPTQModel.load("HuggingFaceTB/SmolLM2-135M", GPTQConfig(bits=4, group_size=128),
               backend=MarlinConfig(fp32=False)).quantize(CalibrationConfig(dataset=texts))
ValueError: Selected backend `BACKEND.MARLIN` with kernel `MarlinLinear` cannot pack quantized weights for format `FORMAT.GPTQ`.

Green - same script with the fix:

Quantize: the retained load backend `BACKEND.MARLIN` cannot pack quantized weights; packing with the method default backend instead.
QUANTIZE OK, pack backend: BACKEND.GPTQ_TORCH kernel: TorchLinear

Reproduced twice: with device="cuda:0" and with the loader's default device.

Unit tests (new nodes in tests/test_backend_config.py):

cd tests && PYTHONPATH=$PWD/..:$PWD /root/venv/bin/python -m pytest test_backend_config.py -q
# 46 passed in 4.04s

Backend/policy families:

cd tests && PYTHONPATH=$PWD/..:$PWD /root/venv/bin/python -m pytest \
  test_backend_config.py test_backend_config_reuse_4446.py test_backend_naming.py \
  test_dynamic_none_rules_5689.py test_policy_snapshot_conformance_4615.py -q -rs
# 95 passed in 4.35s

Lint: ruff check 0.14.2 on all three changed files: all checks passed.
No skips in any run above.

Measured Impact

Functional, not a speed change. The extra select_quant_linear(pack=False) call
runs once per quantize() and only when a load backend was retained.

Case Before After
Retained MarlinConfig(fp32=False) + quantize() ValueError: cannot pack quantized weights packs with BACKEND.GPTQ_TORCH
Retained BACKEND.EXLLAMA_V2 + quantize() same ValueError packs with the method default
Retained BACKEND.TRITON (can pack) packs with TRITON packs with TRITON (unchanged)
Explicit quantize(backend=BACKEND.MARLIN) raises still raises

Model Support / Module Plan

Not applicable: no model, alias, definition, or module-plan change.

AWQ onboarding safety

Not applicable to onboarding: no new model/alias/definition. The change is
method-agnostic and only decides which backend packs; AWQ grouping, search,
replay and fold are untouched.

Logic Flow Documentation

  • This change does not alter a major logic flow.

It inserts one guard between backend inheritance and the existing AUTO/device
branch; the ordering after it is unchanged.

Review Requirements

  • Reviewed this PR.
  • Checked that the code matches existing project structure, APIs, and conventions.
  • Avoided unnecessary monkeypatching and used the project's normal extension points where possible.
  • Minimized and compacted the impacted code surface.
  • Considered and eliminated potential regressions.

Kernel Accuracy Requirements

Not applicable: no kernel change.

Notes

_supports_pack_api is imported from gptqmodel.utils.importer (it already
backs the error this change avoids). The fallback keeps the previous behaviour
for every packable selection and for un-retained AUTO requests, so only the
crashing case changes.

`AwqGEMMLinear.pack` keeps the source scale width (`scales.dtype if
scales.dtype in (fp16, bf16) else fp16`), so a BF16 model's committed bundle
holds BF16 `scales`. `restore_packed_module` rebuilt the template from the
kernel constructor, which allocates `scales` at FP16, and
`packed_module_config` recorded no scale dtype. Every resume of a BF16 AWQ run
therefore failed `checkpoint tensor schema differs` before layer 0.

Record `scales_dtype` when the stored width is not the FP16 template default,
and restore it on the meta template the same way `bias_dtype` is restored
(#4324). FP16 needs no entry, so existing GPTQ and FP16 AWQ checkpoint configs
are unchanged. The recorded width always equals the bundle's, because capture
serializes the live `state_dict()`.

Fixes #6153
…6154)

`quantize(backend=AUTO)` inherits the backend given to the dense
`GPTQModel.load(...)`. Marlin, ExLlamaV2 and AWQ-Marlin have no pack API, so the
inherited selection failed the pack validation before calibration:

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

That is the documented `load(..., backend=MarlinConfig(...))` + `quantize()`
example in docs/backend-selection.md.

Inherit only a selection that can pack. An inference-only retained backend now
packs with the method default, exactly as an un-retained AUTO request does, and
warns once; an explicit `quantize(backend=...)` is not inherited and still
raises. The inheritance rule moves into `inherited_quantize_backend` so the
resolver and `quantize()` cannot disagree about which requests are inherited.

Fixes #6154
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