Add nn loss adapter support in v2 BaseModel with multi-target handling#2238
Add nn loss adapter support in v2 BaseModel with multi-target handling#2238adityashinde0 wants to merge 8 commits intosktime:mainfrom
Conversation
|
hello , Anyone can help , this is my first PR ... |
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2238 +/- ##
=======================================
Coverage ? 86.32%
=======================================
Files ? 167
Lines ? 9819
Branches ? 0
=======================================
Hits ? 8476
Misses ? 1343
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I think i am done any improvement needed @phoeenniixx @PranavBhatP |
phoeenniixx
left a comment
There was a problem hiding this comment.
There are a lot of files that should not be changed for this PR. Please revert those changes and when you are using AI, please use it carefully, and make sure that you are able to understand all the changes it is making.
This reverts commit 6264339.
Thanks !!! |
LLM generated content, by GPT-5
Reference Issues/PRs
Fixes #1970.
What does this implement/fix? Explain your changes.
This PR adds support for using
torch.nnlosses in ptf-v2 while keeping the existing model output contract unchanged.Changes made:
pytorch_forecasting/models/base/_loss_adapter_v2.pyNNLossAdapterhandles shape conversion for nn losses internally.MSELoss,L1Loss) and class-index style losses (e.g.,CrossEntropyLoss,NLLLoss).to_predictionandto_quantilesfallbacks to stay compatible with v2 model APIs.pytorch_forecasting/models/base/_base_model_v2.pynn.Modulelosses directly.NNLossAdapter.Metric/MultiLossusage remains supported._compute_lossMultiLosswhen provided.This addresses the issue where nn losses could not handle list targets and where prediction/target shape expectations differ across loss types.
What should a reviewer concentrate their feedback on?
NNLossAdapterbehavior and shape handling logic for:Metric/MultiLossflow in v2_compute_loss(especially tensor slicing and aggregation strategy)to_prediction/to_quantilesfallbacks are appropriate for nn-loss-backed modelsDid you add any tests for the change?
I validated via local targeted model test runs:
tests/test_models/test_tft_v2.pytests/test_models/test_timexer_v2.pyIf maintainers prefer, I can add dedicated unit tests specifically for
NNLossAdapterand multi-target nn-loss behavior in follow-up.Any other comments?
pytorch_forecasting/models/samformer/_samformer_v2.pyin my working tree. Please let me know if you prefer this in a separate PR to keep [ENH] Add support fornnlosses toptf-v2#1970 strictly scoped.meanvs weighted) for multi-target nn losses if project conventions require a different strategy.PR checklist
pre-commit install.To run hooks independent of commit, execute
pre-commit run --all-files