Repository navigation
Conversation
#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
7b0bec9 to
7b96fd8
Compare
|
Cross-PR note: #6353 (fix for #6346) is a prerequisite for this PR's positional path.
But on current
Verified no internal caller is affected: an AST/ |
|
Honest scoping of the perf claim, from an independent end-to-end smoke pass on real checkpoints (pre-wave
No reproducible slowdown was found at 1B scale on a shared host — the cold/warm deltas are within noise there. The regression this PR fixes is real and reproducible on a tiny checkpoint (cold 0.87 s → 1.52 s, warm 0.365 s → 0.440 s) because the per-layer So treat this PR as restoring the pre-wave kernel for group-aligned layers (a correctness/parity fix — aligned layers keep Output parity is unaffected either way — all six smoke cells produced identical digests and NLL pre- and post-wave. |
… legacy qzeros (#6191, #6178, #6336) Bring #6345's ShapeAware<AutoKernel> dispatcher into #6274's HF bridge selection path: - _shape_safe_gptq_selection() now takes the pack flag and selects the auto-padding fallback with the same pack gate, so a pack=True call still resolves to a packable kernel. - _hf_pack_backend() runs first and resolves the packing backend; the shape-aware decision is layered on the resolved backend. - the legacy floor-width qzeros wrapper is applied to both concrete kernels of the dispatcher (aligned AUTO and partial-group fallback), so #6178's deferral survives the per-layer split. - the plain-HF pack=False AUTO path keeps its constant two selections. Merged test_hf_packing_api.py keeps #6345's per-layer assertions and #6274's pack/inference assertions.
|
Consolidated into #6274 (new head What moved
The constant-selection-count property is preserved: the plain-HF Verification on the consolidated branch
No commit from |
…os in the HF bridge (#6191, #6178, #6336) (#6274) * fix(hf): packable kernel selection and legacy floor-width qzeros in the HF bridge (#6191, #6178) Rebased onto be14824; keeps both the #6344 g_idx repair and the deferred symmetric qzeros materialization in hf_gptqmodel_post_init, and keeps main's #6327 shape-blind fallback contract in test_hf_packing_api. * fix(hf): consolidate packable selection, per-layer shape dispatch and legacy qzeros (#6191, #6178, #6336) Bring #6345's ShapeAware<AutoKernel> dispatcher into #6274's HF bridge selection path: - _shape_safe_gptq_selection() now takes the pack flag and selects the auto-padding fallback with the same pack gate, so a pack=True call still resolves to a packable kernel. - _hf_pack_backend() runs first and resolves the packing backend; the shape-aware decision is layered on the resolved backend. - the legacy floor-width qzeros wrapper is applied to both concrete kernels of the dispatcher (aligned AUTO and partial-group fallback), so #6178's deferral survives the per-layer split. - the plain-HF pack=False AUTO path keeps its constant two selections. Merged test_hf_packing_api.py keeps #6345's per-layer assertions and #6274's pack/inference assertions. * fix(hf): dispatch layer shapes the AUTO kernel cannot build The #6336 per-layer dispatcher only checked the partial-group rule, so an AUTO kernel that passed model-wide validation (in_features/out_features unknown) could still reject the real layer shape. The CPU AVX512 kernel requires out_features % 32 == 0, so a plain-HF load of a model with a 1744-wide intermediate crashed during layer replacement; route those layers to the pre-selected TorchLinear fallback. TorchAtenLinear also advertised SUPPORTS_AUTO_PADDING=True although its CPU int4pack validation rejects a partial last group. That made the shape-blind bridge skip the dispatcher for group_size=32 checkpoints and crash on a 48-wide layer. Declare the contract the op actually enforces. Update the #6169 dtype tests for the dispatcher's second (padding) selection and add regression tests for both paths. * fix(hf): materialize legacy qzeros only for kernels that own the buffer `_materialize_hf_sym_qzeros` rebuilt every deferred symmetric `qzeros` with `register_buffer`, but Marlin keeps its zero point in a packed `Parameter` and never reads the words. An AUTO load of a legacy floor-width checkpoint on CUDA therefore raised `KeyError: attribute 'qzeros' already exists` before `gptqmodel_post_init` could run; the portable Torch kernel was unaffected, which is why the CPU-only coverage missed it. The deferral only hides the legacy width from the core loader, so a kernel that does not own a `qzeros` buffer has nothing left to repair. Skip it, and replace the constructor's meta placeholder with the empty parameter the kernel's own runtime state installs, so a resident layer is not mistaken for an offloaded one. `tests/test_hf_bridge_legacy_qzeros_marlin_6274.py` covers the Marlin load on CUDA, the portable path on CPU, and both branches of the skip directly. --------- Co-authored-by: pr-keeper <pr-keeper@localhost> Co-authored-by: agent <agent@local>
Fixes #6336. Rebased onto #6340 (which merged #6332 and #6334); this PR now carries only the product fix and the per-layer test contract that supersedes #6340's whole-checkpoint assertions.
Problem
_needs_shape_safe_gptq_kernel()is true for the shape-blind AUTO GPTQ call becauseTorchCpuAvx512Linear.SUPPORTS_AUTO_PADDING = False(torch_cpu_avx512.py:172) andMarlinLinear.SUPPORTS_AUTO_PADDING = False(marlin.py:104). #6327's_shape_safe_gptq_selectionthen replaced the AUTO class withTorchLinearfor the whole checkpoint.On CPU,
TorchLinear.post_init→optimize()→ an eagertorch_compile(...)per layer, and the first call imports dynamo/inductor.TorchCpuAvx512Linearinherits the base no-opoptimize(), so it never pays that cost. On CUDA the cost is Marlin→Torch decode/prefill.Measured (CPU, tiny 1-layer MPT GPTQ, aligned
group_size, plainAutoModelForCausalLM.from_pretrained, 3 processes, warm = median of 5):42827b67TorchLinear89dbcf91TorchCpuAvx512LinearTorchCpuAvx512LinearCUDA end-to-end (RTX 4090, aligned g128, fp16):
42827b67→TorchLinear, pre-wave →MarlinLinear, this PR →MarlinLinear; finite forward in all three.Fix
gptqmodel/utils/importer.py:_shape_aware_gptq_kernel()returnsShapeAware<AutoKernel>— a subclass of the already-selected AUTO kernel whose__new__readsin_featuresand dispatches;kernel_for_width()is one modulo test.__instancecheck__keeps Optimum'sisinstance/get_layersworking._shape_safe_gptq_selection()selects the padding kernel once per checkpoint (2select_quant_linearcalls total, independent of module count).Per-layer outcome:
in_features % group_size == 0MarlinLinearon CUDA,TorchCpuAvx512Linearon CPU)TorchLinear(auto-padding)TorchLinear(stays safe)Explicit backend / explicit
in_features/group_size=-1/ non-GPTQ paths are unchanged.Tests
tests/test_hf_bridge_grouped_load_cost_6336.py(7 nodes, CPU-only, structural rather than wall-clock):7/7 fail on
42827b67, 7/7 pass here. Asserts per-layer dispatch (aligned→AUTO, partial→TorchLinear, unknown→TorchLinear), exactly 2select_quant_linearcalls per checkpoint with 36 width decisions adding zero calls,isinstancecovering both kernels, and an end-to-end plain-HF aligned load keeping the host AUTO kernel.tests/test_hf_packing_api.py—test_hf_bridge_forwards_in_features_to_kernel_validation[v1,v2]now asserts the per-layer contract instead of #6340's whole-checkpointTorchLinearfallback, and still provesin_features/out_featuresreachvalidate_quant_linear.Verification
→
307 passed, 5 skipped(all five skips are pre-existing CUDA device-count gates)Broader affected set:
272 passed, 89 skippedacrosstest_hf_bridge_missing_shape_6149,test_hf_packing_api,kernels/test_selection,test_checkpoint_interop_4053,test_checkpoint_compat,test_hf_bridge_cpu_offload_5022,test_hf_bridge_mixed_capability_5084./root/venv/bin/ruff checkon every changed file → All checks passed.Not measured
Absolute CUDA decode/prefill tok/s were not re-benchmarked (the GPUs are shared). The mechanism is verified end-to-end — aligned CUDA layers are
MarlinLinearagain — but the throughput delta itself is unquantified here.