AccumulateGrad: ensure sparse tensor indices and values refcount is always 1 (#34559)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/34559
We check the use_count for indices and values when we avoid a clone
for sparse tensors. The sparse tensor grad itself might have a higher refcount
due to DDP hooks/dist autograd structures holding refs, but the indices and
values inside the sparse tensor should always have a refcount of 1.
ghstack-source-id: 99900534
Test Plan: waitforbuildbot
Differential Revision: D20375239
fbshipit-source-id: 6a654549d13071ab3451cef94259caf7627b575c