The operations such as torch.sum and torch.abs shouldn’t change any behavior and I assume you might have used the code snippets in different parts of your original code.
Before the first backward call, all .grad attributes are set to None.
After the gradients were calculated for the very first time or after you’ve called .zero_grad() on the model or optimizer, the .grad attributes will be filled with values or zeros, respectively.
Let me know, if you get stuck and feel free to post a reproducible code snippet.