Skip to content

fix(offload): remove per-run offload directory after save, teardown, or failure (#4368) - #4409

Merged
Qubitium merged 1 commit into
mainfrom
fix/offload-run-dir-4368
Nov 16, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/offload-run-dir-4368

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4368.

Problem

Every quantize() created <offload_to_disk_path>/run-<uuid16> (one full model) via bind_private_offload_root() and nothing ever removed it — not after save(), not on exception, not on a later run. An explicit offload_to_disk_path therefore grew by one full model per run, across processes too.

Fix

gptqmodel/utils/offload.py now tracks the run directory on the model and adds release_private_offload_root():

  • removes only that run directory; the configured parent and sibling runs are untouched;
  • called from BaseQModel.save()'s finally (after the save-time reader is done with the bundles);
  • called from ModuleLooper._loop and WeightOnlyLooper._loop when the run raises, so a failed run cannot leak;
  • called when a model is re-bound (re-quantized), instead of overwriting the only handle to the old directory;
  • registered as a weakref.finalize on the model, so a collected model releases its directory too. Non-weak-referenceable test doubles still get the explicit path.

Tests

tests/test_offload_run_namespace.py extended (113 lines): one run dir before save and none after, for both the explicit and auto temp path; parent directory preserved; sibling run untouched; release on failure; re-bind releases the previous run; finalizer path.

  • tests/test_offload_run_namespace.py tests/test_offload_files.py tests/test_offload_base_modules_restored.py tests/test_quantize_config_offload_tempdir.py → 101 passed, 2 skipped.
  • tests/test_checkpoint_interop_4053.py tests/test_save_loaded_quantized_model.py → 26 passed; 3 failures in test_save_loaded_quantized_model.py reproduce identically on a clean origin/main worktree (pre-existing, missing local checkpoint).
  • ruff check on all changed files → clean.

Residual risk

  • After save() the run directory is gone, so saving the same already-quantized model a second time without re-quantizing fails. That is the intended trade-off for bounding disk use; re-quantize to save again.
  • The finalizer relies on shutil still being importable at interpreter shutdown; explicit release covers the normal save/failure paths.

@Qubitium
Qubitium merged commit a427804 into main Nov 16, 2026
7 of 9 checks passed
@Qubitium
Qubitium deleted the fix/offload-run-dir-4368 branch November 16, 2026 13:06
Qubitium added a commit that referenced this pull request Nov 16, 2026
#4368 asked for the per-run offload directory to stop accumulating, and
#4409 removed it at the end of save(). That breaks a supported workflow:
save_quantized() streams the bundles but leaves the quantized modules on
meta with an accelerate hook pointing into the run directory, so an
in-session forward or a second save() after save() now raises
FileNotFoundError (tests/test_planar_model_e2e.py fails on main).

Release the directory only when the model can no longer read it: on
teardown (weakref finalizer), on a failed quantization run, and when the
same model binds another run. Document the ownership contract and the
lifecycle, and pin save-then-forward, save-retry, and sequential-run
behavior with CPU regression tests.
Qubitium added a commit that referenced this pull request Nov 16, 2026
#4368 asked for the per-run offload directory to stop accumulating, and
#4409 removed it at the end of save(). That breaks a supported workflow:
save_quantized() streams the bundles but leaves the quantized modules on
meta with an accelerate hook pointing into the run directory, so an
in-session forward or a second save() after save() now raises
FileNotFoundError (tests/test_planar_model_e2e.py fails on main).

Release the directory only when the model can no longer read it: on
teardown (weakref finalizer), on a failed quantization run, and when the
same model binds another run. Document the ownership contract and the
lifecycle, and pin save-then-forward, save-retry, and sequential-run
behavior with CPU regression tests.
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.

[BUG] Every quantize() creates a new full-size run-<uuid> directory under offload_to_disk_path, and it is never deleted (regression from 2bc2f63, #4202)

1 participant