pytorch-forecasting: Type error when trying run trainer.fit with tft

  • PyTorch-Forecasting version: 1.0
  • PyTorch version: 2.0
  • Python version:
  • Operating System: running on google colab

Expected behavior

I executed code trainer.fit. It used to work and now I get a type error.

Actual behavior

I think it has to do with the april 10 release of pytorch-forecasting moving to pytorch 2.0

Code to reproduce the problem

trainer.fit( tft, train_dataloaders=train_dataloader, val_dataloaders=val_dataloader )

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
[<ipython-input-57-127e7bdaac70>](https://localhost:8080/#) in <cell line: 1>()
----> 1 trainer.fit(
      2     tft,
      3     train_dataloaders=train_dataloader,
      4     val_dataloaders=val_dataloader
      5 )

1 frames
[/usr/local/lib/python3.9/dist-packages/pytorch_lightning/utilities/compile.py](https://localhost:8080/#) in _maybe_unwrap_optimized(model)
    123     if isinstance(model, pl.LightningModule):
    124         return model
--> 125     raise TypeError(
    126         f"`model` must be a `LightningModule` or `torch._dynamo.OptimizedModule`, got `{type(model).__qualname__}`"
    127     )

TypeError: `model` must be a `LightningModule` or `torch._dynamo.OptimizedModule`, got `TemporalFusionTransformer`

Paste the command(s) you ran and the output. Including a link to a colab notebook will speed up issue resolution. If there was a crash, please include the traceback here. The code used to initialize the TimeSeriesDataSet and model should be also included.

About this issue

Most upvoted comments

I suggest you to perform the following changes:

import lightning.pytorch as pl # Instead of import pytorch_lightning as pl

# [...]
# Also the way callbacks are imported should be slightly modified.
from lightning.pytorch.callbacks.early_stopping import EarlyStopping
from lightning.pytorch.callbacks import LearningRateMonitor

Everything is up to date in the usage examples section: https://github.com/jdb78/pytorch-forecasting

I use the same version and there is the same problem

pytorch-forecasting==1.0.0 pytorch-lightning==2.0.1.post0 torch==2.0.0

TypeError: model must be a LightningModule or torch._dynamo.OptimizedModule, got TemporalFusionTransformer

Had the same issue but change pytorch_lighting to lightning.pytorch and resolved.

same problem!!!