Repository navigation
fix(backend): inherit explicit enum load backend into quantize (#4582) - #4606
Merged
Merged
Conversation
This was referenced Nov 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4582
TL;DR
resolve_quantize_backendrecorded a dense load's backend only when it was a typedBackendConfig(qcfg._backend_config); an enum/string load (backend=BACKEND.AWQ_TORCH) was used for device selection and then dropped, soquantize(backend=AUTO)fell back to the AUTO chooser. The fix records an explicit non-AUTO enum/string selection inqcfg._load_backendand inherits it inquantize(backend=AUTO)exactly like a typed choice. Invalid values still raise at the load boundary.Root cause
On
97c377509, the inheritance branch read only_backend_config, and the final assignment kept only typed configs:GPTQModel.load(..., backend=BACKEND.AWQ_TORCH)therefore left no retained selection.BaseQModel.quantize(backend=AUTO)(models/base.py:2129) resolvedAUTOand packed withAwqGEMMLinearinstead of the requestedAwqTorchLinear, which changes which shapes are quantizable.New flow
_load_backendholds the normalized enum/string from the load boundary. A typedBackendConfigstill uses_backend_configand carries its options.quantize(backend=AUTO)prefers the typed choice, then the explicit enum/string choice, then AUTO. A quantize-time explicit backend is a one-shot override and does not replace the retained load selection.flowchart TD A["load(backend=X)"] --> B{"BackendConfig instance?"} B -- "yes" --> C["qcfg._backend_config = X"] B -- "no" --> D["normalize_backend(X)<br/>invalid -> ValueError/TypeError"] D --> E{"X == AUTO?"} E -- "no" --> F["qcfg._load_backend = X"] E -- "yes" --> G["clear retained selection"] C --> H["quantize(backend=AUTO)"] F --> H G --> H H --> I{"typed or enum retained?"} I -- "yes" --> J["resolve the retained selection"] I -- "no" --> K["BACKEND.AUTO chooser"] classDef failure fill:#ffe0e8,stroke:#b30000,color:#111; class D failure;97c377509_backend_config(backend_config.py:276)_load_backend(backend_config.py:277-283)BackendConfig(backend_config.py:302)backend_config.py:309-320)The documented behavior and the typed/enum/AUTO table are updated in
docs/backend-selection.md.Tests
tests/test_backend_config_reuse_4446.pynow parametrizes the typed and enum spellings:quantize(backend=AUTO)expectedTorchConfig()BACKEND.GPTQ_TORCHBACKEND.GPTQ_TORCHBACKEND.GPTQ_TORCHAwqTorchConfig()BACKEND.AWQ_TORCHBACKEND.AWQ_TORCHBACKEND.AWQ_TORCHIt also asserts the issue's exact AWQ enum case resolves
AWQ_TORCH(notAWQ_GEMM/AUTO), and that"not-a-backend", an integer, and an arbitrary object raise at load and leave no retained selection.Environment for every run:
OMP_NUM_THREADS=4 MKL_NUM_THREADS=4 OPENBLAS_NUM_THREADS=4 NUMEXPR_NUM_THREADS=4,PYTHONPATH=$PWD.The two fake-load harnesses in
tests/test_backend_config_reuse_4446.pyandtests/test_backend_config.pynow return a no-oplog_kv_cache_estimate, which currentGPTQModel.loadcalls on the returned model. Without that test-only update those files fail on currentmainbefore reaching any backend assertion; no production behavior changed for it.Hardware
CPU-only config/selection logic. CUDA venv
/opt/venvs/cu130t(Py3.14t, torch 2.16.0.dev+cu130) and ROCm venv/opt/venvs/rocm101t. No GPU kernel or real model was executed.Limitations
quantize(backend=AUTO).