cur_z_arr[j].grad is None after when the code is executed. I don\'t know why. I also tried cur_z_arr[j].retain_grad() right before energy.backward()