Repository navigation
perf(offload): skip the forced-offload size preflight - #5881
Merged
Merged
Conversation
Qubitium
marked this pull request as ready for review
November 20, 2026 11:15
Qubitium
force-pushed
the
fix/5850-offload-force-size
branch
from
November 20, 2026 11:21
32dd5fb to
8dd691f
Compare
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 #5850.
offload_to_disk(..., force=True)built a full exportedstate_dict()only to compute a byte count that the forced path never consults;_bundle_module_state_dictthen 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_BYTESpreflight withif 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:
origin/main(c802251f9):python -m pytest -q tests/test_qzeros_disk_offload_4380.py -k forced_offload_converts_qzeros_once->1 failedatassert 2 == 1: "forced disk offload built a second state dict for the unused size preflight (2 v2 -> v1 conversions)".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.pyResult:
153 passed, 1 failed, 2 deselected. The one failure istests/test_offload_quantized_modules_restored_4450.py::test_resumed_packed_module_hook_is_materialized_at_loop_exit; it fails identically onorigin/mainwith onlygptqmodel/utils/offload.pyreverted (pre-existing, unrelated). The 2 deselected nodes carry thecudamarker.Lint:
ruff check gptqmodel/utils/offload.py tests/test_qzeros_disk_offload_4380.py # All checks passedruff format --checkreports pre-existing drift in both files (also present onorigin/main); the added hunks are not among the reported changes. The repository gate (format/check.sh) runsruff checkonly and passes.Measured Impact
Conditions: CPU tensors only,
torch.set_num_threads(1), seed 202, PyTorch 2.15.0. Baseline isorigin/mainatc802251f9; the same script was run with onlygptqmodel/utils/offload.pyreverted. Conversions were counted by wrappinggptqmodel.utils.model_dequant._revert_gptq_v1_qzeros_correction; live bytes were summed from weak references to each returned tensor's storage at conversion time.TorchLinear,qzero_format(2),_checkpoint_format_on_disk = FORMAT.GPTQ, forced disk offload.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.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
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=Truestill writes a bundle where the non-forced path would skip it.