Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Division by zero in rescale_noise_cfg can produce NaNs during inference

Open Beginner friendly
#13,425 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@Akash504-ai is already working on this.

Since Apr 6, 2026.

  • #13426 by @Akash504-ai — open
  • #13704 by @jbbqqf — open
  • #13763 by @arieleli01212 — closed without merging
  • #13989 by @Whning0513 — closed without merging
  • #14334 by @feiiiiii5 — closed without merging

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
python, pytorch

Research direction

Locate the rescale_noise_cfg entry point in the Diffusers source and run the supplied PyTorch reproduction with a zero-variance noise_cfg. Trace the existing handling of std_cfg and add coverage for this edge case. Done means the zero-variance path no longer produces NaN or infinite values during inference.

Written by the indexing model from the issue text.

Description

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

Dominant language
Python
Stars
34.6k
Forks
7.4k
Avg merge
4d 16h
Merged PRs (30d)
44

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from huggingface/diffusers

All issues in huggingface/diffusers

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.