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

Đang mở Phù hợp với người mới
#8,982 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@damienen đang làm issue này rồi.

Từ ngày 2/11/2026.

  • #8983 của @damienen — đang mở
  • #8993 của @siddhant-rajhans — đã đóng, không merge

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python, pytorch
Lĩnh vực
machine-learning

Hướng nghiên cứu

Lỗi nằm trong update_scale ở deepspeed/runtime/fp16/loss_scaler.py, nơi nhánh giảm scale kiểm tra delayed_shift == 1 or cur_hysteresis == 1. Chạy script tái hiện trong issue trên một bản checkout để thấy trường hợp hysteresis=0 vẫn giữ ở 65536. Trước khi thay đổi gì, hãy quyết định 0 hoặc giá trị nhỏ hơn nên hoạt động như 1 hay bị từ chối trong cấu hình, vì issue và #7856 không thống nhất. Hoàn thành khi bản tái hiện giảm scale cho hysteresis=0 và các bài kiểm tra loss scaler hiện có vẫn pass.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
43.3k
Fork
5.1k
Merge trung bình
5 ngày 10 giờ
Pull request đã merge (30 ngày)
85

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của deepspeedai/DeepSpeed

Tất cả issue của deepspeedai/DeepSpeed

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.