Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Division by zero in rescale_noise_cfg can produce NaNs during inference

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

维护者通常 1 天内回复

@Akash504-ai 已经在做这个了。

开始于 2026年4月6日。

  • #13426 来自 @Akash504-ai —— 未关闭
  • #13704 来自 @jbbqqf —— 未关闭
  • #13763 来自 @arieleli01212 —— 已关闭,未合并
  • #13989 来自 @Whning0513 —— 已关闭,未合并
  • #14334 来自 @feiiiiii5 —— 已关闭,未合并

评估

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

调研方向

在 Diffusers 源代码中定位 rescale_noise_cfg 入口点,并使用方差为零的 noise_cfg 运行提供的 PyTorch 复现代码。跟踪现有的 std_cfg 处理方式,并为这一边界情况添加覆盖。完成标准是:方差为零的路径在推理过程中不再产生 NaN 或无穷值。

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

描述

bug
Describe the bug

Bug: Division by zero in rescale_noise_cfg can produce NaNs

Description

The function rescale_noise_cfg performs a division by std_cfg without any numerical stability guard:

noise_pred_rescaled = noise_cfg * (std_text / std_cfg)

If std_cfg becomes zero, this leads to NaN or inf values, which can silently corrupt the diffusion process and produce invalid outputs.

This can happen in edge cases where noise_cfg has zero variance.

Reproduction
import torch

noise_cfg = torch.zeros(1, 4, 64, 64)  # std = 0
noise_pred_text = torch.randn_like(noise_cfg)

std_text = noise_pred_text.std(dim=list(range(1, noise_pred_text.ndim)), keepdim=True)
std_cfg = noise_cfg.std(dim=list(range(1, noise_cfg.ndim)), keepdim=True)

result = noise_cfg * (std_text / std_cfg)
print(result)
Logs

System Info
  • Diffusers: main
  • PyTorch: any
  • OS: any
Who can help?

No response

主要语言
Python
星标
34.7k
派生
7.4k
平均合并
4 天 6 小时
30 天内合并 PR
55

环境准备

从这里开始

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

huggingface/diffusers 的其他 Issue

查看 huggingface/diffusers 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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