I cannot reproduce the bug using some predefined tensors for data and target:
class MyDataset(Dataset):
    def __init__(self):
        self.data = torch.arange(10).float().view(-1, 1)
        self.target = torch.arange(10).float().view(-1, 1) + 1
        
    def __getitem__(self, index):
        x = self.data[index]
        y = self.target[index]
        data_dict={'data': x, 'target': y}
        return data_dict
    
    def __len__(self):
        return len(self.data)

dataset = MyDataset()
for batch in dataset:
    print(batch)

loader = DataLoader(dataset, batch_size=2, shuffle=True)
for batch in loader:
    print(batch)

Could you post an executable code snippet to reproduce this issue?