Skip to content

Fix: Update torch.load to use weights_only=True to prevent security w… #2451

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

Merged
merged 4 commits into from
Jun 26, 2025

Conversation

yaslack
Copy link
Contributor

@yaslack yaslack commented Nov 20, 2024

Fix: Update torch.load to use weights_only=True to prevent security warning

Changes Made:

In this pull request, I updated the torch.load function call to use weights_only=True in order to prevent a security warning related to the unpickling process.

Code Change:

- checkpoint = torch.load(fp, map_location=device)
+ checkpoint = torch.load(fp, map_location=device, weights_only=True)

@bitplane
Copy link

bitplane commented Dec 4, 2024

For anyone else with this issue, I've been doing this for now:

import functools
whisper.torch.load = functools.partial(whisper.torch.load, weights_only=True)

Copy link

@hamirmahal hamirmahal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jongwook this seems like a useful change that would reduce a lot of noise for developers.

Are you open to it?

@bitplane
Copy link

For anyone else with this issue, I've been doing this for now:

import functools
whisper.torch.load = functools.partial(whisper.torch.load, weights_only=True)

This was happening in other things too, so I ended up making a module for it. Trivial, but I found it useful so thought I'd share:

https://github.com/bitplane/torch_weightsonly

@oscardssmith
Copy link

any updates here? this seems like an improvement that should be merged

@jongwook
Copy link
Collaborator

jongwook commented Jun 26, 2025

#2301 was for the same issue but i didn't want to break compatibility with torch==1.10.1 just for this. The commit above should make it work for all version.

@jongwook jongwook merged commit 1f8fc97 into openai:main Jun 26, 2025
10 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.

5 participants