@@ -184,36 +184,78 @@ class GradientClipByValue(BaseGradientClipAttr):
...
@@ -184,36 +184,78 @@ class GradientClipByValue(BaseGradientClipAttr):
classGradientClipByNorm(BaseGradientClipAttr):
classGradientClipByNorm(BaseGradientClipAttr):
"""
"""
Clips tensor values to a maximum L2-norm.
Convert the input multidimensional Tensor :math:`X` to a multidimensional Tensor whose L2 norm does not exceed the given two-norm maximum ( :math:`clip\_norm` ).
The tensor is not passed through this class, but passed through the parametre of ``main_program`` in ``fluid.program_guard``.
This operator limits the L2 norm of the input :math:`X` within :math:`max\_norm`.
This class limits the L2 norm of the input :math:`X` within :math:`clip\_norm`.
If the L2 norm of :math:`X` is less than or equal to :math:`max\_norm`, :math:`Out`
will be the same as :math:`X`. If the L2 norm of :math:`X` is greater than
:math:`max\_norm`, :math:`X` will be linearly scaled to make the L2 norm of
:math:`Out` equal to :math:`max\_norm`, as shown in the following formula:
.. math::
.. math::
Out =
\\left \{
\\begin{aligned}
& X & & if (norm(X) \\leq clip\_norm) \\\\
& \\frac{clip\_norm*X}{norm(X)} & & if (norm(X) > clip\_norm) \\\\
\\end{aligned}
\\right.
Out = \\frac{max\_norm * X}{norm(X)},
where :math:`norm(X)` represents the L2 norm of :math:`X`.
where :math:`norm(X)` represents the L2 norm of :math:`X`.