Skip to content
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

Fix torch.load() frequently warning in PersistentDataset and GDSDataset #8177

Merged
merged 9 commits into from
Oct 25, 2024

Conversation

bnbqq8
Copy link
Contributor

@bnbqq8 bnbqq8 commented Oct 24, 2024

Description

Frequently getting warning massage in a newer Pytorch version (2.4.1 in my case):
"You are using torch.load with weights_only=False (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for weights_only will be flipped to True. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via torch.serialization.add_safe_globals. We recommend you start setting weights_only=True for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature."

This pull request fixes an issue with the torch.load() function in the PersistentDataset and GDSDataset classes by adding weights_only=False. The fix ensures that the torch.load() function maintains load consistency in future versions of PyTorch.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests --disttests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

@bnbqq8 bnbqq8 changed the title Fix torch.load() inconsistency in PersistentDataset and GDSDataset Fix torch.load() in PersistentDataset and GDSDataset Oct 24, 2024
@ericspod
Copy link
Member

Thanks for the contribution, this is a fix that we do need to remove that warning. I'm not sure if the fails recorded here are related to this PR rather than something else wrong with our CICD system but please run them locally to see if you have the same result.

Could you also try with weights_only=True instead? We should be only loading tensors and not code with the datasets so this should work and be more secure. Thanks!

@bnbqq8
Copy link
Contributor Author

bnbqq8 commented Oct 25, 2024

Thanks for the contribution, this is a fix that we do need to remove that warning. I'm not sure if the fails recorded here are related to this PR rather than something else wrong with our CICD system but please run them locally to see if you have the same result.

Could you also try with weights_only=True instead? We should be only loading tensors and not code with the datasets so this should work and be more secure. Thanks!

Thanks for the comment! I believe the failed checks occurred because the weights_only parameter was not introduced in torch.load() until v1.13.0. This is why the checks for vresion bellow v1.13.0 failed.

So, some compatibility work still needs to be done, and I’m working on it. :)

As for setting weights_only=True, I don’t think it's strictly necessary at this point, since the default setting is weights_only=False. We should maintain consistency for now, right? I mean some users might be caching objects other than tensors, which would require weights_only=False.

@KumoLiu
Copy link
Contributor

KumoLiu commented Oct 25, 2024

bnbqq8 and others added 3 commits October 25, 2024 13:38
I, bnbqq8 <[email protected]>, hereby add my Signed-off-by to this commit: e03821d
I, bnbqq8 <[email protected]>, hereby add my Signed-off-by to this commit: 38d5a71
I, bnbqq8 <[email protected]>, hereby add my Signed-off-by to this commit: 719e33d
I, bnbqq8 <[email protected]>, hereby add my Signed-off-by to this commit: 3c2a012
I, bnbqq8 <[email protected]>, hereby add my Signed-off-by to this commit: 5ac10ff

Signed-off-by: bnbqq8 <[email protected]>
@bnbqq8
Copy link
Contributor Author

bnbqq8 commented Oct 25, 2024

@KumoLiu Of course! Thank you for the reminder!

@KumoLiu
Copy link
Contributor

KumoLiu commented Oct 25, 2024

/build

@KumoLiu KumoLiu enabled auto-merge (squash) October 25, 2024 07:17
@bnbqq8 bnbqq8 changed the title Fix torch.load() in PersistentDataset and GDSDataset Fix torch.load() frequently warning in PersistentDataset and GDSDataset Oct 25, 2024
@KumoLiu KumoLiu merged commit 82298ad into Project-MONAI:dev Oct 25, 2024
28 checks passed
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.

3 participants