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