So here is what I am doing

Defined the model class (myModel) using nn.Module
Now in training
called my model as outputs = myModel(inputs)

calculating  loss as loss = Crossentropy(outputs, targets)

Now I am not calling loss.backward(). I use: grads = grad(loss, model.paramaters())


I am getting the error that I mentioned above which means that somehow it is calling backward() function already. I want to prevent that automatic first call of backward().