Torch Run Time Error

I am using OpenNMT-py for an inference purpose, however, it started to show a RuntimeError.
Everything was working well, I thought this is more of a torch issue. Any one who faced this?

RuntimeError: invalid argument 2: dimension 0 out of range of 0D tensor at /pytorch/torch/lib/TH/generic/THTensor.c:24

Many Thanks!

Do you know what line of code caused the RuntimeError?

Hi Richard,

This is the traceback am getting

Traceback (most recent call last):
File “/OpenNMT-py/translate.py”, line 213, in
main(opt)
File “/OpenNMT-py/translate.py”, line 143, in main
= translator.translate(srcBatch, tgtBatch)
File “/OpenNMT-py/onmt/Translator.py”, line 326, in translate
batch = dataset[0]
File “/OpenNMT-py/onmt/Dataset.py”, line 107, in getitem
dtype=self._type)
File “/OpenNMT-py/onmt/Dataset.py”, line 55, in _batchify
lengths = [x.size(0) for x in data]
File “/OpenNMT-py/onmt/Dataset.py”, line 55, in
lengths = [x.size(0) for x in data]
RuntimeError: invalid argument 2: dimension 0 out of range of 0D tensor at /pytorch/torch/lib/TH/generic/THTensor.c:24

Okay, so somewhere in data you have a 0D tensor that shouldn’t be there. If you just initialize a tensor like the following: x = torch.Tensor() you’d get the 0D tensor.

Maybe try checking your inputs to make sure all of the tensors were created properly?

1 Like