Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Hackathon 6th No.26】API improvement for nn.initializer.KaimingNormal and nn.initializer.KaimingUniform 易用性提升 -part #6601

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/api/paddle/nn/initializer/KaimingNormal_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
KaimingNormal
-------------------------------

.. py:class:: paddle.nn.initializer.KaimingNormal(fan_in=None, negative_slope=0.0, nonlinearity='relu')
.. py:class:: paddle.nn.initializer.KaimingNormal(fan_in=None, negative_slope=0.0, nonlinearity='relu', mode='fan_in')



Expand All @@ -14,14 +14,15 @@ Kaiming 正态分布方式的权重初始化函数,方法来自 Kaiming He,X

.. math::

\frac{gain}{\sqrt{{fan\_in}}}
\frac{gain}{\sqrt{{fan\_mode}}}

参数
::::::::::::

- **fan_in** (float16|float32,可选) - 可训练的 Tensor 的 in_features 值。如果设置为 None,程序会自动计算该值。如果你不想使用 in_features,你可以自己设置这个值。默认值为 None。
- **negative_slope** (float,可选) - 只适用于使用 leaky_relu 作为激活函数时的 negative_slope 参数。默认值为 :math:`0.0`。
- **nonlinearity** (str,可选) - 非线性激活函数。默认值为 relu。
- **mode** (str,可选) - 设置 fan_mode 为 'fan_in' 或 'fan_out'。默认值为 'fan_in'。

.. note::

Expand Down
5 changes: 3 additions & 2 deletions docs/api/paddle/nn/initializer/KaimingUniform_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
KaimingUniform
-------------------------------

.. py:class:: paddle.nn.initializer.KaimingUniform(fan_in=None, negative_slope=0.0, nonlinearity='relu')
.. py:class:: paddle.nn.initializer.KaimingUniform(fan_in=None, negative_slope=0.0, nonlinearity='relu', mode='fan_in')



Expand All @@ -14,14 +14,15 @@ Kaiming 均匀分布方式的权重初始化函数,方法来自 Kaiming He,X

.. math::

x = gain \times \sqrt{\frac{3}{fan\_in}}
x = gain \times \sqrt{\frac{3}{fan\_mode}}

参数
::::::::::::

- **fan_in** (float16|float32,可选) - 可训练的 Tensor 的 in_features 值。如果设置为 None,程序会自动计算该值。如果你不想使用 in_features,你可以自己设置这个值。默认值为 None。
- **negative_slope** (float,可选) - 只适用于使用 leaky_relu 作为激活函数时的 negative_slope 参数。默认值为 :math:`0.0`。
- **nonlinearity** (str,可选) - 非线性激活函数。默认值为 relu。
- **mode** (str,可选) - 设置 fan_mode 为 'fan_in' 或 'fan_out'。默认值为 'fan_in'。

.. note::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ torch.nn.init.kaiming_normal_(tensor,
```python
paddle.nn.initializer.KaimingNormal(fan_in=None,
negative_slope=0.0,
nonlinearity='relu')
nonlinearity='relu',
mode='fan_in')
```

两者用法不同:torch 是 inplace 的用法,paddle 是类设置的,具体如下:
Expand All @@ -26,7 +27,7 @@ paddle.nn.initializer.KaimingNormal(fan_in=None,
| tensor | - | n 维 tensor。Paddle 无此参数,因为是通过调用类的 __call__ 函数来进行 tensor 的初始化。 |
| a | negative_slope | 只适用于使用 leaky_relu 作为激活函数时的 negative_slope 参数。仅参数名不一致。 |
| nonlinearity | nonlinearity | 非线性激活函数。参数默认值不一样,PyTorch 默认值为`leaky_relu`,Paddle 默认值为`relu`,Paddle 需保持与 PyTorch 一致。 |
| mode | - | "fan_in"(默认)或 "fan_out"。Paddle 无此参数,mode="fan_out"时,Paddle 无此参数,暂无转写方式。 |
| mode | mode | "fan_in"(默认)或 "fan_out"。 |
| - | fan_in | 可训练的 Tensor 的 in_features 值。PyTorch 无此参数,Paddle 保持默认即可。 |

### 转写示例
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ torch.nn.init.kaiming_uniform_(tensor,
```python
paddle.nn.initializer.KaimingUniform(fan_in=None,
negative_slope=0.0,
nonlinearity='relu')
nonlinearity='relu',
mode='fan_in')
```

两者用法不同:torch 是 inplace 的用法,paddle 是类设置的,具体如下:
Expand All @@ -26,7 +27,7 @@ paddle.nn.initializer.KaimingUniform(fan_in=None,
| tensor | - | n 维 tensor。Paddle 无此参数,因为是通过调用类的 __call__ 函数来进行 tensor 的初始化。 |
| a | negative_slope | 只适用于使用 leaky_relu 作为激活函数时的 negative_slope 参数。仅参数名不一致。 |
| nonlinearity | nonlinearity | 非线性激活函数。参数默认值不一样,PyTorch 默认值为`leaky_relu`,Paddle 默认值为`relu`,Paddle 需保持与 PyTorch 一致。 |
| mode | - | "fan_in"(默认)或 "fan_out"。Paddle 无此参数,mode="fan_out"时,Paddle 无此参数,暂无转写方式。 |
| mode | mode | "fan_in"(默认)或 "fan_out"。 |
| - | fan_in | 可训练的 Tensor 的 in_features 值。PyTorch 无此参数,Paddle 保持默认即可。 |

### 转写示例
Expand Down