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.

mindspore.nn.Adagrad.rst 4.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. mindspore.nn.Adagrad
  2. =====================
  3. .. py:class:: mindspore.nn.Adagrad(*args, **kwargs)
  4. ʹApplyAdagradʵAdagrad㷨
  5. AdagradѧϰŻ
  6. `Efficient Learning using Forward-Backward Splitting <https://proceedings.neurips.cc/paper/2009/file/621bf66ddb7c962aa0d22ac97d69b793-Paper.pdf>`_
  7. ʽ£
  8. .. math::
  9. \begin{array}{ll} \\
  10. h_{t+1} = h_{t} + g\\
  11. w_{t+1} = w_{t} - lr*\frac{1}{\sqrt{h_{t+1}}}*g
  12. \end{array}
  13. :math:`h` ʾݶƽۻͣ:math:`g` ʾ `grads`
  14. :math:`lr` `learning_rate`:math:`w` `params`
  15. .. note::
  16. ڲδʱŻõ `weight_decay` Ӧƺ"beta""gamma"ͨɵȨ˥ԡʱÿ `weight_decay` δãʹŻõ `weight_decay`
  17. ****
  18. - **params** (Union[list[Parameter], list[dict]]) - `Parameter` ɵбֵɵббԪֵʱֵļ"params""lr""weight_decay""grad_centralization""order_params"
  19. - **params** - ǰȨأֵ `Parameter` б
  20. - **lr** - ѡд"lr"ʹöӦֵΪѧϰʡûУʹŻõ `learning_rate` Ϊѧϰʡ
  21. - **weight_decay** - ѡд"weight_decay"ʹöӦֵΪȨ˥ֵûУʹŻõ `weight_decay` ΪȨ˥ֵ
  22. - **grad_centralization** - ѡд"grad_centralization"ʹöӦֵֵΪ͡ûУΪ `grad_centralization` ΪFalseòھ㡣
  23. - **order_params** - ѡӦֵԤڵIJ˳򡣵ʹò鹦ʱͨʹø `parameters` ˳ܡд"order_params"Ըе"order_params"еIJijһ `params` С
  24. - **accum** (float) - ۼ :math:`h` ijʼֵڵ㡣Ĭֵ0.1
  25. - **learning_rate** (Union[float, Tensor, Iterable, LearningRateSchedule]) - Ĭֵ0.001
  26. - **float** - ̶ѧϰʡڵ㡣
  27. - **int** - ̶ѧϰʡڵ㡣ͻᱻתΪ
  28. - **Tensor** - DZһάǹ̶ѧϰʡһάǶ̬ѧϰʣiȡеiֵΪѧϰʡ
  29. - **Iterable** - ̬ѧϰʡiȡiֵΪѧϰʡ
  30. - **LearningRateSchedule** - ̬ѧϰʡѵУŻʹòstepΪ룬 `LearningRateSchedule` ʵ㵱ǰѧϰʡ
  31. - **update_slots** (bool) - ΪTrueۼ :math:`h` ĬֵTrue
  32. - **loss_scale** (float) - ݶϵ0`loss_scale`תΪͨʹĬֵѵʱʹ `FixedLossScaleManager` `FixedLossScaleManager` `drop_overflow_update` ΪFalseʱֵҪ `FixedLossScaleManager` е `loss_scale` ͬйظϸϢclass`mindspore.FixedLossScaleManager` Ĭֵ1.0
  33. - **weight_decay** (Union[float, int]) - ҪȨصȨ˥ֵڵ0.0Ĭֵ0.0
  34. **룺**
  35. **grads** (tuple[Tensor]) - Ż `params` ݶȣ״shape `params` ͬ
  36. ****
  37. Tensor[bool]ֵΪTrue
  38. **쳣**
  39. - **TypeError** - `learning_rate` intfloatTensorIterable `LearningRateSchedule`
  40. - **TypeError** - `parameters` Ԫ `Parameter` ֵ䡣
  41. - **TypeError** - `accum` `loss_scale` float
  42. - **TypeError** - `update_slots` bool
  43. - **TypeError** - `weight_decay` floatint
  44. - **ValueError** - `loss_scale` Сڻ0
  45. - **ValueError** - `accum` `weight_decay` С0
  46. **֧ƽ̨**
  47. ``Ascend`` ``CPU`` ``GPU``
  48. ****
  49. >>> net = Net()
  50. >>> #1) вʹͬѧϰʺȨ˥
  51. >>> optim = nn.Adagrad(params=net.trainable_params())
  52. >>>
  53. >>> #2) ʹò鲢òֵͬ
  54. >>> conv_params = list(filter(lambda x: 'conv' in x.name, net.trainable_params()))
  55. >>> no_conv_params = list(filter(lambda x: 'conv' not in x.name, net.trainable_params()))
  56. >>> group_params = [{'params': conv_params, 'weight_decay': 0.01, 'grad_centralization':True},
  57. ... {'params': no_conv_params, 'lr': 0.01},
  58. ... {'order_params': net.trainable_params()}]
  59. >>> optim = nn.Adagrad(group_params, learning_rate=0.1, weight_decay=0.0)
  60. >>> # conv_params齫ʹŻеѧϰ0.1Ȩ˥0.01ݶĻTrue
  61. >>> # no_conv_params齫ʹøѧϰ0.01ŻеȨ˥0.0ݶĻʹĬֵFalse
  62. >>> # Ż"order_params"õIJ˳²
  63. >>>
  64. >>> loss = nn.SoftmaxCrossEntropyWithLogits()
  65. >>> model = Model(net, loss_fn=loss, optimizer=optim)