Skip to content

perf(offload): skip the forced-offload size preflight - #5881

Merged
Qubitium merged 1 commit into
mainfrom
fix/5850-offload-force-size
Nov 20, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/5850-offload-force-size

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

Fixes #5850.

offload_to_disk(..., force=True) built a full exported state_dict() only to compute a byte count that the forced path never consults; _bundle_module_state_dict then built the state dict again to write the bundle. For a GPTQ v2 runtime kernel, each state dict runs the checkpoint-layout hook that converts live logical zero points to v1 with an allocating unpack/shift/repack. A forced offload therefore converted every zero-point payload twice and kept both converted copies live until the preflight list was released.

The size preflight now runs only when force=False, where it controls the 4 KiB small-module skip. The bundle writer remains the single state-dict producer for forced offloads. Checkpoint bytes, disk-offload forward, and restore semantics are unchanged.

What Changed

  • gptqmodel/utils/offload.py: guard the _SMALL_MODULE_OFFLOAD_BYTES preflight with if not force. The non-forced branch still builds the state dict, applies the same threshold, and returns for small modules.
  • tests/test_qzeros_disk_offload_4380.py: add a CPU regression that counts v2 -> v1 qzero conversions during a forced offload and asserts the bundle, restored state dict, and both forwards stay bitwise identical. Add a control that the non-forced path still skips a below-threshold module and writes an above-threshold module.

No API or behavior change beyond the removed redundant export. No follow-up work.

Tests

New regression:

  • Red on origin/main (c802251f9): python -m pytest -q tests/test_qzeros_disk_offload_4380.py -k forced_offload_converts_qzeros_once -> 1 failed at assert 2 == 1: "forced disk offload built a second state dict for the unused size preflight (2 v2 -> v1 conversions)".
  • Green on this branch: python -m pytest -q -ra tests/test_qzeros_disk_offload_4380.py -> 5 passed.

Neighboring CPU offload/serialization suite:

python -m pytest -q -ra -m "not cuda" \
  tests/test_qzeros_disk_offload_4380.py \
  tests/test_offload_quantized_modules_restored_4450.py \
  tests/test_offload_base_modules_restored.py \
  tests/test_offload_reference_4395.py \
  tests/test_offload_run_namespace.py \
  tests/test_offload_run_cleanup_4368.py \
  tests/test_offload_disk_container_5145.py \
  tests/test_cancelled_quantize_disk_offload_4807.py \
  tests/test_cancelled_quantize_default_offload_4860.py \
  tests/test_disk_backed_layer_outputs.py \
  tests/test_offload_autograd.py \
  tests/test_offload_files.py

Result: 153 passed, 1 failed, 2 deselected. The one failure is tests/test_offload_quantized_modules_restored_4450.py::test_resumed_packed_module_hook_is_materialized_at_loop_exit; it fails identically on origin/main with only gptqmodel/utils/offload.py reverted (pre-existing, unrelated). The 2 deselected nodes carry the cuda marker.

Lint:

ruff check gptqmodel/utils/offload.py tests/test_qzeros_disk_offload_4380.py   # All checks passed

ruff format --check reports pre-existing drift in both files (also present on origin/main); the added hunks are not among the reported changes. The repository gate (format/check.sh) runs ruff check only and passes.

Measured Impact

Conditions: CPU tensors only, torch.set_num_threads(1), seed 202, PyTorch 2.15.0. Baseline is origin/main at c802251f9; the same script was run with only gptqmodel/utils/offload.py reverted. Conversions were counted by wrapping gptqmodel.utils.model_dequant._revert_gptq_v1_qzeros_correction; live bytes were summed from weak references to each returned tensor's storage at conversion time.

  • Unit reproduction (the issue's snippet): one 4096 x 4096 INT4/G32 asymmetric TorchLinear, qzero_format(2), _checkpoint_format_on_disk = FORMAT.GPTQ, forced disk offload.
  • Public API: GPTQModel.load(...).quantize(..., backend=BACKEND.GPTQ_TORCH) on a 2-layer Llama (hidden 64, 14 projections), QuantizeConfig(bits=4, group_size=32, desc_act=False, sym=False, format=FORMAT.GPTQ, device="cpu", offload_to_disk=True, auto_dtype_cast=OFF), one 8-token calibration row, batch size 1.
Metric Units Before After Change
Forced offload v2 -> v1 qzero conversions, 4096 x 4096 INT4/G32 TorchLinear conversions 2 1 -1 (-50%)
Peak simultaneous live converted qzero bytes, same module bytes 524,288 262,144 -262,144 (-50%)
Forced offload v2 -> v1 qzero conversions, 2-layer Llama / 14 projections conversions 28 14 -14 (-50%)
Peak simultaneous live converted qzero bytes, same run bytes 320 192 -128 (-40%)
State-dict tensors bitwise identical to the origin/main run tensors reference 77/77 0 mismatches
Logits bitwise identical to the origin/main run (max abs diff) float reference 0.0 0.0

Unverified: CUDA/ROCm offload paths and accelerator-kernel quantization. The change is device-independent (it only removes a state-dict build before the existing bundle write), and CPU validation covers the affected control flow and serialization.

Model Support / Module Plan

Not applicable: no model type, alias, definition, module-plan, or fusion changes.

AWQ onboarding safety

Not applicable: no new model/alias and no AWQ grouping, search, replay, or folding changes.

Logic Flow Documentation

Not applicable: this is a local guard on an existing size preflight. No stage, dispatch, resolution/selection, persistence format, or restore decision changes; the durable bundle path is the same code and produces the same tensors.

Review Requirements

  • Reviewed this PR.
  • Checked that the code matches existing project structure, APIs, and conventions.
  • Avoided unnecessary monkeypatching and used the project's normal extension points where possible.
  • Minimized and compacted the impacted code surface.
  • Considered and eliminated potential regressions.

Kernel Accuracy Requirements

Not applicable: no kernel, dispatch, pack, or fusion change. The regression asserts the forced-offload bundle, restored state dict, and forwards remain bitwise identical.

Notes

The regression is appended to the existing disk-offload qzero conversion suite rather than adding a new issue-number-only file. The forced test also covers a below-threshold module, so force=True still writes a bundle where the non-forced path would skip it.

@Qubitium
Qubitium marked this pull request as ready for review November 20, 2026 11:15
@Qubitium
Qubitium force-pushed the fix/5850-offload-force-size branch from 32dd5fb to 8dd691f Compare November 20, 2026 11:21
@Qubitium
Qubitium merged commit a6cfbd6 into main Nov 20, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/5850-offload-force-size branch November 20, 2026 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Audit][offload] Forced disk offload converts GPTQ zero points twice to build an unused size estimate

1 participant