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

【Hackathon 7th No.37】为 Paddle 代码转换工具新增 API 转换规则(第 4 组)-part #6884

Merged
merged 8 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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,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/2.6/api/paddle/linalg/householder_product_cn.html#householder-product)
Copy link
Collaborator

Choose a reason for hiding this comment

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

这些2.6统一都换成develop版本的


```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,49 @@
## [ 返回参数类型不一致 ]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)
Copy link
Collaborator

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类型的

Copy link
Contributor Author

Choose a reason for hiding this comment

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

对的,他会多返回一个info

```

两者功能一致但返回参数类型不同,具体如下:

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------ | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| input | x | 表示输入参数为多维 Tensor,它的维度应该为 [*, M, N],其中*为零或更大的批次尺寸,并且最里面的两个维度上的矩阵都应为对称的正定矩阵,仅参数名不一致。 |
| upper | upper | 表示是否返回上三角矩阵或下三角矩阵。 |
| check_errors | - | 是否检查错误,paddle 暂不支持,需转写,目前仅支持 check_errors 为 False 的情况。 |
Copy link
Collaborator

@zhwesky2010 zhwesky2010 Oct 8, 2024

Choose a reason for hiding this comment

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

这种参数应该不重要吧?只是增加一个检查而已,直接去掉对网络的计算应该也不会有问题

直接删除的描述模板如下:不要随便写

infoflow 2024-10-08 18-03-08

| out | - | 表示输出的 Tensor ,Paddle 无此参数,需要转写。 |
Copy link
Collaborator

Choose a reason for hiding this comment

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

如果是返回值不同,应该在下面再加一行:

infoflow 2024-09-23 15-53-21

| 返回值 | 返回值 | Pytorch 返回两个 out 与 info,Paddle 仅返回一个 Tensor:out,需转写。 |
Copy link
Collaborator

Choose a reason for hiding this comment

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

返回值这个还是需要转写的,我的意思是 你不用再注释强调仅支持 check_errors=False 这句话

Copy link
Contributor Author

Choose a reason for hiding this comment

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

懂了,那个强调不需要,我都觉得返回值不转写太奇怪了


### 转写示例

#### 返回值

```python
# PyTorch 写法:
torch.linalg.cholesky_ex(x, upper=False)

# Paddle 写法:
## 注: 仅支持 check_errors=False 时的情况
Copy link
Collaborator

Choose a reason for hiding this comment

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

check_errors是否支持转写,要在上面写清楚

Copy link
Collaborator

Choose a reason for hiding this comment

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

这个还要吗

(paddle.linalg.cholesky(x, upper=False), paddle.zeros(x.shape[:-2], dtype='int64'))
```

#### out: 输出的 Tensor

```python
# PyTorch 写法
torch.linalg.cholesky_ex(x, upper=False, out=output)
Copy link
Collaborator

Choose a reason for hiding this comment

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



# Paddle 写法
paddle.assign((paddle.linalg.cholesky(x, upper=False), paddle.zeros(x.shape[:-2], dtype='int64')),output)
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个语法上就不对,assign一次只能一个

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
## [ 返回参数类型不一致 ]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 暂不支持,需转写,目前仅支持 check_errors 为 False 的情况。 |
Copy link
Collaborator

Choose a reason for hiding this comment

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

这种参数应该不重要吧?只是增加一个检查而已,转换时直接去掉对网络的计算应该也不会有问题

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个参数是不重要的,但是返回值是要有两个,就也加上去了的,不过现在是删掉了

| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 |
| 返回值 | 返回值 | Pytorch 返回两个 out 与 info,Paddle 仅返回一个 Tensor:out,需转写。 |
Copy link
Collaborator

Choose a reason for hiding this comment

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

返回值这个还是需要转写的,我的意思是 你不用再注释强调仅支持 check_errors=False 这句话

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已经好了的


### 转写示例

#### 返回值

```python
# PyTorch 写法:
torch.linalg.inv_ex(x)

# Paddle 写法:
## 注: 仅支持 check_errors=False 时的情况
Copy link
Collaborator

Choose a reason for hiding this comment

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

check_errors是否支持转写,要写清楚

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已经弄好了,单侧也已经好了

Copy link
Collaborator

Choose a reason for hiding this comment

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

这个还要吗

(paddle.linalg.inv(x), paddle.zeros(x.shape[:-2], dtype='int64'))
```

#### out 参数:输出的 Tensor

```python
# PyTorch 写法:
torch.linalg.inv_ex(x, out=y)
Copy link
Collaborator

Choose a reason for hiding this comment

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

同上


# Paddle 写法:
paddle.assign((paddle.linalg.inv(x), paddle.zeros(x.shape[:-2], dtype='int64')), y)
Copy link
Collaborator

Choose a reason for hiding this comment

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

一次只能assign一个,语法完全不对

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## [ 组合替代实现 ]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,需要组合实现。
Copy link
Collaborator

@zhwesky2010 zhwesky2010 Oct 8, 2024

Choose a reason for hiding this comment

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

这种再加个公式吧,只看转写示例并不直观

Copy link
Contributor Author

Choose a reason for hiding this comment

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

公式已经加了


### 转写示例

```python
# PyTorch 写法
y = torch.special.ndtr(a)
Copy link
Collaborator

Choose a reason for hiding this comment

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

不需要加个y=

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个是删掉了的


# Paddle 写法
y = (paddle.erf(a/paddle.sqrt(paddle.to_tensor(2)))-paddle.erf(paddle.to_tensor(-float('inf'))))/2
```
Loading