torch type mismatch error
See original GitHub issueWith python3.6, pytorch0.4.1, cuda9.0, I got the following error when I run train.py with timit example:
$ python train.py examples/timit/seq2seq_config.json
Traceback (most recent call last):
File "train.py", line 146, in <module>
run(config)
File "train.py", line 104, in run
run_state = run_epoch(model, optimizer, train_ldr, *run_state)
File "train.py", line 29, in run_epoch
loss = model.loss(batch)
File "/path/to/speech/models/seq2seq.py", line 57, in loss
out, alis = self.forward_impl(x, y)
File "/path/to/speech/models/seq2seq.py", line 68, in forward_impl
out, alis = self.decode(x, y)
File "/path/to/speech/models/seq2seq.py", line 103, in decode
hx = self.dec_rnn(ix.squeeze(dim=1), hx)
File "/path/to/lib64/python3.6/site-packages/torch/nn/modules/module.py", line 477, in __call__
result = self.forward(*input, **kwargs)
File "/path/to/lib64/python3.6/site-packages/torch/nn/modules/rnn.py", line 794, in forward
self.bias_ih, self.bias_hh,
File "/path/to/lib64/python3.6/site-packages/torch/nn/_functions/rnn.py", line 53, in GRUCell
gh = F.linear(hidden, w_hh)
File "/path/to/lib64/python3.6/site-packages/torch/nn/functional.py", line 1026, in linear
output = input.matmul(weight.t())
RuntimeError: Expected object of type torch.FloatTensor but found type torch.cuda.FloatTensor for argument #2 'mat2'
If I add torch.set_default_tensor_type('torch.cuda.FloatTensor')
in main function,
error becomes:
Traceback (most recent call last):
File "train.py", line 148, in <module>
run(config)
File "train.py", line 110, in run
dev_loss, dev_cer = eval_dev(model, dev_ldr, preproc)
File "train.py", line 57, in eval_dev
preds = model.infer(batch)
File "/path/to/speech/models/seq2seq.py", line 176, in infer
_, argmaxs = self.infer_decode(x, y, end_tok, max_len)
File "/path/to/speech/models/seq2seq.py", line 155, in infer_decode
if torch.sum(y.data == end_tok) == y.numel():
RuntimeError: Expected object of type torch.cuda.LongTensor but found type torch.LongTensor for argument #2 'other'
Do you have idea to solve this?
Issue Analytics
- State:
- Created 5 years ago
- Comments:9
Top Results From Across the Web
torch.where with input Tensor and other Scalar raises ... - GitHub
(1) fails with the error expected scalar type float but found double but (2) works. On closer inspection, it seems that dtype is...
Read more >python 3.x - Type mismatch in pytorch - Stack Overflow
I am trying my hands on PyTorch. I am getting this error: RuntimeError: Expected object ...
Read more >Type mismatch occurs in C++ code with torchscript
The reason of error is tensors generated in the model. Dtype setting in python code with torch.set_default_dtype() is not saved in torchscript.
Read more >I get a message about data type mismatch - Microsoft Support
This error indicates that Access cannot match an input value to the data type it expects for the value. For example, if you...
Read more >Struggling with Titanic competition: tensor type mismatch
I'm running into an error when I try to run the lr_learn tool, getting this error: RuntimeError: Expected object of type torch.cuda.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I managed to execute train.py, but not yet confirmed training was successful or not. The quick (and dirty) remedy to above error was:
And there was also error in train.py
After these, I got these warnings while training.