I think register_forward_hook 136 is good in this case.
def hook(module, input, output):
    setattr(module, "_value_hook", output)

for n, m in resnet101.named_modules():
    if n == "foo":
        m.register_forward_hook(hook)

resnet101(input)

for n, m in resnet101.named_modules():
    if n == "foo":
        in_output = m._value_hook