RuntimeError: isDifferentiableType

mostafa_95: <p>I am attempting to train a nn model on data taken from csv with two inputs and one output, 1 hidden layer.<br>
The following  error is resulted.</p>
<p><strong>RuntimeError: isDifferentiableType(variable.scalar_type())INTERNAL ASSERT FAILED at “…/torch/csrc/autograd/functions/utils.h”:65, please report a bug to PyTorch.</strong></p>
<p>Here is my code :</p>
<pre><code class="lang-auto">import torch
import torch.nn as nn
import tensorflow as tf
import numpy as np 
#In=torch.tensor(np.transpose(X.values))
In = torch.tensor(X.to_numpy())
#Out=torch.tensor(y.values)
Out=torch.tensor(y.to_numpy())
n_in=X.shape[0]
n_h=4
n_out=y.shape[0]
#In= torch.tensor(X.values)
#Out=torch.tensor(y.values)
model = nn.Sequential(nn.Linear(n_in, n_h),
 nn.ReLU(),
 nn.Linear(n_h, n_out),
 nn.ReLU())
model = model.type(torch.LongTensor)
criterion = torch.nn.MSELoss()
optimizer = torch.optim.SGD(model.parameters(), lr=0.01)
for epoch in range(50):
 # Forward pass: Compute predicted y by passing x to the model
 y_pred = model(In)
 # Compute and print loss
 loss = criterion(y_pred, y)
 print('epoch: ', epoch,' loss: ', loss.item())
 # Zero gradients, perform a backward pass, and update the weights.
 optimizer.zero_grad()
 
 # perform a backward pass (backpropagation)
 loss.backward()
 
 # Update the parameters
 optimizer.step()```



</code></pre>
<p>Meanwhile when using random inputs, not errors occur.</p>
<p>To follow with the error<br>
Here is the detailed messages:</p>
<pre><code class="lang-auto">

/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
   1108         if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
   1109                 or _global_forward_hooks or _global_forward_pre_hooks):
-&gt; 1110             return forward_call(*input, **kwargs)
   1111         # Do not call functions when jit is used
   1112         full_backward_hooks, non_full_backward_hooks = [], []

/usr/local/lib/python3.7/dist-packages/torch/nn/modules/container.py in forward(self, input)
    139     def forward(self, input):
    140         for module in self:
--&gt; 141             input = module(input)
    142         return input
    143 

/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
   1108         if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
   1109                 or _global_forward_hooks or _global_forward_pre_hooks):
-&gt; 1110             return forward_call(*input, **kwargs)
   1111         # Do not call functions when jit is used
   1112         full_backward_hooks, non_full_backward_hooks = [], []

/usr/local/lib/python3.7/dist-packages/torch/nn/modules/linear.py in forward(self, input)
    101 
    102     def forward(self, input: Tensor) -&gt; Tensor:
--&gt; 103         return F.linear(input, self.weight, self.bias)
    104 
    105     def extra_repr(self) -&gt; str:

RuntimeError: isDifferentiableType(variable.scalar_type())INTERNAL ASSERT FAILED at "../torch/csrc/autograd/functions/utils.h":65, please report a bug to PyTorch. 
</code></pre>
<p><strong>Please help me with  this error.</strong></p>

ptrblck: <p>The error is raised as you are trying to convert the parameters to <code>LongTensor</code>s here:</p>
<pre><code class="lang-python">model = model.type(torch.LongTensor)
</code></pre>
<p>while floating point types are expected.<br>
The internal assert still looks wrong so feel free to create a GitHub issue linking to this topic so that we could improve the error message.</p>