下载
中文
注册
在模型运行时遇到告警“current tensor is running as_strided, don't perform inplace operations on the returned value.”

在模型运行时遇到告警“current tensor is running as_strided, don't perform inplace operations on the returned value.”

2025/03/18

35

暂无评分
我要评分

问题信息

问题来源产品大类产品子类关键字
官方模型训练PyTorch--

问题现象描述

  • 报错截图

    放大

  • 报错文本
    2.py:10: UserWarning: current tensor is running as_strided, don't perform inplace operations on the returned value. If you encounter this warning and haveprecision issues, you can try torch.npu.config.allow_internal_format = False to resolve precision issues. (Triggered internally at build/CMakeFiles/torch_npu.dir/compiler_depend.ts:123.)
      b[:, :, :, :, 0] = tmp3

原因分析

Ascend Extension for PyTorch中,一些私有格式不支持as_strided,因此私有格式进行as_strided之后,也不支持inplace操作。 如上图所示,打屏信息中如果出现以上告警信息,说明对返回值不应进行inplace操作。

如果用户不主动调用torch_npu.npu_format_cast对私有格式的tensor进行转化,私有格式的tensor一般由卷积类算子输出产生,如conv1d,conv2d,conv3d,_convolution等。

解决措施

如果看到此告警信息,且存在精度问题时,可通过torch.npu.config.allow_internal_format = False关闭私有格式解决。关闭私有格式后,所有算子将不会产生私有格式的tensor,对性能有一定影响。

本页内容