How do I access the hidden states of pre-trained torch models?

I am trying to access the hidden states of a huggingface (PyTorch) model. By state, I mean the internal representation obtain while sending an input into a model. Could someone please help with this?
I have seen some discussion on LSTM hidden states, but I don’t think that’s related to my problem.
For further information, please see my SO question (although its not needed) - pytorch - How do I get access to the "last_hidden_state" for code generation models in huggingface? - Stack Overflow