I think I elaborate on my example more precisely… First, the reason that I create this thread is to make a code more flexible.
I just want to collect some activation for visualization.
Something like this,
m = Model()
act = dict()
def f(m, i, o):
  act["m"] = o.detach().cpu()

m.layer.register_forward_hook(f)

If the target activation comes from module, there is no problem because register_forward_hook is in there. However, how to do the same thing for tensor? In my knowledge, this is the best one…
class Model(nn.Module):
  def __init__(self, act):
    super().__init__()
    self.act = act

  def register_act(self, act):
    self.act = act

  def forward(self, x):
    x = torch.something(x)
    self.act["m"] = x.detach()
    return x

While it works, I don’t like it  because the process of forward depends on self.act. Whenever I use this module, I have to consider the act. I think the hook makes us removing this irritation. I couldn’t figure out the appropriate use case of tensor version register_forward_hook for tensor, which is the reason that lots of specialists don’t implement this functionality.
Thanks anyway, your advice give me lots of useful insight.