<p dir="auto">When the number of layers in the GRU and the number of layers in the hidden size do not match, the GPU throws an error while the CPU does not.</p>
<p dir="auto">The following snippet to illustrates the same:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="      rnn = torch.nn.GRU(input_size=5,hidden_size=4)
      x = torch.randn(3, 4, 5)
      hidden = torch.autograd.Variable(torch.randn(2, 4, 4))
      x = torch.autograd.Variable(x)
      if torch.cuda.is_available():
        rnn = rnn.cuda()
        x = x.cuda()
        hidden = hidden.cuda()
      rnn(x, hidden)"><pre lang="import" class="notranslate"><code class="notranslate">      rnn = torch.nn.GRU(input_size=5,hidden_size=4)
      x = torch.randn(3, 4, 5)
      hidden = torch.autograd.Variable(torch.randn(2, 4, 4))
      x = torch.autograd.Variable(x)
      if torch.cuda.is_available():
        rnn = rnn.cuda()
        x = x.cuda()
        hidden = hidden.cuda()
      rnn(x, hidden)
</code></pre></div>
<p dir="auto">I run RNN sucessfully with the code.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="rnn = nn.RNN(features, hidden_size, num_layers)
o, hidden = rnn(x, hidden)"><pre class="notranslate"><code class="notranslate">rnn = nn.RNN(features, hidden_size, num_layers)
o, hidden = rnn(x, hidden)
</code></pre></div>
<p dir="auto">and I run embedding example. Then, got RuntimeError.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="RuntimeError: inconsistent tensor size, expected r_ [5 x 25], t [5 x 25] and src [2 x 25] to 
have thesame number of elements, but got 125, 125 and 50 elements respectively at 
/opt/conda/conda-bld/pytorch_1503970438496/work/torch/lib/TH/generic/THTensorMath.c:887"><pre class="notranslate"><code class="notranslate">RuntimeError: inconsistent tensor size, expected r_ [5 x 25], t [5 x 25] and src [2 x 25] to 
have thesame number of elements, but got 125, 125 and 50 elements respectively at 
/opt/conda/conda-bld/pytorch_1503970438496/work/torch/lib/TH/generic/THTensorMath.c:887
</code></pre></div>
<p dir="auto">I set <code class="notranslate">batch_first=True</code> to use <code class="notranslate">Embedding</code></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="x.size is [5, 8, 15]
hidden_size is [5, 2, 25]"><pre class="notranslate"><code class="notranslate">x.size is [5, 8, 15]
hidden_size is [5, 2, 25]
</code></pre></div>
<p dir="auto">nothing seems wrong.<br>
And the error info seems not the dim problem?<br>
The error is so strange.</p>