In my use case,
class M(nn.Module):
  def __init__(self):
    super().__init__()
    self.l = nn.Linear(10, 5)
    self.l2 = nn.Linear(5, 1)

  def forward(self, x):
    x = self.l(x)
    x = torch.exp(x)   # Want to hook this tensor in forward pass
    x = self.l2(x)
    return x

Actually, I could make forward hook by separating the former part into a single module something like this.
class FirstLayer(nn.Module):
  def __init__(self):
    super().__init__()
    self.l1 = nn.Linear(10, 5)

  def forward(self, x):
    x = self.l1(x)
    x = torch.exp(x)
    return x

m = FirstLayer()
m.register_forward_hook(lambda x: x)

However, I want to keep my module single so that I don’t care about other module.
Thanks,