未验证 提交 480fbc44 编写于 作者: C Candy2Tang 提交者: GitHub

[xdoctest][task 112] Reformat example code with google style in...

[xdoctest][task 112] Reformat example code with google style in python/paddle/optimizer/sgd.py (#56228)
上级 8f6446d3
...@@ -39,14 +39,14 @@ class SGD(Optimizer): ...@@ -39,14 +39,14 @@ class SGD(Optimizer):
This parameter is required in dygraph mode. \ This parameter is required in dygraph mode. \
The default value is None in static graph mode, at this time all parameters will be updated. The default value is None in static graph mode, at this time all parameters will be updated.
weight_decay (float|WeightDecayRegularizer, optional): The strategy of regularization. \ weight_decay (float|WeightDecayRegularizer, optional): The strategy of regularization. \
It canbe a float value as coeff of L2 regularization or \ It can be a float value as coeff of L2 regularization or \
:ref:`api_fluid_regularizer_L1Decay`, :ref:`api_fluid_regularizer_L2Decay`. :ref:`api_fluid_regularizer_L1Decay`, :ref:`api_fluid_regularizer_L2Decay`.
If a parameter has set regularizer using :ref:`api_fluid_ParamAttr` already, \ If a parameter has set regularizer using :ref:`api_fluid_ParamAttr` already, \
the regularization setting here in optimizer will be ignored for this parameter. \ the regularization setting here in optimizer will be ignored for this parameter. \
Otherwise, the regularization setting here in optimizer will take effect. \ Otherwise, the regularization setting here in optimizer will take effect. \
Default None, meaning there is no regularization. Default None, meaning there is no regularization.
grad_clip (GradientClipBase, optional): Gradient cliping strategy, it's an instance of grad_clip (GradientClipBase, optional): Gradient clipping strategy, it's an instance of
some derived class of ``GradientClipBase`` . There are three cliping strategies some derived class of ``GradientClipBase`` . There are three clipping strategies
( :ref:`api_fluid_clip_GradientClipByGlobalNorm` , :ref:`api_fluid_clip_GradientClipByNorm` , ( :ref:`api_fluid_clip_GradientClipByGlobalNorm` , :ref:`api_fluid_clip_GradientClipByNorm` ,
:ref:`api_fluid_clip_GradientClipByValue` ). Default None, meaning there is no gradient clipping. :ref:`api_fluid_clip_GradientClipByValue` ). Default None, meaning there is no gradient clipping.
name (str, optional): The default value is None. Normally there is no need for user name (str, optional): The default value is None. Normally there is no need for user
...@@ -56,17 +56,17 @@ class SGD(Optimizer): ...@@ -56,17 +56,17 @@ class SGD(Optimizer):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle >>> import paddle
inp = paddle.uniform(min=-0.1, max=0.1, shape=[10, 10], dtype='float32') >>> inp = paddle.uniform(min=-0.1, max=0.1, shape=[10, 10], dtype='float32')
linear = paddle.nn.Linear(10, 10) >>> linear = paddle.nn.Linear(10, 10)
inp = paddle.to_tensor(inp) >>> inp = paddle.to_tensor(inp)
out = linear(inp) >>> out = linear(inp)
loss = paddle.mean(out) >>> loss = paddle.mean(out)
sgd = paddle.optimizer.SGD(learning_rate=0.1, parameters=linear.parameters(), weight_decay=0.01) >>> sgd = paddle.optimizer.SGD(learning_rate=0.1, parameters=linear.parameters(), weight_decay=0.01)
out.backward() >>> out.backward()
sgd.step() >>> sgd.step()
sgd.clear_grad() >>> sgd.clear_grad()
""" """
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册