-
Notifications
You must be signed in to change notification settings - Fork 764
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
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6f2c565
【Hackathon 7th No.42】NO.42 为 Paddle 代码转换工具新增 API 转换规则(第 9 组)
decade-afk 99a57c8
Merge branch 'PaddlePaddle:develop' into itemsize
decade-afk a4f97e4
update
monster1015 d8700c8
update
decade-afk 6ba1da0
update
decade-afk c2b8407
update
decade-afk a8d64f2
update
decade-afk 885d33c
update
decade-afk 1e41589
update
decade-afk 5e96059
update
decade-afk 2e3825c
update
decade-afk 65519ab
update
decade-afk 460c272
update
decade-afk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...t/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_left_shift.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,32 @@ | ||
## [ paddle 参数更多 ]torch.Tensor.bitwise_left_shift | ||
|
||
### [torch.Tensor.bitwise_left_shift](https://pytorch.org/docs/stable/generated/torch.Tensor.bitwise_left_shift.html#torch-tensor-bitwise-left-shift) | ||
|
||
```python | ||
torch.Tensor.bitwise_left_shift(other) | ||
``` | ||
|
||
### [paddle.Tensor.bitwise_left_shift]() | ||
|
||
```python | ||
paddle.Tensor.bitwise_left_shift(y, is_arithmetic=True) | ||
``` | ||
|
||
其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------- | ------------- | ------------------------------------------------------------------- | | ||
| other | y | 表示输入的 Tensor ,仅参数名不一致。 | | ||
| - | is_arithmetic | 用于表明是否执行算术位移, PyTorch 无此参数, Paddle 保持默认即可。 | | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# PyTorch 写法 | ||
out = x.bitwise_left_shift(y) | ||
|
||
# Paddle 写法 | ||
out = x.bitwise_left_shift(y) | ||
``` |
32 changes: 32 additions & 0 deletions
32
.../convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_left_shift_.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,32 @@ | ||
## [ paddle 参数更多 ]torch.Tensor.bitwise_left_shift_ | ||
|
||
### [torch.Tensor.bitwise_left_shift_](https://pytorch.org/docs/stable/generated/torch.Tensor.bitwise_left_shift_.html#torch-tensor-bitwise-left-shift) | ||
|
||
```python | ||
torch.Tensor.bitwise_left_shift_(other) | ||
``` | ||
|
||
### [paddle.Tensor.bitwise_left_shift_]() | ||
|
||
```python | ||
paddle.Tensor.bitwise_left_shift_(y, is_arithmetic=True) | ||
``` | ||
|
||
其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------- | ------------- | ------------------------------------------------------------------- | | ||
| other | y | 表示输入的 Tensor ,仅参数名不一致。 | | ||
| - | is_arithmetic | 用于表明是否执行算术位移, PyTorch 无此参数, Paddle 保持默认即可。 | | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# PyTorch 写法 | ||
out = x.bitwise_left_shift_(y) | ||
|
||
# Paddle 写法 | ||
out = x.bitwise_left_shift_(y) | ||
``` |
32 changes: 32 additions & 0 deletions
32
.../convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_right_shift.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,32 @@ | ||
## [ paddle 参数更多 ]torch.Tensor.bitwise_right_shift | ||
|
||
### [torch.Tensor.bitwise_right_shift](https://pytorch.org/docs/stable/generated/torch.Tensor.bitwise_right_shift.html#torch-tensor-bitwise-right-shift) | ||
|
||
```python | ||
torch.Tensor.bitwise_right_shift(other) | ||
``` | ||
|
||
### [paddle.Tensor.bitwise_right_shift]() | ||
|
||
```python | ||
paddle.Tensor.bitwise_right_shift(y, is_arithmetic=True) | ||
``` | ||
|
||
其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------- | ------------- | ------------------------------------------------------------------- | | ||
| other | y | 表示输入的 Tensor ,仅参数名不一致。 | | ||
| - | is_arithmetic | 用于表明是否执行算术位移, PyTorch 无此参数, Paddle 保持默认即可。 | | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# PyTorch 写法 | ||
out = x.bitwise_right_shift(y) | ||
|
||
# Paddle 写法 | ||
out = x.bitwise_right_shift(y) | ||
``` |
32 changes: 32 additions & 0 deletions
32
...convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_right_shift_.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,32 @@ | ||
## [ paddle 参数更多 ]torch.Tensor.bitwise_right_shift_ | ||
|
||
### [torch.Tensor.bitwise_right_shift_](https://pytorch.org/docs/stable/generated/torch.Tensor.bitwise_right_shift_.html#torch-tensor-bitwise-right-shift) | ||
|
||
```python | ||
torch.Tensor.bitwise_right_shift_(other) | ||
``` | ||
|
||
### [paddle.Tensor.bitwise_right_shift_]() | ||
|
||
```python | ||
paddle.Tensor.bitwise_right_shift_(y, is_arithmetic=True) | ||
``` | ||
|
||
其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------- | ------------- | ------------------------------------------------------------------- | | ||
| other | y | 表示输入的 Tensor ,仅参数名不一致。 | | ||
| - | is_arithmetic | 用于表明是否执行算术位移, PyTorch 无此参数, Paddle 保持默认即可。 | | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# PyTorch 写法 | ||
out = x.bitwise_right_shift_(y) | ||
|
||
# Paddle 写法 | ||
out = x.bitwise_right_shift_(y) | ||
``` |
15 changes: 15 additions & 0 deletions
15
..._convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.col_indices.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,15 @@ | ||
## [ 无参数 ] torch.Tensor.col_indices | ||
|
||
### [torch.Tensor.col_indices](https://pytorch.org/docs/stable/generated/torch.Tensor.col_indices.html) | ||
|
||
```python | ||
torch.Tensor.col_indices() | ||
``` | ||
|
||
### [paddle.Tensor.cols]() | ||
|
||
```python | ||
paddle.Tensor.cols() | ||
``` | ||
|
||
两者功能一致,无参数。 |
15 changes: 15 additions & 0 deletions
15
...convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.crow_indices.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,15 @@ | ||
## [ 无参数 ] torch.Tensor.crow_indices | ||
|
||
### [torch.Tensor.crow_indices](https://pytorch.org/docs/stable/generated/torch.Tensor.crow_indices.html) | ||
|
||
```python | ||
torch.Tensor.crow_indices() | ||
``` | ||
|
||
### [paddle.Tensor.crows]() | ||
|
||
```python | ||
paddle.Tensor.crows() | ||
``` | ||
|
||
两者功能一致,无参数。 |
15 changes: 15 additions & 0 deletions
15
...del_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.data_ptr.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,15 @@ | ||
## [ 无参数 ] torch.Tensor.data_ptr | ||
|
||
### [torch.Tensor.data_ptr](https://pytorch.org/docs/stable/generated/torch.Tensor.data_ptr.html) | ||
|
||
```python | ||
torch.Tensor.data_ptr() | ||
``` | ||
|
||
### [paddle.Tensor.data_ptr](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html) | ||
|
||
```python | ||
paddle.Tensor.data_ptr() | ||
``` | ||
|
||
两者功能一致。 |
19 changes: 19 additions & 0 deletions
19
...el_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.dim_order.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.dim_order | ||
|
||
### [torch.Tensor.dim_order](https://pytorch.org/docs/stable/generated/torch.Tensor.dim_order.html?highlight=dim_order#torch.Tensor.dim_order) | ||
|
||
```python | ||
torch.Tensor.dim_order() | ||
``` | ||
|
||
Paddle 无此 API,需要组合实现。获取张量在内存中的物理布局,PaddlePaddle 的 Tensor 默认是 contiguous 的, 因此可直接返回一个从 0 到 Tensor 的维度长度的列表即可。 | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# PyTorch 写法 | ||
y = x.dim_order() | ||
|
||
# Paddle 写法 | ||
y = tuple([i for i in range(len(x.shape))]) | ||
``` |
25 changes: 25 additions & 0 deletions
25
...onvert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_sparse_csr.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,25 @@ | ||
## [ 无参数 ] torch.Tensor.is_sparse_csr | ||
|
||
### [torch.Tensor.is_sparse_csr](https://pytorch.org/docs/stable/generated/torch.Tensor.is_sparse_csr.html) | ||
|
||
```python | ||
torch.Tensor.is_sparse_csr | ||
``` | ||
|
||
### [paddle.Tensor.is_sparse_csr](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html) | ||
|
||
```python | ||
paddle.Tensor.is_sparse_csr() | ||
``` | ||
|
||
两者功能一致,但使用方式不一致,前者可以直接访问属性,后者需要调用方法,具体如下: | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# torch 版本可以直接访问属性 | ||
x.is_sparse_csr | ||
|
||
# Paddle 版本需要调用 | ||
x.is_sparse_csr() | ||
``` |
15 changes: 15 additions & 0 deletions
15
...del_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.itemsize.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,15 @@ | ||
## [ 无参数 ]torch.Tensor.item_size | ||
|
||
### [torch.Tensor.item_size](https://pytorch.org/docs/stable/generated/torch.Tensor.itemsize.html) | ||
|
||
```python | ||
torch.Tensor.item_size() | ||
``` | ||
|
||
### [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() | ||
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. |
||
``` | ||
|
||
两者功能一致,无参数。 |
19 changes: 19 additions & 0 deletions
19
...model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nbytes.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.nbytes | ||
|
||
### [torch.Tensor.nbytes](https://pytorch.org/docs/stable/generated/torch.Tensor.nbytes.html) | ||
|
||
```python | ||
torch.Tensor.nbytes | ||
``` | ||
|
||
Paddle 无此 API,需要组合实现。 | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# PyTorch 写法 | ||
y = a.nbytes | ||
|
||
# Paddle 写法 | ||
y = a.size * a.element_size() | ||
``` |
35 changes: 35 additions & 0 deletions
35
...model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.stride.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,35 @@ | ||
## [ torch 参数更多 ] torch.Tensor.stride | ||
|
||
### [torch.Tensor.stride](https://pytorch.org/docs/stable/generated/torch.Tensor.stride.html#torch-tensor-stride) | ||
|
||
```python | ||
torch.Tensor.stride(dim=None) | ||
``` | ||
|
||
### [paddle.Tensor.get_strides](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#tensor) | ||
|
||
```python | ||
paddle.Tensor.get_strides() | ||
``` | ||
|
||
PyTorch 相比 Paddle 支持更多其他参数,具体如下: | ||
|
||
### 参数映射 | ||
|
||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------- | ------------ | --------------------------------------------------------------------------------------------- | | ||
| dim | - | 返回指定维度的步长, Pytorch 为可选值,默认返回全部步长,此时无需转写,当有输入值时,需要转写。 | | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# torch 版本, 默认返回全部 | ||
x.stride(dim=None) | ||
|
||
# Paddle 版本 | ||
if dim is not None: | ||
x.get_strides()[dim] | ||
else: | ||
x.get_strides() | ||
``` |
22 changes: 22 additions & 0 deletions
22
...onvert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.to_sparse_coo.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.to_sparse_coo | ||
|
||
### [torch.Tensor.to_sparse_coo](https://pytorch.org/docs/stable/generated/torch.Tensor.to_sparse_coo.html) | ||
|
||
```python | ||
torch.Tensor.to_sparse_coo() | ||
``` | ||
|
||
### [paddle.Tensor.to_sparse_coo]() | ||
|
||
```python | ||
paddle.Tensor.to_sparse_coo(sparse_dim) | ||
``` | ||
|
||
其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: | ||
|
||
### 参数映射 | ||
|
||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------- | ------------ | --------------------------------------------------------------------------------------------- | | ||
| - | sparse_dim | 在新的稀疏张量中包含的稀疏维度的数量,pytorch 中无此参数,paddle 令其为 tensor 输入维度即可。 | |
24 changes: 24 additions & 0 deletions
24
...l_convert/convert_from_pytorch/api_difference/torch/torch.bitwise_left_shift.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,24 @@ | ||
## [ paddle 参数更多 ]torch.bitwise_left_shift | ||
|
||
### [torch.bitwise_left_shift](https://pytorch.org/docs/stable/generated/torch.bitwise_left_shift.html) | ||
|
||
```python | ||
torch.bitwise_left_shift(input, other, *, out=None) | ||
``` | ||
|
||
### [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) | ||
``` | ||
|
||
其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------- | ------------- | ------------------------------------------------------------------- | | ||
| input | x | 表示输入的 Tensor ,仅参数名不一致。 | | ||
| other | y | 表示输入的 Tensor ,仅参数名不一致。 | | ||
| out | out | 表示输出的 Tensor。 | | ||
| - | is_arithmetic | 用于表明是否执行算术位移, PyTorch 无此参数, Paddle 保持默认即可。 | |
24 changes: 24 additions & 0 deletions
24
..._convert/convert_from_pytorch/api_difference/torch/torch.bitwise_right_shift.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,24 @@ | ||
## [ paddle 参数更多 ]torch.bitwise_right_shift | ||
|
||
### [torch.bitwise_right_shift](https://pytorch.org/docs/stable/generated/torch.bitwise_right_shift.html) | ||
|
||
```python | ||
torch.bitwise_right_shift(input, other, *, out=None) | ||
``` | ||
|
||
### [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) | ||
``` | ||
|
||
其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------- | ------------- | ------------------------------------------------------------------- | | ||
| input | x | 表示输入的 Tensor ,仅参数名不一致。 | | ||
| other | y | 表示输入的 Tensor ,仅参数名不一致。 | | ||
| out | out | 表示输出的 Tensor。 | | ||
| - | is_arithmetic | 用于表明是否执行算术位移, PyTorch 无此参数, Paddle 保持默认即可。 | |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
转写示例写简单点,核心一行就行,不用各种print、准备随机变量这些