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