Skip to content

[bugfix] liger all ignore fix - #2079

Open
33013401 wants to merge 2 commits into
InternLM:mainfrom
33013401:ready/liger-all-ignore-fix
Open

33013401 wants to merge 2 commits into
InternLM:mainfrom
33013401:ready/liger-all-ignore-fix

Conversation

@33013401

@33013401 33013401 commented Sep 8, 2026

Copy link
Copy Markdown

修复 Liger all-ignore 场景下的 loss 校准除零问题

当 SP 切分等情况导致本地一次 Liger 调用没有有效 token 时,
使用 valid_count.clamp_min(1) 避免校准公式出现 0/0,
保持正常输入的缩放公式不变,且不引入额外 CPU/GPU 同步。

附带一个 CPU/mock 回归测试,验证可微零 loss 及 hidden/head
零梯度正常

单元测试显示,该改动引入中位增量约 4.58 µs/调用开销,但可处理单 rank all-ignore 问题
该结果不代表完整训练 step 的性能开销。

Bypass Liger CE when a context contains no valid tokens and return a differentiable FP32 zero. This avoids the 0/0 calibration NaN while preserving zero gradients for both inputs.
@33013401 33013401 changed the title Ready/liger all ignore fix [bugfix] liger all ignore fix Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant