RNN Layer, RunTimeError: sizes must be non-negative

import torch
import torch.nn as nn
rnn=nn.GRU(130, 1024, 5).cuda()
inp=torch.rand((960, 125, 130)).cuda()
hid=torch.zeros((5, 125, 1024)).cuda()

out, hid = rnn(inp, hid)

returns RuntimeError: sizes must be non-negative

I don’t understand why or what’s happening here.

If I run the same thing on CPU (same exact code, omitting all intances of .cuda()), it will work.

Could this be a problem of running out of GPU memory?

Does your GPU look like it is running out of memory? You can watch via nvidia-smi.

Do you have cudnn installed? what version of pytorch are you running?