In my case,
x = torch.randn(10, 6, input_size).to(device)
lstm = nn.LSTM(input_size, hidden_size, num_layers, batch_first=True, bidirectional=True).to(device)
h0 = torch.randn(num_layers*2, int(x.size(0)), hidden_size).to(device) # 2 for bidirection 
c0 = torch.randn(num_layers*2, int(x.size(0)), hidden_size).to(device)
out, (hn, cn)  = lstm(x, (h0, c0))

Above code has no problem. But below case within the class sent AttributeError: ‘tuple’ object has no attribute ‘size’.
# Hyper Parameters 
from torchsummary import summary
import torch.optim as optim
num_classes = len(dataid)
input_size = num_classes+3
hidden_size = 256
num_layers = 2
# Model
class ScorePredRNN(nn.Module):
    def __init__(self, input_size, hidden_size, num_layers, num_classes):
        super(ScorePredRNN, self).__init__()
        self.hidden_size = hidden_size
        self.num_layers = num_layers
        self.lstm = nn.LSTM(input_size, hidden_size, num_layers, batch_first=True, bidirectional=True).to(device)
        self.fc = nn.Linear(hidden_size, num_classes)  # 2 for bidirection
   
    def forward(self, x):
        h0 = torch.randn(self.num_layers*2, int(x.size(0)), self.hidden_size).to(device) # 2 for bidirection 
        c0 = torch.randn(self.num_layers*2, int(x.size(0)), self.hidden_size).to(device)     
        # Forward propagate LSTM
        out, (hn, cn)  = self.lstm(x, (h0, c0))#(h0, c0))  # out: tensor of shape (batch_size, seq_length, hidden_size*2)
        # Decode the hidden state of the last time step
        out = self.fc(out[:, -1, :])
        return out
model = ScorePredRNN(input_size, hidden_size, num_layers,  num_classes)#.to(device) 
optimizer = optim.Adam(model.parameters())
criterion = nn.CrossEntropyLoss()
summary(model,(6, input_size))

I can’t find out why this error is occured.
Please help me.