Skip to content
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: prevent accumulation of SelectFields in PyTorchPredictor #2951

Merged
merged 3 commits into from
Aug 7, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/gluonts/torch/model/predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(
self.forecast_generator = forecast_generator
self.output_transform = output_transform
self.device = device
self.provided_fields = False
self.required_fields = ["forecast_start", "item_id", "info"]

def to(self, device) -> "PyTorchPredictor":
Expand All @@ -73,9 +74,11 @@ def network(self) -> nn.Module:
def predict(
self, dataset: Dataset, num_samples: Optional[int] = None
) -> Iterator[Forecast]:
self.input_transform += SelectFields(
self.input_names + self.required_fields, allow_missing=True
)
if self.provided_fields:
self.input_transform += SelectFields(
self.input_names + self.required_fields, allow_missing=True
)
self.provided_fields = True
inference_data_loader = InferenceDataLoader(
dataset,
transform=self.input_transform,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Cameronwood611 the problem is with the += which updates the predictor state every time .predict is invoked. Solution should be to either do here

input_transform = self.input_transform + SelectFields(...)
inference_data_loader = InferenceDataLoader(
    ...,
    transform=input_transform,
    ....,
)

or directly in the constructor

self.input_transform = input_transform + SelectFields(...)

and remove lines 76-78 from here.

Expand Down
Loading