Solved by ptrblck in post #2 
              
              
                Since your forward method just combined the encoder with the decoder, you could use this code: 
model = autoencoder()
x = torch.randn(1, 4)
enc_output = model.encoder(x)

Of course, this wouldn’t work, if your model applies some other calls inside forward. 
Another approach would be to use forward h…