PyTorch在1.3版本及之后,規定forward方法必須是靜態方法。違反了該原則的代碼將會在運行時報下列錯誤:
..\torch\csrc\autograd\python_function.cpp:622: UserWarning: Legacy autograd function with non-static forward method is deprecated and will be removed in 1.3. Please use new-style autograd function with static forward method. (Example: https://pytorch.org/docs/stable/autograd.html#torch.autograd.Function)
解決辦法:
將PyTorch降級到1.2版本及以下,因為這個改進直到1.3版本才正式生效;
手動忽略掉UserWarning:
import warnings
warnings.filterwarnings("ignore")
原文鏈接:https://blog.csdn.net/hhhhhhhhhhwwwwwwwwww/article/details/105850901