Repository navigation
feat(hf): let the bridge validate a caller-supplied in_features (#6149) - #6187
Merged
Merged
Conversation
The HF bridge returns one kernel class for every layer it replaces, so it can only honour a kernel's width contract when the caller passes the width it is about to build. Neither bridge entry point accepted that information, so selection was shape-blind: MarlinLinear has the highest AUTO rank and its constructor rejects any `in_features` that is not a multiple of `group_size`, which is why a SmolLM2 checkpoint (hidden 576, group_size 128) failed during Optimum's layer replacement. Accept `in_features`/`out_features` in `hf_select_quant_linear`, `hf_select_quant_linear_v2` and `select_quant_linear`, and forward them to `BaseQuantLinear.validate` in every AUTO candidate pass (the same check `GPTQModel.load` applies per module). A caller that supplies the width now gets a kernel that can build it; a caller that does not keeps the previous shape-blind answer, which the docs now state explicitly. Optimum already reads `layer.in_features` in `_replace_by_quant_layers` and only needs to pass it here; GPT-QModel does not patch Transformers/Optimum. Refs #6149
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.
Summary
hf_select_quant_linear{,_v2}return one kernel class for every layer theyreplace, so they can only honour a kernel's width contract when the caller says
which width it is about to build. Neither entry point accepted that information,
so selection was shape-blind:
MarlinLinearhas the highest AUTO rank (90) andits constructor rejects any
in_featuresthat is not a multiple ofgroup_size. A SmolLM2 checkpoint (hidden 576,group_size=128) therefore failsinside Optimum's layer replacement:
Optimum already has the shape:
_replace_by_quant_layersreadslayer.in_featuresto build each layer, then constructs the class selectedearlier. It just does not pass it to the bridge. Missing information cannot be
recovered by the selector, so the fix is to make the bridge accept it.
Refs #6149
What Changed
gptqmodel/utils/importer.pyhf_select_quant_linear,hf_select_quant_linear_v2andselect_quant_linearacceptin_features/out_featuresand forward themto
BaseQuantLinear.validatein every AUTO candidate pass (main, dynamicmulti-select, portable fallback, explicit backend).
before, so existing loaders are unaffected.
docs/hf-interop.md: new section 7 documents the contract with a decisiondiagram, plus rows in the failure contract and test tables.
tests/test_hf_packing_api.py: new node covering both bridges.This does not patch Transformers/Optimum (per #4620). The remaining step for
the end-to-end crash is the caller passing
in_features; with that one-linechange Optimum gets a buildable kernel for partial-group layers and keeps Marlin
everywhere else.
Tests
Behaviour,
hf_select_quant_linear_v2(..., pack=False)on a CUDA device map,bits=4, group_size=128, sym=True:in_featuresMarlinLinear(unchanged)MarlinLinearTritonV2LinearTritonV2LinearRed (importer reverted, new tests):