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.42】NO.42 为 Paddle 代码转换工具新增 API 转换规则(第 9 组)-part #6893

Merged
merged 13 commits into from
Oct 16, 2024

Conversation

decade-afk
Copy link
Contributor

No description provided.

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.

文档需严格,同步提交PaConvert的Matcher和单测吧,用实际代码校验一遍

### [paddle.bitwise_left_shift](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/bitwise_left_shift_cn.html#bitwise-left-shift)

```python
paddle.bitwise_left_shift(x, y, is_arithmetic=True, out=None, 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.bitwise_left_shift

类API尽可能对应类API,除非你确实没有再用其他替代

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image
因为真的没有

Copy link
Collaborator

@zhwesky2010 zhwesky2010 Sep 29, 2024

Choose a reason for hiding this comment

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

你这装的是什么版本的

infoflow 2024-09-29 17-27-31

麻烦import最新版本的paddle来验证

### [paddle.bitwise_left_shift_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/bitwise_left_shift__cn.html#bitwise-left-shift)

```python
paddle.bitwise_left_shift_(x, y, is_arithmetic=True, out=None, 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.bitwise_right_shift](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/bitwise_right_shift_cn.html#bitwise-right-shift)

```python
paddle.bitwise_right_shift(x, y, is_arithmetic=True, out=None, 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.bitwise_right_shift_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/bitwise_right_shift__cn.html#bitwise-right-shift)

```python
paddle.bitwise_right_shift_(x, y, is_arithmetic=True, out=None, 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.

同上

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

```python
torch.Tensor.crow_indices()
Copy link
Collaborator

Choose a reason for hiding this comment

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

你这个API签名对吗?

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.dim_order()
```

获取张量在内存中的物理布局,PaddlePaddle 的 Tensor 默认是 contiguous 的, 因此可直接返回一个从0到 Tensor 的维度长度的列表即可。
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.

我改成组合替代吧,这个抱歉,因为写的时候参考了is_continous的文档

### 转写示例

```python
# torch 版本可以直接访问属性
Copy link
Collaborator

Choose a reason for hiding this comment

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

转写示例写简单点,核心一行就行,不用各种print、准备随机变量这些

### [paddle.Tensor.element_size](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#element-size)

```python
paddle.Tensor.element_size()
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.

image
验证倒是还没有


```python
# torch 版本
x = torch.rand(3)
Copy link
Collaborator

Choose a reason for hiding this comment

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

示例简洁,而且看起来有bug

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个我改一下


| PyTorch | PaddlePaddle | 备注 |
| ------- | ------------ | ----------------------------------------------------------------------------------------- |
| - | sparse_dim | 在新的稀疏张量中包含的稀疏维度的数量,pytorch中无此参数,paddle令其为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保持默认,就可以吧

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sparse_dim他并没有默认值

Copy link
Collaborator

Choose a reason for hiding this comment

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

没有tensor维度长度这个说法,改成 输入维度

@zhwesky2010
Copy link
Collaborator

zhwesky2010 commented Sep 29, 2024

麻烦用最新版本的paddle来验证

infoflow 2024-09-29 17-27-31

@decade-afk decade-afk closed this Oct 2, 2024
@decade-afk decade-afk reopened this Oct 2, 2024
@luotao1
Copy link
Collaborator

luotao1 commented Oct 8, 2024

已经弄好了,代码也跑通了

image 图片没有上传成功

@decade-afk
Copy link
Contributor Author

麻烦用最新版本的paddle来验证

infoflow 2024-09-29 17-27-31

已经弄好了的

@decade-afk
Copy link
Contributor Author

已经弄好了,代码也跑通了

image 图片没有上传成功

已经好了

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.

提交reiview前先自查问题

y = a.nbytes

# Paddle 写法
y = paddle.numel(a) * a.element_size()
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个返回的是一个Tensor吧,应该需要返回一个int

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

```python
torch.Tensor.stride(dim)
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个备注下 dim=None

x.stride(dim)

# Paddle 版本
x.get_strides() if dim is None else x.get_strides()[dim]
Copy link
Collaborator

Choose a reason for hiding this comment

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

直接分行写吧,文档更注重可读性

if dim:

else:


| PyTorch | PaddlePaddle | 备注 |
| ------- | ------------ | ----------------------------------------------------------------------------------------- |
| - | sparse_dim | 在新的稀疏张量中包含的稀疏维度的数量,pytorch 中无此参数,paddle 令其为 tensor 输入维度长度即可。 |
Copy link
Collaborator

Choose a reason for hiding this comment

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

tensor输入维度

没有维度长度的说法,维度就是一个标量,标量没有长度。

Copy link
Contributor Author

@decade-afk decade-afk Oct 9, 2024

Choose a reason for hiding this comment

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

好的好的,已经都改了的

@decade-afk
Copy link
Contributor Author

doc和 PaddlePaddle/PaConvert#490 已经全都跑通了,请review @zhwesky2010

y = a.nbytes

# Paddle 写法
y = int(paddle.numel(a) * a.element_size())
Copy link
Collaborator

Choose a reason for hiding this comment

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

为啥不用 a.size * a.element_size(),Tensor转来转去效率不更低吗

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

```python
torch.Tensor.stride(dim)
Copy link
Collaborator

Choose a reason for hiding this comment

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

torch.Tensor.stride(dim=None)


| PyTorch | PaddlePaddle | 备注 |
| ------- | ------------ | --------------------------------------------------------------- |
| dim | - | 返回指定维度的步长,默认返回全部步长,paddle 不支持,需要转写。 |
Copy link
Collaborator

Choose a reason for hiding this comment

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

返回指定维度的步长,Pytorch为可选值,默认返回全部步长,此时无需转写,当有输入值时,需要转写。

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

@zhwesky2010 zhwesky2010 merged commit 5cec675 into PaddlePaddle:develop Oct 16, 2024
2 checks passed
@luotao1 luotao1 changed the title 【Hackathon 7th No.42】NO.42 为 Paddle 代码转换工具新增 API 转换规则(第 9 组) 【Hackathon 7th No.42】NO.42 为 Paddle 代码转换工具新增 API 转换规则(第 9 组)-part Oct 16, 2024
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.

5 participants