From 1f6be29792f4f15b9179caa89fa02d9b2a82c554 Mon Sep 17 00:00:00 2001 From: Jiaqi Date: Thu, 17 Dec 2020 16:58:14 +0800 Subject: [PATCH] cpu check --- mindspore/nn/optim/adam.py | 6 ++++++ mindspore/nn/optim/lazyadam.py | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/mindspore/nn/optim/adam.py b/mindspore/nn/optim/adam.py index e32990cd14..1a68287f9e 100755 --- a/mindspore/nn/optim/adam.py +++ b/mindspore/nn/optim/adam.py @@ -357,6 +357,12 @@ class Adam(Optimizer): if value not in ('CPU', 'Ascend', 'GPU'): raise ValueError("The value must be 'CPU', 'Ascend' or 'GPU', but got value {}".format(value)) + if self._target == "CPU" and value in('Ascend', 'GPU'): + raise ValueError("In the CPU environment, target cannot be set to 'GPU' and 'Ascend'.") + + if self._target == "Ascend" and value == 'GPU': + raise ValueError("In the Ascend environment, target cannot be set to 'GPU'.") + self._is_device = (value != 'CPU') self._target = value diff --git a/mindspore/nn/optim/lazyadam.py b/mindspore/nn/optim/lazyadam.py index 7f755b1392..2aab67f0dc 100644 --- a/mindspore/nn/optim/lazyadam.py +++ b/mindspore/nn/optim/lazyadam.py @@ -263,5 +263,11 @@ class LazyAdam(Optimizer): if value not in ('CPU', 'Ascend', 'GPU'): raise ValueError("The value must be 'CPU', 'Ascend' or 'GPU', but got value {}".format(value)) + if self._target == "CPU" and value in('Ascend', 'GPU'): + raise ValueError("In the CPU environment, target cannot be set to 'GPU' and 'Ascend'.") + + if self._target == "Ascend" and value == 'GPU': + raise ValueError("In the Ascend environment, target cannot be set to 'GPU'.") + self._is_device = (value != 'CPU') self._target = value