I am attempting to train a nn model on data taken from csv with two inputs and one output, 1 hidden layer.
The following error is resulted.
RuntimeError: isDifferentiableType(variable.scalar_type())INTERNAL ASSERT FAILED at “…/torch/csrc/autograd/functions/utils.h”:65, please report a bug to PyTorch.
Here is my code :
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()```
Meanwhile when using random inputs, not errors occur.
To follow with the error
Here is the detailed messages:
/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):
-> 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:
--> 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):
-> 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) -> Tensor:
--> 103 return F.linear(input, self.weight, self.bias)
104
105 def extra_repr(self) -> str:
RuntimeError: isDifferentiableType(variable.scalar_type())INTERNAL ASSERT FAILED at "../torch/csrc/autograd/functions/utils.h":65, please report a bug to PyTorch.
Please help me with this error.