RuntimeError: expected scalar type Double but found Float while tensor is already double

username: Saguaro
cooked: <p>I have come across a very usual error <code>RuntimeError: expected scalar type Double but found Float</code>. But the tensor is already <code>double</code>. So probably it comes from some different place which I don’t see…</p>
<p>It comes from here</p>
<pre><code class="lang-auto">h = self.batch_norms[layer](h)
</code></pre>
<p>Again <code>h</code> is <code>float64</code> (or double) and <code>layer</code> is <code>int</code>.<br>
By the way, <code>self.batch_norms</code> is simple <code>toch.nn.ModuleList</code>, i.e. <code>self.batch_norms = torch.nn.ModuleList()</code> declared in constructor.</p>
<p>Here is a full traceback</p>
<pre><code class="lang-auto">RuntimeError                              Traceback (most recent call last)
C:\Users\ROSTYS~1\AppData\Local\Temp/ipykernel_6476/2774919388.py in &lt;module&gt;
      1 for data in loader:
----&gt; 2     out = model(data.x, data.edge_index, deg)

~\anaconda3\envs\resal\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
   1049         if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
   1050                 or _global_forward_hooks or _global_forward_pre_hooks):
-&gt; 1051             return forward_call(*input, **kwargs)
   1052         # Do not call functions when jit is used
   1053         full_backward_hooks, non_full_backward_hooks = [], []

C:\Users\ROSTYS~1\AppData\Local\Temp/ipykernel_6476/730682502.py in forward(self, x, edge_index, deg)
     58             h = self.convs[layer](h=h, edge_index=edge_index, deg = deg)
     59             h = self.activation(h)
---&gt; 60             h = self.batch_norms[layer](h)
     61 
     62         if self.task == "node":

~\anaconda3\envs\resal\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
   1049         if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
   1050                 or _global_forward_hooks or _global_forward_pre_hooks):
-&gt; 1051             return forward_call(*input, **kwargs)
   1052         # Do not call functions when jit is used
   1053         full_backward_hooks, non_full_backward_hooks = [], []

~\anaconda3\envs\resal\lib\site-packages\torch\nn\modules\batchnorm.py in forward(self, input)
    165         used for normalization (i.e. in eval mode when buffers are not None).
    166         """
--&gt; 167         return F.batch_norm(
    168             input,
    169             # If buffers are not to be tracked, ensure that they won't be updated

~\anaconda3\envs\resal\lib\site-packages\torch\nn\functional.py in batch_norm(input, running_mean, running_var, weight, bias, training, momentum, eps)
   2279         _verify_batch_size(input.size())
   2280 
-&gt; 2281     return torch.batch_norm(
   2282         input, weight, bias, running_mean, running_var, training, momentum, eps, torch.backends.cudnn.enabled
   2283     )

RuntimeError: expected scalar type Double but found Float
</code></pre>
<p>Does somebody know, where is the problem?</p>
<p>Thanks!</p>

username: Saguaro
cooked: <p>Solution was to make sure that the model parameters are also double, i.e. <code>model.double()</code> helped</p>