'parameter types mismatch' when testing a saved model

I am trying to test a trained model on some new test data.

I load the model as below:

model = ModelClass(input_dim=input_dim, vocab_size=vocab_size, model_config=model_config)

Then I load the model_state_dict into this newly created model.

model_state_dict = torch.load(model_path)['model_state_dict']

Everything works fine till here.

When I however run a minibatch of the test data through this model, I get a

RuntimeError: parameter types mismatch. This error is originating from the forward pass of the Encoder RNN. Below is the Traceback:

  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 491, in __call__
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/rnn.py", line 192, in forward
    output, hidden = func(input, self.all_weights, hx, batch_sizes)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/_functions/rnn.py", line 323, in forward
    return func(input, *fargs, **fkwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/_functions/rnn.py", line 287, in forward

The data generating process is the same. I do not see where a types mismatch could come from. Can some one help me in debugging this?


Can you make sure to post the complete error text with full error message?

Also, if you are using GPU, make sure both data and model are in GPU while calling forward method.

@InnovArul, you were right, this mismatch was because model was not on GPU while the transfers where. I am closing this post.