|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- mindspore.nn.Adagrad
- =====================
-
- .. py:class:: mindspore.nn.Adagrad(*args, **kwargs)
-
- ʹApplyAdagradʵAdagrad㷨
-
- AdagradѧϰŻ
- `Efficient Learning using Forward-Backward Splitting <https://proceedings.neurips.cc/paper/2009/file/621bf66ddb7c962aa0d22ac97d69b793-Paper.pdf>`_
- ʽ£
-
- .. math::
- \begin{array}{ll} \\
- h_{t+1} = h_{t} + g\\
- w_{t+1} = w_{t} - lr*\frac{1}{\sqrt{h_{t+1}}}*g
- \end{array}
-
- :math:`h` ʾݶƽۻͣ:math:`g` ʾ `grads`
- :math:`lr` `learning_rate`:math:`w` `params`
-
- .. note::
- ڲδʱŻõ `weight_decay` Ӧƺ"beta""gamma"ͨɵȨ˥ԡʱÿ `weight_decay` δãʹŻõ `weight_decay`
-
- ****
-
- - **params** (Union[list[Parameter], list[dict]]) - `Parameter` ɵбֵɵббԪֵʱֵļ"params""lr""weight_decay""grad_centralization""order_params"
-
- - **params** - ǰȨأֵ `Parameter` б
- - **lr** - ѡд"lr"ʹöӦֵΪѧϰʡûУʹŻõ `learning_rate` Ϊѧϰʡ
- - **weight_decay** - ѡд"weight_decay"ʹöӦֵΪȨ˥ֵûУʹŻõ `weight_decay` ΪȨ˥ֵ
- - **grad_centralization** - ѡд"grad_centralization"ʹöӦֵֵΪ͡ûУΪ `grad_centralization` ΪFalseòھ㡣
- - **order_params** - ѡӦֵԤڵIJ˳ʹò鹦ʱͨʹø `parameters` ˳ܡд"order_params"Ըе"order_params"еIJijһ `params` С
-
- - **accum** (float) - ۼ :math:`h` ijʼֵڵ㡣Ĭֵ0.1
- - **learning_rate** (Union[float, Tensor, Iterable, LearningRateSchedule]) - Ĭֵ0.001
-
- - **float** - ̶ѧϰʡڵ㡣
- - **int** - ̶ѧϰʡڵ㡣ͻᱻתΪ
- - **Tensor** - DZһάǹ̶ѧϰʡһάǶ̬ѧϰʣiȡеiֵΪѧϰʡ
- - **Iterable** - ̬ѧϰʡiȡiֵΪѧϰʡ
- - **LearningRateSchedule** - ̬ѧϰʡѵУŻʹòstepΪ룬 `LearningRateSchedule` ʵ㵱ǰѧϰʡ
-
- - **update_slots** (bool) - ΪTrueۼ :math:`h` ĬֵTrue
- - **loss_scale** (float) - ݶϵ0`loss_scale`תΪͨʹĬֵѵʱʹ `FixedLossScaleManager` `FixedLossScaleManager` `drop_overflow_update` ΪFalseʱֵҪ `FixedLossScaleManager` е `loss_scale` ͬйظϸϢclass`mindspore.FixedLossScaleManager` Ĭֵ1.0
- - **weight_decay** (Union[float, int]) - ҪȨصȨ˥ֵڵ0.0Ĭֵ0.0
-
- **룺**
-
- **grads** (tuple[Tensor]) - Ż `params` ݶȣ״shape `params` ͬ
-
- ****
-
- Tensor[bool]ֵΪTrue
-
- **쳣**
-
- - **TypeError** - `learning_rate` intfloatTensorIterable `LearningRateSchedule`
- - **TypeError** - `parameters` Ԫ `Parameter` ֵ䡣
- - **TypeError** - `accum` `loss_scale` float
- - **TypeError** - `update_slots` bool
- - **TypeError** - `weight_decay` floatint
- - **ValueError** - `loss_scale` Сڻ0
- - **ValueError** - `accum` `weight_decay` С0
-
- **֧ƽ̨**
-
- ``Ascend`` ``CPU`` ``GPU``
-
- ****
-
- >>> net = Net()
- >>> #1) вʹͬѧϰʺȨ˥
- >>> optim = nn.Adagrad(params=net.trainable_params())
- >>>
- >>> #2) ʹò鲢òֵͬ
- >>> conv_params = list(filter(lambda x: 'conv' in x.name, net.trainable_params()))
- >>> no_conv_params = list(filter(lambda x: 'conv' not in x.name, net.trainable_params()))
- >>> group_params = [{'params': conv_params, 'weight_decay': 0.01, 'grad_centralization':True},
- ... {'params': no_conv_params, 'lr': 0.01},
- ... {'order_params': net.trainable_params()}]
- >>> optim = nn.Adagrad(group_params, learning_rate=0.1, weight_decay=0.0)
- >>> # conv_params齫ʹŻеѧϰ0.1Ȩ˥0.01ݶĻTrue
- >>> # no_conv_params齫ʹøѧϰ0.01ŻеȨ˥0.0ݶĻʹĬֵFalse
- >>> # Ż"order_params"õIJ˳²
- >>>
- >>> loss = nn.SoftmaxCrossEntropyWithLogits()
- >>> model = Model(net, loss_fn=loss, optimizer=optim)
|