Here is a reproducible code:
import torch
from torch.utils.data import Dataset
from torch.utils.data.dataloader import DataLoader

class test(Dataset):
    def __init__(self):
        super(test, self).__init__()
        
    def __getitem__(self, idx):
        print(idx)
        return idx

    def __len__(self):
        return 100

test = test()
loader = DataLoader(dataset=test,
                    batch_size=2,
                    num_workers=1)

for data in loader:
    print(data)
    break

and it will print:
0
1
2
3
4
5
tensor([0, 1])

but why the index get printed multiple times? and if you change the batch_size to 1, it will give:
0
1
2
tensor([0])

torch==1.5.1
torchvision==0.6.0a0+35d732a