I change a little bit code to use it with resnet18
import torch
import torch.nn as nn
from torch.utils.data import Dataset, DataLoader
import torchvision.models as models

# Parameters and DataLoaders
input_size = 224
output_size = 1000

batch_size = 256
data_size = 10000

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

class RandomDataset(Dataset):

    def __init__(self, size, length):
        self.len = length
        self.data = torch.randn(length, 3 * size * size).view(length, 3, size, size)

    def __getitem__(self, index):
        return self.data[index]

    def __len__(self):
        return self.len

rand_loader = DataLoader(dataset=RandomDataset(input_size, data_size),
                         batch_size=batch_size, shuffle=True)

model = models.resnet18(pretrained=True)
if torch.cuda.device_count() > 1:
  print("Let's use", torch.cuda.device_count(), "GPUs!")
  model = nn.DataParallel(model)
model.to(device)

for data in rand_loader:
  input = data.to(device)
  output = model(input)
  print("Outside: input size", data.size(),
        "output_size", output.size())

However, using “batch_size=256” on single and multiple GPUs I see the same time (2m6.530s).