torch.autograd.detect_anomaly()

import torch

# 正向传播时:开启自动求导的异常侦测
torch.autograd.set_detect_anomaly(True)

# 反向传播时:在求导时开启侦测
with torch.autograd.detect_anomaly():
    loss.backward()

 

posted @ 2021-03-05 09:57  皮卡皮卡妞  阅读(12867)  评论(0编辑  收藏  举报