mindspore2022/docs/api/api_python/nn/mindspore.nn.ClipByNorm.rst

32 lines
1.1 KiB
ReStructuredText
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

mindspore.nn.ClipByNorm
========================
.. py:function:: mindspore.nn.ClipByNorm(axis=None)
对输入Tensor的值进行裁剪使用 :math:`L_2` 范数控制梯度。
如果输入Tensor的 :math:`L_2` 范数不大于输入 `clip_norm` ,则此层的输出保持不变。
否则Tensor将标准化为
.. math::
\text{output}(X) = \frac{\text{clip_norm} * X}{L_2(X)},
其中 :math:`L_2(X)`:math:`X`:math:`L_2` 范数。
**参数:**
- **axis** (Union[None, int, tuple(int)]) - 指定在哪个维度上计算 :math:`L_2` 范数。如果为None则计算所有维度。默认值None。
**输入:**
- **x** (Tensor) - 输入n维的Tensor数据类型为float32或float16。
- **clip_norm** (Tensor) - shape为 :math:`()`:math:`(1)` 的Tensor。或者其shape可以广播到 `x` 的shape。
**输出:**
Tensor裁剪后的Tensor与输入 `x` 的shape相同数据类型为float32。
**异常:**
- **TypeError** - `axis` 不是None、int、或tuple。
- **TypeError** - `x` 的数据类型既不是float16也不是float32。