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