Hey,
Please refer to two different code snippets.
Y_prob = model(X) #Getting the output from the model
loss = criterion(Y_true, Y_prob) #Some arbitrary loss function used
.
.
.
loss.backward()

Snippet 2:
Y_prob = model(X) #Getting the output from the model
loss = criterion(Y_true, Y_prob) #Some arbitrary loss function used
Y_prob =  Y_prob.detach() #detaching the output from the graph
.
.
.
loss.backward()

I expected that the first snippet would obviously be error-free. Still, snippet 2 should have thrown an error as I am removing the model output from the graph itself, which will throw an error when I will call loss.backward() which will call the backward() of criterion and which will in-turn call for the backward of Y_prob but since Y_prob is already detached, it will throw an error as the grad_fn of the detached object will be None.
But surprisingly, both the snippets work well.  What is it that I am getting wrong here?