update field for torch 0.4

This commit is contained in:
Bryan Marcus McCann 2018-09-18 00:25:24 +00:00 committed by Bryan McCann
parent b82b510de5
commit 2838e23be1
1 changed files with 6 additions and 9 deletions

View File

@ -198,8 +198,7 @@ class Field(RawField):
if len(example) < max_len:
example += [pad_value] * (max_len - len(example))
tensor = torch.LongTensor(batch)
if device != -1:
tensor = tensor.cuda(device)
tensor = tensor.to(device)
else:
padded = self.pad(batch)
tensor = self.numericalize(padded, device=device, train=train, **kwargs)
@ -358,13 +357,11 @@ class Field(RawField):
if self.sequential and not self.batch_first:
arr.t_()
lim_arr.t_()
if device == -1:
if self.sequential:
arr = arr.contiguous()
lim_arr = lim_arr.contiguous()
else:
arr = arr.cuda(device)
lim_arr = lim_arr.cuda(device)
if self.sequential:
arr = arr.contiguous()
lim_arr = lim_arr.contiguous()
arr = arr.to(device)
lim_arr = lim_arr.to(device)
# if self.include_lengths:
# lengths = lengths.cuda(device)
if self.include_lengths: