sktime / pytorch-forecasting

Time series forecasting with PyTorch
https://pytorch-forecasting.readthedocs.io/
MIT License
4.02k stars 639 forks source link

ValueError on first epoch #1173

Open moorehousew opened 2 years ago

moorehousew commented 2 years ago

Expected behavior

I'm trying to do good ol' stock price prediction using TFT. I've followed the stallion example, changing the dataset configuration as required. I'm expecting the call to trainer.fit to work as it would normally...

Actual behaviour

...but it fails on the first training iteration with the traceback included below. I'm almost certain this is a trivial configuration mistake. Please let me know what I'm forgetting to include.

Code to reproduce the problem

Example dataset: MSFT, GOOG, AMZN, AAPL, META- 512 day ticker history (excl. weekends) Screenshot

Colab notebook here: https://colab.research.google.com/drive/1lF6DWoje_qD0PZysNu6UHaoqK9nDstBH?usp=sharing

Traceback:

ValueError                                Traceback (most recent call last)
Cell In [94], line 117
    102 tft = TemporalFusionTransformer.from_dataset(
    103     training,
    104     learning_rate = 0.03,
   (...)
    112     reduce_on_plateau_patience = 4
    113 )
    115 tft.size()
--> 117 trainer.fit(
    118     tft,
    119     train_dataloaders = [train_dataloader],
    120     val_dataloaders = [val_dataloader]
    121 )

[SNIPPED]

File ~/opt/miniconda3/lib/python3.9/site-packages/pytorch_lightning/strategies/strategy.py:378, in Strategy.training_step(self, *args, **kwargs)
    376 with self.precision_plugin.train_step_context():
    377     assert isinstance(self.model, TrainingStep)
--> 378     return self.model.training_step(*args, **kwargs)

File ~/opt/miniconda3/lib/python3.9/site-packages/pytorch_forecasting/models/base_model.py:410, in BaseModel.training_step(self, batch, batch_idx)
    406 def training_step(self, batch, batch_idx):
    407     """
    408     Train on batch.
    409     """
--> 410     x, y = batch
    411     log, out = self.step(x, y, batch_idx)
    412     return log

ValueError: not enough values to unpack (expected 2, got 1)
AjinkyaBankar commented 10 months ago

The error got resolved when I removed square brackets as:

    tft,
    train_dataloaders = train_dataloader,
    val_dataloaders = val_dataloader
)

Also, you need to include min_prediction_idx = training_cutoff + 1 in validation dataset creation steps.