RuntimeError: Inplace update to inference tensor outside InferenceMode is not allowed

问题遇到的现象和发生背景

pytorch出现报错
RuntimeError: Inplace update to inference tensor outside InferenceMode is not allowed.You can make a clone to get a normal tensor before doing inplace update.See https://github.com/pytorch/rfcs/pull/17 for more details.

img

遇到的现象和发生背景

pytorch的meganerf开源程序,在win平台运行,报错运行不了。

程序

1.调用块程序:

val_psnr = psnr(eval_result_rgbs.view(-1, 3), eval_rgbs.view(-1, 3))

2.子函数程序

def psnr(rgbs: torch.Tensor, target_rgbs: torch.Tensor) -> float:
    mse = torch.mean((rgbs - target_rgbs) ** 2)
    return -10 * torch.log10(mse).item()
我的解答思路和尝试过的方法

查找网址后,没找到方法;
尝试自己加上.clone,输入也好,子函数也好,都没有用。
想知道解决方法。

变量都给他加上clone看下,或者在函数前面加上装饰器试试看,目前好像是1.12.x的版本会有这个问题


@smart_inference_mode()
def function():
    pass

我也遇到这个问题,请问找到解决方法了吗

我解决了,这是我在llama下面提的问题https://github.com/facebookresearch/llama/issues/180,可以看看找到的解法。
我也尝试了克隆,发现不起作用,我就把

```
@torch.inference_mode()

```删除了,其实不用推理模式,速度也没慢多少,可能慢了10%~20%吧,虽然包不一样,但是你可以参考下

你好,这个问题解决了吗