AttributeError: 'LSTM' object has no attribute 'weight_hh_l1'

Here is the code.

class EncoderBiLSTM(nn.Module):
    def __init__(self, hidden_size, pretrained_embeddings):
        self.hidden_size = hidden_size
        self.embedding_dim = pretrained_embeddings.shape[1]
        self.vocab_size = pretrained_embeddings.shape[0]
        self.num_layers = 2
        self.dropout = 0.1 if self.num_layers > 1 else 0
        self.bidirectional = True

        self.embedding = nn.Embedding(self.vocab_size, self.embedding_dim)
        self.embedding.weight.requires_grad = False  # 冻结,无需训练
        self.lstm = nn.LSTM(self.embedding_dim, 
                            batch_first = True,
                            dropout = self.dropout,
                            bidirectional = self.bidirectional)

        identity_init = torch.eye(self.hidden_size)
        here will report wrong.
        AttributeError: 'LSTM' object has no attribute 'weight_hh_l1'
        '''[identity_init]*4, dim=0))[identity_init]*4, dim=0))[identity_init]*4, dim=0))[identity_init]*4, dim=0))

lstm =nn.LSTM(...)

I have print the LSTM object’s state_dict(),‘weight_hh_l0’ is exactly there.
Is anyone coudl help me?

The error is about l0 or l1 ?Did you checked that l1 existed?

My bad, I forgot to introduce num_layers parameter. Thank you for your reply.