diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.BCELoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.BCELoss.md index b9805cb8922..5cd295e7960 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.BCELoss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.BCELoss.md @@ -25,7 +25,8 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下: | reduction | reduction | 表示应用于输出结果的计算方式。 | ### 转写示例 -#### size_averagesize_average 为 True +#### size_average +size_average 为 True ```python # PyTorch 写法 torch.nn.BCELoss(weight=w, size_average=True) @@ -43,7 +44,8 @@ torch.nn.BCELoss(weight=w, size_average=False) paddle.nn.BCELoss(weight=w, reduction='sum') ``` -#### reducereduce 为 True +#### reduce +reduce 为 True ```python # PyTorch 写法 torch.nn.BCELoss(weight=w, reduce=True) @@ -61,7 +63,8 @@ torch.nn.BCELoss(weight=w, reduce=False) paddle.nn.BCELoss(weight=w, reduction='none') ``` -#### reductionreduction 为'none' +#### reduction +reduction 为'none' ```python # PyTorch 写法 torch.nn.BCELoss(weight=w, reduction='none') diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.BCEWithLogitsLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.BCEWithLogitsLoss.md index f11f2925181..a05a0bc8ffe 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.BCEWithLogitsLoss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.BCEWithLogitsLoss.md @@ -28,7 +28,8 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下: | pos_weight | pos_weight | 表示正类的权重。 | ### 转写示例 -#### size_averagesize_average 为 True +#### size_average +size_average 为 True ```python # PyTorch 写法 torch.nn.BCEWithLogitsLoss(weight=w, size_average=True) @@ -46,7 +47,8 @@ torch.nn.BCEWithLogitsLoss(weight=w, size_average=False) paddle.nn.BCEWithLogitsLoss(weight=w, reduction='sum') ``` -#### reducereduce 为 True +#### reduce +reduce 为 True ```python # PyTorch 写法 torch.nn.BCEWithLogitsLoss(weight=w, reduce=True) @@ -64,7 +66,8 @@ torch.nn.BCEWithLogitsLoss(weight=w, reduce=False) paddle.nn.BCEWithLogitsLoss(weight=w, reduction='none') ``` -#### reductionreduction 为'none' +#### reduction +reduction 为'none' ```python # PyTorch 写法 torch.nn.BCEWithLogitsLoss(weight=w, reduction='none') diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.CosineEmbeddingLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.CosineEmbeddingLoss.md index 186efe01e13..5f58e0303aa 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.CosineEmbeddingLoss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.CosineEmbeddingLoss.md @@ -21,17 +21,75 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下: | reduction | reduction | 指定应用于输出结果的计算方式。 | ### 转写示例 +#### size_average +size_average 为 True + +```python +# PyTorch 写法 +torch.nn.CosineEmbeddingLoss(weight=w, size_average=True) + +# Paddle 写法 +paddle.nn.CosineEmbeddingLoss(weight=w, reduction='mean') +``` + +size_average 为 False + +```python +# PyTorch 写法 +torch.nn.CosineEmbeddingLoss(weight=w, size_average=False) + +# Paddle 写法 +paddle.nn.CosineEmbeddingLoss(weight=w, reduction='sum') +``` + +#### reduce +reduce 为 True + +```python +# PyTorch 写法 +torch.nn.CosineEmbeddingLoss(weight=w, reduce=True) + +# Paddle 写法 +paddle.nn.CosineEmbeddingLoss(weight=w, reduction='mean') +``` + +reduce 为 False + ```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' +# PyTorch 写法 +torch.nn.CosineEmbeddingLoss(weight=w, reduce=False) + +# Paddle 写法 +paddle.nn.CosineEmbeddingLoss(weight=w, reduction='none') +``` + +#### reduction +reduction 为'none' + +```python +# PyTorch 写法 +torch.nn.CosineEmbeddingLoss(weight=w, reduction='none') + +# Paddle 写法 +paddle.nn.CosineEmbeddingLoss(weight=w, reduction='none') +``` + +reduction 为'mean' + +```python +# PyTorch 写法 +torch.nn.CosineEmbeddingLoss(weight=w, reduction='mean') + +# Paddle 写法 +paddle.nn.CosineEmbeddingLoss(weight=w, reduction='mean') +``` + +reduction 为'sum' + +```python +# PyTorch 写法 +torch.nn.CosineEmbeddingLoss(weight=w, reduction='sum') + +# Paddle 写法 +paddle.nn.CosineEmbeddingLoss(weight=w, reduction='sum') ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.CrossEntropyLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.CrossEntropyLoss.md index 4f5bd45cccd..f6b69e18ead 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.CrossEntropyLoss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.CrossEntropyLoss.md @@ -36,7 +36,8 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下: | - | axis | 进行 softmax 计算的维度索引,PyTorch 无此参数,Paddle 保持默认即可。 | ### 转写示例 -#### size_averagesize_average 为 True +#### size_average +size_average 为 True ```python # PyTorch 写法 torch.nn.CrossEntropyLoss(weight=w, size_average=True) @@ -54,7 +55,8 @@ torch.nn.CrossEntropyLoss(weight=w, size_average=False) paddle.nn.CrossEntropyLoss(weight=w, reduction='sum') ``` -#### reducereduce 为 True +#### reduce +reduce 为 True ```python # PyTorch 写法 torch.nn.CrossEntropyLoss(weight=w, reduce=True) @@ -72,7 +74,8 @@ torch.nn.CrossEntropyLoss(weight=w, reduce=False) paddle.nn.CrossEntropyLoss(weight=w, reduction='none') ``` -#### reductionreduction 为'none' +#### reduction +reduction 为'none' ```python # PyTorch 写法 torch.nn.CrossEntropyLoss(weight=w, reduction='none') diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.HingeEmbeddingLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.HingeEmbeddingLoss.md index bb68acdc67d..b098c562767 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.HingeEmbeddingLoss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.HingeEmbeddingLoss.md @@ -27,17 +27,74 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下: ### 转写示例 #### size_average +size_average 为 True + +```python +# PyTorch 写法 +torch.nn.HingeEmbeddingLoss(weight=w, size_average=True) + +# Paddle 写法 +paddle.nn.HingeEmbeddingLoss(weight=w, reduction='mean') +``` + +size_average 为 False + +```python +# PyTorch 写法 +torch.nn.HingeEmbeddingLoss(weight=w, size_average=False) + +# Paddle 写法 +paddle.nn.HingeEmbeddingLoss(weight=w, reduction='sum') +``` + +#### reduce +reduce 为 True + +```python +# PyTorch 写法 +torch.nn.HingeEmbeddingLoss(weight=w, reduce=True) + +# Paddle 写法 +paddle.nn.HingeEmbeddingLoss(weight=w, reduction='mean') +``` + +reduce 为 False + ```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' +# PyTorch 写法 +torch.nn.HingeEmbeddingLoss(weight=w, reduce=False) + +# Paddle 写法 +paddle.nn.HingeEmbeddingLoss(weight=w, reduction='none') +``` + +#### reduction +reduction 为'none' + +```python +# PyTorch 写法 +torch.nn.HingeEmbeddingLoss(weight=w, reduction='none') + +# Paddle 写法 +paddle.nn.HingeEmbeddingLoss(weight=w, reduction='none') +``` + +reduction 为'mean' + +```python +# PyTorch 写法 +torch.nn.HingeEmbeddingLoss(weight=w, reduction='mean') + +# Paddle 写法 +paddle.nn.HingeEmbeddingLoss(weight=w, reduction='mean') +``` + +reduction 为'sum' + +```python +# PyTorch 写法 +torch.nn.HingeEmbeddingLoss(weight=w, reduction='sum') + +# Paddle 写法 +paddle.nn.HingeEmbeddingLoss(weight=w, reduction='sum') ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.KLDivLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.KLDivLoss.md index 44b60df0963..a80b9250c6c 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.KLDivLoss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.KLDivLoss.md @@ -25,17 +25,74 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下: ### 转写示例 #### size_average +size_average 为 True + +```python +# PyTorch 写法 +torch.nn.KLDivLoss(weight=w, size_average=True) + +# Paddle 写法 +paddle.nn.KLDivLoss(weight=w, reduction='mean') +``` + +size_average 为 False + +```python +# PyTorch 写法 +torch.nn.KLDivLoss(weight=w, size_average=False) + +# Paddle 写法 +paddle.nn.KLDivLoss(weight=w, reduction='sum') +``` + +#### reduce +reduce 为 True + +```python +# PyTorch 写法 +torch.nn.KLDivLoss(weight=w, reduce=True) + +# Paddle 写法 +paddle.nn.KLDivLoss(weight=w, reduction='mean') +``` + +reduce 为 False + ```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' +# PyTorch 写法 +torch.nn.KLDivLoss(weight=w, reduce=False) + +# Paddle 写法 +paddle.nn.KLDivLoss(weight=w, reduction='none') +``` + +#### reduction +reduction 为'none' + +```python +# PyTorch 写法 +torch.nn.KLDivLoss(weight=w, reduction='none') + +# Paddle 写法 +paddle.nn.KLDivLoss(weight=w, reduction='none') +``` + +reduction 为'mean' + +```python +# PyTorch 写法 +torch.nn.KLDivLoss(weight=w, reduction='mean') + +# Paddle 写法 +paddle.nn.KLDivLoss(weight=w, reduction='mean') +``` + +reduction 为'sum' + +```python +# PyTorch 写法 +torch.nn.KLDivLoss(weight=w, reduction='sum') + +# Paddle 写法 +paddle.nn.KLDivLoss(weight=w, reduction='sum') ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.L1Loss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.L1Loss.md index 27d625ae85f..c7155ebfc1c 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.L1Loss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.L1Loss.md @@ -23,17 +23,74 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下: ### 转写示例 #### size_average +size_average 为 True + +```python +# PyTorch 写法 +torch.nn.L1Loss(size_average=True) + +# Paddle 写法 +paddle.nn.L1Loss(reduction='mean') +``` + +size_average 为 False + +```python +# PyTorch 写法 +torch.nn.L1Loss(size_average=False) + +# Paddle 写法 +paddle.nn.L1Loss(reduction='sum') +``` + +#### reduce +reduce 为 True + +```python +# PyTorch 写法 +torch.nn.L1Loss(reduce=True) + +# Paddle 写法 +paddle.nn.L1Loss(reduction='mean') +``` + +reduce 为 False + ```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' +# PyTorch 写法 +torch.nn.L1Loss(reduce=False) + +# Paddle 写法 +paddle.nn.L1Loss(reduction='none') +``` + +#### reduction +reduction 为'none' + +```python +# PyTorch 写法 +torch.nn.L1Loss(reduction='none') + +# Paddle 写法 +paddle.nn.L1Loss(reduction='none') +``` + +reduction 为'mean' + +```python +# PyTorch 写法 +torch.nn.L1Loss(reduction='mean') + +# Paddle 写法 +paddle.nn.L1Loss(reduction='mean') +``` + +reduction 为'sum' + +```python +# PyTorch 写法 +torch.nn.L1Loss(reduction='sum') + +# Paddle 写法 +paddle.nn.L1Loss(reduction='sum') ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.MSELoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.MSELoss.md index 433eb5fbcd3..adfef1dfc58 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.MSELoss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.MSELoss.md @@ -21,15 +21,6 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下: | reduction | reduction | 表示对输出结果的计算方式。 | ### 转写示例 -#### size_average -```python -# Paddle 写法 -torch.nn.MSELoss(size_average=True) - -# Paddle 写法 -paddle.nn.MSELoss(reduction='mean') -``` - #### size_average size_average 为 True diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.MarginRankingLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.MarginRankingLoss.md index 98eb855c012..e6e92148b17 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.MarginRankingLoss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.MarginRankingLoss.md @@ -27,17 +27,74 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下: ### 转写示例 #### size_average +size_average 为 True + +```python +# PyTorch 写法 +torch.nn.MarginRankingLoss(weight=w, size_average=True) + +# Paddle 写法 +paddle.nn.MarginRankingLoss(weight=w, reduction='mean') +``` + +size_average 为 False + +```python +# PyTorch 写法 +torch.nn.MarginRankingLoss(weight=w, size_average=False) + +# Paddle 写法 +paddle.nn.MarginRankingLoss(weight=w, reduction='sum') +``` + +#### reduce +reduce 为 True + +```python +# PyTorch 写法 +torch.nn.MarginRankingLoss(weight=w, reduce=True) + +# Paddle 写法 +paddle.nn.MarginRankingLoss(weight=w, reduction='mean') +``` + +reduce 为 False + ```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' +# PyTorch 写法 +torch.nn.MarginRankingLoss(weight=w, reduce=False) + +# Paddle 写法 +paddle.nn.MarginRankingLoss(weight=w, reduction='none') +``` + +#### reduction +reduction 为'none' + +```python +# PyTorch 写法 +torch.nn.MarginRankingLoss(weight=w, reduction='none') + +# Paddle 写法 +paddle.nn.MarginRankingLoss(weight=w, reduction='none') +``` + +reduction 为'mean' + +```python +# PyTorch 写法 +torch.nn.MarginRankingLoss(weight=w, reduction='mean') + +# Paddle 写法 +paddle.nn.MarginRankingLoss(weight=w, reduction='mean') +``` + +reduction 为'sum' + +```python +# PyTorch 写法 +torch.nn.MarginRankingLoss(weight=w, reduction='sum') + +# Paddle 写法 +paddle.nn.MarginRankingLoss(weight=w, reduction='sum') ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.MultiLabelMarginLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.MultiLabelMarginLoss.md index 936dafc0c66..e21e9406749 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.MultiLabelMarginLoss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.MultiLabelMarginLoss.md @@ -20,17 +20,75 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下: | reduction | reduction | 指定应用于输出结果的计算方式。 | ### 转写示例 +#### size_average +size_average 为 True + +```python +# PyTorch 写法 +torch.nn.MultiLabelMarginLoss(weight=w, size_average=True) + +# Paddle 写法 +paddle.nn.MultiLabelMarginLoss(weight=w, reduction='mean') +``` + +size_average 为 False + +```python +# PyTorch 写法 +torch.nn.MultiLabelMarginLoss(weight=w, size_average=False) + +# Paddle 写法 +paddle.nn.MultiLabelMarginLoss(weight=w, reduction='sum') +``` + +#### reduce +reduce 为 True + +```python +# PyTorch 写法 +torch.nn.MultiLabelMarginLoss(weight=w, reduce=True) + +# Paddle 写法 +paddle.nn.MultiLabelMarginLoss(weight=w, reduction='mean') +``` + +reduce 为 False + ```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' +# PyTorch 写法 +torch.nn.MultiLabelMarginLoss(weight=w, reduce=False) + +# Paddle 写法 +paddle.nn.MultiLabelMarginLoss(weight=w, reduction='none') +``` + +#### reduction +reduction 为'none' + +```python +# PyTorch 写法 +torch.nn.MultiLabelMarginLoss(weight=w, reduction='none') + +# Paddle 写法 +paddle.nn.MultiLabelMarginLoss(weight=w, reduction='none') +``` + +reduction 为'mean' + +```python +# PyTorch 写法 +torch.nn.MultiLabelMarginLoss(weight=w, reduction='mean') + +# Paddle 写法 +paddle.nn.MultiLabelMarginLoss(weight=w, reduction='mean') +``` + +reduction 为'sum' + +```python +# PyTorch 写法 +torch.nn.MultiLabelMarginLoss(weight=w, reduction='sum') + +# Paddle 写法 +paddle.nn.MultiLabelMarginLoss(weight=w, reduction='sum') ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.MultiLabelSoftMarginLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.MultiLabelSoftMarginLoss.md index e42656734a6..604265f4e40 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.MultiLabelSoftMarginLoss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.MultiLabelSoftMarginLoss.md @@ -21,17 +21,75 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下: | reduction | reduction | 指定应用于输出结果的计算方式。 | ### 转写示例 +#### size_average +size_average 为 True + +```python +# PyTorch 写法 +torch.nn.MultiLabelSoftMarginLoss(weight=w, size_average=True) + +# Paddle 写法 +paddle.nn.MultiLabelSoftMarginLoss(weight=w, reduction='mean') +``` + +size_average 为 False + +```python +# PyTorch 写法 +torch.nn.MultiLabelSoftMarginLoss(weight=w, size_average=False) + +# Paddle 写法 +paddle.nn.MultiLabelSoftMarginLoss(weight=w, reduction='sum') +``` + +#### reduce +reduce 为 True + +```python +# PyTorch 写法 +torch.nn.MultiLabelSoftMarginLoss(weight=w, reduce=True) + +# Paddle 写法 +paddle.nn.MultiLabelSoftMarginLoss(weight=w, reduction='mean') +``` + +reduce 为 False + ```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' +# PyTorch 写法 +torch.nn.MultiLabelSoftMarginLoss(weight=w, reduce=False) + +# Paddle 写法 +paddle.nn.MultiLabelSoftMarginLoss(weight=w, reduction='none') +``` + +#### reduction +reduction 为'none' + +```python +# PyTorch 写法 +torch.nn.MultiLabelSoftMarginLoss(weight=w, reduction='none') + +# Paddle 写法 +paddle.nn.MultiLabelSoftMarginLoss(weight=w, reduction='none') +``` + +reduction 为'mean' + +```python +# PyTorch 写法 +torch.nn.MultiLabelSoftMarginLoss(weight=w, reduction='mean') + +# Paddle 写法 +paddle.nn.MultiLabelSoftMarginLoss(weight=w, reduction='mean') +``` + +reduction 为'sum' + +```python +# PyTorch 写法 +torch.nn.MultiLabelSoftMarginLoss(weight=w, reduction='sum') + +# Paddle 写法 +paddle.nn.MultiLabelSoftMarginLoss(weight=w, reduction='sum') ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.MultiMarginLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.MultiMarginLoss.md index 713da40d42d..e45cda33913 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.MultiMarginLoss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.MultiMarginLoss.md @@ -23,20 +23,75 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下: | reduction | reduction | 指定应用于输出结果的计算方式,可选值有 `none`、`mean` 和 `sum`。默认为 `mean`,计算 mini-batch loss 均值。设置为 `sum` 时,计算 mini-batch loss 的总和。设置为 `none` 时,则返回 loss Tensor。默认值下为 `mean`。 | ### 转写示例 +#### size_average +size_average 为 True + +```python +# PyTorch 写法 +torch.nn.MultiMarginLoss(weight=w, size_average=True) + +# Paddle 写法 +paddle.nn.MultiMarginLoss(weight=w, reduction='mean') +``` + +size_average 为 False + +```python +# PyTorch 写法 +torch.nn.MultiMarginLoss(weight=w, size_average=False) + +# Paddle 写法 +paddle.nn.MultiMarginLoss(weight=w, reduction='sum') +``` + +#### reduce +reduce 为 True + +```python +# PyTorch 写法 +torch.nn.MultiMarginLoss(weight=w, reduce=True) + +# Paddle 写法 +paddle.nn.MultiMarginLoss(weight=w, reduction='mean') +``` + +reduce 为 False + ```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' - -# 如果 PyTorch 存在 reduction 参数,则直接覆盖 -if 'reduction' not in kwargs: - kwargs['reduction'] = reduction +# PyTorch 写法 +torch.nn.MultiMarginLoss(weight=w, reduce=False) + +# Paddle 写法 +paddle.nn.MultiMarginLoss(weight=w, reduction='none') +``` + +#### reduction +reduction 为'none' + +```python +# PyTorch 写法 +torch.nn.MultiMarginLoss(weight=w, reduction='none') + +# Paddle 写法 +paddle.nn.MultiMarginLoss(weight=w, reduction='none') +``` + +reduction 为'mean' + +```python +# PyTorch 写法 +torch.nn.MultiMarginLoss(weight=w, reduction='mean') + +# Paddle 写法 +paddle.nn.MultiMarginLoss(weight=w, reduction='mean') +``` + +reduction 为'sum' + +```python +# PyTorch 写法 +torch.nn.MultiMarginLoss(weight=w, reduction='sum') + +# Paddle 写法 +paddle.nn.MultiMarginLoss(weight=w, reduction='sum') ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.NLLLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.NLLLoss.md index f9f20d00838..270510e7b4e 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.NLLLoss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.NLLLoss.md @@ -29,15 +29,6 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下: | reduction | reduction | 表示应用于输出结果的计算方式。 | ### 转写示例 -#### size_average -```python -# Paddle 写法 -torch.nn.NLLLoss(size_average=True) - -# Paddle 写法 -paddle.nn.NLLLoss(reduction='mean') -``` - #### size_average size_average 为 True diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.PoissonNLLLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.PoissonNLLLoss.md index d7cb3058cba..87fc2fcbd35 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.PoissonNLLLoss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.PoissonNLLLoss.md @@ -23,20 +23,75 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下: | reduction | reduction | 指定应用于输出结果的计算方式,可选值有 `none`、`mean` 和 `sum`。默认为 `mean`,计算 mini-batch loss 均值。设置为 `sum` 时,计算 mini-batch loss 的总和。设置为 `none` 时,则返回 loss Tensor。默认值下为 `mean`。两者完全一致。 | ### 转写示例 +#### size_average +size_average 为 True + +```python +# PyTorch 写法 +torch.nn.PoissonNLLLoss(weight=w, size_average=True) + +# Paddle 写法 +paddle.nn.PoissonNLLLoss(weight=w, reduction='mean') +``` + +size_average 为 False + +```python +# PyTorch 写法 +torch.nn.PoissonNLLLoss(weight=w, size_average=False) + +# Paddle 写法 +paddle.nn.PoissonNLLLoss(weight=w, reduction='sum') +``` + +#### reduce +reduce 为 True + +```python +# PyTorch 写法 +torch.nn.PoissonNLLLoss(weight=w, reduce=True) + +# Paddle 写法 +paddle.nn.PoissonNLLLoss(weight=w, reduction='mean') +``` + +reduce 为 False + ```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' - -# 如果 PyTorch 存在 reduction 参数,则直接覆盖 -if 'reduction' not in kwargs: - kwargs['reduction'] = reduction +# PyTorch 写法 +torch.nn.PoissonNLLLoss(weight=w, reduce=False) + +# Paddle 写法 +paddle.nn.PoissonNLLLoss(weight=w, reduction='none') +``` + +#### reduction +reduction 为'none' + +```python +# PyTorch 写法 +torch.nn.PoissonNLLLoss(weight=w, reduction='none') + +# Paddle 写法 +paddle.nn.PoissonNLLLoss(weight=w, reduction='none') +``` + +reduction 为'mean' + +```python +# PyTorch 写法 +torch.nn.PoissonNLLLoss(weight=w, reduction='mean') + +# Paddle 写法 +paddle.nn.PoissonNLLLoss(weight=w, reduction='mean') +``` + +reduction 为'sum' + +```python +# PyTorch 写法 +torch.nn.PoissonNLLLoss(weight=w, reduction='sum') + +# Paddle 写法 +paddle.nn.PoissonNLLLoss(weight=w, reduction='sum') ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.SmoothL1Loss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.SmoothL1Loss.md index a81d3efa0b1..3ea1a12e759 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.SmoothL1Loss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.SmoothL1Loss.md @@ -28,15 +28,7 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下: ### 转写示例 #### size_average -```python -# Paddle 写法 -torch.nn.SmoothL1Loss(size_average=True) - -# Paddle 写法 -paddle.nn.SmoothL1Loss(reduction='mean') -``` - -#### size_averagesize_average 为 True +size_average 为 True ```python # PyTorch 写法 torch.nn.SmoothL1Loss(size_average=True) @@ -54,7 +46,8 @@ torch.nn.SmoothL1Loss(size_average=False) paddle.nn.SmoothL1Loss(reduction='sum') ``` -#### reducereduce 为 True +#### reduce +reduce 为 True ```python # PyTorch 写法 torch.nn.SmoothL1Loss(reduce=True) @@ -72,7 +65,8 @@ torch.nn.SmoothL1Loss(reduce=False) paddle.nn.SmoothL1Loss(reduction='none') ``` -#### reductionreduction 为'none' +#### reduction +reduction 为'none' ```python # PyTorch 写法 torch.nn.SmoothL1Loss(reduction='none') diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.SoftMarginLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.SoftMarginLoss.md index 6868324c3ba..02c1eedd7a9 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.SoftMarginLoss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.SoftMarginLoss.md @@ -24,17 +24,74 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下: ### 转写示例 #### size_average +size_average 为 True + +```python +# PyTorch 写法 +torch.nn.TripletMarginLoss(weight=w, size_average=True) + +# Paddle 写法 +paddle.nn.TripletMarginLoss(weight=w, reduction='mean') +``` + +size_average 为 False + +```python +# PyTorch 写法 +torch.nn.TripletMarginLoss(weight=w, size_average=False) + +# Paddle 写法 +paddle.nn.TripletMarginLoss(weight=w, reduction='sum') +``` + +#### reduce +reduce 为 True + +```python +# PyTorch 写法 +torch.nn.TripletMarginLoss(weight=w, reduce=True) + +# Paddle 写法 +paddle.nn.TripletMarginLoss(weight=w, reduction='mean') +``` + +reduce 为 False + ```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' +# PyTorch 写法 +torch.nn.TripletMarginLoss(weight=w, reduce=False) + +# Paddle 写法 +paddle.nn.TripletMarginLoss(weight=w, reduction='none') +``` + +#### reduction +reduction 为'none' + +```python +# PyTorch 写法 +torch.nn.TripletMarginLoss(weight=w, reduction='none') + +# Paddle 写法 +paddle.nn.TripletMarginLoss(weight=w, reduction='none') +``` + +reduction 为'mean' + +```python +# PyTorch 写法 +torch.nn.TripletMarginLoss(weight=w, reduction='mean') + +# Paddle 写法 +paddle.nn.TripletMarginLoss(weight=w, reduction='mean') +``` + +reduction 为'sum' + +```python +# PyTorch 写法 +torch.nn.TripletMarginLoss(weight=w, reduction='sum') + +# Paddle 写法 +paddle.nn.TripletMarginLoss(weight=w, reduction='sum') ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.TripletMarginLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.TripletMarginLoss.md index b074981e813..eb7e7d35688 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.TripletMarginLoss.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.TripletMarginLoss.md @@ -24,17 +24,75 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下: | reduction | reduction | 指定应用于输出结果的计算方式。 | ### 转写示例 +#### size_average +size_average 为 True + +```python +# PyTorch 写法 +torch.nn.TripletMarginLoss(weight=w, size_average=True) + +# Paddle 写法 +paddle.nn.TripletMarginLoss(weight=w, reduction='mean') +``` + +size_average 为 False + +```python +# PyTorch 写法 +torch.nn.TripletMarginLoss(weight=w, size_average=False) + +# Paddle 写法 +paddle.nn.TripletMarginLoss(weight=w, reduction='sum') +``` + +#### reduce +reduce 为 True + +```python +# PyTorch 写法 +torch.nn.TripletMarginLoss(weight=w, reduce=True) + +# Paddle 写法 +paddle.nn.TripletMarginLoss(weight=w, reduction='mean') +``` + +reduce 为 False + ```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' +# PyTorch 写法 +torch.nn.TripletMarginLoss(weight=w, reduce=False) + +# Paddle 写法 +paddle.nn.TripletMarginLoss(weight=w, reduction='none') +``` + +#### reduction +reduction 为'none' + +```python +# PyTorch 写法 +torch.nn.TripletMarginLoss(weight=w, reduction='none') + +# Paddle 写法 +paddle.nn.TripletMarginLoss(weight=w, reduction='none') +``` + +reduction 为'mean' + +```python +# PyTorch 写法 +torch.nn.TripletMarginLoss(weight=w, reduction='mean') + +# Paddle 写法 +paddle.nn.TripletMarginLoss(weight=w, reduction='mean') +``` + +reduction 为'sum' + +```python +# PyTorch 写法 +torch.nn.TripletMarginLoss(weight=w, reduction='sum') + +# Paddle 写法 +paddle.nn.TripletMarginLoss(weight=w, reduction='sum') ```