autograd

    [PyTorch] RuntimeError: Trying to backward through the graph a second time

    [PyTorch] RuntimeError: Trying to backward through the graph a second time

    Introduction 파이토치를 이용해 다양한 모델을 구현하다 보면, 아래와 같은 에러 메시지를 한번 쯤은 마주할 것이다. RuntimeError: Trying to backward through the graph a second time, but the buffers have already been freed. Specify retain_graph=True when calling backward the first time 오늘은 이 에러 메시지가 어떤 상황에서, 어떤 이유로 출력되는 지 알아보고, 그 해결 방법에 대해 간략히 설명할 예정이다. Autograd Mechanism 기본적으로 파이토치의 autograd 메커니즘은 requires_grad=True 로 설정된 텐서들에 대해, 텐서 데이터가 생..