Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix docs #6993

Merged
merged 19 commits into from
Nov 26, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ torch.Tensor.ormqr(input2, input3, left=True, transpose=False)
### [paddle.linalg.ormqr](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/linalg/ormqr_cn.html#ormqr)

```python
paddle.linalg.ormqr(x, tau, other, left=True, transpose=False)
paddle.linalg.ormqr(x, tau, y, left=True, transpose=False)
```

两者功能一致且参数用法一致,仅参数名不一致,具体如下:
Expand All @@ -19,6 +19,6 @@ paddle.linalg.ormqr(x, tau, other, left=True, transpose=False)
| PyTorch | PaddlePaddle | 备注 |
| --------- | ------------ | ---------------------------------- |
| input2 | tau | Householder 反射系数,仅参数名不同 |
| input3 | other | 用于矩阵乘积,仅参数名不同 |
| input3 | y | 用于矩阵乘积,仅参数名不同 |
| left | left | 决定了矩阵乘积运算的顺序,一致 |
| transpose | transpose | 决定矩阵 Q 是否共轭转置变换,一致 |
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## [参数完全一致]torch.distributed.all_gather_object
## [ 输入参数用法不一致 ]torch.distributed.all_gather_object

### [torch.distributed.all_gather_object](https://pytorch.org/docs/stable/distributed.html?highlight=all_gather_object#torch.distributed.all_gather_object)

Expand All @@ -18,13 +18,12 @@ paddle.distributed.all_gather_object(object_list, obj, group=None)

| PyTorch | PaddlePaddle | 备注 |
| -------- | ------------ | --------------------------------------------- |
| object_list | | 表示用于保存聚合结果的列表。需初始化成与 `group` 等长的列表 |
| | object_list | 表示用于保存聚合结果的列表。需初始化成空列表 |
| object_list | object_list | 表示用于保存聚合结果的列表。PyTorch 需初始化成与 `group` 等长的列表, Paddle 需初始化为空列表,需要转写。 |
| obj | obj | 表示待聚合的对象。 |
| group | group | 表示执行该操作的进程组实例。 |

### 转写示例

#### object_list:保存聚合结果列表
```python
# PyTorch 写法
import torch.distributed as dist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ paddle.nn.GRU(input_size,
| input_size | input_size | 表示输入 x 的大小。 |
| hidden_size | hidden_size | 表示隐藏状态 h 大小。 |
| num_layers | num_layers | 表示循环网络的层数。 |
| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 支持自定义偏置属性, torch 不支持,需要转写。 |
| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 的 bias_ih_attr, bias_hh_attr 参数均需与 PyTorch 设置一致,需要转写。 |
| batch_first | time_major | PyTorch 表示 batch size 是否为第一维,PaddlePaddle 表示 time steps 是否为第一维,它们的意义相反。需要转写。 |
| dropout | dropout | 表示 dropout 概率。 |
| bidirectional | direction | PyTorch 表示是否进行双向 GRU,Paddle 使用字符串表示是双向 GRU(`bidirectional`)还是单向 GRU(`forward`)。 |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## [ 输入参数用法不一致 ]torch.nn.GRUCell
## [ 返回参数类型不一致 ]torch.nn.GRUCell

### [torch.nn.GRUCell](https://pytorch.org/docs/stable/generated/torch.nn.GRUCell.html#torch.nn.GRUCell)
```python
Expand All @@ -10,14 +10,14 @@ torch.nn.GRUCell(input_size, hidden_size, bias=True, device=None, dtype=None)
paddle.nn.GRUCell(input_size, hidden_size, weight_ih_attr=None, weight_hh_attr=None, bias_ih_attr=None, bias_hh_attr=None, name=None)
```

两者功能一致但参数不一,具体如下:
两者功能一致但输入参数用法不一致,且返回参数类型不同,具体如下:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个其实是返回参数个数,下一个PR可以再微调下

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| input_size | input_size | 表示输入 x 的大小。 |
| hidden_size | hidden_size | 表示隐藏状态 h 大小。 |
| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 支持自定义偏置属性, torch 不支持,需要转写。 |
| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置,Paddle 的 bias_ih_attr, bias_hh_attr 参数均需与 PyTorch 设置一致,需要转写。 |
| device | - | 指定 Tensor 的设备,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
| dtype | - | Tensor 的所需数据类型,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
| - |weight_ih_attr| weight_ih 的参数, PyTorch 无此参数, Paddle 保持默认即可。 |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加一行:返回值

Expand All @@ -28,15 +28,23 @@ paddle.nn.GRUCell(input_size, hidden_size, weight_ih_attr=None, weight_hh_attr=N
#### bias:是否使用偏置
```python
# PyTorch 写法
torch.nn.GRU(16, 32, bias=True)

