Repository navigation
fix(offload): reselect resident CPU Marlin with deferred qzeros (#6152 follow-up) - #6391
Merged
Merged
Conversation
added 3 commits
November 29, 2026 13:16
…follow-up) `_marlin_needs_offload_kernel` used `checkpoint_payload_is_meta()` as the offload test. `_HF_DEFER_SYM_QZEROS` hides a legacy symmetric checkpoint's `qzeros`, so an all-CPU Marlin layer has a meta `qzeros` while its packed weight is resident. The bridge then kept Marlin and `post_init` raised `ValueError: GPTQ Marlin requires CUDA tensors, got cpu` instead of reselected the all-CPU load. Use the primary packed weight (`runtime_device`) for the resident-CPU decision, and rebuild the deferred `qzeros` on the replacement kernel when a class swap left it as a meta parameter. The offloaded-layer refusal is unchanged: a meta `qweight` still raises the documented RuntimeError. Regression tests cover the synthetic bridge path, the all-CPU `device_map="auto"` + `max_memory` load of a legacy checkpoint, and the unchanged CPU-offload refusal.
This was referenced Nov 29, 2026
Qubitium
pushed a commit
that referenced
this pull request
Nov 29, 2026
Conflicts in gptqmodel/utils/model.py::_materialize_hf_sym_qzeros: take main's #6391 rebuild, but size the rebuilt buffer with qzeros_standard_shape() and drop the inherited Parameter first. _reselect_offloaded_marlin_kernels swaps __class__ in place, so the replacement still owns Marlin's tile-layout qzeros Parameter; copying that shape into the portable kernel is what produced the forward-time IndexError in #6383.
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
device_map="auto"+max_memorythat resolves the whole model to CPU still crashes for a checkpoint marked pre-7.3.4, even after #6253. It raises the originalValueError: GPTQ Marlin requires CUDA tensors, got cpuinstead of reselecting the layer:This is the all-CPU half of #6152. The disk/CPU-offload half is intentionally unchanged (see below).
Root cause
Two merged changes interact:
_HF_DEFER_SYM_QZEROS(fix(hf): packable selection, per-layer shape dispatch and legacy qzeros in the HF bridge (#6191, #6178, #6336) #6274) hides a legacy symmetric checkpoint'sqzerosfrom the core loader, so the parameter stays a meta placeholder on an otherwise CPU-resident layer._marlin_needs_offload_kernel(fix(hf): reselect offload-safe kernels for Marlin at post-init (#6152) #6253) usedcheckpoint_payload_is_meta()as the "offloaded" test. That is true here, so it entered the offload branch, found no layer-level Accelerate hook, returnedFalse, and keptMarlinLinear.post_initthen reached Marlin's CUDA check on CPU.Even with the reselect decision fixed,
_materialize_hf_sym_qzeros()would still take the "this kernel owns its zero point" branch, because a class swap leaves Marlin'sqzerosas a parameter rather than a buffer. It would replace the placeholder with an empty parameter, and the portable Torch decode would fail.Fix
_marlin_needs_offload_kernel: after the real offload check, decide resident-CPU from the primary packed weight (runtime_device()), which is meta only for a layer whose payload actually lives in an offload map. A metaqzerosplaceholder no longer hides the all-CPU reselect._materialize_hf_sym_qzeros: when a class swap leftqzerosas a parameter on a non-Marlin kernel, rebuild it with the symmetric constant instead of discarding it.qweighton a replacement kernel still raises the documentedRuntimeErrortelling the user to load withoffload_state_dict=Falseand a resident device map.Evidence
Real
Qwen2.5-0.5B-Instruct-gptq-4bit(gptqmodel 1.9.0 sidecar,checkpoint_format: gptq, current-width qzeros), all-CPUdevice_map="auto"+max_memory={0: "100MiB", "cpu": "20GiB"}:3082b02d0ValueError: GPTQ Marlin requires CUDA tensors, got cpuTorchLinearmax|dlogit|=0.0586, argmax agree 100% vs the all-GPU Marlin referenceqzerosafter load is the rebuilt constant0x88888888with the constructor's current width,_HF_DEFER_SYM_QZEROS=False.The documented offload refusal still fires for the same checkpoint with CPU offload (
max_memory={0: "32KiB", "cpu": "4GiB"}):(Note for reviewers:
offload_state_dictis popped and ignored by Transformers 5.23'sfrom_pretrained; only the "resident device map" part of that message is actionable there. Not changed here.)Tests
New nodes:
test_hf_post_init_all_cpu_materializes_deferred_qzeros(CPU-only, synthetic): meta deferredqzeros+ resident CPU weight -> reselect, rebuild, finite forward.test_legacy_symmetric_checkpoint_loads_when_auto_resolves_to_cpu(CUDA): the realdevice_map="auto"+max_memoryall-CPU load of the legacy fixture.test_legacy_deferred_qzeros_on_cpu_offload_still_raises(CUDA): the offload refusal is preserved.Suites (same set as #6253, plus
test_hf_bridge_legacy_qzeros_marlin_6274.py):320 passed, 125 skipped402 passed, 43 skippedruff checkon all changed files: cleanNo merge; this is a follow-up against
3082b02d0.Update: current main and the #6386 fixture fallout
Main advanced to
1615accf9while this PR was open. A cherry-pick onto that head applies cleanly, and the focused suites pass there (CPU:320 passed, 125 skipped; the three new nodes pass on cuda:4).One test-only follow-up was needed: #6386 now rejects a checkpoint whose tokenizer cannot encode ordinary text, and the pre-existing
test_hf_bridge_legacy_qzeros_marlin_6274.pyfixture saved a 3-tokenWordLevelvocabulary. Every test in that file (including the two new nodes) failed atGPTQModel.loadon current main. The fixture now uses the sharedbuild_wordlevel_tokenizer, and the file passes on1615accf9(CPU3 passed, 3 skipped; cuda:46 passed).Note: current main also has 16 pre-existing GPU fixture errors from the same #6386 validation in
test_hf_bridge_cpu_offload_5022.pyandtest_cpu_offload_tied_both_copies_4943.py(reproduced on clean1615accf9without this PR). They are unrelated to this change and are not addressed here.