Skip to content

[BUG] resolve_quantize_backend writes the generated policy into QuantizeConfig.kernel: reusing a qcfg raises "legacy kernel=" errors or leaks typed settings (regression from #4375) #4446

Closed

Description

@Qubitium

Severity: medium. Kind: new bug from e44bb70 (#4375). Confirmed at 489aed6 on CPU and an RTX 4090.

Root cause

gptqmodel/utils/backend_config.py:257-280 (resolve_quantize_backend):

  • if policy is not None: qcfg.kernel = policy stores the adapter it generated in the field that means "the caller supplied a legacy kernel=".
  • On the next call, if kernel is None: kernel = qcfg.kernel reads it back as if the user had supplied it.
  • The identity escape (_backend_kernel) exists only for typed backends, not for the runtime=-only path.

Repro (facebook/opt-125m, CPU is enough)

from gptqmodel import GPTQModel, BACKEND
from gptqmodel.backend import RuntimeConfig, TorchConfig
from gptqmodel.quantization import QuantizeConfig
M = "facebook/opt-125m"

# (a) documented flow: typed backend passed to quantize() after a runtime= qcfg
qcfg = QuantizeConfig(bits=4, runtime=RuntimeConfig(max_packers=2))
m = GPTQModel.load(M, quantize_config=qcfg)
m.quantize(["hello world " * 20] * 4, backend=TorchConfig(streaming=True))
# ValueError: backend=BackendConfig(...) and legacy kernel= cannot be supplied together
# (a 2nd GPTQModel.load(M, quantize_config=qcfg, backend=TorchConfig(...)) raises the same)

# (b) reuse a qcfg with a different runtime
q = QuantizeConfig(bits=4)
GPTQModel.load(M, quantize_config=q, runtime=RuntimeConfig(max_packers=2))
GPTQModel.load(M, quantize_config=q, runtime=RuntimeConfig(max_packers=3))
# ValueError: runtime= and legacy kernel= cannot be supplied together

# (c) typed settings leak into a later "defaults" selection
q = QuantizeConfig(bits=4)
GPTQModel.load(M, quantize_config=q, backend=TorchConfig(streaming=True, stream_tile=128))
GPTQModel.load(M, quantize_config=q, backend=BACKEND.TORCH)
# q.kernel.torch_streaming=True, torch_stream_tile=128; the process policy is also streaming=True.
# Same for m.quantize(backend=BACKEND.MARLIN) after a typed TorchConfig load: torch_streaming stays True.

Expected:

  • (a) and (b) work. The docs say quantize() accepts typed configs and that runtime= is the shared control.
  • (c) uses defaults. The docs say "BACKEND.MARLIN selects Marlin with defaults".

Related: QuantizeConfig.runtime combined with kernel= silently drops the runtime settings

backend_config.py:265-269 reads runtime from the qcfg only when kernel is None, and resolve_kernel_config then lets kernel win:

qcfg = QuantizeConfig(bits=4, runtime=RuntimeConfig(max_packers=2, gptq_fused_block_update=False))
GPTQModel.load(M, quantize_config=qcfg, kernel=KernelConfig(marlin_fp32=False))
# accepted; resolve_kernel_config(qcfg) -> max_packers=None, gptq_fused_block_update=True

The qcfg ends up with both .runtime and .kernel set, a state its own __post_init__ rejects. Passing runtime= and kernel= as arguments does raise the documented ValueError; this path should raise too.


Found during an AI-assisted review (Claude Code, round 13) of 489aed6; repros were run at that commit (A/B against def6e61 where noted) on RTX 4090/5090 (CUDA 13) and/or Radeon AI PRO R9700 (ROCm) unless marked static/suspected.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions