fp16 `hysteresis: 0` (or negative) makes DynamicLossScaler never lower the loss scale, so every overflowing step is skipped forever

未关闭 适合新手
#8,982 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

@damienen 已经在做这个了。

开始于 2026年11月2日。

  • #8983 来自 @damienen —— 未关闭
  • #8993 来自 @siddhant-rajhans —— 已关闭,未合并

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python, pytorch

调研方向

故障位于 deepspeed/runtime/fp16/loss_scaler.py 中的 update_scale,其降低缩放的分支检查 delayed_shift == 1 or cur_hysteresis == 1。在检出的代码上运行 issue 中的复现脚本,观察 hysteresis=0 的情况是否仍停留在 65536。在修改任何内容之前,先决定 0 或更小的值应当等同于 1,还是在配置中被拒绝,因为 issue 与 #7856 的说法不一致。完成的标准是:复现脚本对 hysteresis=0 能降低缩放,且现有的 loss scaler 测试全部通过。

由索引模型根据 Issue 内容生成。

描述

Describe the bug

With fp16.hysteresis set to 0 or a negative number, DynamicLossScaler (the scaler ZeRO stages 1, 2 and 3 use through CreateLossScaler) never lowers its loss scale after an overflow. Every overflowing step is then skipped, and the "Current loss scale already at minimum" exit never triggers because the scale never reaches the minimum.

update_scale tests self.delayed_shift == 1 or self.cur_hysteresis == 1. When the counter starts at 0 or below, it only moves further from 1, so the branch that lowers the scale is never taken. DeepSpeedFP16Config.hysteresis has no validator, so the config loads without complaint. The default (hysteresis: 2) is not affected. The stage 0 fp16 optimizers already back off when cur_hysteresis is not above 1, so the two paths disagree on what 0 means.

To Reproduce

The script loads deepspeed/runtime/fp16/loss_scaler.py as is, with small stand-ins for the few torch and deepspeed names it imports (update_scale is plain Python arithmetic). SRC is a checkout of the repo.

import os, sys, types, logging
src = os.environ.get("SRC", "./src")
def mod(n, **kw):
    m = types.ModuleType(n); m.__dict__.update(kw); sys.modules[n] = m; return m
mod("torch", half="half", bfloat16="bf16", float32="f32")
ds = mod("deepspeed", __path__=[])
comm = mod("deepspeed.comm", get_rank=lambda: 0); ds.comm = comm
mod("deepspeed.utils", log_dist=lambda *a, **k: None, logger=logging.getLogger("x"))
mod("deepspeed.runtime", __path__=[])
mod("deepspeed.runtime.config_utils", DeepSpeedConfigObject=object)
mod("deepspeed.runtime.utils", has_inf_or_nan=lambda x: False)
code = open(os.path.join(src, "deepspeed/runtime/fp16/loss_scaler.py")).read()
ns = {"__name__": "ls"}
exec(compile(code, "loss_scaler.py", "exec"), ns)
for h in (1, 0):
    s = ns["CreateLossScaler"]("half", 0, True, dict(init_scale=2**16, scale_window=1000, delayed_shift=h, consecutive_hysteresis=False, min_scale=1))
    for _ in range(40):
        try: s.update_scale(True)
        except Exception: break
    print(f"hysteresis={h}: scale after 40 overflows = {s.cur_scale}; expected < 65536")

Expected behavior

Both cases lower the scale. Output on main:

hysteresis=1: scale after 40 overflows = 1.0; expected < 65536
hysteresis=0: scale after 40 overflows = 65536; expected < 65536

A value of 0 or below should either behave like 1 (no delay) or be rejected when the config is loaded.

ds_report output

Not run. The script above loads the one file from a source checkout, and DeepSpeed was not installed.

Screenshots

None. The output is text, above.

System info (please complete the following information):

  • OS: Linux container (x86_64)
  • GPU count and types: none, CPU only
  • Interconnects (if applicable): none
  • Python version: 3.13
  • Any other relevant info about your setup: deepspeedai/DeepSpeed main at f818504999bdd57c3e771368aefc301290020d9a. The same code is in v0.19.8 (0eb3a8bcc6d9).

Launcher context

No launcher. The script calls the scaler directly, without deepspeed, MPI or a training run.

Docker context

A plain Python 3.13 container, not a DeepSpeed image.

Additional context

I have not run a ZeRO training job with this setting. The claim covers the scaler class, which ZeRO stages 1 to 3 build with CreateLossScaler.

This issue was prepared with AI assistance and reviewed by a human.

Related

#7856 (open) would reject fp16.hysteresis below 1 at config parse time. This change instead makes DynamicLossScaler treat 0 or less as no delay, matching the stage 0 optimizers from #8647.

主要语言
Python
星标
43.3k
派生
5.1k
平均合并
5 天 10 小时
30 天内合并 PR
85

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

deepspeedai/DeepSpeed 的其他 Issue

查看 deepspeedai/DeepSpeed 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。