Hello @RaLo4 , I have the same problem but could not solve with this. Would you help me, too? I summarized my network below basically:
class Predictor(pl.LightningModule):
  def __init__(self, n_features):
    super().__init__()
    self.model = LSTM(n_features)
    self.criterion = nn.BCELoss()

  def forward(self, x, labels=None): 
    output = self.model(x)
    loss = 0
    if labels is not None:
      loss = self.criterion(output, labels)
    return loss, output

class LSTM(nn.Module): 
  def __init__(self, n_features, n_hidden=256, n_layers=3):        
    super().__init__()
    self.lstm = nn.LSTM( ... )
    self.classifier = nn.Sigmoid()            
  
  def forward(self, x):
    self.lstm.flatten_parameters()
    _, (hidden, _) = self.lstm(x)
    output = hidden[-1]
    return self.classifier(output)

This architecture causes the same error (batch size = 64):

Using a target size (torch.Size([64])) that is different to the input size (torch.Size([64, 256])) is deprecated. Please ensure they have the same size.