To retrieve the hidden or cell states of the last (or any of the) hidden layers, the diagram in whats-the-difference-between-hidden-and-output-in-pytorch-lstm  107  is very helpful and makes it easy to understand.
In short, the number ranges from [0, 1, 2, 3, …, n] for [hidden_layer_1, hidden_layer_2, hidden_layer_3, …, hidden_layer_n] for n hidden layers.
So, with two hidden layers, the hidden  and cell states of the second (or last) hidden layer can be extracted using:



 kmario23:

first_hidden_layer_hidden_state = h_n[0] # torch.Size([1, 1500])
second_hidden_layer_hidden_state = h_n[-1] # torch.Size([1, 1500])


analogously for the cell state:



 kmario23:

first_hidden_layer_cell_state = c_n[0] # torch.Size([1, 1500])
second_hidden_layer_cell_state = c_n[-1] # torch.Size([1, 1500])