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

Fix API docs #7007

Merged
merged 23 commits into from
Dec 5, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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)
```

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

| PyTorch | PaddlePaddle | 备注 |
Expand All @@ -22,7 +22,7 @@ paddle.nn.GRUCell(input_size, hidden_size, weight_ih_attr=None, weight_hh_attr=N
| dtype | - | Tensor 的所需数据类型,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
| - |weight_ih_attr| weight_ih 的参数, PyTorch 无此参数, Paddle 保持默认即可。 |
| - |weight_hh_attr| weight_hh 的参数, PyTorch 无此参数, Paddle 保持默认即可。 |

| forward 类方法返回值 |forward 类方法返回值 | PyTorch 的返回值为更新后的隐藏状态 ret, Paddle 返回值为 ret、 ret, 需要转写。 |
Copy link
Collaborator

Choose a reason for hiding this comment

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

返回了两个ret吗

Copy link
Contributor Author

Choose a reason for hiding this comment

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

是的


### 转写示例
#### bias:是否使用偏置
Expand All @@ -40,6 +40,7 @@ paddle.nn.GRUCell(16, 32, bias_ih_attr=False, bias_hh_attr=False)
```
#### forward 类方法:前向传播
```python
# 返回值个数不一致,Paddle 返回值比 Pytorch 多一个
# PyTorch 写法
rnn = torch.nn.GRUCell(2, 2)
result = rnn(inp, h0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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)
```

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

| PyTorch | PaddlePaddle | 备注 |
Expand All @@ -22,7 +22,7 @@ paddle.nn.LSTMCell(input_size, hidden_size, weight_ih_attr=None, weight_hh_attr=
| - |weight_ih_attr| weight_ih 的参数, PyTorch 无此参数, Paddle 保持默认即可。 |
| - |weight_hh_attr| weight_hh 的参数, PyTorch 无此参数, Paddle 保持默认即可。 |
| - |proj_size|表示是否将 `hidden state` 映射到对应的大小, PyTorch 无此参数, Paddle 保持默认即可。 |

| forward 类方法返回值 |forward 类方法返回值 | PyTorch 的返回值为更新后的隐藏状态和细胞状态 h,c, Paddle 返回值为 h, (h, c), 需要转写。 |

### 转写示例
#### bias:是否使用偏置
Expand All @@ -40,6 +40,7 @@ paddle.nn.LSTMCell(16, 32, bias_ih_attr=False, bias_hh_attr=False)
```
#### forward 类方法:前向传播
```python
# 返回值个数不一致,Paddle 返回值比 Pytorch 多一个
# PyTorch 写法
rnn = torch.nn.LSTMCell(2, 2)
result = rnn(inp, h0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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 | 备注 |
Expand All @@ -20,6 +20,7 @@ paddle.nn.SimpleRNNCell(input_size, hidden_size, activation='tanh', weight_ih_at
| nonlinearity | activation | 表示激活函数类型,仅参数名不一致。 |
| - |weight_ih_attr| weight_ih 的参数, PyTorch 无此参数, Paddle 保持默认即可。 |
| - |weight_hh_attr| weight_hh 的参数, PyTorch 无此参数, Paddle 保持默认即可。 |
| forward 类方法返回值 |forward 类方法返回值 | PyTorch 的返回值为更新后的隐藏状态 ret, Paddle 返回值为 ret、 ret, 需要转写。 |
Copy link
Collaborator

Choose a reason for hiding this comment

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

返回了两个一模一样的ret吗

Copy link
Contributor Author

Choose a reason for hiding this comment

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

是的


### 转写示例
#### bias:是否使用偏置
Expand All @@ -37,6 +38,7 @@ paddle.nn.SimpleRNNCell(16, 32, bias_ih_attr=False, bias_hh_attr=False)
```
#### forward 类方法:前向传播
```python
# 返回值个数不一致,Paddle 返回值比 Pytorch 多一个
# PyTorch 写法
rnn = torch.nn.RNNCell(2, 2)
result = rnn(inp, h0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
### [torch.autograd.grad](https://pytorch.org/docs/stable/generated/torch.autograd.grad.html#torch.autograd.grad)

```python
torch.autograd.grad(outputs, inputs, grad_outputs=None, retain_graph=None, create_graph=False, only_inputs=True, allow_unused=False, is_grads_batched=False)
torch.autograd.grad(outputs, inputs, grad_outputs=None, retain_graph=None, create_graph=False, only_inputs=True, allow_unused=False, is_grads_batched=False, materialize_grads=False)
```

### [paddle.grad](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/grad_cn.html)
Expand All @@ -26,4 +26,5 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下:
| only_inputs | only_inputs | 是否只计算 inputs 的梯度。 |
| allow_unused | allow_unused | 决定当某些 inputs 变量不在计算图中时抛出错误还是返回 None。 |
| is_grads_batched | - | 是否反向使用批量,Paddle 无此参数,暂无转写方式。 |
| materialize_grads | - | 与输入无关变量的梯度,初始化为零还是不初始化,Paddle 无此参数,暂无转写方式。 |
| - | no_grad_vars | 指明不需要计算梯度的变量,PyTorch 无此参数,Paddle 保持默认即可。 |
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下:
torch.frexp(x,out=y)

# Paddle 写法
paddle.assign(paddle.frexp(x), y)
out1, out2 = paddle.frexp(x)
paddle.assign(out1, y[0]), paddle.assign(out2, y[1])
```