torch.nn.GRUCell(16, 32, bias=True)
# Paddle 写法
paddle.nn.GRUCell(16, 32)
```
```python
# PyTorch 写法
torch.nn.GRUCell(16, 32, bias=False)
# Paddle 写法
paddle.nn.GRU(16, 32)
paddle.nn.GRUCell(16, 32, bias_ih_attr=False, bias_hh_attr=False)
```
#### forward 类方法:前向传播
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个加一下注释,说明下paddle返回个数的不同

```python
# PyTorch 写法
torch.nn.GRU(16, 32, bias=False)
rnn = torch.nn.GRUCell(2, 2)
result = rnn(inp, h0)

# Paddle 写法
paddle.nn.GRU(16, 32, bias_ih_attr=False, bias_hh_attr=False)
rnn = paddle.nn.GRUCell(2, 2)
result = rnn(inp, h0)[0]
```
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ paddle.nn.LSTM(input_size,
| input_size | input_size | 表示输入 x 的大小。 |
| hidden_size | hidden_size | 表示隐藏状态 h 大小。 |
| num_layers | num_layers | 表示循环网络的层数。 |
| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 支持自定义偏置属性, torch 不支持,需要转写。 |
| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 的 bias_ih_attr, bias_hh_attr 参数均需与 PyTorch 设置一致,需要转写。 |
| batch_first | time_major | PyTorch 表示 batch size 是否为第一维,PaddlePaddle 表示 time steps 是否为第一维,它们的意义相反。需要转写。 |
| dropout | dropout | 表示 dropout 概率。 |
| bidirectional | direction | PyTorch 表示是否进行双向,Paddle 使用字符串表示是双向 LSTM(`bidirectional`)还是单向 LSTM(`forward`)|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## [ 输入参数用法不一致 ]torch.nn.LSTMCell
## [ 返回参数类型不一致 ]torch.nn.LSTMCell
### [torch.nn.LSTMCell](https://pytorch.org/docs/stable/generated/torch.nn.LSTMCell.html#torch.nn.LSTMCell)
```python
torch.nn.LSTMCell(input_size, hidden_size, bias=True, device=None, dtype=None)
Expand All @@ -9,14 +9,14 @@ torch.nn.LSTMCell(input_size, hidden_size, bias=True, device=None, dtype=None)
paddle.nn.LSTMCell(input_size, hidden_size, weight_ih_attr=None, weight_hh_attr=None, bias_ih_attr=None, bias_hh_attr=None, proj_size=0, name=None)
```

两者功能一致但参数不一,具体如下:
两者功能一致但输入参数用法不一致,且返回参数类型不同,具体如下:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| input_size | input_size | 表示输入 x 的大小。 |
| hidden_size | hidden_size | 表示隐藏状态 h 大小。 |
| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 支持自定义偏置属性, torch 不支持,需要转写。 |
| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 的 bias_ih_attr, bias_hh_attr 参数均需与 PyTorch 设置一致,需要转写。 |
| device | - | 指定 Tensor 的设备,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
| dtype | - | Tensor 的所需数据类型,一般对网络训练结果影响不大,可直接删除。 |
| - |weight_ih_attr| weight_ih 的参数, PyTorch 无此参数, Paddle 保持默认即可。 |
Expand All @@ -29,14 +29,21 @@ paddle.nn.LSTMCell(input_size, hidden_size, weight_ih_attr=None, weight_hh_attr=
```python
# PyTorch 写法
torch.nn.LSTMCell(16, 32, bias=True)

# Paddle 写法
paddle.nn.LSTMCell(16, 32)
```
```python
# PyTorch 写法
torch.nn.LSTMCell(16, 32, bias=False)

# Paddle 写法
paddle.nn.LSTMCell(16, 32, bias_ih_attr=False, bias_hh_attr=False)
```
#### forward 类方法:前向传播
```python
# PyTorch 写法
rnn = torch.nn.LSTMCell(2, 2)
result = rnn(inp, h0)

