Don't save `self` in `index` backward (#25594)
Summary:
`self` isn't necessary for `index` backward, we only need the shape of
`self`. Changing derivatives.yaml to use `zeros_like(self)` triggers a
codepath in the codegen to only save the shape.
Fixes https://github.com/pytorch/pytorch/issues/24853.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/25594
Test Plan:
- I added a new test that is adapted from the code in
https://github.com/pytorch/pytorch/issues/24853. I'm not sure what a
more minimal example would look like because the bug is hard to trigger
because of how autograd handles differential views.
Differential Revision: D17168645
Pulled By: zou3519
fbshipit-source-id: 11f270fed7370730984a93e4316dd937baa351a7