This code illustrates your usage and the wrong flattening:
# setup
input_size = 42 
hidden_size = 128 
num_layers = 2

lstm = nn.LSTM(input_size=input_size, hidden_size=hidden_size,
                        num_layers=num_layers, batch_first=True)

batch_size, seq_len = 3, 4
x = torch.randn(batch_size, seq_len, input_size)
output, (hn, cn) = lstm(x)
print(output.shape) # [batch_size, seq_len, num_directions*hidden_size]
> torch.Size([3, 4, 128])
print(hn.shape) # [num_layers*num_directions, batch_size, hidden_size]
> torch.Size([2, 3, 128])
print(cn.shape) # [num_layers*num_directions, batch_size, hidden_size]
> torch.Size([2, 3, 128])

# this is most likely not what you want!
hn = hn.view(-1, hidden_size)
print(hn.shape) # [num_layers*num_directions*batch_size, hidden_size]
> torch.Size([6, 128])

I guess you might want to use the output (or its last step) instead of flattening the batch dimension into the layer/direction dim of the hidden state.