Repository navigation
fix(offload): remove per-run offload directory after save, teardown, or failure (#4368) - #4409
Merged
Merged
Conversation
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.
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.
Fixes #4368.
Problem
Every
quantize()created<offload_to_disk_path>/run-<uuid16>(one full model) viabind_private_offload_root()and nothing ever removed it — not aftersave(), not on exception, not on a later run. An explicitoffload_to_disk_paththerefore grew by one full model per run, across processes too.Fix
gptqmodel/utils/offload.pynow tracks the run directory on the model and addsrelease_private_offload_root():BaseQModel.save()'sfinally(after the save-time reader is done with the bundles);ModuleLooper._loopandWeightOnlyLooper._loopwhen the run raises, so a failed run cannot leak;weakref.finalizeon 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.pyextended (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 intest_save_loaded_quantized_model.pyreproduce identically on a cleanorigin/mainworktree (pre-existing, missing local checkpoint).ruff checkon all changed files → clean.Residual risk
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.shutilstill being importable at interpreter shutdown; explicit release covers the normal save/failure paths.