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

Conversation

monster1015
Copy link
Contributor

No description provided.

@monster1015
Copy link
Contributor Author

image
请问这是说我代码风格不对吗?
@luotao1

@monster1015
Copy link
Contributor Author

@sunzhongkai588

@luotao1
Copy link
Collaborator

luotao1 commented Sep 23, 2024

是的,请根据日志里的提示用precommit修改代码格式。

@monster1015
Copy link
Contributor Author

是的,请根据日志里的提示用precommit修改代码格式。

好的,请稍等

@monster1015
Copy link
Contributor Author

已经好了,劳烦review一下

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

```python
paddle.gammainc(x, y, 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.

paddle也有类方法 paddle.Tensor.gammainc

类方法 尽量对应到 类方法,实在没有类方法,才对应到非类方法

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

@zhwesky2010 zhwesky2010 Sep 24, 2024

Choose a reason for hiding this comment

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

我在查文档的时候并没有找到对应的方法

不要查文档,不以文档为准,以代码为准。直接下一个paddle的源码、或者import一个最新版paddle

### [paddle.gammainc_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/gammainc__cn.html#gammainc)

```python
paddle.gammainc_(x, y, 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.

同上

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

```python
paddle.gammaincc(x, y, 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.

同上

### [paddle.gammaincc\_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/gammaincc__cn.html#gammaincc)

```python
paddle.gammaincc_(x, y, 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.

同上


| PyTorch | PaddlePaddle | 备注 |
| ------- | ------------ | --------------------------- |
| - | x | 输入的方阵,类型为 Tensor。 |
Copy link
Collaborator

Choose a reason for hiding this comment

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

类方法对应到非类方法,不用对比第一个,直接忽略

因此这种不叫参数名不一致

### [paddle.multigammaln_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/multigammaln__cn.html#multigammaln)

```python
paddle.multigammaln_(x, p, 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.

paddle.Tensor.multigammaln_

### [paddle.linalg.householder_product](https://www.paddlepaddle.org.cn/documentation/docs/zh/2.6/api/paddle/linalg/householder_product_cn.html#householder-product)

```python
paddle.linalg.householder_product(x, tau, 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.

paddle.Tensor.householder_product

### [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

| input | x | 表示输入参数为多维 Tensor,它的维度应该为 [*, M, N],其中*为零或更大的批次尺寸,并且最里面的两个维度上的矩阵都应为对称的正定矩阵,仅参数名不一致。 |
| upper | upper | 表示是否返回上三角矩阵或下三角矩阵。 |
| check_errors | - | 是否检查错误,paddle 暂不支持。 |
| 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

@monster1015
Copy link
Contributor Author

@zhwesky2010 已经修改好了,PaConvert也已经同步修改了

Copy link
Collaborator

@zhwesky2010 zhwesky2010 left a comment

Choose a reason for hiding this comment

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

注意参数映射栏:先简述参数功能,再描述差异

out = x.igamma(y)

# Paddle 写法
out = .gammainc(y)
Copy link
Collaborator

Choose a reason for hiding this comment

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

x掉了


| PyTorch | PaddlePaddle | 备注 |
| ------- | ------------ | ------------- |
| other | y | 正参数 Tensor |
Copy link
Collaborator

Choose a reason for hiding this comment

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

加一个 仅参数名不同


| PyTorch | PaddlePaddle | 备注 |
| ------- | ------------ | ------------- |
| other | y | 正参数 Tensor |
Copy link
Collaborator

Choose a reason for hiding this comment

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

加一个 仅参数名不同,一比一对照模板


| PyTorch | PaddlePaddle | 备注 |
| ------- | ------------ | ------------- |
| other | y | 正参数 Tensor |
Copy link
Collaborator

Choose a reason for hiding this comment

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

一比一对照模板写

@@ -0,0 +1,30 @@
<!--
Copy link
Collaborator

Choose a reason for hiding this comment

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

这些删掉


| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| input2 | tau | 仅参数名字不一致 |
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 写法
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.


```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.

同上


| PyTorch | PaddlePaddle | 备注 |
| --------- | ------------ | ---------------------- |
| input | x | 仅参数名字不一致 |
Copy link
Collaborator

Choose a reason for hiding this comment

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

先简述功能,再描写差异

| other | other | 一致 |
| left | left | 一致 |
| transpose | transpose | 一致 |
| out | - | paddle 无此参数,需转写 |
Copy link
Collaborator

Choose a reason for hiding this comment

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

均同上

@zhwesky2010
Copy link
Collaborator

后续注意根据文档来实现Matcher,注意不要出现文档与Matcher的diff。

如果实现Matcher的过程中,发现文档有误,需及时更正文档

@monster1015
Copy link
Contributor Author

后续注意根据文档来实现Matcher,注意不要出现文档与Matcher的diff。

如果实现Matcher的过程中,发现文档有误,需及时更正文档

抱歉,写的时候有点着急,不过这次可以了的

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

Choose a reason for hiding this comment

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

能否转写 要备注清楚

@@ -0,0 +1,49 @@
## [ torch 参数更多 ]torch.linalg.cholesky_ex
Copy link
Collaborator

@zhwesky2010 zhwesky2010 Sep 27, 2024

Choose a reason for hiding this comment

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

根据分类的优先级排序,这个不能算做 torch参数更多,因为返回参数不同

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是否支持转写,要在上面写清楚

| PyTorch | PaddlePaddle | 备注 |
| ------------ | ------------ | --------------------------------------------------------------------- |
| A | x | 输入 Tensor,仅参数名不一致。 |
| check_errors | - | 是否检查错误,paddle 暂不支持 |
Copy link
Collaborator

Choose a reason for hiding this comment

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

是否支持转写,要写清楚

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.

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

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版本的



# 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一次只能一个

| ------------ | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| 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

| 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.

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

torch.linalg.inv_ex(x, out=y)

# 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一个,语法完全不对


```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.

这个是删掉了的

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.

公式已经加了

@zhwesky2010
Copy link
Collaborator

zhwesky2010 commented Oct 8, 2024

@monster1015

开发注意事项:

  • 务必按照 映射文档模板 编写,一比一对照编写(可以增加内容但不能减少内容),提交review前先自查问题
  • 本次放出来的API,内部已初步分析过,基本上都有相关功能,功能缺失的可能性较小。需尽可能去寻找组合替代实现,判定为功能缺失要慎重,除非paddle完全无相类似功能
  • 先写好映射文档,再根据合入的文档来实现Matcher,注意不要出现文档与Matcher的diff。如果后面实现Matcher时,发现文档有误,需及时返工更正文档

@monster1015
Copy link
Contributor Author

我是先写的docs,然后写的matcher,后面再根据matcher改的

@monster1015
Copy link
Contributor Author

image
然后matcher那里是都通过了,但是codestyle检测不知道为什么一直超时 @zhwesky2010

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.

这个还要吗

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.

这个还要吗

| upper | upper | 表示是否返回上三角矩阵或下三角矩阵。 |
| check_errors | - | 是否检查错误,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
| 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.

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

| A | x | 输入 Tensor,仅参数名不一致。 |
| check_errors | - | 是否检查错误,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
| 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.

已经好了的

Copy link
Collaborator

@zhwesky2010 zhwesky2010 left a comment

Choose a reason for hiding this comment

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

LGTM

后续注意事项:

  1. 后续根据该文档来实现Matcher,注意不要出现文档与Matcher的diff。
  2. 如果实现Matcher的过程中,发现文档有误,需及时回头更正文档

@zhwesky2010 zhwesky2010 merged commit f82f5ed into PaddlePaddle:develop Oct 10, 2024
2 checks passed
@luotao1 luotao1 changed the title 【Hackathon 7th No.37】为 Paddle 代码转换工具新增 API 转换规则(第 4 组) 【Hackathon 7th No.37】为 Paddle 代码转换工具新增 API 转换规则(第 4 组)-part Oct 10, 2024
@monster1015
Copy link
Contributor Author

LGTM

后续注意事项:

  1. 后续根据该文档来实现Matcher,注意不要出现文档与Matcher的diff。
  2. 如果实现Matcher的过程中,发现文档有误,需及时回头更正文档

好的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor PaddlePaddle Hackathon 飞桨黑客松活动issue与PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants