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

FutureWarning: You are using torch.load with weights_only=False #1429

Open
mskaif opened this issue Oct 23, 2024 · 4 comments
Open

FutureWarning: You are using torch.load with weights_only=False #1429

mskaif opened this issue Oct 23, 2024 · 4 comments
Labels

Comments

@mskaif
Copy link

mskaif commented Oct 23, 2024

Describe the bug
FutureWarning: 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.
state = torch.load(filename, lambda storage, loc: storage)

This warning is triggered by all torch.load used in stanza. The issue does not cause any problem with data processing at the moment but the long warnings are distracting.

To Reproduce
Steps to reproduce the behavior:

  1. upgrade torch to 2.4.1

Expected behavior
no error

Environment (please complete the following information):

  • OS: Windows
  • Python version: python 3.12.7
  • Stanza version: 1.9.2
@mskaif mskaif added the bug label Oct 23, 2024
@mskaif
Copy link
Author

mskaif commented Oct 23, 2024

The error can be suppressed by using the following before calling stanza functions but is not a solution

import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)

source: ultralytics/ultralytics#14994 (comment)

@AngledLuffa
Copy link
Collaborator

AngledLuffa commented Oct 23, 2024 via email

AngledLuffa added a commit that referenced this issue Oct 24, 2024
…re in the save files, use weights_only=True. Significantly cuts down on the number of torch warnings. #1429
AngledLuffa added a commit that referenced this issue Oct 24, 2024
…re in the save files, use weights_only=True. Significantly cuts down on the number of torch warnings. #1429
@AngledLuffa
Copy link
Collaborator

Some of the models can be updated to use weights_only=True right away, but others require resaving with enums or other data structures removed. Will have to investigate some more.

AngledLuffa added a commit that referenced this issue Oct 24, 2024
…re in the save files, use weights_only=True. Significantly cuts down on the number of torch warnings. #1429
AngledLuffa added a commit that referenced this issue Oct 24, 2024
…re in the save files, use weights_only=True. Significantly cuts down on the number of torch warnings. #1429
@mskaif
Copy link
Author

mskaif commented Oct 25, 2024

Some of the models can be updated to use weights_only=True right away, but others require resaving with enums or other data structures removed. Will have to investigate some more.

sorry for not getting back earlier. I'm using the built-in models like so:
STANZA_PIPE = stanza.Pipeline(
lang="en",
dir=settings.STANZA_DATA_DIR,
processors="tokenize,mwt,pos",
download_method=None,
use_gpu=False,
)

affected from the pipeline are:
tokenization\trainer.py:82
mwt\trainer.py:201
pos\trainer.py:139
common\pretrain.py:56
common\char_model.py:271

Thank you for the commit!

AngledLuffa added a commit that referenced this issue Oct 25, 2024
…re in the save files, use weights_only=True. Significantly cuts down on the number of torch warnings. #1429
AngledLuffa added a commit that referenced this issue Oct 27, 2024
…re in the save files, use weights_only=True. Significantly cuts down on the number of torch warnings. #1429
AngledLuffa added a commit that referenced this issue Oct 28, 2024
…re in the save files, use weights_only=True. Significantly cuts down on the number of torch warnings. #1429
AngledLuffa added a commit that referenced this issue Oct 28, 2024
…re in the save files, use weights_only=True. Significantly cuts down on the number of torch warnings. #1429
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants