clean nn codec check

This commit is contained in:
jinxiaoxian 2021-06-09 15:00:11 +08:00
parent 5bcaae94a7
commit b16d7cd28f
3 changed files with 21 additions and 28 deletions

View File

@ -368,20 +368,7 @@ class Adam(Optimizer):
"""
If the input value is set to "CPU", the parameters will be updated on the host using the Fused
optimizer operation."""
if not isinstance(value, str):
raise TypeError("The value must be str type, but got value type is {}".format(type(value)))
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
self._set_base_target(value)
class AdamWeightDecay(Optimizer):

View File

@ -286,17 +286,4 @@ class LazyAdam(Optimizer):
"""
If the input value is set to "CPU", the parameters will be updated on the host using the Fused
optimizer operation."""
if not isinstance(value, str):
raise TypeError("The value must be str type, but got value type is {}".format(type(value)))
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
self._set_base_target(value)

View File

@ -248,6 +248,25 @@ class Optimizer(Cell):
optimizer operation."""
raise NotImplementedError
def _set_base_target(self, value):
"""
If the input value is set to "CPU", the parameters will be updated on the host using the Fused
optimizer operation."""
if not isinstance(value, str):
raise TypeError("The value must be str type, but got value type is {}".format(type(value)))
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
def decay_weight(self, gradients):
"""
Weight decay.