Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
@@ -0,0 +1,25 @@
## [ 仅 API 调用方式不一致 ]torch.Tensor.sparse_mask

### [torch.Tensor.sparse_mask](https://pytorch.org/docs/stable/tensors.html#torch.Tensor.sparse_mask)

```python
torch.Tensor.sparse_mask(mask)
```

### [paddle.sparse.mask_as](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/sparse/mask_as_cn.html#paddle/sparse/mask_as_cn#cn-api-paddle-sparse-mask_as)

```python
paddle.sparse.mask_as(x, mask, name=None)
```

两者功能一致,但调用方式不一致,具体如下:

### 转写示例

```python
# PyTorch 写法
out = x.sparse_mask(coo)

# Paddle 写法
out = paddle.sparse.mask_as(x, coo)
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## [ 仅 API 调用方式不一致 ]torch.distributions.distribution.Distribution.log_prob

### [torch.distributions.distribution.Distribution.log_prob](https://pytorch.org/docs/stable/generated/torch.distributions.distribution.Distribution.html#torch.distributions.distribution.Distribution.log_prob)

```python
torch.distributions.distribution.Distribution.log_prob(value)
```

### [paddle.distribution.Distribution.log_prob](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/Distribution/log_prob_cn.html#paddle/distribution/Distribution/log_prob_cn#cn-api-paddle-distribution-Distribution-log_prob)

```python
paddle.distribution.Distribution.log_prob(value)
```

两者功能一致,但调用方式不一致,具体如下:

### 转写示例

```python
# PyTorch 写法
uniform = torch.distributions.Uniform(0.0, 1.0)
result = uniform.log_prob(torch.tensor(0.3))

# Paddle 写法
uniform = paddle.distribution.Uniform(0.0, 1.0)
result = uniform.log_prob(paddle.to_tensor(0.3))
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## [ 仅 API 调用方式不一致 ]torch.max

### [torch.max](https://pytorch.org/docs/stable/generated/torch.max.html)

```python
torch.max(input, *, out=None)
Copy link
Collaborator

Choose a reason for hiding this comment

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

这几个签名直接写 torch.max(*args, **kwargs)

max、min、median、nanmedian

```

### [paddle.compat.max](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/compat/max_cn.html#paddle/compat/max_cn#cn-api-paddle-compat-max)

```python
paddle.compat.max(input, *, out=None)
```

两者功能一致,但调用方式不一致,具体如下:

### 转写示例

```python
# PyTorch 写法
result = torch.max(x)
Copy link
Collaborator

Choose a reason for hiding this comment

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

备注一下:torch.max有多种签名与用法,均只需修改torch前缀为paddle.compat


# Paddle 写法
result = paddle.compat.max(x)

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## [ 仅 API 调用方式不一致 ]torch.median

### [torch.median](https://pytorch.org/docs/stable/generated/torch.median.html)

```python
torch.median(input)
```

### [paddle.compat.median](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/compat/median_cn.html#paddle/compat/median_cn#cn-api-paddle-compat-median)

```python
paddle.compat.median(input, dim=None, keepdim=False, *, out=None)
Copy link
Collaborator

Choose a reason for hiding this comment

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

上面如果按*args, **kwargs写,这里也这样写吧

```

两者功能一致,但调用方式不一致,具体如下:

### 转写示例

```python
# PyTorch 写法
result = torch.median(input)
Copy link
Collaborator

Choose a reason for hiding this comment

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

同上


# Paddle 写法
result = paddle.compat.median(input)

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## [ 仅 API 调用方式不一致 ]torch.min

### [torch.min](https://pytorch.org/docs/stable/generated/torch.min.html)

```python
torch.min(input, *, out=None)
```

### [paddle.compat.min](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/compat/min_cn.html#paddle/compat/min_cn#cn-api-paddle-compat-min)

```python
paddle.compat.min(input, *args, out=None, **kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

*args, **kwargs

```

两者功能一致,但调用方式不一致,具体如下:
Copy link
Collaborator

Choose a reason for hiding this comment

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

同上


### 转写示例

