GRUCell and LSTMCell on GPU do not support broadcasting, while RNNCell supports broadcasting on both CPU and GPU. This inconsistency is not expected and not documented.
Here's the example code:
import torch
import torch.nn as nn
from torch.autograd import Variable
rnn = nn.RNNCell(10, 20)
gru = nn.GRUCell(10, 20)
input = Variable(torch.randn(3, 10))
h0 = Variable(torch.randn(1, 20)) # this should be (3, 20)
# both cells support broadcasting on CPU
hx_rnn = rnn(input, h0)
hx_gru = gru(input, h0)
assert hx_rnn.size() == hx_gru.size()
# send models and variables to GPU
rnn.cuda()
gru.cuda()
input = input.cuda()
h0 = h0.cuda()
# RNNCell is OK
try:
hx_rnn_cuda = rnn(input, h0)
except RuntimeError as e:
print('rnn error\n', e)
# GRUCell on GPU does not support broadcasting
try:
hx_gru_cuda = gru(input, h0)
except RuntimeError as e:
print('gru error\n', e)
The output of this example is:
gru error
invalid argument 3: Input and Hidden tensor sizes should be the same. at /pytorch/torch/lib/THCUNN/generic/FusedRNNKernel.cu:19
Is this a known issue or not expected?
GRUCell and LSTMCell on GPU do not support broadcasting, while RNNCell supports broadcasting on both CPU and GPU. This inconsistency is not expected and not documented.
Here's the example code:
The output of this example is:
Is this a known issue or not expected?