If you are gonna use the dataset class from Pytorch you will have whole control how your data is gonna load and you can ensure that no memory leak happens
for making pairs of batches you can use dataloader API and create batches of the dataset according to your need slr was quite preoccupied with work