Solved by spanev in post #2 
              
              
                Hi @smu226, 
You should be able to do it with hooks: 
global view_output
def hook_fn(module, input, output):
    global view_output
    view_output = output
net = Encoder()
hook = net.encoder[-2].register_forward_hook(hook_fn)
# call hook.remove() to remove

so after each forward pass you will find …