Thank you for the explanation. If it is a common source of bugs, then raising an error makes sense.
Is it possible to make the message more helpful? It can say that backward() / autograd.grad() is called on a tensor that does not require_grad or does not have grad_fn; make sure to call it from under enable_grad / not under no_grad.
I.e. the part “element 0 of tensors” is misleading, and some guidance on why the tensors may miss grad_fn can be helpful too. Not sure that my example addresses all failure cases though.