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

文章讲述了在使用一个旧的开源仓库时遇到关于Autograd机制的警告,由于PyTorch版本更新导致的`AutoNonVariableTypeMode`被弃用。作者提供了在新版本中使用`InferenceMode`和`AutoDispatchBelowADInplaceOrView`的解决方案,以及如何处理自定义backward过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言

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

错误信息

[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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值