I am not quite sure how to properly use a WeightedRandomSampler with a DataLoader. Both constructors take a batch_size argument. DataLoader also has an optional sampler argument. I am trying to use a WeightedRandomSampler as the sampler in my DataLoader as follows:
sampler = WeightedRandomSampler(trainset.sample_weights, batch_size=BATCH_SIZE, replacement=False)
trainloader = DataLoader(dataset=trainset, batch_size=BATCH_SIZE, num_workers=6, sampler=sampler)
valloader   = DataLoader(dataset=valset, batch_size=BATCH_SIZE, num_workers=6, shuffle=True)

However, when I iterate over the trainloader, I only get one batch!!! even though BATCH_SIZE=8 and len(trainset) is in the thousands!!! if I remove the sampler argument from my DataLoader, I get the correct number of batches of size 8 each with the last batch < 8. Why do I get only one batch when I pass the sampler to my DataLoader? I am new to torch and trying to learn it. I tried reading the source code, but really unclear as to what’s going on.