Division by zero in rescale_noise_cfg can produce NaNs during inference
Maintainers usually reply within 1 day
@Akash504-ai is already working on this.
Since Apr 6, 2026.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Domain
- machine-learning
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
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
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from huggingface/diffusers
-
UniPCMultistepScheduler fails in torch.linalg.solve under a float64 default dtype: the unit entry of rks takes the default dtypePossibly taken @DawnofGenX claimed this 5 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
huggingface/diffusers#14888 ·
Maintainers usually reply within 1 day
-
WanAnimatePipeline.get_i2v_mask() defaults device to "cuda", which raises on non-CUDA accelerators (NPU/XPU/MPS)Possibly taken @li-lizhe claimed this 8 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
huggingface/diffusers#14881 ·
Maintainers usually reply within 1 day
-
IndexError when preprocessing an empty image or video listPossibly taken @MohammadHijjawi97 claimed this 13 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
huggingface/diffusers#14864 ·
Maintainers usually reply within 1 day
-
Windows: check_ai.py fails decoding UTF-8 guides with the default localePossibly taken @tanvir-ux claimed this 12 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
huggingface/diffusers#14837 ·
Maintainers usually reply within 1 day
-
TangentialClassifierFreeGuidance.is_conditional reads an attribute that does not existPossibly taken @dafahaha claimed this 18 days ago. Openbug needs-env-info pipelines
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
huggingface/diffusers#14794 ·
Maintainers usually reply within 1 day
All issues in huggingface/diffusers
Similar issues
-
bug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
debpalash/VoiceStudio#2624 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Make Catch2 optional when `RDK_BUILD_CPP_TESTS=OFF`Possibly taken @pechersky claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 2 days
-
There are a few redundant calls to `fdesc._setCloseOnExec()`Possibly taken @gudnimg claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day