-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Prevent recursive symlink creation iwhen save_last='link'
and save_top_k=-1
#21186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent recursive symlink creation iwhen save_last='link'
and save_top_k=-1
#21186
Conversation
…in ModelCheckpoint - Added a check in _link_checkpoint to compare absolute paths of filepath and linkpath - Only create symlink if paths differ, avoiding self-linking when save_last='link' and save_top_k=-1 - Updated test to assert the fix prevents the recursive symlink bug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a bug in PyTorch Lightning's ModelCheckpoint callback where using save_last='link'
with save_top_k=-1
creates a recursive symlink that points to itself.
- Adds path comparison logic to prevent self-referencing symlinks in
_link_checkpoint
method - Updates test coverage to verify the fix works correctly
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
File | Description |
---|---|
src/lightning/pytorch/callbacks/model_checkpoint.py | Adds absolute path comparison to prevent recursive symlink creation |
tests/tests_pytorch/callbacks/test_model_checkpoint_additional_cases.py | Adds comprehensive regression test for the symlink bug scenario |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
tests/tests_pytorch/callbacks/test_model_checkpoint_additional_cases.py
Outdated
Show resolved
Hide resolved
save_last='link'
and save_top_k=-1
Fix ModelCheckpoint recursive symlink creation when save_last='link' and save_top_k=-1
What does this PR do?
This PR fixes a bug in PyTorch Lightning's ModelCheckpoint callback where using
save_last='link'
withsave_top_k=-1
creates a recursive symlink (last.ckpt -> last.ckpt
). This occurs when the last checkpoint saved is thelast.ckpt
file itself, leading to a self-referencing symlink.Changes Made:
filepath
andlinkpath
save_last='link'
andsave_top_k=-1
This ensures the checkpoint functionality works correctly without creating invalid symlinks, maintaining backward compatibility.
Fixes #21110
No breaking changes introduced.
📚 Documentation preview 📚: https://pytorch-lightning--21186.org.readthedocs.build/en/21186/