You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

optim.py 1.5 kB

5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Copyright 2019 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """Mock the MindSpore mindspore/nn/optim.py."""
  16. from .cell import Cell
  17. class Parameter:
  18. """Mock the MindSpore Parameter class."""
  19. def __init__(self, learning_rate):
  20. self._name = "Parameter"
  21. self.default_input = learning_rate
  22. @property
  23. def name(self):
  24. """The property of name."""
  25. return self._name
  26. def __repr__(self):
  27. format_str = 'Parameter (name={name})'
  28. return format_str.format(name=self._name)
  29. class Optimizer(Cell):
  30. """Mock the MindSpore Optimizer class."""
  31. def __init__(self, learning_rate):
  32. super(Optimizer, self).__init__()
  33. self.learning_rate = Parameter(learning_rate)
  34. class Momentum(Optimizer):
  35. """Mock the MindSpore Momentum class."""
  36. def __init__(self, learning_rate):
  37. super(Momentum, self).__init__(learning_rate)
  38. self.dynamic_lr = False