0
votes

When I use PyTorch to import weak_script_method, the code throws an error:

from torch._jit_internal import weak_script_method ImportError: cannot import name 'weak_script_method'

The code is:

from torch._jit_internal import weak_script_method

Does anyone have an idea about this? How to fix this error?

1
Do you get the error even if you remove the first 4 lines? - peer
removed, the error still shows up - Sirius
Great! That means you can remove them from the question as they are not relevant. - peer
Great!~~~ I removed them from the question. But do you have any other ideas about this error?? - Sirius
Well, since it's only one line it is probably your installation that is causing the error. I suspect that maybe you're using a version of torch that doesn't have weak_script_method. What is you torch version? (print(torch.__version__)) - peer

1 Answers

0
votes

weak_script_method is in _jit_internal.py in version v1.1.0

As you can look up here:
https://github.com/pytorch/pytorch/blob/v1.1.0/torch/_jit_internal.py

In version v1.2.0 is is no longer there:
https://github.com/pytorch/pytorch/blob/v1.1.0/torch/_jit_internal.py

by inspecting the history you can find this commit which has removed the function you want:
https://github.com/pytorch/pytorch/commit/10c4b98ade8349d841518d22f19a653a939e260c#diff-ee07db084d958260fd24b4b02d4f078d

I've never needed weak_script_method myself and I don't know what you need it for. It seems the pytorch developers don't need it any longer...
Best of luck!