Hi Yanli,
I am not sure whether tensor.register_hook will work, but the documentation mentioned that,

Forward and backward hooks defined on  module  and its submodules won’t be invoked anymore, unless the hooks are initialized in the  forward()  method.

Besides I need to first collect the whole gradient and then do some modification. Now I am turning to torch.distributed.all_reduce, but it will be easier if there is a way to do this via DistributedDataParallel.