-
Notifications
You must be signed in to change notification settings - Fork 826
update torch.* mapping #5618
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
update torch.* mapping #5618
Changes from all commits
Commits
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
417 changes: 219 additions & 198 deletions
417
docs/guides/model_convert/convert_from_pytorch/pytorch_api_mapping_cn.md
Large diffs are not rendered by default.
Oops, something went wrong.
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,33 @@ | ||
## torch.abs | ||
### [torch.abs](https://pytorch.org/docs/stable/generated/torch.abs.html?highlight=abs#torch.abs) | ||
|
||
```python | ||
torch.abs(input, | ||
*, | ||
out=None) | ||
``` | ||
|
||
### [paddle.abs](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/abs_cn.html#abs) | ||
|
||
```python | ||
paddle.abs(x, | ||
name=None) | ||
``` | ||
|
||
其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下: | ||
### 参数差异 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| input | x | 输入的 Tensor。 | | ||
| out | - | 表示输出的 Tensor,PaddlePaddle 无此参数。 | | ||
|
||
|
||
### 转写示例 | ||
#### out:指定输出 | ||
```python | ||
# Pytorch 写法 | ||
torch.abs([-3, -5], out=y) | ||
|
||
# Paddle 写法 | ||
y = paddle.abs([-3, -5]) | ||
``` |
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,33 @@ | ||
## torch.absolute | ||
### [torch.absolute](https://pytorch.org/docs/stable/generated/torch.absolute.html?highlight=absolute#torch.absolute) | ||
|
||
```python | ||
torch.absolute(input, | ||
*, | ||
out=None) | ||
``` | ||
|
||
### [paddle.abs](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/abs_cn.html#abs) | ||
|
||
```python | ||
paddle.abs(x, | ||
name=None) | ||
``` | ||
|
||
其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下: | ||
### 参数差异 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| input | x | 输入的 Tensor。 | | ||
| out | - | 表示输出的 Tensor,PaddlePaddle 无此参数。 | | ||
|
||
|
||
### 转写示例 | ||
#### out:指定输出 | ||
```python | ||
# Pytorch 写法 | ||
torch.absolute([-3, -5], out=y) | ||
|
||
# Paddle 写法 | ||
y = paddle.abs([-3, -5]) | ||
``` |
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,33 @@ | ||
## torch.acos | ||
### [torch.acos](https://pytorch.org/docs/stable/generated/torch.acos.html?highlight=acos#torch.acos) | ||
|
||
```python | ||
torch.acos(input, | ||
*, | ||
out=None) | ||
``` | ||
|
||
### [paddle.acos](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/acos_cn.html#acos) | ||
|
||
```python | ||
paddle.acos(x, | ||
name=None) | ||
``` | ||
|
||
其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下: | ||
### 参数差异 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| input | x | 输入的 Tensor。 | | ||
| out | - | 表示输出的 Tensor,PaddlePaddle 无此参数。 | | ||
|
||
|
||
### 转写示例 | ||
#### out:指定输出 | ||
```python | ||
# Pytorch 写法 | ||
torch.acos([3, 5], out=y) | ||
|
||
# Paddle 写法 | ||
y = paddle.acos([3, 5]) | ||
``` |
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.add | ||
### [torch.add](https) | ||
|
||
```python | ||
torch.add(input, | ||
other, | ||
*, | ||
alpha=1, | ||
out=None) | ||
``` | ||
|
||
### [paddle.add](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/add_cn.html#add) | ||
|
||
```python | ||
paddle.add(x, | ||
y, | ||
name=None) | ||
``` | ||
|
||
其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下: | ||
### 参数差异 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| input | x | 输入的 Tensor。 | | ||
| other | y | 输入的 Tensor。 | | ||
| alpha | - | other 的乘数,PaddlePaddle 无此参数。 | | ||
| out | - | 表示输出的 Tensor,PaddlePaddle 无此参数。 | | ||
|
||
|
||
### 转写示例 | ||
#### alpha:other 的乘数 | ||
```python | ||
# Pytorch 写法 | ||
torch.add([3, 5], [2, 3], alpha=2) | ||
|
||
# Paddle 写法 | ||
paddle.add([3, 5], 2 * [2, 3]) | ||
``` | ||
|
||
#### out:指定输出 | ||
```python | ||
# Pytorch 写法 | ||
torch.add([3, 5], [2, 3], out=y) | ||
|
||
# Paddle 写法 | ||
y = paddle.add([3, 5], [2, 3]) | ||
``` |
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,20 @@ | ||
## torch.addmv | ||
### [torch.addmv](https://pytorch.org/docs/stable/generated/torch.addmv.html?highlight=addmv#torch.addmv) | ||
```python | ||
torch.addmv(input, mat, vec, beta=1, alpha=1, out=None) | ||
``` | ||
|
||
### 功能介绍 | ||
用于实现矩阵(`mat`)与向量(`vec`)相乘,再加上输入(`input`),公式为: | ||
$ out = β * input + α * (mat @ vec) $ | ||
PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。 | ||
|
||
```python | ||
import paddle | ||
|
||
def addmv(input, mat, vec, beta=1, alpha=1, out=None): | ||
mv = alpha * paddle.matmul(mat, vec) | ||
input = beta * input | ||
out = mv + input | ||
return out | ||
``` |
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.addr | ||
### [torch.addr](https://pytorch.org/docs/stable/generated/torch.addr.html?highlight=addr#torch.addr) | ||
```python | ||
torch.addr(input, vec1, vec2, beta=1, alpha=1, out=None) | ||
``` | ||
|
||
### 功能介绍 | ||
用于实现矩阵(`vec`)与向量(`vec`)相乘,再加上输入(`input`),公式为: | ||
$out = β * input + α * (vec1 ⊗ vec2)$ | ||
PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。 | ||
|
||
```python | ||
import paddle | ||
|
||
def addr(input, vec1, vec2, beta=1, alpha=1, out=None): | ||
row = vec1.shape[0] | ||
column = vec2.shape[0] | ||
vec1 = paddle.unsqueeze(vec1, 0) | ||
vec1 = paddle.transpose(vec1, [1, 0]) | ||
vec1 = paddle.expand(vec1, [row, column]) | ||
new_vec2 = paddle.zeros([column, column], dtype=vec2.dtype) | ||
new_vec2[0, :] = vec2 | ||
out = alpha * paddle.matmul(vec1, new_vec2) | ||
out = beta * input + out | ||
return out | ||
``` |
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,23 @@ | ||
## torch.all | ||
### [torch.all](https://pytorch.org/docs/stable/generated/torch.all.html?highlight=all#torch.all) | ||
|
||
```python | ||
torch.all(input) | ||
``` | ||
|
||
### [paddle.all](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/all_cn.html#all) | ||
|
||
```python | ||
paddle.all(x, | ||
axis=None, | ||
keepdim=False, | ||
name=None) | ||
``` | ||
|
||
其中 Paddle 相比 Pytorch 支持更多其他参数,具体如下: | ||
### 参数差异 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| input | x | 输入的多维 Tensor。 | | ||
ustiniankw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - | axis | 计算逻辑与运算的维度,Pytorch 无,保持默认即可。 | | ||
| - | keepdim | 是否在输出 Tensor 中保留减小的维度,Pytorch 无,保持默认即可。 | |
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,28 @@ | ||
## torch.allclose | ||
### [torch.allclose](https://pytorch.org/docs/stable/generated/torch.allclose.html?highlight=allclose#torch.allclose) | ||
|
||
```python | ||
torch.allclose(input, | ||
other, | ||
rtol=1e-05, | ||
atol=1e-08, | ||
equal_nan=False) | ||
``` | ||
|
||
### [paddle.allclose](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/allclose_cn.html#allclose) | ||
|
||
```python | ||
paddle.allclose(x, | ||
y, | ||
rtol=1e-05, | ||
atol=1e-08, | ||
equal_nan=False, | ||
name=None) | ||
``` | ||
|
||
两者功能一致且参数用法一致,仅参数名不同,具体如下: | ||
### 参数差异 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| input | x | 输入的 Tensor。 | | ||
| other | y | 输入的 Tensor。 | |
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.any | ||
### [torch.any](https://pytorch.org/docs/stable/generated/torch.any.html?highlight=any#torch.any) | ||
|
||
```python | ||
torch.any(input) | ||
``` | ||
|
||
### [paddle.any](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/any_cn.html#any) | ||
|
||
```python | ||
paddle.any(x, | ||
axis=None, | ||
keepdim=False, | ||
name=None) | ||
``` | ||
|
||
两者功能一致且参数用法一致,仅参数名不同,具体如下: | ||
### 参数差异 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| input | x | 输入的多维 Tensor。 | |
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,56 @@ | ||
## torch.arange | ||
|
||
### [torch.arange](https://pytorch.org/docs/stable/generated/torch.arange.html?highlight=arange#torch.arange) | ||
|
||
```python | ||
torch.arange(start=0, | ||
end, | ||
step=1, | ||
*, | ||
out=None, | ||
dtype=None, | ||
layout=torch.strided, | ||
device=None, | ||
requires_grad=False) | ||
``` | ||
|
||
### [paddle.arange](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/arange_cn.html#arange) | ||
|
||
```python | ||
paddle.arange(start=0, | ||
end=None, | ||
step=1, | ||
dtype=None, | ||
name=None) | ||
``` | ||
|
||
其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下: | ||
### 参数差异 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| out | - | 表示输出的 Tensor,PaddlePaddle 无此参数。 | | ||
| layout | - | 表示布局方式,PaddlePaddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | | ||
| device | - | 表示 Tensor 存放位置,PaddlePaddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | | ||
| requires_grad | - | 表示是否不阻断梯度传导,PaddlePaddle 无此参数。 | | ||
|
||
|
||
### 转写示例 | ||
#### out:指定输出 | ||
```python | ||
# Pytorch 写法 | ||
torch.arange(5, out=y) | ||
|
||
# Paddle 写法 | ||
y = paddle.arange(5) | ||
``` | ||
|
||
|
||
#### requires_grad:是否需要求反向梯度,需要修改该 Tensor 的 stop_gradient 属性 | ||
```python | ||
# Pytorch 写法 | ||
x = torch.arange(5, requires_grad=True) | ||
|
||
# Paddle 写法 | ||
x = paddle.arange(5) | ||
x.stop_gradient = False | ||
``` |
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,33 @@ | ||
## torch.arccos | ||
### [torch.arccos](https://pytorch.org/docs/stable/generated/torch.arccos.html?highlight=arccos#torch.arccos) | ||
|
||
```python | ||
torch.arccos(input, | ||
*, | ||
out=None) | ||
``` | ||
|
||
### [paddle.acos](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/acos_cn.html#acos) | ||
|
||
```python | ||
paddle.acos(x, | ||
name=None) | ||
``` | ||
|
||
其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下: | ||
### 参数差异 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| input | x | 输入的 Tensor。 | | ||
| out | - | 表示输出的 Tensor,PaddlePaddle 无此参数。 | | ||
|
||
|
||
### 转写示例 | ||
#### out:指定输出 | ||
```python | ||
# Pytorch 写法 | ||
torch.arccos([3, 5], out=y) | ||
|
||
# Paddle 写法 | ||
y = paddle.acos([3, 5]) | ||
``` |
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,33 @@ | ||
## torch.arcsin | ||
### [torch.arcsin](https://pytorch.org/docs/stable/generated/torch.arcsin.html?highlight=arcsin#torch.arcsin) | ||
|
||
```python | ||
torch.arcsin(input, | ||
*, | ||
out=None) | ||
``` | ||
|
||
### [paddle.asin](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/asin_cn.html#asin) | ||
|
||
```python | ||
paddle.asin(x, | ||
name=None) | ||
``` | ||
|
||
其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下: | ||
### 参数差异 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| input | x | 输入的 Tensor。 | | ||
| out | - | 表示输出的 Tensor,PaddlePaddle 无此参数。 | | ||
|
||
|
||
### 转写示例 | ||
#### out:指定输出 | ||
```python | ||
# Pytorch 写法 | ||
torch.arcsin([-0.5962, 1.4985, -0.4396, 1.4525], out=y) | ||
|
||
# Paddle 写法 | ||
y = paddle.asin([-0.5962, 1.4985, -0.4396, 1.4525]) | ||
``` |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.