Repository navigation
test(docs,hf): assert #6327 fallback and fix docs contract refs - #6340
Conversation
Fixes #6332, #6334 - test_hf_packing_api: the bridge now forwards in_features/out_features to validate_quant_linear and, for a shape-blind AUTO selection, falls back to the portable auto-padding TorchLinear instead of the ValueError removed by #6327. Spy on validate_quant_linear (covering both candidates) and assert the fallback plus the forwarded widths. - docs/backend-selection: import BaseQuantLinear so the registration example is self-contained and runnable. - test_docs_contract_refs: refresh the hf_packing_api block 1 digest. It is still a continuation snippet (`linear`, `scales`, `zeros`, `g_idx` come from the prose), so the skip remains correct.
The fenced example referenced `MyKernelBase` without defining it, so `test_doc_python_example_runs` raised `NameError`. It now subclasses `BaseQuantLinear`, the real base `register_kernel` requires, so the block executes. Also refreshes the reviewed `docs/hf_packing_api.md::1` skip digest, whose snippet changed. Carried over from #6340, which is superseded by this PR for the `test_hf_packing_api.py` half: the per-layer `ShapeAware` contract here replaces #6327's whole-checkpoint fallback that #6340 asserted.
|
Superseded by #6345, which carries both of this PR's fixes and the product fix they belong with. #6334 (docs) — carried into #6345 verbatim: #6332 ( Combined verification on #6345: → No work is lost; closing this one so #6332/#6334/#6336 have a single owner. |
#6327's `_shape_safe_gptq_selection` replaced the AUTO kernel with `TorchLinear` for the whole checkpoint, because `TorchCpuAvx512Linear.SUPPORTS_AUTO_PADDING` and `MarlinLinear.SUPPORTS_AUTO_PADDING` are both False. Group-aligned layers therefore lost their real kernel, and on CPU `TorchLinear.post_init` runs an eager `torch_compile` per layer: cold 0.87 s -> 1.52 s, warm 0.365 s -> 0.440 s. `_shape_aware_gptq_kernel()` now returns `ShapeAware<AutoKernel>`, a subclass of the already-selected AUTO kernel whose `__new__` dispatches on `in_features`: aligned widths keep the AUTO kernel, partial groups get the auto-padding `TorchLinear`. A metaclass `__instancecheck__` keeps Optimum's `isinstance`/`get_layers` working, and the padding kernel is selected once per checkpoint rather than per module. Rebased onto #6340, whose whole-checkpoint fallback assertions this replaces with the per-layer contract. Fixes #6336
Fixes #6332, #6334
What changed
Only three files, all inside this worktree;
gptqmodel/utils/importer.pyis untouched.#6332 —
tests/test_hf_packing_api.pyThe test expected the
ValueErrorthat #6323 added and #6327 replaced with theauto-padding Torch fallback. #6327's fallback is the intended contract, so the
test now asserts it instead of reverting it:
gptqmodel.utils.importer.validate_quant_linear(the selectionboundary, so both candidates are covered) and records
(kernel_cls, in_features, out_features);TorchLinear, while Marlin was stillvalidated first with
in_features=None— i.e. the result is a fallback, nota missing candidate;
select(in_features=896, out_features=896) is MarlinLinearandselect(in_features=576, out_features=576) is TorchLinear, and that bothwidths reached
validate_quant_linearfor the Marlin and Torch calls.This keeps the original invariant (the bridge forwards
in_features/out_featuresto kernel validation) and adds the fallback contract.Fallback correctness:
PackedGroupedQuantLinear._validateaccepts a partialgroup when
cls.SUPPORTS_AUTO_PADDINGis true, andTorchLineardeclaresSUPPORTS_AUTO_PADDING = True; the partial-group576/128call is actuallyvalidated and returns
TorchLinear. No product bug found in the fallback.#6334 —
docs/backend-selection.mdThe registration example subclassed the undefined
MyKernelBase. The examplenow imports the real base class,
BaseQuantLinear(the classregister_kernelrequires and its own docstring uses), so the block isself-contained and executes. It is not skip-listed and not deleted.
#6334 —
tests/test_docs_contract_refs.pyNOT_EXECUTED_BLOCKS[docs/hf_packing_api.md::1]digest refreshed12964d5cda1f→1f0f998865c6, reason updated to mentionzeros.Chosen: keep the block skipped. It is a continuation snippet:
linear,scales,zeros, andg_idxare defined only in the prose, so it cannot runas a standalone program. The digest was stale because the block changed (it now
passes
linear.in_features/linear.out_features), not because it becamerunnable.
Red → green
Before (current
main42827b67):After:
Exact commands
Skips are the five pre-existing CUDA-only nodes in
test_hf_packing_api.py(one NVIDIA GPU / two / three devices required); no new skips or xfails.
Draft only — not merged.