These two lines might increase the memory, if the appended tensors are still attached to the computation graph:
values.append(value)
log_probs.append(log_prob)

You could call detach() on them and see if the memory usage goes down.