BUG记录Exception: Current loss scale already at minimum - cannot decrease scale anymore. Exiting run.

我的实验时基于huggingface/diffusers开发的,使用了pytorch_lightning,使用了AMP以及deepspeed zero stage2,初次实验未使用scale learning rate策略,正常运行,没有报错,但是使用了scale_lr之后,报错

Exception: Current loss scale already at minimum - cannot decrease scale anymore. Exiting run.

在网上搜了很多,有用的信息有:

  1. 主要思路是skip这个exception,可以追溯的codes: https://gitlab.cl.uni-heidelberg.de/will/fairseq/-/commit/03ef3ab8ce7575ff4501872353dec503dceb199d#313a3e8165b59023666f532b7b5d5844b29e9e90
    对应的修改文件
    deepspeed.runtime.fp16.loss_scaler
  2. 这个错误可能是某些bad batch导致的,有人提供了这样的思路,很遗憾不支持FP16 :https://github.com/Lightning-AI/lightning/issues/4956
  3. 还有人提出将fp16改成bf16(没测试)
  4. 观察梯度变化
from lightning.pytorch.utilities import grad_norm


def on_before_optimizer_step(self, optimizer):
    # Compute the 2-norm for each layer
    # If using mixed precision, the gradients are already unscaled here
    norms = grad_norm(self.layer, norm_type=2)
    self.log_dict(norms)

看是否出现梯度爆炸的情况,出现的话使用梯度clip的形式处理

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值