Skip to content

fix(offload): keep per-run bundles after save so in-session forward works - #4416

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

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

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

#4409 fixed the unbounded growth of offload_to_disk_path by deleting the per-run run-<uuid> directory at the end of save(). That is too early: save_quantized() streams the bundles but leaves the quantized modules on meta with an accelerate offload hook pointing into that directory, so any in-session use after save() now fails.

tests/test_planar_model_e2e.py::test_planar_model_quantize_save_reload_inference[4] fails on current main (0b78e472d):

E  FileNotFoundError: No such file or directory:
   /tmp/gptqmodel_3ftme_oi/run-f2577e83d1b542c4/model.layers.0.self_attn.q_proj/module.safetensors
   (accelerate/utils/offload.py:179, reading `qzeros_format` during the post-save forward)

This PR keeps #4368's goal (an explicit offload root no longer grows by one full model per run) while releasing the directory only when the model can no longer read it.

What Changed

  • gptqmodel/models/base.py: save() no longer calls release_private_offload_root(). The timer bookkeeping in the finally block is unchanged.
  • Cleanup remains in place where it is safe: weakref.finalize on model teardown, release_private_offload_root() in the ModuleLooper/WeightOnlyLooper failure branch, and before the same model binds a new run.
  • tests/test_offload_run_namespace.py: test_base_model_save_releases_private_run_dir becomes test_base_model_save_keeps_private_run_dir_for_in_session_use (save keeps the bundles, a second save works, teardown removes them).
  • tests/test_offload_run_cleanup_4368.py (new): save-then-teardown, failed-save-then-retry, and two sequential runs on a shared explicit root with no accumulation.
  • docs/offload-run-directories.md (new) plus links from README.md and docs/README.md: the ownership/lifecycle contract with Mermaid state and flow diagrams.

No API change: release_private_offload_root() and the _private_offload_* attributes are unchanged.

Tests

CPU-only (GPTQ_BYPASS_SAFETY_CHECKS=1, CUDA_VISIBLE_DEVICES="", PYTHONPATH = worktree):

pytest tests/test_offload_run_cleanup_4368.py tests/test_offload_run_namespace.py -q
# 12 passed

pytest "tests/test_planar_model_e2e.py::test_planar_model_quantize_save_reload_inference[4]" -q
# 1 passed  (fails on main 0b78e472d with FileNotFoundError)

pytest tests/test_offload_autograd.py tests/test_offload_base_modules_restored.py \
       tests/test_offload_files.py tests/test_offload_run_namespace.py \
       tests/test_offload_run_cleanup_4368.py tests/test_quantize_config_offload_tempdir.py \
       tests/test_loader_offload_staging_4385.py -q
# 112 passed, 6 skipped

ruff check gptqmodel/models/base.py tests/test_offload_run_namespace.py \
           tests/test_offload_run_cleanup_4368.py
# All checks passed!

Notes

#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
Qubitium merged commit 03f778e into main Nov 16, 2026
8 of 9 checks passed
@Qubitium
Qubitium deleted the fix/issue-4368-offload-run-cleanup branch November 16, 2026 13:14
@Qubitium

Copy link
Copy Markdown
Collaborator Author

CI note: the only failing check is AWQ CPU (dense) → tests/test_awq_hf_cpu.py::test_real_checkpoint_awq_cpu_roundtrip[dense] (relative_rmse 0.2344 vs the 0.20 threshold). That test uses offload_to_disk=False, so this diff cannot affect it, and it also fails on unmodified main (0b78e472d) in a clean worktree on CPU (assert 0.20010976493358612 < 0.2). It is a pre-existing AWQ quality-threshold flake, not a regression from this PR. ruff-check and the offload/planar suites pass.

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.

1 participant