Invalid Device id Error when I assign more device_ids

When I assign more than two devices to device_ids, it gives me an Invalid Device id Error. Though I am using almost the same code for different models for many gpus.

torch.backends.cudnn.benchmark = True
models = torch.nn.DataParallel(models, device_ids=[0, 1])