sktime / pytorch-forecasting

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

[DOC] How does one initialise a network without `from_dataset`? #1548

Open chrism2671 opened 6 months ago

chrism2671 commented 6 months ago

Expected behavior

Code:

from pytorch_forecasting.models import NBeats, BaseModel
from pytorch_lightning import Trainer, LightningModule

model = NBeats()
trainer.fit(model, train, valid)

Result:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
[<ipython-input-102-a9a3146dfc98>](https://localhost:8080/#) in <cell line: 1>()
----> 1 trainer.fit(model, train,valid)

1 frames
[/usr/local/lib/python3.10/dist-packages/pytorch_lightning/utilities/compile.py](https://localhost:8080/#) in _maybe_unwrap_optimized(model)
    130         return model
    131     _check_mixed_imports(model)
--> 132     raise TypeError(
    133         f"`model` must be a `LightningModule` or `torch._dynamo.OptimizedModule`, got `{type(model).__qualname__}`"
    134     )

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

I'm trying to use the naked networks without the rest of the stuff around pytorch_forecasting.

I've read the source code I do believe this should work; but I must be doing something stupid.

Is it possible to add an example or FAQ of how to use pytorch_forecasting without from_dataset?

benHeid commented 1 week ago

You are using the old pytorch_lightning. I suppose you need to import lightning.pytorch instead.

TODO:

are you having a good location, where the extension of the documentation would fit? Would you like to contribute it?