Hello, I’m new to PyTorch and I apologize if this is a stupid question, but I am really stuck with this problem. I have a Dataset created from Numpy objects X and y, and I want to create a DataLoader to pass batches of data to my model. I have another Numpy array users, with the same length as X and y, which tells me which data instance comes from which user (think an array like [0, 0, 0, 1, 1, 2, 2, 2,...]).
I want to batch the dataset such that each batch contains all instances from one user. The number of instances per user can vary, so the batch size is not fixed. I cannot figure out how to do this, but I feel like there should be an easy way that I’m just missing (is this what the batch_sampler argument is for?). Can anyone help with some pointers or a toy example?
Edited to clarify: There are multiple (X,y) pairs for each user in the dataset, and I want to assign all (X,y) pairs belonging to user 1 to batch 1, user 2 to batch 2, and so on. Hope that helps!