Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Chunking issue for LSTM forecasting #87

Open
RabbITCybErSeC opened this issue Apr 19, 2022 · 1 comment
Open

[BUG] Chunking issue for LSTM forecasting #87

RabbITCybErSeC opened this issue Apr 19, 2022 · 1 comment

Comments

@RabbITCybErSeC
Copy link

RabbITCybErSeC commented Apr 19, 2022

Describe the bug

Hi, I am trying to implement the LSTM method on the Itrust SWAT datasets using Merlion. However, I am running into a chunking issue for LSTM. LSTM is the only model where I encounter this issue. I resampled the training_data for every second to have a consistent interval. However, the issue remains. I wonder whether this is a bug or a problem in my code.

Lastly, do you have an example notebook with an LSTM example? So far, I wasn't able to identify any LSTM example configs. Making it hard to try something out quickly.

To Reproduce

Below I have the code for my LSTM model.

from merlion.models.forecast.prophet import Prophet, ProphetConfig
from merlion.models.forecast.smoother import MSES, MSESConfig
from merlion.models.forecast.lstm import LSTM, LSTMConfig, LSTMTrainConfig
from merlion.models.forecast.base import ForecasterBase

lstm_config = LSTMConfig(len(test_data),
                         nhid=100,
                         model_strides=(1,),
                         target_seq_index=None,
                         transform=None,
                         max_score=1,
                         threshold=None,
                         enable_calibrator=True,
                         enable_threshold=True)

training_config_lstm = LSTMTrainConfig(lr=1e-05,
                                       batch_size=500,
                                       epochs=100,
                                       seq_len=30,
                                       data_stride=1,
                                       valid_split=0.2,
                                       checkpoint_file='checkpoint.pt')


lstm = LSTM(lstm_config)
lstm.train(training_data,train_config=training_config_lstm)

Expected behavior
No, chunking problem.

Screenshots

RuntimeError                              Traceback (most recent call last)
/tmp/ipykernel_62686/1285329270.py in <module>
   62 
   63 lstm = LSTM(lstm_config)
---> 64 lstm.train(training_data,train_config=training_config_lstm)
   65 #len(test_data)

~/.local/lib/python3.9/site-packages/merlion/models/forecast/lstm.py in train(self, train_data, train_config)
  303                         batch = batch.cuda()
  304                     self.optimizer.zero_grad()
--> 305                     out = self.model(batch[:, : -(self.max_forecast_steps + 1)], future=self.max_forecast_steps)
  306                     loss = F.l1_loss(out, batch[:, 1:])
  307                     loss.backward()

~/.local/lib/python3.9/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
 1108         if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
 1109                 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1110             return forward_call(*input, **kwargs)
 1111         # Do not call functions when jit is used
 1112         full_backward_hooks, non_full_backward_hooks = [], []

~/.local/lib/python3.9/site-packages/merlion/models/forecast/lstm.py in forward(self, input, future)
  198         :return: the predicted values including both 1-step predictions and the future step predictions
  199         """
--> 200         outputs = [rnn(input[:, ::stride]) for stride, rnn in zip(self.strides, self.rnns)]
  201         batch_sz, dim = outputs[0].shape
  202         preds = [

~/.local/lib/python3.9/site-packages/merlion/models/forecast/lstm.py in <listcomp>(.0)
  198         :return: the predicted values including both 1-step predictions and the future step predictions
  199         """
--> 200         outputs = [rnn(input[:, ::stride]) for stride, rnn in zip(self.strides, self.rnns)]
  201         batch_sz, dim = outputs[0].shape
  202         preds = [

~/.local/lib/python3.9/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
 1108         if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
 1109                 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1110             return forward_call(*input, **kwargs)
 1111         # Do not call functions when jit is used
 1112         full_backward_hooks, non_full_backward_hooks = [], []

~/.local/lib/python3.9/site-packages/merlion/models/forecast/lstm.py in forward(self, input)
  146         self.reset(bsz=input.size(0))
  147 
--> 148         for i, input_t in enumerate(input.chunk(input.size(1), dim=1)):
  149             self.h_t, self.c_t = self.lstm1(input_t, (self.h_t, self.c_t))
  150             self.h_t2, self.c_t2 = self.lstm2(self.h_t, (self.h_t2, self.c_t2))

RuntimeError: chunk expects `chunks` to be greater than 0, got: 0

Desktop (please complete the following information):

  • OS: [e.g. Ubuntu 21.10 LTS]
  • Merlion Version [e.g. 1.0.0]

Additional context

Thank you for considering my issue.
If any more information is required please let me know.

@RabbITCybErSeC RabbITCybErSeC changed the title [BUG] Chucking issue for LSTM forecasting [BUG] Chunking issue for LSTM forecasting Apr 19, 2022
@AlvinAi96
Copy link

I got the same problem. It seems that LSTM is hard to compatible with the self-define train config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants