Repository navigation
fix(qlinear): size GPTQ buffers by pack_factor and skip Laguna g_proj quantization - #2983
Merged
Merged
Conversation
… quantization (#84) * fix(qlinear): use pack_factor for qweight/qzeros buffer sizing and mark Laguna g_proj as non-quantizable * test(qlinear): add buffer shape test for out_features=48/72
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This was referenced Nov 28, 2026
Qubitium
added a commit
that referenced
this pull request
Nov 29, 2026
…6409) * fix(hf): defer a legacy qzeros only on a real floor-width mismatch `_hf_legacy_qzeros_quant_linear` wraps every symmetric checkpoint from a pre-7.3.4 producer with `_HF_DEFER_SYM_QZEROS = True`. The deferral hides `qzeros` from the loader's expected-key set, which is only needed when the checkpoint stores the pre-#2983 floor width (`out_features // 32 * bits`). The two widths are identical for a 32-aligned projection, but the buffer was still hidden: the module kept its constructor (meta) `qzeros`, and `_materialize_hf_sym_qzeros` only runs from `hf_gptqmodel_post_init`, which Optimum calls *after* `accelerate.dispatch_model`. A GPU/disk placement then failed with ValueError: qzeros is on the meta device, we need a `value` to put in on 0. Measured on the published `ModelCloud/DeepSeek-R1-Distill-Qwen-7B-gptqmodel-4bit-vortex-v1` (`meta.quantizer: gptqmodel:1.7.4`; all 196 `qzeros` already ceil-width) with `max_memory={0: "3GiB", "cpu": "14GiB"}`: the load fails before this change and loads with finite logits after it. The constructor now clears the deferral for a 32-aligned layer, so the checkpoint tensor is loaded normally; a genuine floor-width layer keeps the deferral and is still regenerated after loading. `tests/test_deferred_qzeros_dispatch_6396.py` pins both branches, including a GPU-gated mixed-map load+forward on the real checkpoint. Two `test_hf_bridge_cpu_offload_5022.py` fixtures that hand-build a legacy Marlin layer use a floor-width shape (or re-apply the loader marker), because a 32-aligned layer no longer defers. * test(hf): pin the matching-width offload path and bound the GPU node A 32-aligned legacy checkpoint no longer defers `qzeros`, so the old "legacy deferred qzeros on CPU offload still raises" node no longer describes it: the refusal only guards a genuine floor-width buffer. Rename it to pin the new outcome (the checkpoint loads), and keep the floor-width deferral covered by the resident-CPU node in `test_deferred_qzeros_dispatch_6396.py`. The GPU-gated real-checkpoint node keeps only the 3GiB map: a 1GiB cap reselected all 196 layers to the portable kernel, whose optional inductor compile makes the node a multi-minute run without adding coverage of the dispatch failure (the 3GiB map still exercises it). --------- Co-authored-by: agent <agent@local>
Qubitium
added a commit
that referenced
this pull request
Nov 29, 2026
* test(qzeros): pin the symmetric-qzeros state machine invariants Six changes landed on the symmetric ``qzeros`` path in one day (#6388, #6392, #6391, #6395, #6409 and the pending #6157 normalization). Each was verified on its own; nothing pinned the combination, and a later edit can satisfy one fix while breaking another. The state machine has three markers (``_HF_LEGACY_QZEROS``, ``_HF_CHECKPOINT_SYM``, ``_HF_DEFER_SYM_QZEROS``) and two word encodings, selected by ``_load_target_qzeros_format()``. The tests assert: - a 32-aligned legacy projection never defers, and a real floor-width mismatch always does (#6409 / #6396); - an asymmetric floor-width checkpoint is refused, never silently wrong; - a deferred module materializes to the standard shape with a resolved layout that agrees with the one the kernel decodes; - materialization is idempotent across 2/3/4/8-bit; - the deferral marker and a materialized buffer are mutually exclusive; - a float ``qzeros`` buffer (int4pack affine offsets) is never filled with a packed word -- skipped until the #6157 normalizer exists; - a clean checkpoint's word survives the load, and every pre- and post-#2983 producer lands on the same decoded zero point. ``qzero_format()`` is deliberately not read as a decode answer before ``_qzeros_format_established``: every kernel is ``REQUIRES_FORMAT_V2``, so the constructor placeholder ``1`` disagrees with the decoded ``2`` until a load resolves it (#4377). That distinction is the whole reason the first #6157 draft corrupted clean checkpoints. Test-only. Verified 49 passed / 13 skipped on main (a4471c5) and 50 / 12 with #6419 applied; 68 passed / 17 skipped together with the four existing qzeros test files, so there is no global-state pollution. Every skip is a kernel-geometry or environment gate with a precise reason. * test(qzeros): spell out the unreachable return after a pytest.skip ``_legacy_module_or_skip`` ended with a bare ``pytest.skip(...)`` call, which reads as an implicit ``return None`` to static analysis and made CodeQL flag the function for mixing explicit and implicit returns. ``pytest.skip`` raises, so the added return is unreachable; it exists only to make every non-exceptional path explicit, and the comment says so. Behaviour unchanged: 49 passed, 13 skipped, identical to before. --------- Co-authored-by: agent <agent@local>
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
Fixes two related issues for Laguna S-2.1:
GPTQQuantLinear._register_gptq_buffers(and the fallbackPackableQuantLinear.pack) sized packed buffers with// pack_dtype_bits * bits. This only equals// pack_factorwhen the dimension is a multiple ofpack_dtype_bits(32), so layers likeself_attn.g_projwithout_features=48or72got aqzerosbuffer with too few columns andload_checkpointfailed with a shape mismatch.g_projis tiny (0.28–0.42 MB dense) and not worth quantizing. Mark it as:!inLagunaQModel.module_treeso it is bypassed during dense → quantization.What Changed
gptqmodel/nn_modules/qlinear/__init__.py:_register_gptq_buffersnow allocatesqweightrows andqzeroscolumns withmath.ceil(features / self.pack_factor).PackableQuantLinear.packuses the samepack_factor-based sizing forqweight/qzeros.gptqmodel/models/definitions/laguna.py:self_attn.g_projchanged from:0to:!sosimple_layer_modulesexcludes it from quantization.tests/kernels/test_qlinear_hierarchy.py:test_gptq_quant_linear_buffer_shapes_for_non_word_aligned_out_featurescoveringout_features=48and72.Tests
python -m pytest tests/kernels/test_qlinear_hierarchy.py::test_gptq_quant_linear_buffer_shapes_for_non_word_aligned_out_features -q # 1 passedruff check gptqmodel/nn_modules/qlinear/__init__.py gptqmodel/models/definitions/laguna.py tests/kernels/test_qlinear_hierarchy.py --config format/ruff.tomlpasses.git diff --checkpasses.Notes
g_proj:!change applies to the dense → quantization path. Existing checkpoints quantized withg_proj.qweightwill treat it as unexpected unless the loader is taught to dequantize them, but the primary goal is to avoid quantizing these tiny layers going forward.