https://www.pianshen.com/article/57371204499/
梯度回传过程中可能会梯度消失或者爆炸,为了避免这种情况,设置一个梯度剪裁。
利用torch.nn.utils.clip_grad_norm_(parameters, max_norm, norm_type=2)完成。
参数1是模型参数,参数2是最大梯度范数,参数3是范数类型,默认为L2范数。
PS. 在train的过程中做这个,val和test过程中不做。
使用案例:
https://www.pianshen.com/article/57371204499/
梯度回传过程中可能会梯度消失或者爆炸,为了避免这种情况,设置一个梯度剪裁。
利用torch.nn.utils.clip_grad_norm_(parameters, max_norm, norm_type=2)完成。
参数1是模型参数,参数2是最大梯度范数,参数3是范数类型,默认为L2范数。
PS. 在train的过程中做这个,val和test过程中不做。
使用案例: