Skip to content

fix: preserve infinite losses in weighted reductions - #1602

Closed
kiwoongyoon wants to merge 1 commit into
Nixtla:mainfrom
kiwoongyoon:gitcontribute/20260903-013537-739214-Nixtla-neuralforecast-issue-1601
Closed

fix: preserve infinite losses in weighted reductions#1602
kiwoongyoon wants to merge 1 commit into
Nixtla:mainfrom
kiwoongyoon:gitcontribute/20260903-013537-739214-Nixtla-neuralforecast-issue-1601

Conversation

@kiwoongyoon

Copy link
Copy Markdown

Title: fix: preserve infinite losses in weighted reductions

Summary

  • Preserve signed infinities in _divide_no_nan instead of replacing them with zero.
  • Ignore zero-weight entries before multiplying weighted losses, preventing masked infinities from producing NaN.
  • Cover unmasked and masked positive/negative infinite predictions with an MAE regression test.

Fixes #1601

Test evidence

  • pytest tests/test_losses/test_pytorch.py::test_MAE_infinite_predictions -q — 1 passed
  • pytest tests/test_losses/test_pytorch.py -q — 16 passed
  • ruff check neuralforecast/losses/pytorch.py tests/test_losses/test_pytorch.py — passed
  • git diff --check — passed

Risks or notes for maintainers

_weighted_mean is shared by point losses, so zero-weight non-finite values are now ignored consistently wherever masks or zero horizon weights are used. No public API or dependency changes are included.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@marcopeix

Copy link
Copy Markdown
Contributor

@kiwoongyoon Thanks for raising the issue and drafting a PR. I think I have a more complete fix in #1603

@marcopeix

Copy link
Copy Markdown
Contributor

Closing since merging #1603

@marcopeix marcopeix closed this Sep 3, 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.

[Losses] _divide_no_nan turns an infinite loss into 0.0, so broken trials win Auto search

3 participants