크크루쿠쿠

RuntimeError: Output 0 of UnbindBackward is a view and is being modified inplace. 본문

StackOverflow

RuntimeError: Output 0 of UnbindBackward is a view and is being modified inplace.

JH_KIM 2022. 2. 24. 10:23
RuntimeError: Output 0 of UnbindBackward is a view and is being modified inplace. This view is the output of a function that returns multiple views. Such functions do not allow the output views to be modified inplace. You should replace the inplace operation by an out-of-place one.

torch version 1.7 버전부터 발생하는 문제이다.

아마 backward 과정에 bind 되어있어 문제가 되어서 수정된것으로 보인다.

 

>>> x = torch.randn(5, 10, requires_grad=True)
>>> for i, v in enumerate(x):
>>>     v.fill_(i)

이러한 코드를

>>> x = torch.randn(5, 10, requires_grad=True)
>>> for i, v in enumerate([x[j] for j in range(x.size(0))]):
>>>   v.fill_(i)

이렇게 unbind 해주면 오류가 해결된다.

Comments