The `device` argument should be set by using `torch.device` or passing a string as an argument
My data iterator currently runs on the CPU as device=0 argument is deprecated. But I need it to run on the GPU with the rest of the model etc. 

Here is my code: 

pad_idx = TGT.vocab.stoi["&lt;blank&gt;"]
model = make_model(len(SRC.vocab), len(TGT.vocab), N=6)
model = model.to(device)
criterion = LabelSmoothing(size=len(TGT.vocab), padding_idx=pad_idx, smoothing=0.1)
criterion = criterion.to(device)
BATCH_SIZE = 12000
train_iter = MyIterator(train, device, batch_size=BATCH_SIZE,
                        repeat=False, sort_key=lambda x: (len(x.src), len(x.trg)),
                        batch_size_fn=batch_size_fn, train=True)
valid_iter = MyIterator(val, device, batch_size=BATCH_SIZE,
                        repeat=False, sort_key=lambda x: (len(x.src), len(x.trg)),
                        batch_size_fn=batch_size_fn, train=False)
#model_par = nn.DataParallel(model, device_ids=devices)


The above code gives this error: 

The `device` argument should be set by using `torch.device` or passing a string as an argument. This behavior will be deprecated soon and currently defaults to cpu.
The `device` argument should be set by using `torch.device` or passing a string as an argument. This behavior will be deprecated soon and currently defaults to cpu.


I have tried passing in 'cuda' as an argument instead of device=0 but I receive this error:

&lt;ipython-input-50-da3b1f7ed907&gt; in &lt;module&gt;()
    10     train_iter = MyIterator(train, 'cuda', batch_size=BATCH_SIZE,
    11                             repeat=False, sort_key=lambda x: (len(x.src), len(x.trg)),
---&gt; 12                             batch_size_fn=batch_size_fn, train=True)
    13     valid_iter = MyIterator(val, 'cuda', batch_size=BATCH_SIZE,
    14                             repeat=False, sort_key=lambda x: (len(x.src), len(x.trg)),

TypeError: __init__() got multiple values for argument 'batch_size'


I have also tried passing in device as an argument. Device being defined as device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')

But receive the same error as just above. 

Any suggestions would be much appreciated, thanks.

pad_idx = TGT.vocab.stoi["&lt;blank&gt;"]
model = make_model(len(SRC.vocab), len(TGT.vocab), N=6)
model = model.to(device)
criterion = LabelSmoothing(size=len(TGT.vocab), padding_idx=pad_idx, smoothing=0.1)
criterion = criterion.to(device)
BATCH_SIZE = 12000
train_iter = MyIterator(train, batch_size=BATCH_SIZE, device = torch.device('cuda'),
                        repeat=False, sort_key=lambda x: (len(x.src), len(x.trg)),
                        batch_size_fn=batch_size_fn, train=True)
valid_iter = MyIterator(val, batch_size=BATCH_SIZE, device = torch.device('cuda'),
                        repeat=False, sort_key=lambda x: (len(x.src), len(x.trg)),
                        batch_size_fn=batch_size_fn, train=False)


After lot's of trial and error I managed to set device as  device = torch.device('cuda') instead of device=0
