I’m doing some permutation testing experiments, that is; iterating n times over the the model. I would like thus to randomly sample m samples from the total available samples. One way to do this is define the loader as a function, something like:
def get_loader(dataset, my_sampler_size):
    loader = torch.utils.data.DataLoader(
            dataset,
            batch_size=100,         
            num_workers=4,             
            sampler = SubSetRandSampler(torch.randint(0, len(dataset), (my_sampler_size,)) ), # SubSetRandSampler(range(1000)),
            shuffle= False, 
            pin_memory=True)
    return loader

Clearly, this function needs to be called before each iteration (permutation).
I there a neater way to do this?