allow integer device for BatchEncoding (#9271)

Fixes #9244

Co-authored-by: Jethro Kuan <jethro.kuan@bytedance.com>
This commit is contained in:
Jethro Kuan
2020-12-24 16:01:56 +08:00
committed by GitHub
parent 6c091abef2
commit 222dbdb203

View File

@@ -781,7 +781,7 @@ class BatchEncoding(UserDict):
# This check catches things like APEX blindly calling "to" on all inputs to a module
# Otherwise it passes the casts down and casts the LongTensor containing the token idxs
# into a HalfTensor
if isinstance(device, str) or isinstance(device, torch.device):
if isinstance(device, str) or isinstance(device, torch.device) or isinstance(device, int):
self.data = {k: v.to(device=device) for k, v in self.data.items()}
else:
logger.warning(