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

映射文档 No. 54 #5852

Merged
merged 3 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -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 | 表示应用于输出结果的计算方式。 |

### 转写示例
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 | 表示正类的权重。 |

Expand Down
Original file line number Diff line number Diff line change
@@ -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 支持在损失函数值为无穷大时将损失值及其梯度置为 0,paddle 暂无此功能,具体如下:
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里直接写 其中,Pytorch 相比 Paddle 支持更多其他参数,具体如下: 即可~

Copy link
Contributor Author

Choose a reason for hiding this comment

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

你好,已修改👌


### 参数映射

| PyTorch | Paddle | 备注 |
| ------------- | --------- | ------------------------------------------------------------ |
| blank | blank | 空格标记的 ID 值。 |
| reduction | reduction | 表示应用于输出结果的计算方式。 |
| zero_infinity | - | 是否将无穷大损失及其梯度置 0,Paddle 无此参数,需要转写,paddle 暂无转写方式。 |
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -26,13 +26,13 @@ paddle.nn.CrossEntropyLoss(weight=None,
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| weight | weight | 表示每个类别的权重。 |
| <font color='red'> size_average </font> | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 |
| size_average | - | PyTorch 已弃用,Paddle 无此参数,需要转写。|
| ignore_index | ignore_index | 表示忽略的一个标签值。 |
| <font color='red'> reduce </font> | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 |
| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 |
| reduction | reduction | 表示应用于输出结果的计算方式。 |
| <font color='red'> label_smoothing </font> | - | 指定计算损失时的平滑量,Paddle 无此功能,暂无转写方式。 |
| - | <font color='red'> soft_label </font> | 指明 label 是否为软标签,Pytorch 无此参数,Paddle 保持默认即可。 |
| - | <font color='red'> axis </font> | 进行 softmax 计算的维度索引,Pytorch 无此参数,Paddle 保持默认即可。 |
| label_smoothing | - | 指定计算损失时的平滑量,Paddle 无此功能,暂无转写方式。 |
| - | soft_label | 指明 label 是否为软标签,Pytorch 无此参数,Paddle 保持默认即可。 |
| - | axis | 进行 softmax 计算的维度索引,Pytorch 无此参数,Paddle 保持默认即可。 |

### 转写示例
#### size_average
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
```
Original file line number Diff line number Diff line change
Expand Up @@ -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 无此功能,暂无转写方式。 |

Expand Down
Original file line number Diff line number Diff line change
@@ -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'
```
Original file line number Diff line number Diff line change
@@ -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'
```
Original file line number Diff line number Diff line change
Expand Up @@ -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 损失的阈值参数。 |

### 转写示例
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
```