Hey, can you please check my code and let me know how to correct this error?
%%time
loss_arr = []
loss_epoch_arr = []
max_epochs = 30
for epoch in range(max_epochs):
for i, data in enumerate(trainloader, 0):

    inputs, labels = data
    inputs, labels = inputs.to(cuda0), labels.to(cuda0)
    

    opt.zero_grad()

    outputs = model(inputs)
    _,labels = torch.max(labels.data, 1)
    _, pred = torch.max(outputs.data, 1)
    loss = soft_dice_loss(pred, labels)
    loss.backward()
    opt.step()
    
    loss_arr.append(loss.item())
    
loss_epoch_arr.append(loss.item())
print('Epoch: %d/%d, valid Dloss: %0.2f, Train DLoss: %0.2f' % (epoch, max_epochs, evaluation(validloader, model), evaluation(trainloader, model)))

plt.plot(loss_epoch_arr)
plt.show()
“RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn”