From e6800c7b2c7d2003a436e74ffbdd5dfef6befb0d Mon Sep 17 00:00:00 2001 From: Ran chongzhi <57489288+ranchongzhi@users.noreply.github.com> Date: Tue, 9 May 2023 18:22:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=A0=E5=B0=84=E6=96=87=E6=A1=A3=20No.=2054?= =?UTF-8?q?=20(#5852)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 新增5个api映射文档,修改5个原有文档的内容 * modify torch.nn.CTCLoss.md --- .../api_difference/nn/torch.nn.BCELoss.md | 4 +- .../nn/torch.nn.BCEWithLogitsLoss.md | 6 +-- .../api_difference/nn/torch.nn.CTCLoss.md | 26 ++++++++++ .../nn/torch.nn.CrossEntropyLoss.md | 12 ++--- .../nn/torch.nn.HingeEmbeddingLoss.md | 48 +++++++++++++++++++ .../api_difference/nn/torch.nn.KLDivLoss.md | 4 +- .../nn/torch.nn.MarginRankingLoss.md | 48 +++++++++++++++++++ .../api_difference/nn/torch.nn.NLLLoss.md | 48 +++++++++++++++++++ .../nn/torch.nn.SmoothL1Loss.md | 6 +-- .../nn/torch.nn.SoftMarginLoss.md | 45 +++++++++++++++++ 10 files changed, 231 insertions(+), 16 deletions(-) create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CTCLoss.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.HingeEmbeddingLoss.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MarginRankingLoss.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.NLLLoss.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SoftMarginLoss.md diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BCELoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BCELoss.md index c6bff2e1da8..912a147a09d 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BCELoss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BCELoss.md @@ -21,8 +21,8 @@ paddle.nn.BCELoss(weight=None, | PyTorch | PaddlePaddle | 备注 | | ------------- | ------------ | ------------------------------------------------------ | | weight | weight | 表示每个 batch 二值交叉熵的权重。 | -| size_average | - | PyTorch 已弃用。 | -| reduce | - | PyTorch 已弃用。 | +| size_average | - | PyTorch 已弃用,paddle 需要转写。 | +| reduce | - | PyTorch 已弃用,paddle 需要转写。 | | reduction | reduction | 表示应用于输出结果的计算方式。 | ### 转写示例 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BCEWithLogitsLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BCEWithLogitsLoss.md index 08a2bac96c3..44c6b57b591 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BCEWithLogitsLoss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BCEWithLogitsLoss.md @@ -1,5 +1,5 @@ # [ torch 参数更多 ]torch.nn.BCEWithLogitsLoss -### [torch.nn.BCEWithLogitsLoss](https) +### [torch.nn.BCEWithLogitsLoss](https://pytorch.org/docs/1.13/generated/torch.nn.BCEWithLogitsLoss.html#bcewithlogitsloss) ```python torch.nn.BCEWithLogitsLoss(weight=None, @@ -23,8 +23,8 @@ paddle.nn.BCEWithLogitsLoss(weight=None, | PyTorch | PaddlePaddle | 备注 | | ------------- | ------------ | ------------------------------------------------------ | | weight | weight | 表示每个 batch 二值交叉熵的权重。 | -| size_average | - | PyTorch 已弃用。 | -| reduce | - | PyTorch 已弃用。 | +| size_average | - | PyTorch 已弃用,paddle 需要转写。 | +| reduce | - | PyTorch 已弃用,paddle 需要转写。 | | reduction | reduction | 表示应用于输出结果的计算方式。 | | pos_weight | pos_weight | 表示正类的权重。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CTCLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CTCLoss.md new file mode 100644 index 00000000000..8c302b0ef1a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CTCLoss.md @@ -0,0 +1,26 @@ +# [torch 参数更多]torch.nn.CTCLoss + +### [torch.nn.CTCLoss](https://pytorch.org/docs/1.13/generated/torch.nn.CTCLoss.html#torch.nn.CTCLoss) + +```python +torch.nn.CTCLoss(blank=0, + reduction='mean', + zero_infinity=False) +``` + +### [paddle.nn.CTCLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/CTCLoss_cn.html#ctcloss) + +```python +paddle.nn.CTCLoss(blank=0, + reduction='mean') +``` + +其中,Pytorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | Paddle | 备注 | +| ------------- | --------- | ------------------------------------------------------------ | +| blank | blank | 空格标记的 ID 值。 | +| reduction | reduction | 表示应用于输出结果的计算方式。 | +| zero_infinity | - | 是否将无穷大损失及其梯度置 0,Paddle 无此参数,需要转写,paddle 暂无转写方式。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CrossEntropyLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CrossEntropyLoss.md index 90d2e662f42..80213853a79 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CrossEntropyLoss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CrossEntropyLoss.md @@ -1,5 +1,5 @@ # [torch 参数更多]torch.nn.CrossEntropyLoss -### [torch.nn.CrossEntropyLoss](https://pytorch.org/docs/stable/generated/torch.nn.CrossEntropyLoss.html?highlight=crossentropyloss#torch.nn.CrossEntropyLoss) +### [torch.nn.CrossEntropyLoss](https://pytorch.org/docs/1.13/generated/torch.nn.CrossEntropyLoss.html#torch.nn.CrossEntropyLoss) ```python torch.nn.CrossEntropyLoss(weight=None, @@ -26,13 +26,13 @@ paddle.nn.CrossEntropyLoss(weight=None, | PyTorch | PaddlePaddle | 备注 | | ------------- | ------------ | ------------------------------------------------------ | | weight | weight | 表示每个类别的权重。 | -| size_average | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| size_average | - | PyTorch 已弃用,Paddle 无此参数,需要转写。| | ignore_index | ignore_index | 表示忽略的一个标签值。 | -| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | | reduction | reduction | 表示应用于输出结果的计算方式。 | -| label_smoothing | - | 指定计算损失时的平滑量,Paddle 无此功能,暂无转写方式。 | -| - | soft_label | 指明 label 是否为软标签,Pytorch 无此参数,Paddle 保持默认即可。 | -| - | axis | 进行 softmax 计算的维度索引,Pytorch 无此参数,Paddle 保持默认即可。 | +| label_smoothing | - | 指定计算损失时的平滑量,Paddle 无此功能,暂无转写方式。 | +| - | soft_label | 指明 label 是否为软标签,Pytorch 无此参数,Paddle 保持默认即可。 | +| - | axis | 进行 softmax 计算的维度索引,Pytorch 无此参数,Paddle 保持默认即可。 | ### 转写示例 #### size_average diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.HingeEmbeddingLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.HingeEmbeddingLoss.md new file mode 100644 index 00000000000..27a44738862 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.HingeEmbeddingLoss.md @@ -0,0 +1,48 @@ +# [torch 参数更多]torch.nn.HingeEmbeddingLoss + +### [torch.nn.HingeEmbeddingLoss](https://pytorch.org/docs/1.13/generated/torch.nn.HingeEmbeddingLoss.html#hingeembeddingloss) + +```python +torch.nn.HingeEmbeddingLoss(margin=1.0, + size_average=None, + reduce=None, + reduction='mean') +``` + +### [paddle.nn.HingeEmbeddingLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/HingeEmbeddingLoss_cn.html#hingeembeddingloss) + +```python +paddle.nn.HingeEmbeddingLoss(margin=1.0, + reduction='mean', + name=None) +``` + +Pytorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | Paddle | 备注 | +| ------------ | --------- | ------------------------------------------------------------ | +| margin | margin | 当 label 为-1 时,该值决定了小于 margin 的 input 才需要纳入 hinge embedding loss 的计算。 | +| size_average | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduction | reduction | 表示应用于输出结果的计算方式。 | + +### 转写示例 + +#### size_average + +```python +# Pytorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True + +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.KLDivLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.KLDivLoss.md index 1be74f84e64..7918de4ed45 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.KLDivLoss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.KLDivLoss.md @@ -18,8 +18,8 @@ paddle.nn.KLDivLoss(reduction='mean') ### 参数差异 | PyTorch | PaddlePaddle | 备注 | | ------------- | ------------ | ------------------------------------------------------ | -| size_average | - | 已弃用。 | -| reduce | - | 已弃用。 | +| size_average | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | | reduction | reduction | 表示对输出结果的计算方式。 | | log_target | - | 指定目标是否为日志空间,Paddle 无此功能,暂无转写方式。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MarginRankingLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MarginRankingLoss.md new file mode 100644 index 00000000000..fd5fe4b2574 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MarginRankingLoss.md @@ -0,0 +1,48 @@ +# [torch 参数更多]torch.nn.MarginRankingLoss + +### [torch.nn.MarginRankingLoss](https://pytorch.org/docs/1.13/generated/torch.nn.MarginRankingLoss.html#marginrankingloss) + +```python +torch.nn.MarginRankingLoss(margin=0.0, + size_average=None, + reduce=None, + reduction='mean') +``` + +### [paddle.nn.MarginRankingLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/MarginRankingLoss_cn.html#marginrankingloss) + +```python +paddle.nn.MarginRankingLoss(margin=0.0, + reduction='mean', + name=None) +``` + +Pytorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | Paddle | 备注 | +| ------------ | --------- | -------------------------------------------- | +| margin | margin | 用于加和的 margin 值。 | +| size_average | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduction | reduction | 表示应用于输出结果的计算方式。 | + +### 转写示例 + +#### size_average + +```python +# Pytorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True + +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.NLLLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.NLLLoss.md new file mode 100644 index 00000000000..f7f9efb6c6e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.NLLLoss.md @@ -0,0 +1,48 @@ +# [torch 参数更多]torch.nn.NLLLoss + +### [torch.nn.NLLLoss](https://pytorch.org/docs/1.13/generated/torch.nn.NLLLoss.html?highlight=nllloss#torch.nn.NLLLoss) + +```python +torch.nn.NLLLoss(weight=None, + size_average=None, + ignore_index=- 100, + reduce=None, + reduction='mean') +``` + +### [paddle.nn.NLLLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/NLLLoss_cn.html#nllloss) + +```python +paddle.nn.NLLLoss(weight=None, + ignore_index=- 100, + reduction='mean', + name=None) +``` + +Pytorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 +| PyTorch | Paddle | 备注 | +| ------------ | ------------ | -------------------------------------------- | +| weight | weight | 表示每个类别的权重。 | +| size_average | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| ignore_index | ignore_index | 表示忽略的一个标签值。 | +| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduction | reduction | 表示应用于输出结果的计算方式。 | + +### 转写示例 +#### size_average +```python +# Pytorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True + +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SmoothL1Loss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SmoothL1Loss.md index dc49038a606..9bccd7db8bd 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SmoothL1Loss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SmoothL1Loss.md @@ -20,9 +20,9 @@ paddle.nn.SmoothL1Loss(reduction='mean', ### 参数映射 | PyTorch | PaddlePaddle | 备注 | | ------------- | ------------ | ------------------------------------------------------ | -| size_average | - | 已弃用。 | -| reduce | - | 已弃用。 | -| reduction | reduction | 表示对输出 Tensor 的计算方式。 | +| size_average | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduction | reduction | 表示应用于输出结果的计算方式。 | | beta | delta | SmoothL1Loss 损失的阈值参数。 | ### 转写示例 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SoftMarginLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SoftMarginLoss.md new file mode 100644 index 00000000000..eb68fa1d050 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SoftMarginLoss.md @@ -0,0 +1,45 @@ +# [torch 参数更多]torch.nn.SoftMarginLoss + +### [torch.nn.SoftMarginLosss](https://pytorch.org/docs/1.13/generated/torch.nn.SoftMarginLoss.html#torch.nn.SoftMarginLoss) + +```python +torch.nn.SoftMarginLoss(size_average=None, + reduce=None, + reduction='mean') +``` + +### [paddle.nn.SoftMarginLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/SoftMarginLoss_cn.html#softmarginloss) + +```python +paddle.nn.SoftMarginloss(reduction='mean', + name=None) +``` + +Pytorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | Paddle | 备注 | +| ------------ | --------- | -------------------------------------------- | +| size_average | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduction | reduction | 表示应用于输出结果的计算方式。 | + +### 转写示例 + +#### size_average + +```python +# Pytorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True + +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' +```