Repository navigation
fix(gptq): delegate native GPTQModel loads - #2469
Open
ZX-ModelCloud wants to merge 7 commits into
Open
ZX-ModelCloud wants to merge 7 commits into
ZX-ModelCloud wants to merge 7 commits into
Conversation
Qubitium
suggested changes
Jul 28, 2026
ZX-ModelCloud
marked this pull request as ready for review
July 29, 2026 02:18
Qubitium
suggested changes
Jul 30, 2026
Contributor
There was a problem hiding this comment.
@ZX-ModelCloud Unit test is testing pr change but actually not testing why we want this PR upstreamed to transformers. For example, you need write a specific test using hf/modelcloud hosted small quantied moe model with dynamic bit/groups gptq and test that it only loads correctly with our delegate.
This appears to be the last change I see before we can remove the wip tag.
|
This PR has been marked as stale because it has been open for 90 days with no activity. This thread will be automatically closed in 30 days if no further activity occurs. |
The load delegate claimed every checkpoint that records a gptqmodel entry in `meta.quantizer`. Optimum writes `["optimum:<v>", "gptqmodel:<v>"]` for every checkpoint it saves (see `GPTQQuantizer.to_dict`), so Optimum-owned checkpoints were rerouted through GPTQModel and reloaded with a different kernel than the one Optimum had selected. Before this change a saved bloom-560m asset was reloaded as `TorchLinear` from a delegate invocation. Only treat a checkpoint as native when it names GPTQModel and does not name Optimum, and only when the manifest is resolvable on disk. Hub repo ids and other unresolvable paths keep the existing Optimum path. Also repair two defects on the delegated path: - `get_no_split_module_classes` raised AttributeError because the delegate never sets `block_name_to_quantize`, and `load_quantized_model` calls it right after `convert_model`. Resolve the block name lazily. - `load_quantized_model` never forwarded `checkpoint_files`, so the delegate could not read the tensor manifest and silently declined real native checkpoints. Forward the shard/index paths. Regression tests cover the Optimum-owned checkpoint, the unresolvable Hub repo id, a delegate that declines with None, and the no-split crash.
The act-order baseline quantizes bloom-560m to a perplexity of 34 with the current GPTQModel kernels. The expectation was changed to 33 in "fix test_quantization.py", which makes the test fail with 34 != 33 on both CUDA and ROCm. Verified against the pre-change tree, which passes with 34. Keep the original threshold instead of relaxing the assertion, so a real perplexity regression still fails the suite.
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.
What does this PR do?
This PR allows Optimum to delegate native GPTQModel checkpoint preparation and post-initialization to GPTQModel when its optional loading bridge is available.
The existing GPTQ loading path discovers linear modules from the model structure and replaces them using a globally selected
QuantLinearimplementation. Native GPTQModel checkpoints may instead contain:Replacing modules outside that manifest can incorrectly convert an intentionally dense layer or select a kernel that does not support its shape.
This PR:
hf_gptqmodel_prepare_model_for_loadandhf_gptqmodel_post_init_for_load.There is no new hard dependency. GPTQModel versions that do not expose the bridge APIs continue using the existing Optimum behavior.
Testing
pytest -q tests/gptq/test_quantization.py -k "GPTQNativeLoadBridgeTest or GPTQPostInitTest"ruff check optimum/gptq/quantizer.py tests/gptq/test_quantization.pypython -m py_compile optimum/gptq/quantizer.py tests/gptq/test_quantization.pyBefore submitting
Who can review?
GPTQ and quantization: @SunMarc, @IlyasMoutawwakil