Hi, thanks for the reply. The model outputs a total of three values, and I’m only using two right now:
output1, output2, _ = self.model(input_profiles_pos, input_drugs_pos)
neg_output1, output2, _ = self.model(input_profiles_neg, input_drugs_neg)

loss = self.criterion(output2, output1, neg_output1)

Just for some random background information, this is a bioinformatics project and profiles and drugs refer to genes and chemical compounds. self.criterion is triplet loss.
Each of the outputs’ .grad_fn returns:
>>> output1.grad_fn
<CopyBackwards object at 0x7f2caeee7278>
>>> neg_output1.grad_fn
<CopyBackwards object at 0x7f2caeee7278>

The code that I’m using is fairly long, but I’ll edit it into the original question.
I’m also not using any .detach or .data calls in the code.