반응형
a.reatain_grad()를 통해 gradient가 사라지는 것을 예방할 수 있다.
계산그래프에서 leaf node가 아닌 tensor의 gradient는 계산 후 날라가는데, retain_grad를 통해 날라가지 않고 붙잡을 수 있다.
https://blog.paperspace.com/pytorch-hooks-gradient-clipping-debugging/
Debugging and Visualisation in PyTorch using Hooks
In this post, we cover debugging and Visualisation in PyTorch. We go over PyTorch hooks and how to use them to debug our backpass, visualise activations and modify gradients.
blog.paperspace.com
반응형
'Python > PyTorch 공부' 카테고리의 다른 글
[PyTorch] CLIP의 text encoder에는 attention mask가 존재합니다. (0) | 2022.08.01 |
---|---|
[PyTorch] Multi_head_attention에서 target sequence length와 source sequence length 의미 (0) | 2022.07.27 |
[PyTorch] register_hook을 사용하여 Transformer 내부의 Attention matrix(Torch.Tensor)의 gradient 받아오기 (0) | 2022.07.14 |
[Pytorch] Sementation mask 시각화 하기 (0) | 2022.06.26 |
[Pytorch] List를 Tensor로 변경하기. torch.stack (0) | 2022.05.22 |