You are storing the computation graph in every iteration by appending loss directly to your logging:
losses.update(loss, input1.size(0))

Change this line to the following and check the memory issue again:
losses.update(loss.item(), input1.size(0))