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/encoders with fit from ds #829

Merged
merged 3 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion darts/models/forecasting/torch_forecasting_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,8 @@ def predict(
else future_covariates
)

if self.encoders.encoding_available:
# encoders are set when calling fit(), but not when calling fit_from_dataset()
if self.encoders is not None and self.encoders.encoding_available:
past_covariates, future_covariates = self.encoders.encode_inference(
n=n,
target=series,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def test_fit_with_fit_epochs(self, init_trainer):
input_chunk_length=IN_LEN, output_chunk_length=OUT_LEN, **kwargs
)
multiple_ts = [self.ts_pass_train] * 10
epochs = 42
epochs = 3

model.fit(multiple_ts, epochs=epochs)
init_trainer.assert_called_with(max_epochs=epochs, trainer_params=ANY)
Expand All @@ -491,7 +491,7 @@ def test_fit_from_dataset_with_epochs(self, init_trainer):
future_covariates=None,
max_samples_per_ts=None,
)
epochs = 42
epochs = 3

model.fit_from_dataset(train_dataset, epochs=epochs)
init_trainer.assert_called_with(max_epochs=epochs, trainer_params=ANY)
Expand All @@ -500,6 +500,24 @@ def test_fit_from_dataset_with_epochs(self, init_trainer):
model.fit_from_dataset(train_dataset, epochs=epochs)
init_trainer.assert_called_with(max_epochs=epochs, trainer_params=ANY)

def test_predit_after_fit_from_dataset(self):
model_cls, kwargs, _ = models_cls_kwargs_errs[0]
model = model_cls(
input_chunk_length=IN_LEN, output_chunk_length=OUT_LEN, **kwargs
)

multiple_ts = [self.ts_pass_train] * 10
train_dataset = model._build_train_dataset(
multiple_ts,
past_covariates=None,
future_covariates=None,
max_samples_per_ts=None,
)
model.fit_from_dataset(train_dataset, epochs=3)

# test predict() works after fit_from_dataset()
model.predict(n=1, series=multiple_ts[0])

def test_sample_smaller_than_batch_size(self):
"""
Checking that the TorchForecastingModels do not crash even if the number of available samples for training
Expand Down