I don’t know where the required shape of 7 is coming from, but from the docs:

h_n: tensor of shape (D∗num_layers,N,H out) containing the final hidden state for each element in the batch.

Given that you are using num_layers=2 and bidirectional=False, dim0 is expected to have the shape 2.