named_children()
-
RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn프로그래밍/에러 처리 2022. 12. 6. 17:26
Pytorch Lightning에서 model의 모든 layer를 freeze하는 테스트를 진행했다. 이때 freeze 사용된 코드는 아래와 같다. for params in model.parameters(): params.requires_grad = False 그러나 위의 코드를 실행했을 경우 Trainer.fit 부분에서 아래의 에러가 발생했다. RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn 이리저리 살펴본 결과 결국 pytorch lightning에서 모든 레이어가 params.requires_grad = False일 경우 evaluate 모드와 다름이 없어 에러가 발생하는 것으로 보인다. 이후 ..