In the last line you are re-creating a tensor, thus detaching the tensor from the computation graph.
I’m not sure, what self.labelInterest is, but it seems to be some kind of filter to get the current class.
Could you try to remove the creation of a new tensor and just return (1- dice)?