fp16 `hysteresis: 0` (or negative) makes DynamicLossScaler never lower the loss scale, so every overflowing step is skipped forever
维护者通常 2 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 72/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
调研方向
故障位于 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 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
deepspeedai/DeepSpeed 的其他 Issue
-
[Bug] DeepSpeedEngine.step leaves _running_engine_step=True permanently on exception, corrupting is_gradient_accumulation_boundary()可能已有人在做 @its-amann 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 85/100
deepspeedai/DeepSpeed#9190 · 1 条评论 ·
维护者通常 2 天内回复
-
[Bug] PipelineEngine._exec_reduce_grads and _exec_optimizer_step leave _force_grad_boundary=True permanently after any exception可能已有人在做 @bantianyue 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
deepspeedai/DeepSpeed#9183 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
deepspeedai/DeepSpeed#9019 · 2 条评论 ·
维护者通常 2 天内回复
-
[BUG] OneCycle applies the minimum momentum to the first Adam update可能已有人在做 @ai-yang 于 30 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
deepspeedai/DeepSpeed#8951 ·
维护者通常 2 天内回复
-
init_inference rejects dtype=torch.int8 on every accelerator可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
deepspeedai/DeepSpeed#8577 ·
维护者通常 2 天内回复
查看 deepspeedai/DeepSpeed 的全部 Issue
相似的 Issue
-
area/auth comp/agent P3 type/bug
难度 2/5 1-3 小时 新手友好度 88/100
NousResearch/hermes-agent#161417 ·
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 75/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
Dao-AILab/flash-attention#3251 ·
维护者通常 2 天内回复
-
[New Check]: sqlserver_public_network_access_disabled可能已有人在做 @pouria-l 今天认领。 未关闭feature-request status/needs-triage
难度 2/5 1-3 小时 新手友好度 78/100
prowler-cloud/prowler#13607 · 1 条评论 ·
维护者通常 1 天内回复
-
external langchain
难度 1/5 1 小时以内 新手友好度 90/100
langchain-ai/docs#8184 ·
维护者通常 1 天内回复