From 1d3b80b7f9d399b49e622365109587288bb3bd2b Mon Sep 17 00:00:00 2001 From: yh_cc Date: Mon, 23 Dec 2019 10:37:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=5Fmove=5Fmodel=5Fto=5Fdevice?= =?UTF-8?q?=E4=B8=AD=E5=BD=93device=3Dtorch.device('cpu')=E4=BC=9A?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastNLP/core/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fastNLP/core/utils.py b/fastNLP/core/utils.py index d7092d48..27f266fa 100644 --- a/fastNLP/core/utils.py +++ b/fastNLP/core/utils.py @@ -223,8 +223,8 @@ def _move_model_to_device(model, device): model.cuda() return model else: - if not torch.cuda.is_available() and ( - device != 'cpu' or (isinstance(device, torch.device) and device.type != 'cpu')): + if not torch.cuda.is_available() and ((isinstance(device, str) and device!='cpu') or + (isinstance(device, torch.device) and device.type != 'cpu')): raise ValueError("There is no usable gpu. set `device` as `cpu` or `None`.") if isinstance(model, torch.nn.DataParallel):