ccarliu / m3ae

GNU Affero General Public License v3.0
5 stars 0 forks source link

A view was created in no_grad mode and is being modified inplace with grad mode enabled. This view was created inside a custom Function (or because an input was returned as-is) and the autograd logic to handle view+inplace would override the custom backward associated with the custom Function, leading to incorrect gradients. This behavior is forbidden. You can fix this by cloning the output of the custom Function. #15

Open yuyuyu13 opened 2 months ago

yuyuyu13 commented 2 months ago

Traceback (most recent call last): File "pretrain.py", line 240, in main(arguments) File "pretrain.py", line 177, in main segs_S1,maskratio,,_= model_1(inputs_S1, patch_locations) File "/root/miniconda3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl return forward_call(*input, kwargs) File "/root/miniconda3/lib/python3.8/site-packages/torch/nn/parallel/data_parallel.py", line 166, in forward return self.module(*inputs[0], *kwargs[0]) File "/root/miniconda3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl return forward_call(input, kwargs) File "/root/m3ae/model/Unet.py", line 830, in forward x[l] = x[l] mask + self.limage[:, :, location[0][0][l]: location[0][1][l], location[1][0][l]: location[1][1][l], location[2][0][l]: location[2][1][l]] (1-mask) # not detach here RuntimeError: A view was created in no_grad mode and is being modified inplace with grad mode enabled. This view was created inside a custom Function (or because an input was returned as-is) and the autograd logic to handle view+inplace would override the custom backward associated with the custom Function, leading to incorrect gradients. This behavior is forbidden. You can fix this by cloning the output of the custom Function.

yuyuyu13 commented 2 months ago

出现这种错误该如何解决?