Skip to content

Commit

Permalink
【映射文档】更新与维护部分 api 的映射文档 (PaddlePaddle#6476)
Browse files Browse the repository at this point in the history
* update scripts

* update docs

* fix apiname in pytorch_api_mapping_cn.md
  • Loading branch information
RedContritio authored Jan 22, 2024
1 parent 64646ff commit c2b5bec
Show file tree
Hide file tree
Showing 56 changed files with 241 additions and 208 deletions.
2 changes: 1 addition & 1 deletion docs/guides/model_convert/convert_from_pytorch/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
api_mappings.json
docs_mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
### [torch.Tensor.addmm_](https://pytorch.org/docs/stable/generated/torch.Tensor.addmm_.html)

```python
torch.Tensor.addmm(mat1, mat2, *, beta=1, alpha=1)
torch.Tensor.addmm_(mat1, mat2, *, beta=1, alpha=1)
```

### [paddle.Tensor.addmm_]()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
torch.Tensor.arctan2(other)
```

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

```python
paddle.atan2(x, y, name=None)
paddle.Tensor.atan2(y, name=None)
```

两者功能一致且参数用法一致,仅参数名不一致,具体如下:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
torch.Tensor.bernoulli(*, generator=None)
```

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

```python
paddle.bernoulli(x, name=None)
paddle.Tensor.bernoulli(name=None)
```

PyTorch 相比 Paddle 支持更多其他参数,具体如下:
Expand All @@ -29,5 +29,5 @@ y = x.bernoulli()

# paddle 写法
x = paddle.to_tensor([0.2, 0.6, 0.8])
y = paddle.bernoulli(x)
y = x.bernoulli()
```
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
## [参数不一致]torch.Tensor.cholesky_solve
## [ 仅参数名不一致 ]torch.Tensor.cholesky_solve

### [torch.Tensor.cholesky_solve](https://pytorch.org/docs/stable/generated/torch.Tensor.cholesky_solve.html#torch-tensor-cholesky-solve)

```python
torch.Tensor.cholesky_solve(input2,upper=False)
torch.Tensor.cholesky_solve(input2, upper=False)
```

### [paddle.linalg.cholesky_solve](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/cholesky_solve_cn.html#cholesky-solve)
### [paddle.Tensor.cholesky_solve]()

```python
paddle.linalg.cholesky_solve(x,y,upper=False,name=None)
paddle.Tensor.cholesky_solve(y, upper=False, name=None)
```

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

### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ------- | ------------ | -------------------------------------------------------------------------- |
| - | x | 表示线性方程中 B 矩阵,PyTorch 中为当前 Tensor。参数用法不一致,需要转写。 |
| input2 | y | 表示线性方程中 A 矩阵的 Cholesky 分解矩阵 u。仅参数名不一致。 |
| upper | upper | 表示输入 x 是否是上三角矩阵,True 为上三角矩阵,False 为下三角矩阵。 |

### 转写示例
# torch 写法
x.cholesky_solve(y)

# paddle 写法
paddle.linalg.cholesky_solve(x, y)
```
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
torch.Tensor.coalesce()
```

### [paddle.sparse.coalesce](paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#chunk-chunks-axis-0-name-none)
### [paddle.Tensor.coalesce](https://www.paddlepaddle.org.cn/documentation/docs/en/develop/api/paddle/Tensor/coalesce_en.html)

```python
paddle.sparse.coalesce(x)
paddle.Tensor.coalesce(name=None)
```

两者功能一致,无参数。
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## [ 仅 paddle 参数更多 ]torch.Tenor.cov
### [torch.Tenor.cov](https://pytorch.org/docs/stable/generated/torch.Tensor.cov.html#torch.Tensor.cov)
## [ 仅 paddle 参数更多 ]torch.Tensor.cov
### [torch.Tensor.cov](https://pytorch.org/docs/stable/generated/torch.Tensor.cov.html#torch.Tensor.cov)

```python
torch.Tensor.cov(*, correction=1, fweights=None, aweights=None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下:
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------------------------ |
| device | device_id | 目标 GPU 设备,仅参数名不一致。 |
| non_blocking | blocking | 是否使用同步拷贝,仅参数名不一致。 |
| non_blocking | blocking | 是否同步或异步拷贝,PyTorch 和 Paddle 取值相反,需要转写。 |
| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
torch.Tensor.det()
```

### [paddle.linalg.det](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/det_cn.html#det)
### [paddle.Tensor.det]()

```python
paddle.linalg.det(x)
paddle.Tensor.det(name=None)
```

两者功能一致,均无参数。
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
torch.Tensor.diagflat(offset=0)
```

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

```python
paddle.diagflat(x, offset=0, name=None)
paddle.Tensor.diagflat(offset=0, name=None)
```

两者功能参数完全一致,其中 torch 是类成员函数,而 paddle 是非类成员函数,因此第一个参数 `x` 不进行对比,其他参数的映射为
两者功能一致,参数完全一致,具体如下

### 参数映射

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
## [ 无参数 ]torch.Tensor.expm1

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

```python
torch.Tensor.expm1()
```

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

```python
paddle.expm1(x, name=None)
paddle.Tensor.expm1(name=None)
```

两者功能一致,无参数。
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
torch.Tensor.floor_divide(other)
```

### [paddle.Tesnor.floor_divide](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#floor-divide-y-name-none)
### [paddle.Tensor.floor_divide](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#floor-divide-y-name-none)

```python
paddle.Tensor.floor_divide(y, name=None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
torch.Tensor.floor_divide_(other)
```

### [paddle.Tesnor.floor_divide_]()
### [paddle.Tensor.floor_divide_]()

```python
paddle.Tensor.floor_divide_(y)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
torch.Tensor.get_device()
```

### [paddle.device.get_device]()
### [paddle.Tensor.place.gpu_device_id]()

```python
paddle.device.get_device()
paddle.Tensor.place.gpu_device_id()
```

两者功能一致且无参数。
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
torch.Tensor.index_add(dim, index, source, *, alpha=1)
```

### [paddle.index_add](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/index_add_cn.html#index-add)
### [paddle.Tensor.index_add]()

```python
paddle.index_add(x, index, axis, value, name=None)
paddle.Tensor.index_add(index, axis, value, name=None)
```

其中 PyTorch 与 Paddle 参数有差异,具体如下:
### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| - | <font color='red'> x </font> | 表示输入的 Tensor 。 |
| <font color='red'> dim </font> | <font color='red'> axis </font> | 表示进行运算的轴,仅参数名不一致。 |
| <font color='red'> index </font> | <font color='red'> index </font> | 包含索引下标的 1-D Tensor。 |
| <font color='red'> source </font> | <font color='red'> value </font> | 被加的 Tensor,仅参数名不一致。 |
Expand All @@ -29,5 +28,5 @@ paddle.index_add(x, index, axis, value, name=None)
x.index_add(dim=1, index=index, source=source, alpha=alpha)

# Paddle 写法
paddle.index_add(x, index=index, axis=1, value=alpha*source)
x.index_add(index=index, axis=1, value=alpha*source)
```
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ paddle.Tensor.index_add_(index, axis, value)
```

其中 PyTorch 与 Paddle 参数有差异,具体如下:

### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
### [torch.Tensor.is_contiguous](https://pytorch.org/docs/stable/generated/torch.Tensor.is_contiguous.html#torch-tensor-is-contiguous)

```
Tensor.is_contiguous(memory_format=torch.contiguous_format)
torch.Tensor.is_contiguous(memory_format=torch.contiguous_format)
```

判断 Tensor 是否是 contiguous 的,PaddlePaddle 的 Tensor 默认是 contiguous 的, 因此可直接视作为 True。
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
torch.Tensor.istft(n_fft, hop_length=None, win_length=None, window=None, center=True, normalized=False, onesided=None, length=None, return_complex=False)
```

### [paddle.signal.istft](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/signal/istft_cn.html#istft)
### [paddle.Tensor.istft]()

```python
paddle.signal.istft(x,
n_fft,
paddle.Tensor.istft(n_fft,
hop_length=None,
win_length=None,
window=None,
Expand All @@ -22,7 +21,9 @@ paddle.signal.istft(x,
```

两者功能一致且参数完全一致,具体如下:

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| n_fft | n_fft | 表示离散傅里叶变换的样本点个数。 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
### [torch.Tensor.minimum](https://pytorch.org/docs/stable/generated/torch.Tensor.minimum.html)

```python
torch.Tensor.maximum(other)
torch.Tensor.minimum(other)
```

### [paddle.Tensor.minimum](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#minimum-y-axis-1-name-none)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
torch.Tensor.multinomial(num_samples, replacement=False, *, generator=None)
```

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

```python
paddle.multinomial(x, num_samples=1, replacement=False, name=None)
paddle.Tensor.multinomial(num_samples=1, replacement=False, name=None)
```

PyTorch 相比 Paddle 支持更多其他参数,具体如下:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
### [torch.Tensor.nansum](https://pytorch.org/docs/stable/generated/torch.Tensor.nansum.html?highlight=nansum#torch.Tensor.nansum)

```python
Tensor.nansum(dim=None,
torch.Tensor.nansum(dim=None,
keepdim=False,
dtype=None)
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
torch.Tensor.outer(vec2)
```

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

```python
paddle.outer(x, y)
paddle.Tensor.outer(y)
```

两者功能一致且参数用法一致,仅参数名不一致,具体如下:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
torch.Tensor.pinverse()
```

### [paddle.linalg.pinv](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/pinv_cn.html#pinv)
### [paddle.Tensor.pinv]()

```python
paddle.linalg.pinv(x,
rcond=1e-15,
paddle.Tensor.pinv(rcond=1e-15,
hermitian=False,
name=None)
```

其中 Paddle 相比 PyTorch 支持更多参数,具体如下:

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| - | rcond | 奇异值(特征值)被截断的阈值,PyTorch 无此参数,Paddle 保持默认即可。 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
torch.Tensor.pow(exponent)
```

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

```python
paddle.pow(x, y)
paddle.Tensor.pow(y)
```

两者功能一致且参数用法一致,仅参数名不一致,具体如下:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
torch.Tensor.reciprocal()
```

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

```python
paddle.reciprocal(x)
paddle.Tensor.reciprocal()
```

两者功能一致,无参数。
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
### [torch.Tensor.reciprocal_](https://pytorch.org/docs/stable/generated/torch.Tensor.reciprocal_.html?highlight=torch+tensor+reciprocal_#torch.Tensor.reciprocal_)

```python
x.reciprocal_()
torch.Tensor.reciprocal_()
```

### [paddle.Tensor.reciprocal_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#id11)

```python
x.reciprocal_()
paddle.Tensor.reciprocal_()
```

两者功能一致,无参数。
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
torch.Tensor.remainder(divisor)
```

### [paddle.remainder](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/remainder_cn.html#remainder)
### [paddle.Tensor.remainder](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#remainder-y-name-none)

```python
paddle.remainder(x, y)
paddle.Tensor.remainder(y, name=None)
```


其中 Paddle 与 PyTorch 运算除数参数所支持的类型不一致,具体如下:

### 参数映射
Expand All @@ -23,8 +22,8 @@ paddle.remainder(x, y)
#### divisor:除数为 Scalar
```python
# PyTorch 写法
y = x.remainder(1)
x.remainder(1)

# Paddle 写法
paddle.remainder(x, y=paddle.to_tensor(1))
x.remainder(y=paddle.to_tensor(1))
```
Loading

0 comments on commit c2b5bec

Please sign in to comment.