Hi, thanks for your reply. I have a question inside the hook_fn.
Why you use grad.clone() inside the hook function, can’t we just use
def hook_fn(grad):
    grad[mask] = 0
    return grad

I notice your comment “you are not allowed to modify inplace what is given”
Does this mean we need to clone gradient inside register_hook functions for tensors?
Since the tow functions have the same return values.
Thanks a lot.