Open simonyelisey opened 5 months ago
please use the 0.7.0 branch and try?
@kashif
I cloned 0.7.0 branch but it has caused new error:
ImportError Traceback (most recent call last)
Cell In[5], line 5
3 from pts.model.time_grad import TimeGradEstimator
4 # from pts.model.transformer_tempflow import TransformerTempFlowEstimator
----> 5 from pts import Trainer
7 from diffusers import DEISMultistepScheduler
ImportError: cannot import name 'Trainer' from 'pts' (.../pytorch-ts/pts/__init__.py)
hmm that still looks like its the older stuff...
I solved ImportError from previous comment by adding trainer.py to pts from master to 0.7.0 and editing init.py in the same folder.
But I've got new error seems like #158
ValidationError Traceback (most recent call last)
Input In [22], in <cell line: 3>()
1 # scheduler = DEISMultistepScheduler(num_train_timesteps=150, beta_end=0.1)
----> 3 estimator = TimeGradEstimator(
4 target_dim=int(electricity.metadata.feat_static_cat[0].cardinality),
5 prediction_length=electricity.metadata.prediction_length,
6 context_length=electricity.metadata.prediction_length,
7 cell_type='GRU',
8 input_size=1288,
9 freq=electricity.metadata.freq,
10 loss_type='l2',
11 scaling=True,
12 diff_steps=100,
13 beta_end=0.1,
14 beta_schedule="linear",
15 trainer=Trainer(
16 device=device,
17 epochs=1,
18 learning_rate=1e-3,
19 num_batches_per_epoch=3,
20 batch_size=64,
21 )
22 )
...
343 object_setattr(__pydantic_self__, '__dict__', values)
ValidationError: 1 validation error for TimeGradEstimatorModel
scheduler
field required (type=value_error.missing)
Any thoughts?
right you need also now give the esitmator the diffusers scheduler... see a running example here: https://github.com/kashif/time_match/blob/main/Time-Grad-Solar.ipynb
also don't think the trainer stuff from pts is needed as the 0.7.0 branch uses gluont's trainer
@kashif above comments helped to move ahead, but I've got next error:
TypeError Traceback (most recent call last)
Input In [35], in <cell line: 1>()
----> 1 predictor = estimator.train(electricity_dataset_train, cache_data=True, shuffle_buffer_length=1024)
File ~/anaconda3/envs/env1/lib/python3.9/site-packages/gluonts/torch/model/estimator.py:246, in PyTorchLightningEstimator.train(self, training_data, validation_data, shuffle_buffer_length, cache_data, ckpt_path, **kwargs)
237 def train(
238 self,
239 training_data: Dataset,
(...)
244 **kwargs,
245 ) -> PyTorchPredictor:
--> 246 return self.train_model(
247 training_data,
248 validation_data,
249 shuffle_buffer_length=shuffle_buffer_length,
250 cache_data=cache_data,
251 ckpt_path=ckpt_path,
252 ).predictor
File ~/anaconda3/envs/env1/lib/python3.9/site-packages/gluonts/torch/model/estimator.py:209, in PyTorchLightningEstimator.train_model(self, training_data, validation_data, from_predictor, shuffle_buffer_length, cache_data, ckpt_path, **kwargs)
200 custom_callbacks = self.trainer_kwargs.pop("callbacks", [])
201 trainer = pl.Trainer(
202 **{
203 "accelerator": "auto",
...
--> 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 `TimeGradLightningModule`
right cause pytorch-lighting has changed its API... so in the lightning module file of time-grad do:
from lightning import LightningModule
and then subclass from that:
class TimeGradLightningModule(LightningModule):
https://github.com/zalandoresearch/pytorch-ts/issues/159#issuecomment-1908199600 helped to solve previous issue but now after all epochs I'm getting new error:
ValidationError Traceback (most recent call last)
Input In [39], in <cell line: 1>()
----> 1 predictor = estimator.train(electricity_dataset_train, cache_data=True, shuffle_buffer_length=1024)
File ~/anaconda3/envs/env1/lib/python3.9/site-packages/gluonts/torch/model/estimator.py:246, in PyTorchLightningEstimator.train(self, training_data, validation_data, shuffle_buffer_length, cache_data, ckpt_path, **kwargs)
237 def train(
238 self,
239 training_data: Dataset,
(...)
244 **kwargs,
245 ) -> PyTorchPredictor:
--> 246 return self.train_model(
247 training_data,
248 validation_data,
249 shuffle_buffer_length=shuffle_buffer_length,
250 cache_data=cache_data,
251 ckpt_path=ckpt_path,
252 ).predictor
File ~/anaconda3/envs/env1/lib/python3.9/site-packages/gluonts/torch/model/estimator.py:230, in PyTorchLightningEstimator.train_model(self, training_data, validation_data, from_predictor, shuffle_buffer_length, cache_data, ckpt_path, **kwargs)
223 else:
224 best_model = training_network
226 return TrainOutput(
227 transformation=transformation,
...
343 object_setattr(__pydantic_self__, '__dict__', values)
ValidationError: 1 validation error for PyTorchPredictorModel
device
str type expected (type=type_error.str)
Seems like I need to pass device
argument but I can't understand where should I pass it to.
Tried to pass it to estimator.train(device='cpu')
but I got the same error.
hmm let me think i thought i fixed this issue as well... are you sure you are on the 0.7.0 branch?
actually try: pip install -U gluonts
@kashif yes I'm on branch 0.7.0. https://github.com/zalandoresearch/pytorch-ts/issues/159#issuecomment-1910119265 didn't help.
so in the estimator set the device to a string:
...
return PyTorchPredictor(
input_transform=transformation + prediction_splitter,
input_names=PREDICTION_INPUT_NAMES,
prediction_net=module,
batch_size=self.batch_size,
prediction_length=self.prediction_length,
device="cuda" if torch.cuda.is_available() else "CPU",
)
That works! Thank you @kashif so much!
Hi folks!
I'm trying to reproduce Time-Grad example notebook and getting this error:
Does anybody know solution?
Dependencies: