This discussion may be helpful.
Usually, in such situations some sort of padding has to be introduced for each batch so all elements match in size. This can be achieved by defining your own collate_fn
that is then passed to DataLoader
as an argument.