Skip to content

Fix delete_original crash for regular checkpoint files - #362

Open
Nikhi00718 wants to merge 1 commit into
lyogavin:mainfrom
Nikhi00718:Nikhi00718/fix-delete-original-double-delete
Open

Nikhi00718 wants to merge 1 commit into
lyogavin:mainfrom
Nikhi00718:Nikhi00718/fix-delete-original-double-delete

Conversation

@Nikhi00718

Copy link
Copy Markdown

Summary

delete_original=True currently crashes while deleting a regular checkpoint file. split_and_save_layers() passes a Path, but remove_real_and_linked_file() compares os.path.realpath()'s string result with that Path, assumes the file is linked, and removes the same file twice.

This patch checks os.path.islink() directly, so regular files are removed once and symlink targets are removed only for actual symlinks.

Fixes #297.

Verification

  • Added regression coverage for absolute Path, relative Path, absolute string, and symlink inputs.
  • 47 passed, 1 skipped in the focused splitter/LoRA/test suite; the skipped test requires Windows symlink permission.
  • python -m compileall -q air_llm eval examples rlhf scripts training anima_100k
  • Verified a tiny end-to-end split_and_save_layers(..., delete_original=True) run.

Please review when you have a chance, @lyogavin.

@Hotragn

Hotragn commented Sep 16, 2026

Copy link
Copy Markdown

Verified this one works — I ran it against the real call shape (split_and_save_layers passes a Path) and a relative-string call, and both delete exactly once with no crash. os.path.islink() is the right question to ask; the old realpath(to_delete) != to_delete comparison was always true for a Path because realpath() returns a str.

Just so it's visible to whoever triages: there are four open PRs on this same helper.

PR opened approach result on my test
#303 2026-07-19 os.path.islink() PASS
#337 2026-08-07 islink + os.fspath + swallows FileNotFoundError PASS
#362 (this) 2026-09-09 os.path.islink() PASS
#333 2026-08-05 only initialises targetpath = None still FileNotFoundError

Your diff is logically identical to #303, which landed first and also ships a test. Nothing wrong with your version — just flagging the overlap so the maintainer doesn't review the same change three times, and so you don't spend more effort on something already covered. #337 is the only one that differs meaningfully: it normalises with os.fspath and tolerates an already-missing file, which matters if the HF cache blob is shared between snapshots.

(I couldn't exercise the symlink path — no symlink permission on this box without elevation — so that part is unverified by me.)

This branch has not been deployed

No deployments
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.

delete_original can delete a shard and then crash

2 participants