In the fist example, the reshape op is applied on the leaf node torch.arange(60, dtype=torch.float32, requires_grad=True), so a is no longer a leaf node (instead it represents the reshape op).
In the second example, changing the flag requires_grad of the node a doesn’t add an additional op on top it (a is still a leaf) so after the backward call, grad is properly assigned.
Note: to get a grad of the non-leaf node, use register_hook.