728x90
RuntimeError: element 0 of variables does not require grad and does not have a grad_fn
Autograd에서 미분(differentiation)하는 경우 grad_fn은 기울기를 계산하는 것을 도와주는 함수이다. 기울기를 계산해서 학습을 해야하는데, 설정된 텐서값이 그게 되지 않는다는 것이다. 손실함수를 계산할 때, 필요한 값들이 no_grad 처리가 되어 있진 않은지 보고 `required_grad_(True)'로 설정해두면 해결됨
a = torch.tensor([2., 3.], requires_grad=True)
b = torch.tensor([6., 4.])
b.requires_grad_(True)
728x90
'Skills > Error' 카테고리의 다른 글
[Error] bash: sudo: command not found (2) | 2023.07.18 |
---|---|
[Error] RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation (2) | 2023.07.12 |
[Error] 개발 환경 세팅 - 각종 설치 (0) | 2023.07.06 |
[Error] You can enable repos with yum-config-manager --enable <repo> (0) | 2023.04.28 |
[Error] 'base'로 셀을 실행하려면 ipykernel 패키지를 설치하거나 업데이트해야합니다 (0) | 2023.04.28 |
댓글