본문 바로가기
딥러닝/파이토치

pytorch - RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [1, 512, 4, 4]] is at version 2; expected version 1 instead. Hint: enable anomaly detection to find the opera..

by 프룹 2021. 8. 28.
반응형

# 개발 환경

Pytorch Version : 1.7.0

# 오류 내용

RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [1, 512, 4, 4]] is at version 2; expected version 1 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).

# 해결

with torch.autograd.set_detect_anomaly(True):

로 Train Part를 감싸주면 된다.

 

반응형

댓글