-
Notifications
You must be signed in to change notification settings - Fork 761
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
Fix incorrect input routing for models #3186
Merged
Merged
Conversation
This file contains 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
shchur
added
bug
Something isn't working
bug fix
(one of pr required labels)
and removed
bug
Something isn't working
labels
May 31, 2024
shchur
commented
May 31, 2024
@@ -82,6 +82,14 @@ def make_distribution_forecast(distr, *args, **kwargs) -> Forecast: | |||
raise NotImplementedError | |||
|
|||
|
|||
def make_predictions(prediction_net, inputs: dict): | |||
# MXNet predictors only support positional arguments | |||
if prediction_net.__class__.__module__.startswith("gluonts.mx"): |
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.
I couldn't find a more elegant way to use different logic for MXNet and PyTorch models :/
I tried @singledispatch
, but that doesn't work for subclasses (i.e., we'd need to define it for all subclasses of pl.LightningModule
in GluonTS, and same for MXNet).
lostella
added
pending v0.15.x backport
This contains a fix to be backported to the v0.15.x branch
pending v0.14.x backport
This contains a fix to be backported to the v0.14.x branch
labels
May 31, 2024
lostella
approved these changes
May 31, 2024
lostella
pushed a commit
to lostella/gluonts
that referenced
this pull request
May 31, 2024
Fixes awslabs#3185 *Description of changes:* There is currently a bug where the model inputs may be routed incorrect by the forecast generator. This effectively results in `past_feat_dynamic_real` and `past_feat_dynamic_cat` being ignored by the TFT model. MWE: ```python from unittest import mock import numpy as np import pandas as pd from gluonts.torch.model.tft import TemporalFusionTransformerEstimator freq = "D" N = 50 data = [ {"target": np.arange(N), "past_feat_dynamic_real": np.random.rand(1, N).astype("float32"), "start": pd.Period("2020-01-01", freq=freq)} ] predictor = TemporalFusionTransformerEstimator(prediction_length=1, freq=freq, past_dynamic_dims=[1], trainer_kwargs={"max_epochs": 1}).train(data) with mock.patch("gluonts.torch.model.tft.module.TemporalFusionTransformerModel._preprocess") as mock_fwd: try: fcst = list(predictor.predict(data)) except: pass call_kwargs = mock_fwd.call_args[1] call_kwargs["feat_dynamic_cat"] # tensor([[[0.8073]]]) call_kwargs["past_feat_dynamic_real"] # None ``` The bug occurs because model inputs are passed as positional arguments instead of keyword arguments. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. **Please tag this pr with at least one of these labels to make our release process faster:** BREAKING, new feature, bug fix, other change, dev setup
Merged
lostella
added a commit
that referenced
this pull request
May 31, 2024
*Description of changes:* backporting fixes - #3186 By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. **Please tag this pr with at least one of these labels to make our release process faster:** BREAKING, new feature, bug fix, other change, dev setup Co-authored-by: Oleksandr Shchur <shchuro@amazon.com>
lostella
removed
the
pending v0.15.x backport
This contains a fix to be backported to the v0.15.x branch
label
May 31, 2024
kashif
pushed a commit
to kashif/gluon-ts
that referenced
this pull request
Jun 15, 2024
Fixes awslabs#3185 *Description of changes:* There is currently a bug where the model inputs may be routed incorrect by the forecast generator. This effectively results in `past_feat_dynamic_real` and `past_feat_dynamic_cat` being ignored by the TFT model. MWE: ```python from unittest import mock import numpy as np import pandas as pd from gluonts.torch.model.tft import TemporalFusionTransformerEstimator freq = "D" N = 50 data = [ {"target": np.arange(N), "past_feat_dynamic_real": np.random.rand(1, N).astype("float32"), "start": pd.Period("2020-01-01", freq=freq)} ] predictor = TemporalFusionTransformerEstimator(prediction_length=1, freq=freq, past_dynamic_dims=[1], trainer_kwargs={"max_epochs": 1}).train(data) with mock.patch("gluonts.torch.model.tft.module.TemporalFusionTransformerModel._preprocess") as mock_fwd: try: fcst = list(predictor.predict(data)) except: pass call_kwargs = mock_fwd.call_args[1] call_kwargs["feat_dynamic_cat"] # tensor([[[0.8073]]]) call_kwargs["past_feat_dynamic_real"] # None ``` The bug occurs because model inputs are passed as positional arguments instead of keyword arguments. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. **Please tag this pr with at least one of these labels to make our release process faster:** BREAKING, new feature, bug fix, other change, dev setup
lostella
removed
the
pending v0.14.x backport
This contains a fix to be backported to the v0.14.x branch
label
Nov 7, 2024
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.
Fixes #3185
Description of changes:
There is currently a bug where the model inputs may be routed incorrect by the forecast generator. This effectively results in
past_feat_dynamic_real
andpast_feat_dynamic_cat
being ignored by the TFT model.MWE:
The bug occurs because model inputs are passed as positional arguments instead of keyword arguments.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Please tag this pr with at least one of these labels to make our release process faster: BREAKING, new feature, bug fix, other change, dev setup