One solution can be torch.utils.data.IterableDataset   where the length of datasets and batch size can be controlled by custom user-defined function in dataset class.
https://pytorch.org/docs/stable/data.html#iterable-style-datasets 1