It depends how you would like to handle the targets during training.
You could use a custom collate_fn as a fix for this particular error in the DataLoader and return a list, which contains targets of different sizes.
However, I guess you would need to use a valid batch to calculate the loss during training, so you could e.g. use pad_sequence 104 or another valid approach.