关于pytorch userwarning坑的记录一
文章目录
记录一下最近使用pytorch时出现的几个关于userwarning的坑
1.UserWarning: masked_fill_ received a mask with dtype torch.uint8, this behavior is now deprecated,please use a mask with dtype torch.bool instead.
/opt/conda/condabld/pytorch_1587428091666/work/aten/src/ATen/native/cuda/LegacyDefinitions.cpp:19: UserWarning: masked_fill_ received a mask with dtype torch.uint8, this behavior is now deprecated,please use a mask with dtype torch.bool instead.
这种情况需要把`
masked_fill_(data)
`
改成
masked_filled(data.bool())
2.RuntimeError: Subtraction, the - operator, with a bool tensor is not supported. If you are trying to invert a mask, use the ~ or logical_not() operator instead.
这是因为 pytorch版本的问题,出现这种问题一般是因为你跑的代码当初可能写在pytorch1.2版本之前,而你现在的运行环境>=pytorch1.2因此,汇报上述错误,这是只需把
1-mask()
改成
~mask()
即可搞定
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论