mindspore.nn.optim_ex.Optimizer

class mindspore.nn.optim_ex.Optimizer(params, defaults)[source]

Base class for all optimizers.

Warning

This is an experimental optimizer API that is subject to change. This module must be used with lr scheduler module in LRScheduler Class .

Parameters
  • params (Union[list(Parameter), list(dict)]) – an iterable of mindspore.Parameter or dict. Specifies what Tensors should be optimized.

  • defaults – (dict): a dict containing default values of optimization options (used when a parameter group doesn’t specify them).

Raises
  • TypeError – If learning_rate is not one of int, float, Tensor.

  • TypeError – If element of parameters is neither Parameter nor dict.

  • TypeError – If weight_decay is neither float nor int.

  • ValueError – If weight_decay is less than 0.

  • ValueError – If learning_rate is a Tensor, but the dimension of tensor is greater than 1.

Supported Platforms:

Ascend GPU CPU

add_param_group(group_id, param_group)[source]

Add a param group to the Optimizer.param_groups.

Parameters
  • group_id (int) – Specifies the group index.

  • param_group (dict) – Specifies what Parameters should be optimized along with group specific optimization options.