Legacy autograd function with non-static forward method is deprecated and will be removed in 1.3.


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM