From 222dbdb2039678564444b51fdd35975fce468fe1 Mon Sep 17 00:00:00 2001 From: Jethro Kuan Date: Thu, 24 Dec 2020 16:01:56 +0800 Subject: [PATCH] allow integer device for BatchEncoding (#9271) Fixes #9244 Co-authored-by: Jethro Kuan --- src/transformers/tokenization_utils_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/transformers/tokenization_utils_base.py b/src/transformers/tokenization_utils_base.py index beff5ed2f4..91966ba319 100644 --- a/src/transformers/tokenization_utils_base.py +++ b/src/transformers/tokenization_utils_base.py @@ -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(