Skip to content

test(docs,hf): assert #6327 fallback and fix docs contract refs - #6340

Merged
Qubitium merged 1 commit into
mainfrom
fix/6332-6334-tests
Nov 29, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/6332-6334-tests

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #6332, #6334

What changed

Only three files, all inside this worktree; gptqmodel/utils/importer.py is untouched.

#6332 — tests/test_hf_packing_api.py

The test expected the ValueError that #6323 added and #6327 replaced with the
auto-padding Torch fallback. #6327's fallback is the intended contract, so the
test now asserts it instead of reverting it:

  • spies on gptqmodel.utils.importer.validate_quant_linear (the selection
    boundary, so both candidates are covered) and records
    (kernel_cls, in_features, out_features);
  • asserts a shape-blind AUTO call returns TorchLinear, while Marlin was still
    validated first with in_features=None — i.e. the result is a fallback, not
    a missing candidate;
  • asserts select(in_features=896, out_features=896) is MarlinLinear and
    select(in_features=576, out_features=576) is TorchLinear, and that both
    widths reached validate_quant_linear for the Marlin and Torch calls.

This keeps the original invariant (the bridge forwards in_features /
out_features to kernel validation) and adds the fallback contract.

Fallback correctness: PackedGroupedQuantLinear._validate accepts a partial
group when cls.SUPPORTS_AUTO_PADDING is true, and TorchLinear declares
SUPPORTS_AUTO_PADDING = True; the partial-group 576/128 call is actually
validated and returns TorchLinear. No product bug found in the fallback.

#6334 — docs/backend-selection.md

The registration example subclassed the undefined MyKernelBase. The example
now imports the real base class, BaseQuantLinear (the class
register_kernel requires and its own docstring uses), so the block is
self-contained and executes. It is not skip-listed and not deleted.

#6334 — tests/test_docs_contract_refs.py

NOT_EXECUTED_BLOCKS[docs/hf_packing_api.md::1] digest refreshed
12964d5cda1f → 1f0f998865c6, reason updated to mention zeros.

Chosen: keep the block skipped. It is a continuation snippet: linear,
scales, zeros, and g_idx are defined only in the prose, so it cannot run
as a standalone program. The digest was stale because the block changed (it now
passes linear.in_features / linear.out_features), not because it became
runnable.

Red → green

Before (current main 42827b67):

tests/test_hf_packing_api.py::test_hf_bridge_forwards_in_features_to_kernel_validation[v1] FAILED
tests/test_hf_packing_api.py::test_hf_bridge_forwards_in_features_to_kernel_validation[v2] FAILED
  Failed: DID NOT RAISE ValueError
tests/test_docs_contract_refs.py::test_doc_python_example_runs[docs/backend-selection.md::1] FAILED
  NameError: name 'MyKernelBase' is not defined
tests/test_docs_contract_refs.py::test_doc_block_skip_lists_are_current FAILED
  NOT_EXECUTED_BLOCKS[docs/hf_packing_api.md::1] changed
4 failed, 296 passed, 5 skipped

After:

2 passed, 59 deselected   # the two #6332 nodes
9 passed, 225 deselected  # backend-selection / hf_packing_api / skip-list nodes
300 passed, 5 skipped     # full required suite

Exact commands

cd /root/openai-audit/i-633234/tests
PYTHONPATH=/root/openai-audit/i-633234:/root/openai-audit/i-633234/tests CUDA_VISIBLE_DEVICES="" \
  /root/venv/bin/python -m pytest test_hf_packing_api.py test_docs_contract_refs.py \
  test_hf_bridge_missing_shape_6149.py -q -rs -p no:cacheprovider
# 300 passed, 5 skipped in 126.57s

/root/venv/bin/ruff check tests/test_hf_packing_api.py tests/test_docs_contract_refs.py
# All checks passed!

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.

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.
@Qubitium
Qubitium marked this pull request as ready for review November 29, 2026 09:41
@Qubitium
Qubitium merged commit be14824 into main Nov 29, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/6332-6334-tests branch November 29, 2026 09:42
Qubitium added a commit that referenced this pull request Nov 29, 2026
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.
@Qubitium

Copy link
Copy Markdown
Collaborator Author

Superseded by #6345, which carries both of this PR's fixes and the product fix they belong with.

#6334 (docs) — carried into #6345 verbatim: docs/backend-selection.md now subclasses BaseQuantLinear so the example runs (not skip-listed), and the docs/hf_packing_api.md::1 digest is refreshed. Same two files, same content.

#6332 (test_hf_packing_api.py) — carried, but re-targeted. This PR asserted #6327's whole-checkpoint TorchLinear fallback. #6345 replaces that mechanism with per-layer ShapeAware<AutoKernel> dispatch (see #6336 — the whole-checkpoint swap cost every group-aligned layer its AUTO kernel and, on CPU, an eager torch_compile per layer: cold 0.87 s → 1.52 s, warm 0.365 s → 0.440 s). So the two nodes now assert the per-layer contract, which is strictly the better outcome: a group-aligned layer keeps MarlinLinear/TorchCpuAvx512Linear, a partial-group layer gets TorchLinear, and in_features/out_features are still proven to reach validate_quant_linear.

Combined verification on #6345:

pytest test_hf_packing_api.py test_docs_contract_refs.py \
       test_hf_bridge_grouped_load_cost_6336.py test_hf_bridge_missing_shape_6149.py -q -rs

→ 307 passed, 5 skipped

No work is lost; closing this one so #6332/#6334/#6336 have a single owner.

Qubitium added a commit that referenced this pull request Nov 29, 2026
#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant