Code sample in this section: https://github.com/Devinterview-io/pytorch-interview-questions?tab=readme-ov-file#code-example-autograd-in-action
x.grad is the partial derivative of w with respect to x, which is $\frac{\partial{w}}{\partial{z}}$ $\frac{\partial{z}}{\partial{x}}$
$\frac{\partial{w}}{\partial{z}}$ = $2x$
$\frac{\partial{z}}{\partial{x}}$ = $y$
Thus $\frac{\partial{w}}{\partial{z}}$ $\frac{\partial{z}}{\partial{x}}$ = $2zy$. $y$ was initialized to 4, and $z$ = $xy$ = 12. So $2zy$ = 2 times 12 times 4 = 96.
Likewise you can work out the value of y.grad using the chain rule as well, and it's 72.