-
Notifications
You must be signed in to change notification settings - Fork 764
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* model_convert add torch.is_nonzero .etc * model_convert add is_nonzero .etc * model_convert add is_nonzero .etc * model_convert add is_nonzero .etc * add xlogy.etc * add randn_like .etc * comment * add vdot etc. * add aminmax etc. * fix parameter * add bucketizr etc. * add bucketizr etc. * add bucketizr etc. * add sinc etc. * add sinc etc. * add sinc etc.
- Loading branch information
Showing
20 changed files
with
423 additions
and
43 deletions.
There are no files selected for viewing
20 changes: 0 additions & 20 deletions
20
...onvert/convert_from_pytorch/api_difference/Tensor/tensor.Torch.count_nonzero.md
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
.../model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.hypot.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
## [ 组合替代实现 ]torch.Tensor.hypot | ||
|
||
### [torch.Tensor.hypot](https://pytorch.org/docs/stable/generated/torch.Tensor.hypot.html#torch.Tensor.hypot) | ||
|
||
```python | ||
torch.Tensor.hypot(other) | ||
``` | ||
|
||
给定直角三角形的直角边,求斜边; Paddle 无此 API,需要组合实现。 | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# Pytorch 写法 | ||
y = a.hypot(b) | ||
|
||
# Paddle 写法 | ||
y = (a**2 + b**2) ** (1/2) | ||
``` |
36 changes: 36 additions & 0 deletions
36
.../model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.istft.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
## [ 参数完全一致 ]torch.Tensor.istft | ||
### [torch.Tensor.istft](https://pytorch.org/docs/stable/generated/torch.Tensor.istft.html#torch.Tensor.istft) | ||
|
||
```python | ||
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/api/paddle/signal/istft_cn.html#istft) | ||
|
||
```python | ||
paddle.signal.istft(x, | ||
n_fft, | ||
hop_length=None, | ||
win_length=None, | ||
window=None, | ||
center=True, | ||
normalized=False, | ||
onesided=True, | ||
length=None, | ||
return_complex=False, | ||
name=None) | ||
``` | ||
|
||
两者功能一致且参数完全一致,具体如下: | ||
### 参数映射 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| n_fft | n_fft | 表示离散傅里叶变换的样本点个数。 | | ||
| hop_length | hop_length | 表示相邻两帧偏移的样本点个数。 | | ||
| win_length | win_length | 表示信号窗的长度。 | | ||
| window | window | 表示长度为 win_length 的 Tensor 。 | | ||
| center | center | 表示是否将输入信号进行补长。 | | ||
| normalized | normalized | 表示是否将傅里叶变换的结果乘以值为 1/sqrt(n) 的缩放系数。 | | ||
| onesided | onesided | 表示是否返回一个实信号。 | | ||
| length | length | 表示输出信号的长度。 | | ||
| return_complex | return_complex | 表示输出的重构信号是否为复信号。 | |
15 changes: 9 additions & 6 deletions
15
...model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logdet.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
## [ 无参数 ] torch.Tensor.logdet | ||
## [ 组合替代实现 ]torch.Tensor.logdet | ||
|
||
### [torch.Tensor.logdet](https://pytorch.org/docs/stable/generated/torch.Tensor.logdet.html) | ||
### [torch.Tensor.logdet](https://pytorch.org/docs/stable/generated/torch.Tensor.logdet.html#torch.Tensor.logdet) | ||
|
||
```python | ||
torch.Tensor.logdet() | ||
``` | ||
Paddle 无此 API,需要组合实现。 | ||
|
||
### [paddle.linalg.slogdet](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/linalg/slogdet_cn.html) | ||
### 转写示例 | ||
|
||
```python | ||
paddle.linalg.slogdet(x) | ||
``` | ||
# Pytorch 写法 | ||
y = input.logdet() | ||
|
||
两者功能一致,用于计算矩阵的对数行列式。 | ||
# Paddle 写法 | ||
y = paddle.log(paddle.linalg.det(input)) | ||
``` |
22 changes: 22 additions & 0 deletions
22
...del_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.pinverse.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
## [ 仅 Paddle 参数更多 ]torch.Tensor.pinverse | ||
### [torch.Tensor.pinverse](https://pytorch.org/docs/stable/generated/torch.Tensor.pinverse.html#torch.Tensor.pinverse) | ||
|
||
```python | ||
torch.Tensor.pinverse() | ||
``` | ||
|
||
### [paddle.linalg.pinv](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/linalg/pinv_cn.html#pinv) | ||
|
||
```python | ||
paddle.linalg.pinv(x, | ||
rcond=1e-15, | ||
hermitian=False, | ||
name=None) | ||
``` | ||
|
||
其中 Paddle 相比 Pytorch 支持更多参数,具体如下: | ||
### 参数映射 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| - | rcond | 奇异值(特征值)被截断的阈值,Pytorch 无此参数,Paddle 保持默认即可。 | | ||
| - | hermitian | 是否为 hermitian 矩阵或者实对称矩阵,Pytorch 无此参数,Paddle 保持默认即可。| |
19 changes: 19 additions & 0 deletions
19
...l_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.reshape_as.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
## [ 组合替代实现 ]torch.Tensor.reshape_as | ||
|
||
### [torch.Tensor.reshape_as](https://pytorch.org/docs/stable/generated/torch.Tensor.reshape_as.html#torch.Tensor.reshape_as) | ||
|
||
```python | ||
torch.Tensor.reshape_as(other) | ||
``` | ||
|
||
Paddle 无此 API,需要组合实现。 | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# Pytorch 写法 | ||
y = a.reshape_as(b) | ||
|
||
# Paddle 写法 | ||
y = paddle.reshape(a, b.shape) | ||
``` |
21 changes: 9 additions & 12 deletions
21
...model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.select.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,19 @@ | ||
## [ 仅参数名不一致 ]torch.Tensor.select | ||
## [ 组合替代实现 ]torch.Tensor.select | ||
|
||
### [torch.Tensor.select](https://pytorch.org/docs/stable/generated/torch.Tensor.select.html?highlight=select#torch.Tensor.select) | ||
|
||
```python | ||
torch.Tensor.select(dim, index) | ||
``` | ||
|
||
### [paddle.index_select](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#index-select-index-axis-0-name-none) | ||
Paddle 无此 API,需要组合实现。 | ||
|
||
```python | ||
paddle.Tensor.index_select(index, axis=0, name=None) | ||
``` | ||
|
||
两者功能一致且参数用法一致,仅参数名不一致,具体如下: | ||
### 转写示例 | ||
|
||
### 参数映射 | ||
```python | ||
# Pytorch 写法 | ||
y = a.select(dim=dim, index=index) | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| dim | axis | 指定进行运算的轴,仅参数名不同。 | | ||
| index | index | 包含索引下标的 1-D Tensor | | ||
# Paddle 写法 | ||
y = paddle.index_select(a, index=paddle.to_tensor([index]), axis=dim).squeeze(dim) | ||
``` |
20 changes: 20 additions & 0 deletions
20
...s/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sinc.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
## [ 组合替代实现 ]torch.Tensor.sinc | ||
|
||
### [torch.Tensor.sinc](https://pytorch.org/docs/stable/generated/torch.Tensor.sinc.html#torch.Tensor.sinc) | ||
|
||
```python | ||
torch.Tensor.sinc() | ||
``` | ||
|
||
Paddle 无此 API,需要组合实现。 | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# Pytorch 写法 | ||
y = a.sinc() | ||
|
||
# Paddle 写法 | ||
import numpy | ||
y = paddle.where(a==0, x=paddle.to_tensor([1], dtype=a.dtype), y=paddle.sin(numpy.pi*a)/(numpy.pi*a)) | ||
``` |
31 changes: 31 additions & 0 deletions
31
...odel_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.slogdet.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
## [ 参数不一致 ]torch.linalg.slogdet | ||
### [torch.linalg.slogdet](https://pytorch.org/docs/stable/generated/torch.linalg.slogdet.html#torch.linalg.slogdet) | ||
|
||
```pythonpa | ||
torch.linalg.slogdet(A, *, out=None) | ||
``` | ||
|
||
### [paddle.linalg.slogdet](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/linalg/slogdet_cn.html#slogdet) | ||
|
||
```python | ||
paddle.linalg.slogdet(x) | ||
``` | ||
|
||
两者功能一致但参数类型不一致,Pytorch 返回 named tuple,Paddle 返回 Tensor,需要转写。具体如下: | ||
### 参数映射 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| <font color='red'> A </font> | <font color='red'> x </font> | 表示输入的 Tensor ,仅参数名不一致。 | | ||
| <font color='red'> out </font> | - | 表示输出的 Tuple ,Paddle 无此参数,暂无转写方式。 | | ||
|
||
|
||
### 转写示例 | ||
#### 返回类型不一致 | ||
```python | ||
# Pytorch 写法 | ||
y = torch.linalg.slogdet(a) | ||
|
||
# Paddle 写法 | ||
result = paddle.linalg.slogdet(a) | ||
y = tuple([result[0], result[1]]) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
.../model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SyncBatchNorm.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
## [ 参数不一致 ]torch.nn.SyncBatchNorm | ||
### [torch.nn.SyncBatchNorm](https://pytorch.org/docs/stable/generated/torch.nn.SyncBatchNorm.html#torch.nn.SyncBatchNorm) | ||
|
||
```python | ||
torch.nn.SyncBatchNorm(num_features, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True, process_group=None, device=None, dtype=None) | ||
``` | ||
|
||
### [paddle.nn.SyncBatchNorm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/SyncBatchNorm_cn.html#syncbatchnorm) | ||
|
||
```python | ||
paddle.nn.SyncBatchNorm(num_features, epsilon=1e-5, momentum=0.9, weight_attr=None, bias_attr=None, data_format='NCHW', name=None) | ||
``` | ||
|
||
两者功能一致但参数不一致,部分参数名不同,具体如下: | ||
### 参数映射 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| num_features | num_features | 表示输入 Tensor 通道数。 | | ||
| eps | epsilon | 为了数值稳定加在分母上的值。 | | ||
| momentum | momentum | 表示归一化函数中的超参数, PyTorch 和 Paddle 公式实现细节不一致,两者正好是相反的,需要进行转写。 | | ||
| - | weight_attr | 指定权重参数属性的对象。如果为 False, 则表示每个通道的伸缩固定为 1,不可改变。默认值为 None,表示使用默认的权重参数属性。 | | ||
| - | bias_attr | 指定偏置参数属性的对象。如果为 False, 则表示每一个通道的偏移固定为 0,不可改变。默认值为 None,表示使用默认的偏置参数属性。 | | ||
| - | data_format | 指定输入数据格式, Pytorch 无此参数,Paddle 保持默认即可。 | | ||
| affine | - | 是否进行反射变换, PaddlePaddle 无此参数,需要进行转写。 | | ||
| track_running_stats | use_global_stats | 表示是否已加载的全局均值和方差。 | | ||
| process_group | - | 统计信息的同步分别在每个进程组内发生, PaddlePaddle 无此参数,暂无转写方式。 | | ||
| device | - | 设备类型,PaddlePaddle 无此参数。可直接删除。 | | ||
| dtype | - | 参数类型,PaddlePaddle 无此参数。需要转写 | | ||
|
||
### 转写示例 | ||
#### affine:是否进行反射变换 | ||
```python | ||
affine=False 时,表示不更新: | ||
|
||
# PyTorch 写法 | ||
m = torch.nn.SyncBatchNorm(24, affine=False) | ||
|
||
# Paddle 写法 | ||
m = paddle.nn.SyncBatchNorm(24, weight_attr=False, bias_attr=False) | ||
|
||
affine=True 时,表示更新: | ||
|
||
# PyTorch 写法 | ||
m = torch.nn.SyncBatchNorm(24) | ||
|
||
# Paddle 写法 | ||
m = paddle.nn.SyncBatchNorm(24) | ||
``` | ||
|
||
#### momentum: | ||
```python | ||
# PyTorch 写法 | ||
m = torch.nn.SyncBatchNorm(24, momentum=0.2) | ||
|
||
# Paddle 写法 | ||
m = paddle.nn.SyncBatchNorm(24, momentum=0.8) | ||
``` | ||
|
||
#### dtype: | ||
```python | ||
# PyTorch 写法 | ||
m = torch.nn.SyncBatchNorm(24, momentum=0.2, dtype=torch.float32) | ||
y = m(x) | ||
|
||
# Paddle 写法 | ||
m = paddle.nn.SyncBatchNorm(24, momentum=0.8) | ||
y = m(x).astype(paddle.float32) | ||
``` |
19 changes: 19 additions & 0 deletions
19
docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.hypot.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
## [ 组合替代实现 ]torch.hypot | ||
|
||
### [torch.hypot](https://pytorch.org/docs/stable/generated/torch.hypot.html#torch.hypot) | ||
|
||
```python | ||
torch.hypot(input, other, *, out=None) | ||
``` | ||
|
||
给定直角三角形的直角边,求斜边; Paddle 无此 API,需要组合实现。 | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# Pytorch 写法 | ||
y = torch.hypot(a, b) | ||
|
||
# Paddle 写法 | ||
y = (a**2 + b**2) ** (1/2) | ||
``` |
19 changes: 19 additions & 0 deletions
19
docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.select.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
## [ 组合替代实现 ]torch.select | ||
|
||
### [torch.select](https://pytorch.org/docs/stable/generated/torch.select.html#torch.select) | ||
|
||
```python | ||
torch.select(input, dim, index) | ||
``` | ||
|
||
Paddle 无此 API,需要组合实现。 | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# Pytorch 写法 | ||
y = torch.select(a, dim=dim, index=index) | ||
|
||
# Paddle 写法 | ||
y = paddle.index_select(a, index=paddle.to_tensor([index]), axis=dim).squeeze(dim) | ||
``` |
20 changes: 20 additions & 0 deletions
20
docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sinc.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
## [ 组合替代实现 ]torch.sinc | ||
|
||
### [torch.sinc](https://pytorch.org/docs/stable/generated/torch.sinc.html#torch.sinc) | ||
|
||
```python | ||
torch.sinc(input, *, out=None) | ||
``` | ||
|
||
Paddle 无此 API,需要组合实现。 | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# Pytorch 写法 | ||
y = torch.sinc(a) | ||
|
||
# Paddle 写法 | ||
import numpy | ||
y = paddle.where(a==0, x=paddle.to_tensor([1], dtype=a.dtype), y=paddle.sin(numpy.pi*a)/(numpy.pi*a)) | ||
``` |
Oops, something went wrong.