Pytorch Autograd

Creator
Creator
Seonglae ChoSeonglae Cho
Created
Created
2024 Mar 8 13:49
Editor
Edited
Edited
2025 Jul 20 19:20
torch Tensor.backward()
Without this, the computation graph of the loss continues to accumulate. This is why we need to call backward() every time in
Gradient Accumulation
 

Custom autograd

import torch from torch.autograd import Function class CustomReLU(Function): @staticmethod def forward(ctx, input): ctx.save_for_backward(input) return input.clamp(min=0) @staticmethod def backward(ctx, grad_output): input, = ctx.saved_tensors grad_input = grad_output.clone() grad_input[input < 0] = 0.1 # Modified gradient for negative values return grad_input
 

Trace anomaly

with torch.autograd.set_detect_anomaly(True):     loss.backward()
 
 
torch.autograd 에 대한 간단한 소개
torch.autograd 는 신경망 학습을 지원하는 PyTorch의 자동 미분 엔진입니다. 이 단원에서는 autograd가 신경망 학습을 어떻게 돕는지에 대한 개념적 이해를 할 수 있습니다. 배경(Background): 신경망(NN; Neural Network)은 어떤 입력 데이터에 대해 실행되는 중첩(nested)된 함수들의 모음(collection)입니다. 이 함수들은 PyTorch에서 Tensor로 저장되는, (가중치(weight)와 편향(bias)로 구성된) 매개변수들로 정의됩니다. 신경망을 학습하는 것은 2단계로 이...
torch.autograd 에 대한 간단한 소개
 
 
 

Recommendations