```python
# PyTorch 写法
result = torch.min(x)

# Paddle 写法
result = paddle.compat.min(x)

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## [ 仅 API 调用方式不一致 ]torch.nanmedian

### [torch.nanmedian](https://pytorch.org/docs/stable/generated/torch.nanmedian.html)

```python
torch.nanmedian(input)
```

### [paddle.compat.nanmedian](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/compat/nanmedian_cn.html#paddle/compat/nanmedian_cn#cn-api-paddle-compat-nanmedian)

```python
paddle.compat.nanmedian(input, dim=None, keepdim=False, *, out=None)
Copy link
Collaborator

Choose a reason for hiding this comment

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

*args, **kwargs

```

两者功能一致,但调用方式不一致,具体如下:

### 转写示例

```python
# PyTorch 写法
result = torch.nanmedian(input)
Copy link
Collaborator

Choose a reason for hiding this comment

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

同上


# Paddle 写法
result = paddle.compat.nanmedian(input)

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## [ 仅 API 调用方式不一致 ]torch.nn.Unfold

### [torch.nn.Unfold](https://pytorch.org/docs/stable/generated/torch.nn.Unfold.html#torch.nn.Unfold)

```python
torch.nn.Unfold(kernel_size, dilation=1, padding=0, stride=1)
```

### [paddle.compat.Unfold](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/compat/Unfold_cn.html#paddle/compat/Unfold_cn#cn-api-paddle-compat-Unfold)

```python
paddle.compat.Unfold(kernel_size, dilation=1, padding=0, stride=1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

paconvert更新为paddle.compat.nn.Unfold

```

两者功能一致,但调用方式不一致,具体如下:

### 转写示例

```python
# PyTorch 写法
unfold = torch.nn.Unfold(kernel_size=(2, 2))

# Paddle 写法
unfold = paddle.compat.Unfold(kernel_size=(2, 2))
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个更新成了 paddle.compat.nn.Unfold


```
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## [ 仅 API 调用方式不一致 ]torch.nn.functional.pad

### [torch.nn.functional.pad](https://pytorch.org/docs/stable/nn.functional.html#torch.nn.functional.pad)

```python
torch.nn.functional.pad(input, pad, mode="constant", value=None)
```

### [paddle.compat.pad](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/compat/pad_cn.html#paddle/compat/pad_cn#cn-api-paddle-compat-pad)

```python
paddle.compat.pad(input, pad, mode="constant", value=0.0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

paconvert更新为paddle.compat.nn.functional.pad

```

两者功能一致,但调用方式不一致,具体如下:

### 转写示例

```python
# PyTorch 写法
result = torch.nn.functional.pad(x, [0, 0, 0, 0, 0, 1, 2, 3], value=1)

# Paddle 写法
result = paddle.compat.pad(x, [0, 0, 0, 0, 0, 1, 2, 3], value=1)

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## [ 仅 API 调用方式不一致 ]torch.nn.functional.softmax

### [torch.nn.functional.softmax](https://pytorch.org/docs/stable/nn.functional.html#torch.nn.functional.softmax)

```python
torch.nn.functional.softmax(input, dim=None, _stacklevel=3, dtype=None)
```

### [paddle.compat.softmax](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/compat/softmax_cn.html#paddle/compat/softmax_cn#cn-api-paddle-compat-softmax)

```python
paddle.compat.softmax(input, dim=None, dtype, *, out=None)
Copy link
Collaborator

Choose a reason for hiding this comment

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

如果是 [仅API调用方式不一致],上下的签名,API参数部分应该都是一样的,或者paddle比torch参数更多

这里需要再整体核对下,为什么会有的参数不符合上面的情况。

paddle.compat.softmax的_stacklevel、dtype都是一样的。多一个out。

```

两者功能一致,但调用方式不一致,具体如下:

### 转写示例

```python
# PyTorch 写法
result = torch.nn.functional.softmax(x, -1)

# Paddle 写法
result = paddle.compat.softmax(x, -1)

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## [ 仅 API 调用方式不一致 ]torch.optim.Optimizer.add_param_group

