Repository navigation
Conversation
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
.bin/.ptcheckpoints are converted to safetensors with a full model-sized copy. Before this change everyLazyTurtlemade a new copy in the systemTMPDIRand only removed it at interpreter exit, so repeatedload()calls leaked one model copy each.This change makes the conversion a refcounted, per-source cache:
LazyTurtles for the same source + conversion-relevant config share one converted directory; only one conversion runs.weakref.finalize), or explicitly through the newLazyTurtle.close()/ context-manager API.os.replace), so a partial/crashed conversion is never reused.offload_path=argument,offload_to_disk_path/offload_folderin model-init kwargs, ortarget_model.quantize_config.offload_to_disk_path); otherwise it falls back to the system temp dir.atexitcleanup remains as a last-resort safety net.What Changed
gptqmodel/utils/structure.py_CONVERSION_CACHE, per-pathRLocks, refcounts), atomic staging/publish, andweakref.finalizelease release.LazyTurtle.__init__/maybe_createacceptoffload_path;_resolve_checkpoint_sourcereuses cached conversions.LazyTurtle.close(),__enter__/__exit__, and lease registration._export_checkpoint_to_safetensors()so it writes into the staging dir.tests/test_lazy_turtle_conversion_cache.py(new)close()releases it while the turtle is alive (and is idempotent).Tests
CPU-only (no GPU); the CUDA extensions are not required for these tests.
Model Support / Module Plan
N/A — no new model types or registry entries.
Notes
LazyTurtle.maybe_create(..., offload_path=...)is the wiring point forquantize_config.offload_to_disk_path. Themodels/loader.pycall site is owned by #4204, so it is not touched in this PR; forwardingquantize_config.offload_to_disk_paththere (one kwarg) makes the default quantization path place the conversion on the configured offload volume as well. The leak/reuse fixes and the explicit offload-path support are already active without that forwarding.Fixes #4205