[DDP][PT2D] Ignore gradient sync if the gradient is not defined (#120419)
From the test, accum_grad_hook can still be fired even if the gradient is None. We need to ignore the gradient sync for this case.
Differential Revision: [D54076485](https://our.internmc.facebook.com/intern/diff/D54076485/)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/120419
Approved by: https://github.com/yf225, https://github.com/XilunWu