-
Notifications
You must be signed in to change notification settings - Fork 705
[ENH] Add Metrics
support to ptf-v2
#1960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
The important question right now is should the
|
Hi @fkiraly, @agobbifbk, @PranavBhatP But the actual issue is not with the pytorch-forecasting/pytorch_forecasting/metrics/point.py Lines 91 to 93 in 106f82f
The base pytorch-forecasting/pytorch_forecasting/metrics/base_metrics/_base_metrics.py Lines 100 to 108 in 106f82f
As you see here, even the 3D loss = (self.to_prediction(y_pred) - target).abs() / (target.abs() + 1e-8) here, if So, we need to either change the
Or We could change the This is what happens in v1 as well, you could see the docstring of pytorch-forecasting/pytorch_forecasting/data/timeseries/_timeseries.py Lines 2600 to 2604 in 106f82f
(NOTE: Here EDIT: I manually checked the shape of |
Ok thx for the explanation. Do you confirm that in v1, in case of multi target, the batching process creates a list of 2d tensors? If is this the case, somewhere in the code relative to the loss, there is a place in which there is an iteration along this list and the loss functions for each target are summed up, isn't it? If yes, could we just change the iteration process based on the combination type/dimension of the target tensor and reuse all v1 metric module? |
Yes, that happens in multiloss = MultiLoss(
metrics=[MASE(), MASE(), MASE()], # One MASE per target
weights=[1.0, 1.0, 1.0] # Optional weights
) See
Yes, we could do this, we can iterate over the last dimension of the tensor (in case of 3D The changes to the v2 would be to lose the last dimension (for 3D |
Thanks for the useful explanation, @phoeenniixx! Also @PranavBhatP - could you kindly point me to the best and most precise description of the current metric API? (or paste one here) I understand the change would be necessary if we keep the current metrics API - so I would like to think a little bit about whether the metrics API could be improved instead. |
key methods of
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
The current example notebook used |
The only change i could understand is the one @agobbifbk suggested - changing the looping logic, but still we'd need to change the
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1960 +/- ##
=======================================
Coverage ? 87.21%
=======================================
Files ? 158
Lines ? 9301
Branches ? 0
=======================================
Hits ? 8112
Misses ? 1189
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:
|
What I understand:
|
Yes, I agree, but there is one thing: We have to do this as |
Hi @fkiraly, @agobbifbk, so right now we have 2 possibilities:
|
I agree that these are the options, but I would be against a change in the metrics, since a lot of the existing metric implementations might break with a change in the API and the whole test framework would need major changes. I would go ahead with option 1 :) |
@phoeenniixx, I think the example you posted is not what we are talking about? Because there is talk about lists of tensors. None of the specs you posted involve lists explicitly. Can I please repeat my query, @phoeenniixx, @PranavBhatP? please make sure to include the case we are actually discussing here, i.e., lists of something - and the alternative designs |
What @PranavBhatP shared here: #1960 (comment), ig sums up the API (mainly for single target ig)? I will add some clarifications based on my understanding:
@PranavBhatP, please correct me if there are some misconceptions from my side Based on this info, i could come up with 2 appraoches mentioned here: #1960 (comment) |
@phoeenniixx, thanks, I was looking exactly for this, the multi-target specs! Can you clarify how option 2 in #1960 (comment) would work if we have losses with different Or would it not work at all? I have a slight preference towards option 1 currently since the above may pose an issue - but it might be worth exploring if it can be prevented in option 2 (or if I misunderstand this, please help clarify) |
According to my mental model, what happens right now is for multi-target, we have to use If we were to pass a 3D tensor (in case of
So, based on this, different |
Hi @fkiraly, I have removed the usage of |
Also, the notebooks are working locally, so I think the fix of #1965 should work... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
The increased complexity in the case distinctions are making me feel a bit uneasy, but I am thinking it is ok, based on our discussion. The concrete classes also seem to become more streamlined - this is a good sign.
Some requests:
- can you kindly write full docstrings for the returns of
__getitem__
in the D2 classes changed? I am aware these were not there before, but it feels crucial now to ensure the contract is well documented. - the
__init__
warning message in the D2 layer classes refers to the wrong class, this should be fixed (pre-existing but easy to fix) - docstring in
BaseModel
should be attached to the class, not the__init__
method - docstring in
BaseModel
should refer toMetric
more clearly, e.g., descendant of what? And "metric inpytorch-forecasting
API"? - in Tide, can we add a probabilistic loss to replace the Poisson loss?
Model is only compatible with the point prediction losses right now, but I think we could make some improvements there in the future. |
Are you referring to V1 or V2 implementation? Maybe it worth to fix it since we are working on this, what do you think? |
Actually both :) |
Well I think in the DSIP implementation it is sufficient to use the |
Fixes #1956, Fixes #1844
This PR tries to make
v2
compatible withMetrics
. It also changes the contract of tensors to match v1:list
for multi-target and atensor
for single-targetStacks on #1965