Skip to content

fix(loader): put LazyTurtle pickle conversion under offload_to_disk_path - #4340

Merged
Qubitium merged 1 commit into
mainfrom
fix/issue-4319-lazyturtle-offload-path
Nov 16, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/issue-4319-lazyturtle-offload-path

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4319

Root cause

LazyTurtle.maybe_create() already accepted offload_path, and
LazyTurtle._conversion_root_for() uses it, but
ModelLoader.from_pretrained() never passed it
(gptqmodel/models/loader.py:2015). _infer_conversion_root() could not
recover it either: the HF shell model has no quantize_config, and
offload_to_disk_path is not in the HF model_init_kwargs. So a .bin/.pt
source was always converted under tempfile.gettempdir() (the incomplete
#4205 fix).

Fix

Pass quantize_config.offload_to_disk_path as offload_path= when the loader
constructs the turtle. _normalize_conversion_root() makes it absolute;
_conversion_root_for() keeps the existing tempfile.gettempdir() fallback
for the unset case only. No new config field and no environment switch.

Test

tests/test_lazy_turtle_conversion_cache.py::test_loader_converts_bin_under_configured_offload_path_not_tmpdir

  • Drives the real ModelLoader.from_pretrained() path with a .bin-only local
    source (fake checkpoint class, no network).
  • Sets offload_to_disk_path to tmp_path/configured-offload.
  • Pins tempfile.gettempdir() to an empty tmp_path/system-tmp.
  • Asserts the converted directory is a direct child of the configured offload
    path and that no lazyturtle-* directory appears under the pinned TMPDIR.
  • Asserts the conversion is leased to the turtle and removed after the turtle
    and loader instance are released (cleanup/retention).

Verified the test fails on the pre-fix code: assert converted.parent == offload reported the pinned TMPDIR as the parent. It passes with the fix.

Verification

  • ruff check gptqmodel docs/eora tests setup.py -> All checks passed!
  • pytest tests/test_lazy_turtle_conversion_cache.py -q -> 6 passed
  • pytest tests/test_local_model_paths.py tests/test_quantize_config_offload_tempdir.py -q -> 31 passed, 2 skipped
  • CPU-only; no GPU used.

Residual risk

  • The conversion root is chosen once at turtle construction. Mutating
    quantize_config.offload_to_disk_path after from_pretrained() returns does
    not move an existing conversion. That matches the rest of the offload path,
    which also snapshots the path at load time.
  • The existing staging-plus-rename publication in _perform_conversion() is
    unchanged, so this does not add cross-filesystem atomicity guarantees. A
    configured path on a filesystem without atomic directory rename keeps the
    previous behavior.
  • The regression test uses the loader's fake-model harness rather than a real
    HF checkpoint, so it pins the wiring (the actual bug) and the
    conversion-root semantics; the transformer-specific export path remains
    covered by the existing conversion tests.

…ath (#4319)

LazyTurtle converts a .bin/.pt checkpoint into a full safetensors copy, but the loader never passed the configured offload root to maybe_create, so the copy always landed in the system TMPDIR. Pass quantize_config.offload_to_disk_path through; LazyTurtle still falls back to tempfile.gettempdir() only when no path is configured.

Regression test builds a .bin-only local source, pins TMPDIR to an empty directory, and asserts the converted directory is a child of the configured offload path and absent from TMPDIR. It also asserts the conversion is removed when the turtle is released.
@Qubitium
Qubitium merged commit 688208d into main Nov 16, 2026
8 of 9 checks passed
@Qubitium
Qubitium deleted the fix/issue-4319-lazyturtle-offload-path branch November 16, 2026 09:09
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] LazyTurtle .bin → safetensors conversion still goes to the system TMPDIR and ignores offload_to_disk_path (incomplete fix of #4205)

1 participant