I have the similar problem like this. My model returns two value,  pos_score and  neg_scores, first is the positive value the other is the sampled negative values.
My loss funciton like this:
def loss_function(pos_score, neg_scores):
		return  -torch.mean(torch.log(
				F.sigmoid(pos_score - neg_scores)),0) #BPR loss

I still cannot find where the preallocated buffer updated when I run the model on second time.
Could you please help me with that?Thanks!