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

オープン 初心者向け
#8,982 コメント 0 件 リアクション 0 件 担当者 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 の再現スクリプトを実行し、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時間
マージ済み PR(30日)
85

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

deepspeedai/DeepSpeed のほかの issue

deepspeedai/DeepSpeed の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。