Skip to content

Commit db09700

Browse files
authored
【映射文档】更新部分修复的 API 文档 (#6696)
* update torch.all and torch.any * update torch.all and torch.any * update torch.diff * update CrossEntropyLoss * update Unfold * update torch.diff * fix errors * fix: add torch.feature_alpha_dropout
1 parent 930e036 commit db09700

File tree

10 files changed

+55
-42
lines changed

10 files changed

+55
-42
lines changed

docs/api/paddle/nn/CrossEntropyLoss_cn.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
CrossEntropyLoss
44
-------------------------------
55

6-
.. py:class:: paddle.nn.CrossEntropyLoss(weight=None, ignore_index=-100, reduction='mean', soft_label=False, axis=-1, use_softmax=True, name=None)
6+
.. py:class:: paddle.nn.CrossEntropyLoss(weight=None, ignore_index=-100, reduction='mean', soft_label=False, label_smoothing=0.0, axis=-1, use_softmax=True, name=None)
77
88
默认情况下, CrossEntropyLoss 使用 softmax 实现(即 use_softmax=True )。该函数结合了 softmax 操作的计算和交叉熵损失函数,以提供更稳定的数值计算。
99

docs/api/paddle/nn/functional/cross_entropy_cn.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
cross_entropy
44
-------------------------------
55

6-
.. py:function:: paddle.nn.functional.cross_entropy(input, label, weight=None, ignore_index=-100, reduction="mean", soft_label=False, axis=-1, name=None)
6+
.. py:function:: paddle.nn.functional.cross_entropy(input, label, weight=None, ignore_index=-100, reduction="mean", soft_label=False, label_smoothing=0.0, axis=-1, name=None)
77
88
实现了 softmax 交叉熵损失函数。该函数会将 softmax 操作、交叉熵损失函数的计算过程进行合并,从而提供了数值上更稳定的计算。
99

docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.cross_entropy.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ torch.nn.functional.cross_entropy(input,
77
target,
88
weight=None,
99
size_average=None,
10-
ignore_index=- 100,
10+
ignore_index=-100,
1111
reduce=None,
1212
reduction='mean',
1313
label_smoothing=0.0)
@@ -19,25 +19,28 @@ torch.nn.functional.cross_entropy(input,
1919
paddle.nn.functional.cross_entropy(input,
2020
label,
2121
weight=None,
22-
ignore_index=- 100,
22+
ignore_index=-100,
2323
reduction='mean',
2424
soft_label=False,
25-
axis=- 1,
25+
label_smoothing=0.0,
26+
axis=-1,
2627
use_softmax=True)
2728
```
29+
2830
两者功能一致,torch 参数更多,具体如下:
31+
2932
### 参数映射
3033

3134
| PyTorch | PaddlePaddle | 备注 |
3235
| ------------- | ------------ | ------------------------------------------------------ |
3336
| input | input | 表示预测的 Tensor 。 |
34-
| target | label | 表示真实的 Tensor |
37+
| target | label | 表示真实的 Tensor,仅参数名不同|
3538
| weight | weight | 表示权重。 |
3639
| size_average | - | 已弃用 。 |
3740
| ignore_index | ignore_index | 表示忽略的标签值 。 |
3841
| reduce | - | 已弃用 。 |
3942
| reduction | reduction | 表示应用于输出结果的计算方式 。 |
40-
| label_smoothing | - | 指定计算损失时的平滑量, Paddle 无此参数,暂无转写方式|
43+
| label_smoothing | label_smoothing | 指定计算损失时的平滑量,参数完全一致|
4144
| - | soft_label | 指明 label 是否为软标签, PyTorch 无此参数, Paddle 保持默认即可。|
4245
| - | axis | 进行 softmax 计算的维度索引, PyTorch 无此参数, Paddle 保持默认即可。|
4346
| - | use_softmax | 指定是否对 input 进行 softmax 归一化, PyTorch 无此参数, Paddle 保持默认即可。|

docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CrossEntropyLoss.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
```python
55
torch.nn.CrossEntropyLoss(weight=None,
66
size_average=None,
7-
ignore_index=- 100,
7+
ignore_index=-100,
88
reduce=None,
99
reduction='mean',
1010
label_smoothing=0.0)
@@ -17,11 +17,13 @@ paddle.nn.CrossEntropyLoss(weight=None,
1717
ignore_index=-100,
1818
reduction='mean',
1919
soft_label=False,
20+
label_smoothing=0.0,
2021
axis=-1,
2122
name=None)
2223
```
2324

2425
PyTorch 相比 Paddle 支持更多其他参数,具体如下:
26+
2527
### 参数映射
2628

2729
| PyTorch | PaddlePaddle | 备注 |
@@ -31,7 +33,7 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下:
3133
| ignore_index | ignore_index | 表示忽略的一个标签值。 |
3234
| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 |
3335
| reduction | reduction | 表示应用于输出结果的计算方式。 |
34-
| label_smoothing | - | 指定计算损失时的平滑量,Paddle 无此参数,暂无转写方式|
36+
| label_smoothing | label_smoothing | 指定计算损失时的平滑量,参数完全一致|
3537
| - | soft_label | 指明 label 是否为软标签,PyTorch 无此参数,Paddle 保持默认即可。 |
3638
| - | axis | 进行 softmax 计算的维度索引,PyTorch 无此参数,Paddle 保持默认即可。 |
3739

docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LSTM.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ paddle.nn.LSTM(input_size,
2929
```
3030

3131
两者功能一致但参数不一致,部分参数名不同,具体如下:
32+
3233
### 参数映射
3334

3435
| PyTorch | PaddlePaddle | 备注 |

docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Unfold.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## [ 输入参数类型不一致 ]torch.nn.Unfold
1+
## [ 仅参数名不一致 ]torch.nn.Unfold
22
### [torch.nn.Unfold](https://pytorch.org/docs/stable/generated/torch.nn.Unfold.html?highlight=nn+unfold#torch.nn.Unfold)
33

44
```python
@@ -17,15 +17,17 @@ paddle.nn.Unfold(kernel_size=[3, 3],
1717
dilation=1,
1818
name=None)
1919
```
20-
其中 Paddle 与 PyTorch 前四个参数所支持的参数类型不一致,具体如下:
20+
21+
其中功能一致, 仅参数名不一致,具体如下:
22+
2123
### 参数映射
2224

2325
| PyTorch | PaddlePaddle | 备注 |
2426
| ------------- | ------------ | ------------------------------------------------------ |
25-
| kernel_size | kernel_sizes | 卷积核大小, PyTorch 参数类型为 int、tuple(int) 或者 list(int), Paddle 参数类型为 int 或者 list(int)。 |
26-
| dilation | dilations | 卷积膨胀,PyTorch 参数类型为 int、tuple(int) 或者 list(int), Paddle 参数类型为 int 或者 list(int)。 |
27-
| padding | paddings | 每个维度的扩展,PyTorch 参数类型为 int、tuple(int) 或者 list(int), Paddle 参数类型为 int 或者 list(int)。 |
28-
| stride | strides | 步长大小,PyTorch 参数类型为 int、tuple(int) 或者 list(int), Paddle 参数类型为 int 或者 list(int)。|
27+
| kernel_size | kernel_sizes | 卷积核的尺寸。 |
28+
| dilation | dilations | 卷积膨胀 |
29+
| padding | paddings | 每个维度的扩展,仅参数名不一致。 |
30+
| stride | strides | 卷积步长,仅参数名不一致。 |
2931

3032
### 转写示例
3133
``` python
Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## [ 输入参数类型不一致 ]torch.all
1+
## [ 仅参数名不一致 ]torch.all
22

33
### [torch.all](https://pytorch.org/docs/stable/generated/torch.all.html?highlight=all#torch.all)
44

@@ -15,21 +15,12 @@ paddle.all(x,
1515
name=None)
1616
```
1717

18-
其中 Paddle 与 PyTorch `input` 参数所支持的类型不一致,具体如下:
18+
其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下:
1919

2020
### 参数映射
2121

2222
| PyTorch | PaddlePaddle | 备注 |
2323
| ------------- | ------------ | ------------------------------------------------------ |
24-
| input | x | 输入的多维 Tensor ,PyTorch 支持布尔和数值类型的输入,Paddle 仅支持布尔类型,需要转写|
24+
| input | x | 输入的多维 Tensor ,参数完全一致|
2525
| dim | axis | 表示运算的维度,仅参数名不一致。 |
2626
| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度,参数完全一致。 |
27-
28-
### 转写示例
29-
```python
30-
# PyTorch 写法
31-
y = torch.all(x)
32-
33-
# Paddle 写法
34-
y = paddle.all(x.astype('bool'))
35-
```
Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## [ 输入参数类型不一致 ]torch.any
1+
## [ 仅参数名不一致 ]torch.any
22

33
### [torch.any](https://pytorch.org/docs/stable/generated/torch.any.html?highlight=any#torch.any)
44

@@ -15,21 +15,12 @@ paddle.any(x,
1515
name=None)
1616
```
1717

18-
其中 Paddle 与 PyTorch `input` 参数所支持的类型不一致,具体如下:
18+
其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下:
1919

2020
### 参数映射
2121

2222
| PyTorch | PaddlePaddle | 备注 |
2323
| ------------- | ------------ | ------------------------------------------------------ |
24-
| input | x | 输入的多维 Tensor ,PyTorch 支持布尔和数值类型的输入,Paddle 仅支持布尔类型,需要转写|
24+
| input | x | 输入的多维 Tensor ,仅参数名不一致|
2525
| dim | axis | 表示运算的维度,仅参数名不一致。 |
2626
| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度,参数完全一致。 |
27-
28-
### 转写示例
29-
```python
30-
# PyTorch 写法
31-
y = torch.any(x)
32-
33-
# Paddle 写法
34-
y = paddle.any(x.astype('bool'))
35-
```

docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.diff.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## [ 输入参数用法不一致 ]torch.diff
1+
## [ 仅参数名不一致 ]torch.diff
22
### [torch.diff](https://pytorch.org/docs/stable/generated/torch.diff.html?highlight=diff#torch.diff)
33

44
```python
@@ -20,14 +20,14 @@ paddle.diff(x,
2020
name=None)
2121
```
2222

23-
两者功能一致,但参数 `n` 的支持范围不同,具体如下:
23+
其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下:
2424

2525
### 参数映射
2626

2727
| PyTorch | PaddlePaddle | 备注 |
2828
| ------------- | ------------ | ------------------------------------------------------ |
2929
| <font color='red'> input </font> | <font color='red'> x </font> | 表示输入的 Tensor ,仅参数名不一致。 |
30-
| n | n | 表示需要计算前向差值的次数。torch 支持 n 为任意值,paddle 仅支持 n=1,暂无转写方式。 |
30+
| n | n | 表示需要计算前向差值的次数。 |
3131
| <font color='red'> dim </font> | <font color='red'> axis </font> | 表示进行运算的轴,仅参数名不一致。 |
3232
| prepend | prepend | 表示在计算前向差值之前,沿着指定维度 axis 附加到输入 x 的前面。 |
3333
| append | append | 表示在计算前向差值之前,沿着指定维度 axis 附加到输入 x 的后面。 |
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## [ 仅参数名不一致 ]torch.feature_alpha_dropout
2+
3+
### [torch.feature\_alpha\_dropout](https://pytorch.org/docs/stable/jit_builtin_functions.html)
4+
5+
```python
6+
torch.feature_alpha_dropout(input, p, training)
7+
```
8+
9+
### [paddle.nn.functional.feature\_alpha\_dropout](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/functional/feature_alpha_dropout_cn.html#feature_alpha-dropout)
10+
11+
```python
12+
paddle.nn.functional.feature_alpha_dropout(x, p=0.5, training=True, name=None)
13+
```
14+
15+
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下:
16+
17+
### 参数映射
18+
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| -------- | ------------ | -- |
21+
| input | x | 输入的多维 Tensor,仅参数名不一致。 |
22+
| p | p | 将输入节点置 0 的概率。 |
23+
| training | training | 标记是否为训练阶段。 |

0 commit comments

Comments
 (0)