This is the part of the Generator network. The error occurs in the last three line.
class TextEncoder(nn.Module):
    def __init__(self, hidden_size, embed_size, vocab_size, rnn_type, num_layers=1, bidirectional=True, dropout=0.5, num_convs=3):
        super(TextEncoder, self).__init__()
        self.bidirectional = bidirectional
        self.num_convs = num_convs
        self.embedding = nn.Embedding(vocab_size, embed_size)
        
        convs = []
        for _ in range(num_convs):
            conv_layer = nn.Sequential(
                    ConvNorm(embed_size,
                            embed_size,
                            kernel_size=5, stride=1,
                            padding=(5 - 1) // 2,
                            dilation=1, w_init_gain='relu'),
                    nn.BatchNorm1d(embed_size),
                    nn.ReLU(inplace=True))
            convs.append(conv_layer)
        self.conv = nn.ModuleList(convs)
        
        self.rnn = RNNModel(embed_size, hidden_size, rnn_type, num_layers, bidirectional)
        scale = 2 if bidirectional else 1
        self.fc = nn.Linear(hidden_size * scale, hidden_size)
        self.dropout = nn.Dropout(dropout)

    def forward(self, x):
        # seq_len X bs
        batch_size = x.shape[1]
        # seq_len X bs X emb_dim
        x = self.embedding(x)
        if self.num_convs > 0:
            # bs X emb_dim X seq_len
            x = x.permute(1, 2, 0)
            for layer in self.conv:
                x = layer(x)
            x = x.permute(2, 0, 1)
        x = self.dropout(x)

        # seq_len X bs X hid_size * num_direc, num_direc*num_layer*hid_size
        outputs, hidden = self.rnn(x)
        if self.bidirectional:
            hidden = torch.tanh(self.fc(torch.cat((hidden[-2,:,:], hidden[-1,:,:]), dim = 1))) # error occurs in this line
        else:
            hidden = torch.tanh(self.fc(hidden[-1,:,:]))
        return outputs, hidden