My bad, I missed out the dist when declaring the variable log_probs_plus_log_pi:
log_probs_plus_log_pi = (-0.5 * F * torch.cuda.FloatTensor([2 * math.pi * self.std**2] + dist).log() + pi.log()

Anyways, dist is definitely a part of the computational graph so what would happen if I deleted it from memory - would the backward pass be affected?