小编Oli*_*ver的帖子

应使用“torch.device”或传递字符串作为参数来设置“device”参数

我的数据迭代器当前在 CPU 上运行,因为device=0参数已被弃用。但我需要它与模型的其余部分等一起在 GPU 上运行。

这是我的代码:

pad_idx = TGT.vocab.stoi["<blank>"]
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)
Run Code Online (Sandbox Code Playgroud)

上面的代码给出了这个错误:

The `device` argument should be set by using `torch.device` or passing a string as an argument. This behavior will be deprecated …
Run Code Online (Sandbox Code Playgroud)

python nlp machine-learning deep-learning pytorch

5
推荐指数
1
解决办法
7798
查看次数

标签 统计

deep-learning ×1

machine-learning ×1

nlp ×1

python ×1

pytorch ×1