Skip to content

fix: isolate offload bundles per quantize run (#4202) - #4297

Merged
Qubitium merged 1 commit into
mainfrom
pr/4202
Nov 16, 2026
Merged

Qubitium merged 1 commit into
mainfrom
pr/4202

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Disk-offload bundles were keyed by module name only (<root>/<module path>),
and the root comes from a QuantizeConfig that is routinely shared by several
models: the automatic temporary directory, copy.copy, and copy.deepcopy all
hand out the same directory. A second quantize() therefore replaced the first
model's finalized bundles in place, and save() later read whatever bundle was
on disk -- silently writing the other model's qweight/scales.

Each quantization run now binds a private run-<id> subdirectory under the
configured offload root and keeps a private config copy on the model. Writes and
the save-time bundle lookup use the same namespace, and a later run on another
model cannot move this model's lookup. An explicit offload_to_disk_path is
still the root the user asked for; only the per-run subdirectory is added.

What Changed

  • gptqmodel/utils/offload.py: add bind_private_offload_root(), which creates
    a unique per-run directory under the configured root and installs a shallow
    config copy on the model.
  • gptqmodel/looper/module_looper.py: bind the private namespace at looper
    construction and point processors that still hold the shared config object at
    the private copy.
  • gptqmodel/looper/weight_only_looper.py: same for the weight-only lifecycle.

Tests

$ python3 -m pytest tests/test_offload_run_namespace.py -q
3 passed

$ python3 -m pytest tests/test_offload_run_namespace.py \
    tests/test_offload_base_modules_restored.py \
    tests/test_module_looper_disk_probe.py \
    tests/test_quantize_config_offload_tempdir.py \
    tests/test_checkpoint_processor_adapter.py -q
22 passed, 4 skipped

$ ruff check gptqmodel/utils/offload.py gptqmodel/looper/module_looper.py \
    gptqmodel/looper/weight_only_looper.py tests/test_offload_run_namespace.py
All checks passed!

End-to-end repro (two same-architecture tiny Llama models, one shared
QuantizeConfig, default offload_to_disk=True): the two models report distinct
run-* roots after quantization, and the first model's saved
model.layers.0.self_attn.q_proj.qweight is bit-equal to a fresh first-model-only
reference (A == ref: True) while differing from the second model
(A == B: False).

Fixes #4202

Rebased onto main after #4295 merged; this PR now contains only the #4202 changes.

Base automatically changed from pr/4203 to main November 16, 2026 08:22
@Qubitium
Qubitium merged commit 2bc2f63 into main Nov 16, 2026
8 of 9 checks passed
@Qubitium
Qubitium deleted the pr/4202 branch November 16, 2026 08:28
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