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

Compatiblity with PyTorch 2.4+ (weights_only default value changed) #619

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

const-volatile
Copy link

@const-volatile const-volatile commented Dec 30, 2024

Starting from version 2.4 PyTorch introduces a stricter check for the objects which can be loaded with torch.load(); to use bark successfully with PyTorch>=2.4 the weights_only attribute needs to be set explicitly.

Without this change the following error will occur:

python3 -m bark --text "Hello, my name is Suno." --output_filename "example.wav"

Oops, an error occurred: Weights only load failed. This file can still be loaded, to do so you have two options, do those steps only if you trust the source of the checkpoint. 
	(1) In PyTorch 2.6, we changed the default value of the `weights_only` argument in `torch.load` from `False` to `True`. Re-running `torch.load` with `weights_only` set to `False` will likely succeed, but it can result in arbitrary code execution. Do it only if you got the file from a trusted source.
	(2) Alternatively, to load with `weights_only=True` please check the recommended steps in the following error message.
	WeightsUnpickler error: Unsupported global: GLOBAL numpy.core.multiarray.scalar was not an allowed global by default. Please use `torch.serialization.add_safe_globals([scalar])` or the `torch.serialization.safe_globals([scalar])` context manager to allowlist this global if you trust this class/function.

Check the documentation of torch.load to learn more about types accepted by default with weights_only https://pytorch.org/docs/stable/generated/torch.load.html.

Starting from version 2.4 PyTorch introduces a stricter check for the objects which can be loaded with torch.load(); to use bark successfully with PyTorch>=2.4 the weights_only attribute needs to be set explicitly
@davidpedrosa
Copy link

Same here.

For the time being, or in case the PR does not get merged, a workaround as explained here would be to set TORCH_FORCE_NO_WEIGHTS_ONLY_LOAD environment variable to "1".

You can do it in your operating system or just in python code (e.g. os.environ['TORCH_FORCE_NO_WEIGHTS_ONLY_LOAD'] = '1') before using the library.

However, you'll get a warning like this:

UserWarning: Environment variable TORCH_FORCE_NO_WEIGHTS_ONLY_LOAD detected, since the`weights_only` argument was not explicitly passed to torch.load, forcing weights_only=False.

As const-volatile pointed out, starting in version 2.4, pytorch wants you to explicitly pass weights_only parameter. If you do so, it would ignore the variable.

@suryakumaran2611
Copy link

When will this be merged?

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