`model` must be a `LightningModule` or `torch._dynamo.OptimizedModule`, got `TemporalFusionTransformer`
Asked Answered
R

3

5

im trying to temporal fusion transformer from pytorch_forecasting module but im getting the error in trainer.fit method:model must be a LightningModule or torch._dynamo.OptimizedModule, got TemporalFusionTransformer.I'm just replicating this paper from 'towardsdatascience'.reference:https://towardsdatascience.com/temporal-fusion-transformer-time-series-forecasting-with-deep-learning-complete-tutorial-d32c1e51cd91#:~:text=T%20emporal%20F%20usion%20T,dynamics%20of%20multiple%20time%20sequences.

Ramer answered 13/4, 2023 at 7:51 Comment(0)
N
6

There has been an update to pytorch-forecasting requirements and pytorch lightning no longer imports as lightning.pytorch, but pytorch_lightning.

Changing this in pytorch-forecasting basemodel.py solved the issue for me.

Nonalcoholic answered 13/4, 2023 at 16:37 Comment(0)
S
3

Soffies' answer is basically correct. The fundamental reason is that import/from lightning.pytorch is incompatible with import/from pytorch_lightning. In pytorch_forecasting, the author uses import lightning.pytorch extensively. Therefore, all you need to do is to replace 'pytorch_lightning' with 'lightning.pytorch' in the your code. Additionally, I encountered this issue after updating to torch2

Springer answered 28/4, 2023 at 3:13 Comment(1)
would you recommend to change to lightning.pytorch or pytorch_lightening in the long run? Is any preferred?Kapp
G
1

replace your imports

from lightning.pytorch import Trainer #❌
from pytorch_lightning import Trainer #✅
Glutenous answered 30/3 at 0:28 Comment(1)
In my case i changed from 2nd to 1st. The 2nd one didn't work. but as I changed import from pytorch_lightning to lightning.pytorch, it worked.Thanks..Sandbox

© 2022 - 2024 — McMap. All rights reserved.