Improve basicAutogradNotImplementedFallback + new tests (#105591)
This PR:
- removes some reference count bumps (to potentially improve overhead)
- adds some tests for undefined gradients
Pull Request resolved: https://github.com/pytorch/pytorch/pull/105591
Approved by: https://github.com/soulitzer