# Paddle 写法
rnn = paddle.nn.LSTMCell(2, 2)
result = rnn(inp, h0)[1]
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ paddle.nn.SimpleRNN(input_size, hidden_size, num_layers=1, activation='tanh', di
| hidden_size | hidden_size | 表示隐藏状态 h 大小。 |
| num_layers | num_layers | 表示循环网络的层数。 |
| nonlinearity | activation | 表示激活函数类型,仅参数名不一致。 |
| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 支持自定义偏置属性, torch 不支持,需要转写。 |
| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 的 bias_ih_attr, bias_hh_attr 参数均需与 PyTorch 设置一致,需要转写。 |
| batch_first | time_major | PyTorch 表示 batch size 是否为第一维,PaddlePaddle 表示 time steps 是否为第一维,它们的意义相反。需要转写。 |
| dropout | dropout | 表示 dropout 概率。 |
| bidirectional | direction | PyTorch 表示是否进行双向 RNN,Paddle 使用字符串表示是双向 RNN(`bidirectional`)还是单向 RNN(`forward`)。 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ paddle.nn.layer.rnn.RNNBase(mode, input_size, hidden_size,
| input_size | input_size | 表示输入 x 的大小。 |
| hidden_size | hidden_size | 表示隐藏状态 h 大小。 |
| num_layers | num_layers | 表示循环网络的层数。 |
| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 支持自定义偏置属性, torch 不支持,需要转写。 |
| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 的 bias_ih_attr, bias_hh_attr 参数均需与 PyTorch 设置一致,需要转写。 |
| batch_first | time_major | PyTorch 表示 batch size 是否为第一维,PaddlePaddle 表示 time steps 是否为第一维,它们的意义相反。需要转写。 |
| dropout | dropout | 表示 dropout 概率。 |
| bidirectional | direction | PyTorch 表示是否进行双向 RNN,Paddle 使用字符串表示是双向 RNN(`bidirectional`)还是单向 RNN(`forward`)。 |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## [ 输入参数用法不一致 ]torch.nn.RNNCell
## [ 返回参数类型不一致 ]torch.nn.RNNCell
### [torch.nn.RNNCell](https://pytorch.org/docs/stable/generated/torch.nn.RNNCell.html#torch.nn.RNNCell)
```python
torch.nn.RNNCell(input_size, hidden_size, bias=True, nonlinearity='tanh', device=None, dtype=None)
Expand All @@ -9,14 +9,14 @@ torch.nn.RNNCell(input_size, hidden_size, bias=True, nonlinearity='tanh', device
paddle.nn.SimpleRNNCell(input_size, hidden_size, activation='tanh', weight_ih_attr=None, weight_hh_attr=None, bias_ih_attr=None, bias_hh_attr=None, name=None)
```

两者功能一致但参数不一致,部分参数名不同,具体如下:
两者功能一致但输入参数用法不一致,且返回参数类型不同,具体如下:
### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| input_size | input_size | 表示输入 x 的大小。 |
| hidden_size | hidden_size | 表示隐藏状态 h 大小。 |
| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 支持自定义偏置属性, torch 不支持,需要转写。 |
| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 的 bias_ih_attr, bias_hh_attr 参数均需与 PyTorch 设置一致,需要转写。 |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

| nonlinearity | activation | 表示激活函数类型,仅参数名不一致。 |
| - |weight_ih_attr| weight_ih 的参数, PyTorch 无此参数, Paddle 保持默认即可。 |
| - |weight_hh_attr| weight_hh 的参数, PyTorch 无此参数, Paddle 保持默认即可。 |
Expand All @@ -26,14 +26,22 @@ paddle.nn.SimpleRNNCell(input_size, hidden_size, activation='tanh', weight_ih_at
```python
# PyTorch 写法
torch.nn.RNNCell(16, 32, bias=True)

# Paddle 写法
paddle.nn.SimpleRNNCell(16, 32)
```
```python
# PyTorch 写法
torch.nn.RNNCell(16, 32, bias=False)

# Paddle 写法
paddle.nn.SimpleRNNCell(16, 32, bias_ih_attr=False, bias_hh_attr=False)
```
#### forward 类方法:前向传播
```python
# PyTorch 写法
rnn = torch.nn.RNNCell(2, 2)
result = rnn(inp, h0)

# Paddle 写法
rnn = paddle.nn.SimpleRNNCell(2, 2)
result = rnn(inp, h0)[0]
```
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## [ 仅参数名不一致 ]torch.ormqr
## [ torch 参数更多 ]torch.ormqr

### [torch.ormqr](https://pytorch.org/docs/stable/generated/torch.ormqr.html#torch.ormqr)

Expand All @@ -12,13 +12,15 @@ torch.ormqr(input, tau, other, left=True, transpose=False, *, out=None)
paddle.linalg.ormqr(x, tau, other, left=True, transpose=False)
```

PyTorch 相比 Paddle 支持更多其他参数,具体如下:

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| --------- | ------------ | ---------------------------------------------- |
| input | x | 输入的参数,用于表示矩阵 Q ,仅参数名字不一致 |
| tau | tau | Householder 反射系数,一致 |
| other | other | 用于矩阵乘积,一致 |
| input2 | tau | Householder 反射系数,一致 |
| input3 | other | 用于矩阵乘积,一致 |
| left | left | 决定了矩阵乘积运算的顺序,一致 |
| transpose | transpose | 决定矩阵 Q 是否共轭转置变换,一致 |
| out | - | paddle 无此参数,需转写 |
Expand Down