Repository navigation
Expose stable hf_ kernel/packing/repacking APIs (#726) - #3251
Merged
Merged
Conversation
Add `gptqmodel.utils.packing` with stable, `hf_`-prefixed entry points for external integrators (optimum, auto-round) as requested in #726: - `hf_check_packing_feasibility()`: probe whether a kernel can pack a quantization contract on the target device. `repack=True` probes repack targets instead of raw-weight packers (Marlin/ExllamaV2 consume GPTQ tensors and convert them in `post_init()`). - `hf_check_best_packing_format()`: rank formats by fastest feasible kernel priority and return the preferred feasible format. - `hf_pack_layer()` / `BaseQuantLinear.hf_pack()`: layer-wise packing that mirrors the internal pack path (original/block/gpu), synthesizes symmetric zero points when omitted, and requires explicit zeros for `sym=False`. - `hf_post_init()`: layer-scoped `post_init()` for a layer or every quantized child of a container, with kwargs for kernels such as ExllamaV2 that need a scratch space. - `hf_repack_layer()`: repack a quantized layer for another backend via native `repack_from_gptq`/`repack_from_awq` hooks or layout-compatible copies, aligning GPTQ v1/v2 qzero flavors; sources whose buffers are a private runtime ABI (Marlin/Machete/Swordfish/BitBLAS) are rejected. Add `tests/test_hf_packing_api.py` with CPU and CUDA coverage (pack parity against `pack_original`/`pack_block`, feasibility/best-format probing, GPU packing, Marlin and ExllamaV2 repack targets, multi-GPU device forms) and document the API in `docs/hf_packing_api.md`, linked from the README.
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.
Implements the stable hf_ kernel/packing/repacking API requested in #726 for external integrators.
API surface
Correctness fixes
Validation
Environment:
Installed and exercised optional backends:
Results:
The remaining Machete and Swordfish skips are hardware-gated: RTX 4090 is SM89, while Machete requires Hopper SM90 and Swordfish requires Blackwell SM100/SM103/SM110. MLX kernels have no supported device in this CUDA/NVIDIA environment.
Documentation: docs/hf_packing_api.md
Closes #726.