zalandoresearch / pytorch-ts

PyTorch based Probabilistic Time Series forecasting framework based on GluonTS backend
MIT License
1.21k stars 190 forks source link

Getting error in embedding #34

Open nocciolate opened 3 years ago

nocciolate commented 3 years ago

Hi, while trying to reproduce the simple example from the "quick start" section, I keep getting the follow error message:

`Traceback (most recent call last):
  File "C:/Users/User/PycharmProjects/binance_conda/NEW/test-123.py", line 73, in <module>
    predictor = estimator.train(training_data=training_data)
  File "C:\Users\User\AppData\Roaming\Python\Python38\site-packages\pts\model\estimator.py", line 148, in train
    return self.train_model(training_data).predictor
  File "C:\Users\User\AppData\Roaming\Python\Python38\site-packages\pts\model\estimator.py", line 133, in train_model
    self.trainer(
  File "C:\Users\User\AppData\Roaming\Python\Python38\site-packages\pts\trainer.py", line 52, in __call__
    output = net(*inputs)
  File "C:\ProgramData\Miniconda3\envs\binance_conda\lib\site-packages\torch\nn\modules\module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "C:\Users\User\AppData\Roaming\Python\Python38\site-packages\pts\model\deepar\deepar_network.py", line 246, in forward
    distr = self.distribution(
  File "C:\Users\User\AppData\Roaming\Python\Python38\site-packages\pts\model\deepar\deepar_network.py", line 221, in distribution
    rnn_outputs, _, scale, _ = self.unroll_encoder(
  File "C:\Users\User\AppData\Roaming\Python\Python38\site-packages\pts\model\deepar\deepar_network.py", line 168, in unroll_encoder
    embedded_cat = self.embedder(feat_static_cat)
  File "C:\ProgramData\Miniconda3\envs\binance_conda\lib\site-packages\torch\nn\modules\module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "C:\Users\User\AppData\Roaming\Python\Python38\site-packages\pts\modules\feature.py", line 30, in forward
    [
  File "C:\Users\User\AppData\Roaming\Python\Python38\site-packages\pts\modules\feature.py", line 31, in <listcomp>
    embed(cat_feature_slice.squeeze(-1))
  File "C:\ProgramData\Miniconda3\envs\binance_conda\lib\site-packages\torch\nn\modules\module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "C:\ProgramData\Miniconda3\envs\binance_conda\lib\site-packages\torch\nn\modules\sparse.py", line 124, in forward
    return F.embedding(
  File "C:\ProgramData\Miniconda3\envs\binance_conda\lib\site-packages\torch\nn\functional.py", line 1852, in embedding
    return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
RuntimeError: Expected tensor for argument #1 'indices' to have scalar type Long; but got torch.IntTensor instead (while checking arguments for embedding)
`
mayunhe-cs commented 3 years ago

I get the same error with you. By adding .long() after feat_static_cat at line 168 in deepar_network.py, the error may be fixed.

kashif commented 3 years ago

Thanks for the fix @mayunhe-cs I'll check how to make this be long by default.