Skip to content

在KaimingNormal/Uniform中加入mode参数 #7324

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

Merged
merged 3 commits into from
Jun 25, 2025
Merged
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
3 changes: 2 additions & 1 deletion 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 @@ -22,6 +22,7 @@ Kaiming 正态分布方式的权重初始化函数,方法来自 Kaiming He,X
- **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_in' 或 'fan_out'。当设置为 'fan_in' 时,将使用 fan_in 参数进行初始化。当设置为 'fan_out' 时,将使用可训练 Tensor 的 out_features 值进行初始化。默认为 'fan_in'。

.. note::

Expand Down
3 changes: 2 additions & 1 deletion 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 @@ -22,6 +22,7 @@ Kaiming 均匀分布方式的权重初始化函数,方法来自 Kaiming He,X
- **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_in' 或 'fan_out'。当设置为 'fan_in' 时,将使用 fan_in 参数进行初始化。当设置为 'fan_out' 时,将使用可训练 Tensor 的 out_features 值进行初始化。默认为 'fan_in'。

.. note::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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 @@ -27,7 +28,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"。参数完全一致。 |
| generator | - | 用于采样的伪随机数生成器,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
| - | 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