### [torch.optim.Optimizer.add_param_group](https://pytorch.org/docs/stable/generated/torch.optim.Optimizer.html#torch.optim.Optimizer.add_param_group)

```python
torch.optim.Optimizer.add_param_group(param_group)
```

### [paddle.optimizer.Optimizer._add_param_group](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/Optimizer/_add_param_group_cn.html#paddle/optimizer/Optimizer/_add_param_group_cn#cn-api-paddle-optimizer-Optimizer-_add_param_group)

```python
paddle.optimizer.Optimizer._add_param_group(param_group)
```

两者功能一致,但调用方式不一致,具体如下:

### 转写示例

```python
# PyTorch 写法
optimizer = torch.optim.SGD(pg1, lr=0.1, momentum=0.9, weight_decay=0.0005)
optimizer.add_param_group({
'params': pg2,
'lr': 0.1 * 2,
'weight_decay': 0.0
})

# Paddle 写法
optimizer = paddle.optimizer.SGD(learning_rate=0.1, parameters=pg1, weight_decay=0.0005)
optimizer._add_param_group({
'params': pg2,
'learning_rate': 0.1 * 2,
'weight_decay': 0.0
})

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## [ 仅 API 调用方式不一致 ]torch.optim.Optimizer.load_state_dict

### [torch.optim.Optimizer.load_state_dict](https://pytorch.org/docs/stable/generated/torch.optim.Optimizer.html#torch.optim.Optimizer.load_state_dict)

```python
torch.optim.Optimizer.load_state_dict(state_dict)
```

### [paddle.optimizer.Optimizer.load_state_dict](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/Optimizer/load_state_dict_cn.html#paddle/optimizer/Optimizer/load_state_dict_cn#cn-api-paddle-optimizer-Optimizer-load_state_dict)

```python
paddle.optimizer.Optimizer.load_state_dict(state_dict)
```

两者功能一致,但调用方式不一致,具体如下:

### 转写示例

```python
# PyTorch 写法
optim = torch.optim.SGD([theta], lr=1.0)
result = optim.state_dict()
optim.load_state_dict(result)

# Paddle 写法
optim = paddle.optimizer.SGD(learning_rate=1.0, parameters=[theta])
result = optim.state_dict()
optim.load_state_dict(result)

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## [ 仅 API 调用方式不一致 ]torch.sort

### [torch.sort](https://pytorch.org/docs/stable/generated/torch.sort.html)

```python
torch.sort(input, dim=-1, descending=False, *, stable=False, out=None)
```

### [paddle.compat.sort](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/compat/sort_cn.html#paddle/compat/sort_cn#cn-api-paddle-compat-sort)

```python
paddle.compat.sort(input, dim=-1, descending=False, stable=False, out=None)
```

两者功能一致,但调用方式不一致,具体如下:

### 转写示例

```python
# PyTorch 写法
result = torch.sort(a)

# Paddle 写法
result = paddle.compat.sort(a)

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## [ 仅 API 调用方式不一致 ]torch.split

### [torch.split](https://pytorch.org/docs/stable/generated/torch.split.html)

```python
torch.split(tensor, split_size_or_sections, dim=0)
```

### [paddle.compat.split](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/compat/split_cn.html#paddle/compat/split_cn#cn-api-paddle-compat-split)

```python
paddle.compat.split(tensor, split_size_or_sections, dim=0)
```

两者功能一致,但调用方式不一致,具体如下:

### 转写示例

```python
# PyTorch 写法
result = torch.split(a, 2)

# Paddle 写法
result = paddle.compat.split(a, 2)

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## [ 仅 API 调用方式不一致 ]torchvision.io.ImageReadMode.GRAY

### [torchvision.io.ImageReadMode.GRAY](https://pytorch.org/vision/stable/generated/torchvision.io.ImageReadMode.html#torchvision.io.ImageReadMode.GRAY)

```python
torchvision.io.ImageReadMode.GRAY
```

两者功能一致,但调用方式不一致,具体如下:

### 转写示例

```python
## PyTorch 写法
mode = torchvision.io.ImageReadMode.GRAY

## Paddle 写法
mode = 'gray'
```
Loading