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.
`model` must be a `LightningModule` or `torch._dynamo.OptimizedModule`, got `TemporalFusionTransformer`
Asked Answered
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.
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
would you recommend to change to lightning.pytorch or pytorch_lightening in the long run? Is any preferred? –
Kapp
replace your imports
from lightning.pytorch import Trainer #❌
from pytorch_lightning import Trainer #✅
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.