-
Notifications
You must be signed in to change notification settings - Fork 756
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
【Hackathon 7th No.37】为 Paddle 代码转换工具新增 API 转换规则(第 4 组)-part #6884
Changes from all commits
614e281
46ac3dc
a9c013c
67a3eed
d5980ae
35226d4
810e997
05498ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
## [ 仅参数名不一致 ]torch.Tensor.igamma | ||
|
||
### [torch.Tensor.igamma](https://pytorch.org/docs/stable/generated/torch.Tensor.igamma.html#torch.Tensor.igamma) | ||
|
||
```python | ||
torch.Tensor.igamma(other) | ||
``` | ||
|
||
### [paddle.Tensor.gammainc](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/gammainc_cn.html#gammainc) | ||
|
||
```python | ||
paddle.Tensor.gammainc(y, name=None) | ||
``` | ||
|
||
两者功能一致且参数用法一致,仅参数名不一致,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------- | ------------ | --------------------------- | | ||
| other | y | 正参数 Tensor,仅参数名不同 | | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# PyTorch 写法 | ||
out = x.igamma(y) | ||
|
||
# Paddle 写法 | ||
out = x.gammainc(y) | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
## [ 仅参数名不一致 ]torch.Tensor.igamma_ | ||
|
||
### [torch.Tensor.igamma_](https://pytorch.org/docs/stable/generated/torch.Tensor.igamma_.html#torch.Tensor.igamma_) | ||
|
||
```python | ||
torch.Tensor.igamma_(other) | ||
``` | ||
|
||
### [paddle.Tensor.gammainc_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/gammainc__cn.html#gammainc) | ||
|
||
```python | ||
paddle.Tensor.gammainc_(y, name=None) | ||
``` | ||
|
||
两者功能一致且参数用法一致,仅参数名不一致,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------- | ------------ | --------------------------- | | ||
| other | y | 正参数 Tensor,仅参数名不同 | | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# PyTorch 写法 | ||
out = x.igamma_(y) | ||
|
||
# Paddle 写法 | ||
out = x.gammainc_(y) | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
## [ 仅参数名不一致 ]torch.Tensor.igammac | ||
|
||
### [torch.Tensor.igammac](https://pytorch.org/docs/stable/generated/torch.Tensor.igammac.html#torch.Tensor.igammac) | ||
|
||
```python | ||
torch.Tensor.igammac(other) | ||
``` | ||
|
||
### [paddle.Tensor.gammaincc](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/gammaincc_cn.html#gammaincc) | ||
|
||
```python | ||
paddle.Tensor.gammaincc(y, name=None) | ||
``` | ||
|
||
两者功能一致且参数用法一致,仅参数名不一致,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------- | ------------ | --------------------------- | | ||
| other | y | 正参数 Tensor,仅参数名不同 | | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# PyTorch 写法 | ||
out = x.igammac(y) | ||
|
||
# Paddle 写法 | ||
out = x.gammaincc(y) | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
## [ 仅参数名不一致 ]torch.Tensor.igammac\_ | ||
|
||
### [torch.Tensor.igammac_](https://pytorch.org/docs/stable/generated/torch.Tensor.igammac_.html#torch.Tensor.igammac_) | ||
|
||
```python | ||
torch.Tensor.igammac_(other) | ||
``` | ||
|
||
### [paddle.Tensor.gammaincc_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/gammaincc__cn.html#gammaincc) | ||
|
||
```python | ||
paddle.Tensor.gammaincc_(y, name=None) | ||
``` | ||
|
||
两者功能一致且参数用法一致,仅参数名不一致,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------- | ------------ | --------------------------- | | ||
| other | y | 正参数 Tensor,仅参数名不同 | | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# PyTorch 写法 | ||
out = x.igammac_(y) | ||
|
||
# Paddle 写法 | ||
out = x.gammaincc_(y) | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
## [ 无参数 ]torch.Tensor.matrix_exp | ||
|
||
### [torch.Tensor.matrix_exp](https://pytorch.org/docs/stable/generated/torch.Tensor.matrix_exp.html#torch-tensor-matrix-exp) | ||
|
||
```python | ||
torch.Tensor.matrix_exp() | ||
``` | ||
|
||
### [paddle.linalg.matrix_exp](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/matrix_exp_cn.html) | ||
|
||
```python | ||
paddle.linalg.matrix_exp(x, name=None) | ||
``` | ||
|
||
两者功能一致,无参数。 | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# PyTorch 写法 | ||
out = x.matrix_exp() | ||
|
||
# Paddle 写法 | ||
out = paddle.linalg.matrix_exp(x) | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
## [ 参数完全一致 ]torch.Tensor.mvlgamma | ||
|
||
### [torch.Tensor.mvlgamma](https://pytorch.org/docs/stable/generated/torch.Tensor.mvlgamma.html#torch-tensor-mvlgamma) | ||
|
||
```python | ||
torch.Tensor.mvlgamma(p) | ||
``` | ||
|
||
### [paddle.Tensor.multigammaln](https://github.com/PaddlePaddle/Paddle/blob/be090bd0bc9ac7a8595296c316b3a6ed3dc60ba6/python/paddle/tensor/math.py#L5099) | ||
|
||
```python | ||
paddle.Tensor.multigammaln(p, name=None) | ||
``` | ||
|
||
两者功能一致,参数完全一致,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------- | ------------ | ---------------------------------------------------- | | ||
| p | p | 多元伽马函数积分空间的维度。 | | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# PyTorch 写法 | ||
y = x.mvlgamma(p) | ||
|
||
# Paddle 写法 | ||
y = x.multigammaln(p) | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
## [ 参数完全一致 ]torch.Tensor.mvlgamma_ | ||
|
||
### [torch.Tensor.mvlgamma_](https://pytorch.org/docs/stable/generated/torch.Tensor.mvlgamma_.html#torch-tensor-mvlgamma) | ||
|
||
```python | ||
torch.Tensor.mvlgamma_(p) | ||
``` | ||
|
||
### [paddle.Tensor.multigammaln_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/multigammaln__cn.html#multigammaln) | ||
|
||
```python | ||
paddle.Tensor.multigammaln_(p, name=None) | ||
``` | ||
|
||
两者功能一致,参数完全一致,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------- | ------------ | ---------------------------------------------------- | | ||
| p | p | 多元伽马函数积分空间的维度。 | | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# PyTorch 写法 | ||
y = x.mvlgamma_(p) | ||
|
||
# Paddle 写法 | ||
y = x.multigammaln_(p) | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
## [ 仅参数名不一致 ]torch.Tensor.orgqr | ||
|
||
### [torch.Tensor.orgqr](https://pytorch.org/docs/stable/generated/torch.Tensor.orgqr.html#torch.Tensor.orgqr) | ||
|
||
```python | ||
torch.Tensor.orgqr(input2) | ||
``` | ||
|
||
### [paddle.Tensor.householder_product](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/householder_product_cn.html#householder-product) | ||
|
||
```python | ||
paddle.Tensor.householder_product(tau, name=None) | ||
``` | ||
|
||
两者功能一致且参数用法一致,仅参数名不一致,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------- | ------------ | ------------------------------ | | ||
| input2 | tau | 用于计算矩阵乘积,仅参数名不同 | |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
## [ 仅参数名不一致 ]torch.Tensor.ormqr | ||
|
||
### [torch.Tensor.ormqr](https://pytorch.org/docs/stable/generated/torch.Tensor.orgqr.html#torch.Tensor.orgqr) | ||
|
||
```python | ||
torch.Tensor.ormqr(input2, input3, left=True, transpose=False) | ||
``` | ||
|
||
### [paddle.linalg.ormqr](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/linalg/ormqr_cn.html#ormqr) | ||
|
||
```python | ||
paddle.linalg.ormqr(x, tau, other, left=True, transpose=False) | ||
``` | ||
|
||
两者功能一致且参数用法一致,仅参数名不一致,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| --------- | ------------ | ---------------------------------- | | ||
| input2 | tau | Householder 反射系数,仅参数名不同 | | ||
| input3 | other | 用于矩阵乘积,仅参数名不同 | | ||
| left | left | 决定了矩阵乘积运算的顺序,一致 | | ||
| transpose | transpose | 决定矩阵 Q 是否共轭转置变换,一致 | |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
## [ 返回参数类型不一致 ]torch.linalg.cholesky_ex | ||
|
||
### [torch.linalg.cholesky_ex](https://pytorch.org/docs/stable/generated/torch.linalg.cholesky_ex.html) | ||
|
||
```python | ||
torch.linalg.cholesky_ex(input, *, upper=False, check_errors=False, out=None) | ||
``` | ||
|
||
### [paddle.linalg.cholesky](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/cholesky_cn.html) | ||
|
||
```python | ||
paddle.linalg.cholesky(x, upper=False, name=None) | ||
``` | ||
|
||
两者功能一致但返回参数类型不同,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------ | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| input | x | 表示输入参数为多维 Tensor,它的维度应该为 [*, M, N],其中*为零或更大的批次尺寸,并且最里面的两个维度上的矩阵都应为对称的正定矩阵,仅参数名不一致。 | | ||
| upper | upper | 表示是否返回上三角矩阵或下三角矩阵。 | | ||
| check_errors | - | 是否检查错误,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | | ||
| out | - | 表示输出的 Tensor ,Paddle 无此参数,需要转写。 | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| 返回值 | 返回值 | Pytorch 返回两个 out 与 info,Paddle 仅返回一个 Tensor:out,需转写。 | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 返回值这个还是需要转写的,我的意思是 你不用再注释强调仅支持 check_errors=False 这句话 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 懂了,那个强调不需要,我都觉得返回值不转写太奇怪了 |
||
|
||
### 转写示例 | ||
|
||
#### 返回值 | ||
|
||
```python | ||
# PyTorch 写法 | ||
torch.linalg.cholesky_ex(x, upper=False) | ||
|
||
# Paddle 写法 | ||
(paddle.linalg.cholesky(x, upper=False), paddle.zeros(x.shape[:-2], dtype='int32')) | ||
``` | ||
|
||
#### out: 输出的 Tensor | ||
|
||
```python | ||
# PyTorch 写法 | ||
torch.linalg.cholesky_ex(x, upper=False, out=output) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
|
||
# Paddle 写法 | ||
out1 = paddle.linalg.cholesky(x, upper=False) | ||
out2 = paddle.zeros(x.shape[:-2], dtype='int32') | ||
paddle.assign(out1, output=output[0]), paddle.assign(out2, output=output[1]) | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
## [ 返回参数类型不一致 ]torch.linalg.inv_ex | ||
|
||
### [torch.linalg.inv_ex](https://pytorch.org/docs/stable/generated/torch.linalg.inv_ex.html) | ||
|
||
```python | ||
torch.linalg.inv_ex(A, *, check_errors=False, out=None) | ||
``` | ||
|
||
### [paddle.linalg.inv](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/inv_cn.html) | ||
|
||
```python | ||
paddle.linalg.inv(x, name=None) | ||
monster1015 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
两者功能一致但返回参数类型不同,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------ | ------------ | --------------------------------------------------------------------- | | ||
| A | x | 输入 Tensor,仅参数名不一致。 | | ||
| check_errors | - | 是否检查错误,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | | ||
| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | | ||
| 返回值 | 返回值 | Pytorch 返回两个 out 与 info,Paddle 仅返回一个 Tensor:out,需转写。 | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 返回值这个还是需要转写的,我的意思是 你不用再注释强调仅支持 check_errors=False 这句话 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已经好了的 |
||
|
||
### 转写示例 | ||
|
||
#### 返回值 | ||
|
||
```python | ||
# PyTorch 写法 | ||
torch.linalg.inv_ex(x) | ||
|
||
# Paddle 写法 | ||
(paddle.linalg.inv(x), paddle.zeros(x.shape[:-2], dtype='int32')) | ||
``` | ||
|
||
#### out 参数:输出的 Tensor | ||
|
||
```python | ||
# PyTorch 写法 | ||
torch.linalg.inv_ex(x, out=y) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同上 |
||
|
||
# Paddle 写法 | ||
out1 = paddle.linalg.inv(x) | ||
out2 = paddle.zeros(x.shape[:-2], dtype='int32') | ||
paddle.assign(out1, output=y[0]), paddle.assign(out2, output=y[1]) | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
## [ 组合替代实现 ]torch.special.ndtr | ||
|
||
### [torch.special.ndtr](https://pytorch.org/docs/stable/special.html#torch.special.ndtr) | ||
|
||
```python | ||
torch.special.ndtr(input, *, out=None) | ||
``` | ||
|
||
Paddle 无此 API,需要组合实现。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这种再加个公式吧,只看转写示例并不直观 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 公式已经加了 |
||
|
||
对应公式: | ||
$$ | ||
\operatorname{ndtr}(x)=\frac{1}{\sqrt{2 \pi}} \int_{-\infty}^{x} e^{-\frac{1}{2} t^{2}} d t | ||
$$ | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# PyTorch 写法 | ||
torch.special.ndtr(a) | ||
|
||
# Paddle 写法 | ||
(paddle.erf(a/paddle.sqrt(paddle.to_tensor(2)))-paddle.erf(paddle.to_tensor(-float('inf'))))/2 | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cholesky_ex与cholesky是不是返回值不同,cholesky_ex会多返回一种info类型的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对的,他会多返回一个info