Warning: AutoNonVariableTypeMode is deprecated and will be removed in 1.10 release

前言

使用一个古老的开源仓库时触发的。

错误信息

[W LegacyTypeDispatch.h:74] Warning: AutoNonVariableTypeMode is deprecated and will be removed in 1.10 release. For kernel implementations please use AutoDispatchBelowADInplaceOrView instead, If you are looking for a user facing API to enable running your inference-only workload, please use c10::InferenceMode. Using AutoDispatchBelowADInplaceOrView in user code is under risk of producing silent wrong result in some edge cases. See Note [AutoDispatchBelowAutograd] for more details. (function operator())

原因

因为torch的版本更新后,autograd机制做了点调整。
引入了inference mode

https://github.com/ailzhang/rfcs/blob/rfc0011/RFC-0011-InferenceMode.md

解决方案

看torch官方Note

https://github.com/pytorch/pytorch/blob/main/docs/cpp/source/notes/inference_mode.rst#migration-guide-from-autononvariabletypemode

在原来的cpp代码中有

at::AutoNonVariableTypeMode g;

表示禁用自动求导。
但这个方法不安全。

根据官方指引

1. 只想在inference mode下使用

替换成

c10::InferenceMode guard;

2. 想自定义backward过程

替换成

at::AutoDispatchBelowADInplaceOrView guard;

Note AutoDispatchBelowADInplaceOrView is just a new name of AutoNonVariableTypeMode since it explains the guard’s functionality better.

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值