Hey everyone.
I’m trying to train this exmaple:

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
print(device)

class TwoLayerNet(torch.nn.Module):
    def __init__(self, D_in, H, D_out):
        super(TwoLayerNet, self).__init__()
        self.linear1 = torch.nn.Linear(D_in, H)
        self.linear2 = torch.nn.Linear(H, D_out)

    def forward(self, x):
        h_relu = self.linear1(x).clamp(min=0)
        y_pred = self.linear2(h_relu)
        return y_pred

m = TwoLayerNet(1, 10, 2)
m.to(device)

criterion = torch.nn.MSELoss(reduction='sum')
optimizer = torch.optim.SGD(m.parameters(), lr=1e-4)

y = m(torch.Tensor([[1]]).cuda())
loss = criterion(y, torch.Tensor([[1, 1]]).cuda())
optimizer.zero_grad()
loss.backward()

And I got an error
RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn