Even if I did, that shouldn’t be a problem for now because the memory increases even without that part.
Anyways, the rest of the training code looks like this
def training(self):
    model = modeler(num1, num2, K)
    if self.cuda_available == True: 
        model = model.cuda(self.cuda)
        
    criterion = torch.nn.MarginRankingLoss(margin=self.margin)
    optimizer = optim.SGD(model.parameters(), lr = self.lRate)

    for epoch in range(numEpoch):
        filename = 'somefile.pkl'
    
        data = pkl.load(open(filename))           
        train_by_dataloader = Dataset_triplet(data)
        train_loader = DataLoader(dataset=train_by_dataloader, batch_size=self.batch_size, shuffle=True)
    
    
        for batch_idx, batch in enumerate(train_loader):
            u = Variable(batch['u'])
            i = Variable(batch['i'])
            j = Variable(batch['j'])
            optimizer.zero_grad()
    
            pos, reg = model(u, i)
            neg, _ = model(u, j)
    
         if self.cuda_available == True:
             loss = criterion(pos, neg, Variable(torch.FloatTensor([-1])).cuda(self.cuda))
         else:
             loss = criterion(pos, neg, Variable(torch.FloatTensor([-1])))
    
         loss += self.reg1 * reg
         loss.backward()
         optimizer.step()
    
    
         totalLoss += loss.item()