By better, I think @Naruto-Sasuke means that your code would “look” better and would have less lines, therefore less surface area for software bugs. AFIK, Pytorch internally is able to see what are the variables that have been worked upon and is able to find the required grads, without us explicitly asking to calculate the grads for each of the branches.