[ENH] Add support for nn losses to ptf-v2 (Followup on #2073)#2331
Draft
Faakhir30 wants to merge 4 commits into
Draft
[ENH] Add support for nn losses to ptf-v2 (Followup on #2073)#2331Faakhir30 wants to merge 4 commits into
Faakhir30 wants to merge 4 commits into
Conversation
…ytorch-forecasting into nidhi_nn_losses
Signed-off-by: Faakhir30 <zahidfaakhir@gmail.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2331 +/- ##
=======================================
Coverage ? 87.22%
=======================================
Files ? 169
Lines ? 9895
Branches ? 0
=======================================
Hits ? 8631
Misses ? 1264
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reference Issues/PRs
Fixes #1970
What does this implement/fix? Explain your changes.
Followups on existing PR #2073 by @Nidhicodes
By @Nidhicodes:
-Introduces NNLossAdapter, a lightweight wrapper that adapts nn.Module losses to the ptf-v2 loss/metric API.
-Enables users to pass native PyTorch losses directly to models (e.g. DLinear(loss=nn.MSELoss())) without manual wrapping.
-Ensures compatibility with BaseModel.predict() by implementing to_prediction and to_quantiles.
The adapter:
-Handles (target, weight) inputs by applying weights internally while respecting the loss’s original reduction.
-Supports multi-target predictions by splitting [B, T, N] tensors and summing losses across targets.
-Enforces point-prediction-only usage (H=1) for losses that are not horizon-aware, with clear error messages otherwise.
Further updates:
self._lossinstead ofself.lossWhat should a reviewer concentrate their feedback on?
Did you add any tests for the change?
Any other comments?
PR checklist
pre-commit install.To run hooks independent of commit, execute
pre-commit run --all-files