Sorry, I wasn’t clear.
f1 is the inverse of the cross-entropy losses and it needs to be calculated after every batch is forward propagated. So, new_value basically denotes the cross-entropy losses for that batch. I am trying to update the values in f1 and use it to calculate error as mentioned above, which will be used in calculating the final loss. After updating f1, calling loss.backward() is resulting in the above error. How can I update f1 in every iteration?