Skip to content

Commit

Permalink
【Hackathon 5th No.43】API转换21-41 (#6280)
Browse files Browse the repository at this point in the history
* Add api_mapping

* Fix

* Fix
  • Loading branch information
co63oc committed Nov 2, 2023
1 parent 52acbcd commit 0cfe43a
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 9 deletions.
8 changes: 4 additions & 4 deletions docs/api/paddle/nn/PoissonNLLLoss_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
PoissonNLLLoss
-------------------------------

.. py:class:: paddle.nn.PoissonNLLLoss(log_input=True, full=False, eps=1e-8, reduction='mean', name=None)
.. py:class:: paddle.nn.PoissonNLLLoss(log_input=True, full=False, epsilon=1e-8, reduction='mean', name=None)
该接口可创建一个 PoissonNLLLoss 可调用类,计算输入 :attr:`input` 和标签 :attr:`label` 间的 `Poisson negative log likelihood loss` 损失。该 loss 适用于真实标签服从于泊松分布时,即

Expand All @@ -14,9 +14,9 @@ PoissonNLLLoss
当 `log_input` 设置为 `True` 时,损失函数的数学计算公式为:

.. math::
\text{loss}(\text{input}, \text{label}) = \text{input} - \text{label} * \log(\text{input}+\text{eps}) + \log(\text{label!})
\text{loss}(\text{input}, \text{label}) = \text{input} - \text{label} * \log(\text{input}+\text{epsilon}) + \log(\text{label!})
其中 `eps` 是 ``True`` 时使用的常数小量,使得 loss 计算过程中不会导致对 0 求对数情况的出现。
其中 `epsilon` 是 ``True`` 时使用的常数小量,使得 loss 计算过程中不会导致对 0 求对数情况的出现。
当 `log_input` 设置为 `False` 时,损失函数的数学计算公式为:

.. math::
Expand All @@ -33,7 +33,7 @@ PoissonNLLLoss
:::::::::
- **log_input** (bool,可选) - 输入是否为对数函数映射后结果,默认值为 ``True``。
- **full** (bool,可选) - 是否在损失计算中包括 Stirling 近似项。默认值为 ``False``。
- **eps** (float,可选) - 在 :attr:`log_input` 为 ``True`` 时使用的常数小量。默认值为 1e-8。
- **epsilon** (float,可选) - 在 :attr:`log_input` 为 ``True`` 时使用的常数小量。默认值为 1e-8。
- **reduction** (str,可选) - 指定应用于输出结果的计算方式,可选值有 ``none``、``mean`` 和 ``sum``。默认为 ``mean``,计算 ``mini-batch`` loss 均值。设置为 ``sum`` 时,计算 ``mini-batch`` loss 的总和。设置为 ``none`` 时,则返回 loss Tensor。默认值下为 ``mean``。
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为 None。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ torch.nn.PoissonNLLLoss(log_input=True, full=False, size_average=None, eps=1e-08
### [paddle.nn.PoissonNLLLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/PoissonNLLLoss_cn.html)

```python
paddle.nn.PoissonNLLLoss(log_input=True, full=False, eps=1e-8, reduction='mean', name=None)
paddle.nn.PoissonNLLLoss(log_input=True, full=False, epsilon=1e-8, reduction='mean', name=None)
```

Pytorch 相比 Paddle 支持更多其他参数,具体如下:
Expand All @@ -21,7 +21,7 @@ Pytorch 相比 Paddle 支持更多其他参数,具体如下:
| log_input | log_input | 输入是否为对数函数映射后结果。 |
| full | full | 是否在损失计算中包括 Stirling 近似项。 |
| size_average | - | 已废弃(可用 `reduction` 代替)。表示是否采用 batch 中各样本 loss 平均值作为最终的 loss。如果置 False,则采用加和作为 loss。默认为 True,paddle 需要转写。 |
| eps | eps |`log_input` 为 True 时使用的常数小量。默认值为 1e-8。 |
| eps | epsilon |`log_input` 为 True 时使用的常数小量。默认值为 1e-8,仅参数名不一致|
| reduce | - | 已废弃(可用 `reduction` 代替)。表示是否采用输出单个值作为 loss。如果置 False,则每个元素输出一个 loss 并忽略 `size_average`。默认为 True,paddle 需要转写。 |
| reduction | reduction | 指定应用于输出结果的计算方式,可选值有 `none``mean``sum`。默认为 `mean`,计算 mini-batch loss 均值。设置为 `sum` 时,计算 mini-batch loss 的总和。设置为 `none` 时,则返回 loss Tensor。默认值下为 `mean`。两者完全一致。 |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Pytorch 相比 Paddle 支持更多其他参数,具体如下:
| size_average | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 |
| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 |
| reduction | reduction | 表示应用于输出结果的计算方式。 |
| beta | delta | SmoothL1Loss 损失的阈值参数。 |
| beta | delta | SmoothL1Loss 损失的阈值参数,beta 不为 1.0 时 Paddle 不支持,暂无转写方式|

### 转写示例
#### size_average
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ torch.broadcast_tensors(x, y)
# Paddle 写法
paddle.broadcast_tensors([x, y])
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## [仅参数名不一致]torch.finfo

### [torch.finfo](https://pytorch.org/docs/stable/type_info.html#torch-finfo)

```python
torch.finfo(type)
```

### [paddle.finfo](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/finfo_cn.html)

```python
paddle.finfo(dtype)
```

两者功能一致,参数名不一致,具体如下:

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------- | ------------ | -------------------------------- |
| type | dtype | 输入的数据类型,仅参数名不一致。 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## [参数完全一致]torch.iinfo

### [torch.iinfo](https://pytorch.org/docs/stable/type_info.html#torch-iinfo)

```python
torch.iinfo(type)
```

### [paddle.iinfo](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/iinfo_cn.html)

```python
paddle.iinfo(dtype)
```

paddle 参数和 torch 参数完全一致,具体如下:

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------- | ------------ | -------------------------------- |
| type | dtype | 输入的数据类型,仅参数名不一致。 |
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@
| REFERENCE-MAPPING-ITEM(`torch.get_default_dtype`, https://github.com/PaddlePaddle/docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.get_default_dtype.md) |
| REFERENCE-MAPPING-ITEM(`torch.is_grad_enabled`, https://github.com/PaddlePaddle/docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.is_grad_enabled.md) |
| REFERENCE-MAPPING-ITEM(`torch.manual_seed`, https://github.com/PaddlePaddle/docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.manual_seed.md) |
| [torch.can_cast](https://pytorch.org/docs/stable/generated/torch.can_cast.html#torch-can-cast) | 功能缺失 |


***持续更新...***

Expand Down Expand Up @@ -513,7 +515,8 @@
| REFERENCE-MAPPING-ITEM(`torch.nn.TransformerEncoderLayer`, https://github.com/PaddlePaddle/docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.TransformerEncoderLayer.md) |
| REFERENCE-MAPPING-ITEM(`torch.nn.TripletMarginLoss`, https://github.com/PaddlePaddle/docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.TripletMarginLoss.md) |
| REFERENCE-MAPPING-ITEM(`torch.nn.parameter.Parameter`, https://github.com/PaddlePaddle/docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.nn.parameter.Parameter.md) |

| [torch.nn.MultiLabelMarginLoss](https://pytorch.org/docs/stable/generated/torch.nn.MultiLabelMarginLoss) | 功能缺失 |
| [torch.nn.CTCLoss](https://pytorch.org/docs/stable/generated/torch.nn.CTCLoss.html#torch.nn.CTCLoss) | 功能缺失,torch 的 log_softmax+ctc_loss 相当于 paddle 的 ctc_loss |

***持续更新...***

Expand Down Expand Up @@ -608,6 +611,8 @@
| REFERENCE-MAPPING-ITEM(`torch.nn.functional.threshold`, https://github.com/PaddlePaddle/docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.threshold.md) |
| REFERENCE-MAPPING-ITEM(`torch.nn.functional.unfold`, https://github.com/PaddlePaddle/docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.unfold.md) |
| REFERENCE-MAPPING-ITEM(`torch.nn.functional.upsample_bilinear`, https://github.com/PaddlePaddle/docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.upsample_bilinear.md) |
| (torch.nn.functional.multilabel_margin_loss)[https://pytorch.org/docs/stable/generated/torch.nn.functional.multilabel_margin_loss.html#torch.nn.functional.multilabel_margin_loss] | 功能缺失 |
| (torch.nn.functional.ctc_loss)[https://pytorch.org/docs/stable/generated/torch.nn.functional.ctc_loss.html#torch.nn.functional.ctc_loss] | 功能缺失,torch 的 log_softmax+ctc_loss 相当于 paddle 的 ctc_loss |

***持续更新...***

Expand Down

0 comments on commit 0cfe43a

Please sign in to comment.