-
Notifications
You must be signed in to change notification settings - Fork 823
映射文档 No. 27 #5821
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
Merged
Merged
映射文档 No. 27 #5821
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
21 changes: 21 additions & 0 deletions
21
...nvert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.take_along_dim.md
This file contains hidden or 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,21 @@ | ||
## [ 仅参数名不一致 ]torch.Tensor.take_along_dim | ||
### [torch.Tensor.take_along_dim](https://pytorch.org/docs/1.13/generated/torch.Tensor.take_along_dim.html?highlight=torch+tensor+take_along_dim#torch.Tensor.take_along_dim) | ||
|
||
```python | ||
torch.Tensor.take_along_dim(indices, | ||
dim) | ||
``` | ||
|
||
### [paddle.Tensor.take_along_axis]( ) | ||
|
||
```python | ||
paddle.Tensor.take_along_axis(indices, | ||
axis) | ||
``` | ||
|
||
两者功能一致,参数名不一致,具体如下: | ||
### 参数映射 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| indices | indices | 索引矩阵,包含沿轴提取 1d 切片的下标,必须和 arr 矩阵有相同的维度,需要能够 broadcast 与 arr 矩阵对齐,数据类型为:int、int64。 | | ||
| dim | axis | 指定沿着哪个维度获取对应的值,数据类型为:int,仅参数名不一致。 | |
35 changes: 35 additions & 0 deletions
35
...convert/convert_from_pytorch/api_difference/linalg/torch.linalg.matrix_power.md
This file contains hidden or 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.linalg.matrix_power | ||
### [torch.linalg.matrix_power](https://pytorch.org/docs/1.13/generated/torch.linalg.matrix_power.html?highlight=torch+linalg+matrix_power#torch.linalg.matrix_power) | ||
|
||
```python | ||
torch.linalg.matrix_power(A, | ||
n, | ||
*, | ||
out=None) | ||
``` | ||
|
||
### [paddle.linalg.matrix_power](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/linalg/matrix_power_cn.html) | ||
|
||
```python | ||
paddle.linalg.matrix_power(x, | ||
n, | ||
name=None) | ||
``` | ||
|
||
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: | ||
### 参数映射 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| A | x | 输入的欲进行 n 次幂运算的一个或一批方阵,类型为 Tensor,仅参数名不一致。 | | ||
| n | n | 输入的幂次,类型为 int。 | | ||
|out | - | 表示输出的 Tensor , Paddle 无此参数,需要进行转写。 | | ||
|
||
### 转写示例 | ||
#### out:指定输出 | ||
```python | ||
# Pytorch 写法 | ||
torch.linalg.matrix_power(x, 3, out = y) | ||
|
||
# Paddle 写法 | ||
paddle.assign(paddle.linalg.matrix_power(x, 3), y) | ||
``` |
24 changes: 24 additions & 0 deletions
24
docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.dsplit.md
This file contains hidden or 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.dsplit | ||
### [torch.dsplit](https://pytorch.org/docs/1.13/generated/torch.dsplit.html#torch.dsplit) | ||
|
||
```python | ||
torch.dsplit(input, | ||
indices_or_sections) | ||
``` | ||
|
||
### [paddle.split](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/split_cn.html) | ||
|
||
```python | ||
paddle.split(x, | ||
num_or_sections, | ||
axis=0, | ||
name=None) | ||
``` | ||
|
||
Paddle 相比 PyTorch 支持更多其他参数,具体如下: | ||
### 参数映射 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| input | x | 输入多维 Tensor ,仅参数名不一致。 | | ||
| indices_or_sections | num_or_sections | 用于分割的 int 或 list 或 tuple ,仅参数名不一致。 | | ||
| - | axis | 表示需要分割的维度,PyTorch 无此参数,Paddle 需要设置为 2。 | |
32 changes: 32 additions & 0 deletions
32
...model_convert/convert_from_pytorch/api_difference/others/torch.special.expm1.md
This file contains hidden or 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 @@ | ||
## [ torch 参数更多 ]torch.special.expm1 | ||
### [torch.special.expm1](https://pytorch.org/docs/1.13/special.html#torch.special.expm1) | ||
|
||
```python | ||
torch.special.expm1(input, | ||
*, | ||
out=None) | ||
``` | ||
|
||
### [paddle.expm1](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/expm1_cn.html) | ||
|
||
```python | ||
paddle.expm1(x, | ||
name=None) | ||
``` | ||
|
||
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: | ||
### 参数映射 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| input | x | 该 OP 的输入为多维 Tensor。数据类型为:float16、float32、float64,仅参数名不一致。 | | ||
| out | - | 表示输出的 Tensor , Paddle 无此参数,需要进行转写。 | | ||
|
||
### 转写示例 | ||
#### out:指定输出 | ||
```python | ||
# Pytorch 写法 | ||
torch.special.expm1([2, 3, 8, 7], [1, 5, 3, 3], out=y) | ||
|
||
# Paddle 写法 | ||
paddle.assign(paddle.expm1([2, 3, 8, 7], [1, 5, 3, 3]), y) | ||
``` |
26 changes: 26 additions & 0 deletions
26
...rt_from_pytorch/api_difference/utils/torch.utils.cpp_extension.CUDAExtension.md
This file contains hidden or 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,26 @@ | ||
## [ torch 参数更多 ]torch.utils.cpp_extension.CUDAExtension | ||
### [torch.utils.cpp_extension.CUDAExtension](https://pytorch.org/docs/1.13/cpp_extension.html?highlight=torch+utils+cpp_extension+cudaextension#torch.utils.cpp_extension.CUDAExtension) | ||
|
||
```python | ||
torch.utils.cpp_extension.CUDAExtension(name, | ||
sources, | ||
*args, | ||
**kwargs) | ||
``` | ||
|
||
### [paddle.utils.cpp_extension.CUDAExtension](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/utils/cpp_extension/CUDAExtension_cn.html) | ||
|
||
```python | ||
paddle.utils.cpp_extension.CUDAExtension(sources, | ||
*args, | ||
**kwargs) | ||
``` | ||
|
||
Pytorch 相比 Paddle 支持更多其他参数,具体如下: | ||
### 参数映射 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| name | - | 参数 name,PaddlePaddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | | ||
| sources | sources | 用于指定自定义 OP 对应的源码文件。 | | ||
|*args | *args | 用于指定 Extension 的其他参数,支持的参数与 setuptools.Extension 一致。 | | ||
| **kwargs | **kwargs | 用于指定 Extension 的其他参数,支持的参数与 setuptools.Extension 一致。 | |
26 changes: 26 additions & 0 deletions
26
...ert_from_pytorch/api_difference/utils/torch.utils.cpp_extension.CppExtension.md
This file contains hidden or 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,26 @@ | ||
## [ torch 参数更多 ]torch.utils.cpp_extension.CppExtension | ||
### [torch.utils.cpp_extension.CppExtension](https://pytorch.org/docs/1.13/cpp_extension.html?highlight=torch+utils+cpp_extension+cppextension#torch.utils.cpp_extension.CppExtension) | ||
|
||
```python | ||
torch.utils.cpp_extension.CppExtension(name, | ||
sources, | ||
*args, | ||
**kwargs) | ||
``` | ||
|
||
### [paddle.utils.cpp_extension.CppExtension](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/utils/cpp_extension/CppExtension_cn.html) | ||
|
||
```python | ||
paddle.utils.cpp_extension.CppExtension(sources, | ||
*args, | ||
**kwargs) | ||
``` | ||
|
||
Pytorch 相比 Paddle 支持更多其他参数,具体如下: | ||
### 参数映射 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| name | - | 参数 name,PaddlePaddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | | ||
| sources | sources | 用于指定自定义 OP 对应的源码文件。 | | ||
|*args | *args | 用于指定 Extension 的其他参数,支持的参数与 setuptools.Extension 一致。 | | ||
| **kwargs | **kwargs | 用于指定 Extension 的其他参数,支持的参数与 setuptools.Extension 一致。 | |
47 changes: 47 additions & 0 deletions
47
...ert/convert_from_pytorch/api_difference/utils/torch.utils.cpp_extension.load.md
This file contains hidden or 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,47 @@ | ||
## [ torch 参数更多 ]torch.utils.cpp_extension.load | ||
### [torch.utils.cpp_extension.load](https://pytorch.org/docs/1.13/cpp_extension.html?highlight=torch+utils+cpp_extension+load#torch.utils.cpp_extension.load) | ||
|
||
```python | ||
torch.utils.cpp_extension.load(name, | ||
sources, | ||
extra_cflags=None, | ||
extra_cuda_cflags=None, | ||
extra_ldflags=None, | ||
extra_include_paths=None, | ||
build_directory=None, | ||
verbose=False, | ||
with_cuda=None, | ||
is_python_module=True, | ||
is_standalone=False, | ||
keep_intermediates=True) | ||
``` | ||
|
||
### [paddle.utils.cpp_extension.load](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/utils/cpp_extension/load_cn.html) | ||
|
||
```python | ||
paddle.utils.cpp_extension.load(name, | ||
sources, | ||
extra_cxx_cflags=None, | ||
extra_cuda_cflags=None, | ||
extra_ldflags=None, | ||
extra_include_paths=None, | ||
build_directory=None, | ||
verbose=False) | ||
``` | ||
|
||
Pytorch 相比 Paddle 支持更多其他参数,具体如下: | ||
### 参数映射 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| name | name | 用于指定编译自定义 OP 时,生成的动态链接库的名字。 | | ||
| sources | sources | 用于指定自定义 OP 对应的源码文件。 | | ||
| extra_cflags | extra_cxx_cflags | 用于指定编译 cuda 源文件时额外的编译选项。 | | ||
| extra_cuda_cflags | extra_cuda_cflags | 用于指定编译 cuda 源文件时额外的编译选项。 | | ||
| extra_ldflags |extra_ldflags | 用于指定编译自定义 OP 时额外的链接选项。 | | ||
| extra_include_paths | extra_include_paths | 用于指定编译 cpp 或 cuda 源文件时,额外的头文件搜索目录。 | | ||
| build_directory | build_directory | 用于指定存放生成动态链接库的目录。 | | ||
| verbose | verbose | 用于指定是否需要输出编译过程中的日志信息,默认为 False。 | | ||
| with_cuda | - | 决定是否将 CUDA 头文件和库添加到 build。 PaddlePaddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | | ||
| is_python_module | - | 默认为 True,将生成的共享库作为 Python 模块导入,PaddlePaddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | | ||
| is_standalone | - | 默认为 False,将构建的扩展作为一个普通的动态库加载到进程中,如果是 True,则构建一个独立的可执行文件,PaddlePaddle 无此参数,一般对网络训练结果影响不大,可直接删除。| | ||
| keep_intermediates | - | 默认为 True,保留中间文件,PaddlePaddle 无此参数,一般对网络训练结果影响不大,可直接删除。| |
24 changes: 24 additions & 0 deletions
24
...vert/convert_from_pytorch/api_difference/utils/torch.utils.data.random_split.md
This file contains hidden or 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 @@ | ||
## [ 参数完全一致 ]torch.utils.data.random_split | ||
### [torch.utils.data.random_split](https://pytorch.org/docs/1.13/data.html?highlight=torch+utils+data+random_split#torch.utils.data.random_split) | ||
|
||
```python | ||
torch.utils.data.random_split(dataset, | ||
lengths, | ||
generator=<torch._C.Generator object>) | ||
``` | ||
|
||
### [paddle.io.random_split](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/io/random_split_cn.html) | ||
|
||
```python | ||
paddle.io.random_split(dataset, | ||
lengths, | ||
generator=None) | ||
``` | ||
|
||
两者参数和用法完全一致,具体如下: | ||
### 参数映射 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| dataset | dataset | 表示可迭代数据集。 | | ||
| lengths | lengths | 总和为原数组长度的,子集合长度数组。 | | ||
| generator | generator | 指定采样 data_source 的采样器。默认值为 None。 | |
18 changes: 18 additions & 0 deletions
18
...ert/convert_from_pytorch/api_difference/utils/torch.utils.dlpack.from_dlpack.md
This file contains hidden or 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,18 @@ | ||
## [ 仅参数名不一致 ]torch.utils.dlpack.from_dlpack | ||
### [torch.utils.dlpack.from_dlpack](https://pytorch.org/docs/1.13/dlpack.html?highlight=torch+utils+dlpack+from_dlpack#torch.utils.dlpack.from_dlpack) | ||
|
||
```python | ||
torch.utils.dlpack.from_dlpack(ext_tensor) | ||
``` | ||
|
||
### [paddle.utils.dlpack.from_dlpack](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/utils/dlpack/from_dlpack_cn.html) | ||
|
||
```python | ||
paddle.utils.dlpack.from_dlpack(dlpack) | ||
``` | ||
|
||
两者功能一致,参数名不一致,具体如下: | ||
### 参数映射 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| ext_tensor | dlpack | DLPack,即带有 dltensor 的 PyCapsule 对象,仅参数名不一致。 | |
18 changes: 18 additions & 0 deletions
18
...nvert/convert_from_pytorch/api_difference/utils/torch.utils.dlpack.to_dlpack.md
This file contains hidden or 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,18 @@ | ||
## [ 仅参数名不一致 ]torch.utils.dlpack.to_dlpack | ||
### [torch.utils.dlpack.to_dlpack](https://pytorch.org/docs/1.13/dlpack.html?highlight=torch+utils+dlpack+to_dlpack#torch.utils.dlpack.to_dlpack) | ||
|
||
```python | ||
torch.utils.dlpack.to_dlpack(tensor) | ||
``` | ||
|
||
### [paddle.utils.dlpack.to_dlpack](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/utils/dlpack/to_dlpack_cn.html) | ||
|
||
```python | ||
paddle.utils.dlpack.to_dlpack(x) | ||
``` | ||
|
||
两者功能一致,参数名不一致,具体如下: | ||
### 参数映射 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| tensor | x | Paddle Tensor,仅参数名不一致。 | |
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.
转写还是直接写为y = paddle.linalg.matrix_power(x, 3)即可,同时为了示例的简便,可以不用定义
x = paddle.to_tensor([[1, 2, 3], [4, 5, 6], [7,8,9]])
, 直接使用即可,下面类似