Repository navigation
fix(qlinear): restore bare-module state_dict() and classify MPS kernels in the audit (#4130) - #4138
Merged
Merged
Conversation
Qubitium
added a commit
that referenced
this pull request
Nov 15, 2026
…4123) (#4141) * fix(rocm): pin every Hessian builder and serialize mixed BLAS scopes (#4123) #4105 scoped the deterministic rocBLAS pin to `ProcessorStep.GPTQ`, which dropped QQQ (it builds an X^T X Hessian in `add_batch`) and the other Hessian builders. QQQ then accumulated on hipBLASLt and four runs produced three distinct checkpoints differing in 490/627 tensors. - base: gate on a `_HESSIAN_PROCESSOR_STEPS` set (GPTQ, QQQ, VPTQ, MACaQ, EXL3, FP8_GSQ) instead of `ProcessorStep.GPTQ`, and always enter the guard: Hessian builders pin rocBLAS, AWQ/ParoQuant/RTN pin hipBLASLt. - rocm: carry a `_QUANT_BLAS_GUARD_TARGET` on the refcounted guard and make a mixed-backend run wait for the active one instead of flipping the process-global backend mid-run (AWQ vs serial was 319/627 differing). - rocm: warn for the opt-out spellings (""/0/off/default) too, not only the two opt-ins. - cpp: refresh the staged in-checkout include root every call, because the cache fingerprint hashes the staged copy, so a stale stage hid header edits. - docs: correct "AWQ/RTN/QQQ have no Hessian", add the per-method determinism/concurrency tables, and scope the split-K=1 speed claim. * test(rocm): hash 0-dim checkpoint tensors and record merged-tree counts (#4123) Current main adds a 0-dim `qzeros_format` scalar to the checkpoint (#4138), which the cross-process child script could not `view(torch.uint8)`. Flatten before the view so the scalar is hashed too, and record the merged-tree confirmation (GPTQ 0/963, QQQ 0/627 over four runs each). * docs(rocm): correct the guard primitive line range (#4123) --------- Co-authored-by: GPTQModel Bot <[email protected]>
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.
Fixes #4130
TL;DR
Two test regressions on
main.state_dict()raisedAttributeErroron every GPTQ kernel built through__new__without__init__(Machete was just the first test to reach it), and the kernel-contract audit had no category for platform-restricted kernels, so two newly registered MPS-only MLX kernels made it red. 3 files, +79/−4.1.
AttributeError: 'MacheteLinear' object has no attribute '_qzeros_format'Root cause
#4103 (0ff46b6) made
_save_to_state_dictemit the qzero layout for every GPTQ kernel. The emitted code comes fromGPTQQuantLinear._emitted_qzeros_format(gptqmodel/nn_modules/qlinear/__init__.py:1448), which ended in a bareself._qzeros_formatread (old line 1450).__init__assigns that attribute (__init__.py:1327), but modules built through__new__never run it — the packing tests construct exactly that (tests/test_packing_numeric_boundaries.py:84_bare). Nothing in the family defaulted, so serialization itself raised.The sibling reads in the same family were already defensive:
_checkpoint_qzeros_formatusesgetattr(self, "_checkpoint_format_on_disk", None)/getattr(self, "format", None), and_is_runtime_layoutusesgetattr(self, flag, False)for its three flags._qzeros_formatwas the only unguarded read reachable from_emitted_qzeros_formatand_write_state_dict_layout_metadata;checkpoint_layout_qzerosand the publicqzero_format()getter read the same attribute.The hole is family-wide, not Machete-specific. On parent
6f9ad69e6, a bareTorchLinearfails the same way:Fail-before (parent
6f9ad69e6)Fix
GPTQQuantLinear._runtime_qzeros_format()(gptqmodel/nn_modules/qlinear/__init__.py:1426) returnsgetattr(self, "_qzeros_format", 1)— the value__init__installs — and is now the single reader used by_emitted_qzeros_format,checkpoint_layout_qzeros, and theqzero_format()getter, so the whole family shares one default instead of only the attribute the failing test hit.Pass-after
The new
test_bare_gptq_module_state_dict_uses_the_v1_layout_defaultpins the contract for a portable GPTQ kernel and a CUDA-only one; both params raise the traceback above on parent and pass on the branch.2.
test_audit_covers_every_registered_kernel: two MLX kernels unaccounted forRoot cause
The audit compared the registry against three hand-written sets (
tests/test_rocm_kernel_contracts.py:92old). #4097 registeredMacaqMlxQuantLinear(gptqmodel/nn_modules/qlinear/mlx.py:1061) andNF12MlxQuantLinear(mlx.py:1122); both declareSUPPORTS_DEVICES = [DEVICE.MPS]andSUPPORTS_PLATFORM = [PLATFORM.DARWIN], and neither had an inventory entry.Fail-before (parent
6f9ad69e6)Fix
The audit now has a platform classification, not a looser allowlist:
PLATFORM_RESTRICTED_KERNELSrecords the two reviewed kernels (tests/test_rocm_kernel_contracts.py:60)._platform_restricted_kernels()(:69) derives the bucket from the shipped declaration: any registered kernel whoseSUPPORTS_PLATFORMomits bothLINUXandALL. A newly registered MPS-only kernel is classified automatically instead of re-breaking the test.test_audit_covers_every_registered_kernel(:121) still requires an exact match, now including the derived bucket, and asserts the explicit entries really are platform-restricted.test_platform_restricted_kernels_declare_reachable_families(:131) holds the new bucket to a contract: noLINUX, noDEVICE.ROCM, and noDEVICE.CUDAon a Darwin-only kernel. Without it the derived bucket would let an MPS kernel claim an unreachable family and still pass.A Linux-capable kernel with no inventory entry still fails the equality — the audit is not widened.
Guard probe (scratch, not committed) against the shipped test functions:
Pass-after
Validation
Both regressions are CPU-reproducible. Parent baselines were captured in a clean
git worktreeatorigin/main(6f9ad69e6).pytest -q tests/test_packing_numeric_boundaries.py tests/test_rocm_kernel_contracts.py tests/test_checkpoint_state_invariant.pypytest -q tests/test_checkpoint_compat.py tests/test_hf_packing_api.pypytest -q tests/kernels/test_qlinear_hierarchy.py tests/test_qzero_offsets.pyruff check gptqmodel docs/eora tests setup.pyAll checks passed!All checks passed!Hardware: RTX 4090
GPU-1892aea4-cc09-827c-b9a5-93d4eef7f5ae(CUDA_VISIBLE_DEVICESpinned) and R9700 gfx1201 (HIP_VISIBLE_DEVICES=0). The suites run on CPU; pinning only keepsdevice_map="auto"inside a single GPU family. The ROCm skips are the CUDA-only parametrizations (e.g.MacheteLinearoncuda).Pre-existing, not caused by this PR
tests/test_hf_packing_api.py::test_gpu_feasibility_and_best_formatfails on ROCm on parent6f9ad69e6as well: it expectshf_check_packing_feasibility(..., backend=BACKEND.MARLIN, device="cuda:0")to be true, and Marlin is CUDA-only. Reproduced in the clean parent worktree with the same command.tests/test_checkpoint_compat.py(noCUDA_VISIBLE_DEVICES) failstest_untied_lm_head_quantizes_and_reloadsbecausedevice_map="auto"spans the host's 4090s (SM 8.9) and RTX 5090 (SM 12.0) and the selector rejects mixed compute capabilities. Pinning to the 4090 makes it pass; unrelated to this change.state_dict():ExllamaV2Linear/AwqExllamaV2Linearread_native_shuffledandBitsAndBytesLinear/BitsAndBytesMlxQuantLinearread_cpu_packing_activedirectly in their own_save_to_state_dictoverrides. Those reads exist in0ff46b6~1(pre-fix(checkpoint): make state_dict() a real checkpoint for every kernel (#4091) #4103), no test exercises them, and they are outside the_emitted_qzeros_format/_write_state_dict_layout_metadatafamily this issue names, so they are left untouched.Scope
Per the issue, the #4121 TeleChat2 regression is another worker's fix;
gptqmodel/looper/awq_processor.pyandtests/test_telechat2_coverage.pyare untouched, as aregptqmodel/models/loader.py,gptqmodel/utils/hf.py,gptqmodel/quantization/, andgptqmodel/looper/*_processor.py.