Repository navigation
[ENH] Adding Support of Distribution Loss in v2 Models - #2420
Muhammad-Rebaal wants to merge 15 commits into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2420 +/- ##
=======================================
Coverage ? 88.90%
=======================================
Files ? 218
Lines ? 11713
Branches ? 0
=======================================
Hits ? 10414
Misses ? 1299
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:
|
phoeenniixx
left a comment
There was a problem hiding this comment.
Can you please add some tests here? To see if the shapes are correct etc?
Maybe we can update the test framework even here - to loop over the losses (like in v1). That can happen in a separate PR stacked over this PR.
|
Hi @phoeenniixx, |
| def test_transform_output_dict_target_scale(): | ||
| """Dict target_scale applies affine denormalization correctly.""" | ||
| model = _make_model() | ||
| raw = torch.randn(4, 12, 1) | ||
| center = torch.tensor([10.0, 20.0, 30.0, 40.0]) | ||
| scale = torch.tensor([2.0, 3.0, 4.0, 5.0]) | ||
| target_scale = {"center": center, "scale": scale} | ||
|
|
||
| result = model.transform_output(raw, target_scale) | ||
|
|
||
| assert result.shape == raw.shape | ||
| assert torch.allclose(result[0], raw[0] * 2.0 + 10.0) | ||
| assert torch.allclose(result[3], raw[3] * 5.0 + 40.0) | ||
|
|
||
|
|
||
| def test_transform_output_plain_tensor_target_scale(): |
There was a problem hiding this comment.
how are these two tests useful? Why not direclty use the DistributionLoss?
There was a problem hiding this comment.
These two tests only validate the affine denormalization path (pred * scale + center), which is the straightforward case.
I'll add those distribution loss tests as well
There was a problem hiding this comment.
My doubt is - DistributionLoss does somethign similar no?
(i have not looked at the math of the losses, so i may be wrong)
There was a problem hiding this comment.
These 2 tests are checking specifically making sure that Quantile Loss and Point Forecasts (like MAE) get un-scaled correctly, since I made changes in the transform_output function as well.
phoeenniixx
left a comment
There was a problem hiding this comment.
I think we are still lacking the tests that check If DistributionLoss works as intended with v2.
Also, this should be present in the test framework? why the base model?
By adding "support" we should also update the models which have this todo, no?
Ok I'll add that specific tests as well
Yeah I got your point up here so that each time it would run it would also check it .
I thought for the model we'd open an umbrella issue that would adding support for each. Although If that's your vision to add in all models I'll update that as well. |
We should try with atleast 1-2 models otherwise how would we know if this is working or not? |
…l/pytorch-forecasting into distribution_loss
…l/pytorch-forecasting into distribution_loss
|
Hi @phoeenniixx, I've made these changes :
|
| "max_prediction_length": self.max_prediction_length, | ||
| "min_encoder_length": self._min_encoder_length, | ||
| "min_prediction_length": self._min_prediction_length, | ||
| "target_normalizer": self.target_normalizer, |
There was a problem hiding this comment.
should we pass a whole object in metadata? is this actually necessary? I think metadata should be lightweight and only should have the "metadata" and not objects unless it is actually 100% necessary
There was a problem hiding this comment.
why are we changing the forward logic of this model?
There was a problem hiding this comment.
There should be a cleaner and more robust way to handles the shapes?
phoeenniixx
left a comment
There was a problem hiding this comment.
Nice!
This is looking better.
I just have few concerns (pls see above)
Fixes #2389
Hi @phoeenniixx,
In order to add support I've done the following changes :
transform_outputinBaseModelto scale predictions back to their real-world numbers.output_sizeinBaseModelto tell the model how many numbers to predict.target_normalizerto__init__inTslibBaseModelto pass the data scaler to the model.