Skip to content

fix(looper): materialize non-persistent buffers before the resume hook (#4777) - #4781

Merged
Qubitium merged 1 commit into
mainfrom
fix/issue-4777-qqq-resume-nonpersistent
Nov 17, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/issue-4777-qqq-resume-nonpersistent

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4777. Regression from #4611 (2f1682053).

Problem

Resuming any QQQ quantization crashed at restore, before any work was done:

ValueError: workspace is on the meta device, we need a `value` to put in on cpu.

GPTQCheckpoint.restore() rebuilds each finished module on meta, writes an accelerate offload index.json from
module.state_dict(), and calls attach_disk_offload_hook(module, directory). state_dict() excludes
non-persistent buffers by definition, so QQQLinear.workspace - the split-K lock array, registered with
persistent=False - had no stored value. Accelerate's init_hook then tried to move every buffer, found workspace
still on meta, and raised.

All 10 checkpoint-recovery cases for QQQ (term, kill-before, kill-after, error; dense, EoRA and MoE) died
here, so a resumed QQQ run could never complete.

Fix

gptqmodel/utils/offload.py - attach_disk_offload_hook materializes non-persistent meta buffers on CPU before
disk_offload:

  • they are runtime scratch and never checkpoint state, so allocating them is the correct treatment (adding them to
    the index would also mean writing workspace into a checkpoint that has no meaning for it);
  • persistent buffers are untouched - the index still carries them and the hook still loads them;
  • the helper is generic, not QQQ-specific: the issue notes any kernel with a non-persistent buffer would hit the same
    accelerate path.

It runs after the "index must exist" check and before disk_offload, so the failure mode for a missing bundle is
unchanged.

Tests

New tests/test_checkpoint_resume_nonpersistent_4777.py (3 cases, CPU-only, no QQQ native extension needed) builds
the safetensors bundle + index.json exactly as restore() does, then:

  1. restores a QQQTorchLinear built under torch.device("meta") and asserts workspace is no longer meta, keeps
    its shape/dtype, and is zeroed;
  2. runs the loop-exit restore_disk_offloaded_modules() and asserts no meta tensor remains and the resumed module's
    forward is bit-identical to the source module;
  3. asserts persistent state (B, s_channel, s_group) still comes from the bundle, not from a zero fill.

Red on unmodified main (dba142d2f): 3/3 fail with the issue's ValueError.

Green on this branch: 3/3 new, plus tests/test_offload_files.py, tests/test_offload_reference_4395.py,
tests/test_offload_quantized_modules_restored_4450.py and tests/test_checkpoint_modules.py -> 161 passed / 9
skipped, with only the pre-existing test_qqq_optional_group_scales_schema failure (needs a buildable QQQ CUDA
extension; fails identically on main here). ruff check clean.

The 10 tests/test_checkpoint_method_compatibility.py recovery cases need CUDA plus the native QQQ extension, which
cannot build on this host (no CUDA_HOME/nvcc); the unit-level test above covers the exact restore step they die
in.

#4777)

Resuming any QQQ quantization crashed at restore, before doing any work:

    ValueError: workspace is on the meta device, we need a `value` to put in on cpu.

`GPTQCheckpoint.restore` rebuilds each finished module on `meta`, writes the
offload index from `module.state_dict()`, then calls
`attach_disk_offload_hook`. `state_dict()` excludes non-persistent buffers by
definition, so `QQQLinear.workspace` - the split-K lock array, registered with
`persistent=False` - had no stored value. Accelerate's hook init then tried to
move every buffer, found `workspace` on meta, and raised. Every resume path for
QQQ was affected, so a resumed run could never finish.

`attach_disk_offload_hook` now materializes non-persistent meta buffers on CPU
before `disk_offload`. They are runtime scratch and never checkpoint state, so
allocating them is the correct treatment rather than adding them to the index.
Persistent buffers are untouched: the index still carries them.

The fix is generic, not QQQ-specific: any kernel with a non-persistent buffer
would have hit the same accelerate path.

Tests: new `tests/test_checkpoint_resume_nonpersistent_4777.py` builds the
bundle + index exactly as `restore` does, restores a `QQQTorchLinear` on meta,
and asserts (a) the workspace is materialized with the right shape/dtype and
zeroed, (b) the loop-exit restore leaves no meta tensor and the resumed module's
forward is bit-identical to the source module, (c) persistent state still comes
from the bundle, not from a zero fill. Runs on CPU; no ggml/QQQ extension
needed.

Red on unmodified main (dba142d): 3/3 fail with the issue's ValueError.
@Qubitium
Qubitium merged commit 92ed8a6 into main Nov 17, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/issue-4777-qqq-resume-nonpersistent branch November 17, 2026 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant