-
Notifications
You must be signed in to change notification settings - Fork 750
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
映射文档 No.61 #5902
Merged
Merged
映射文档 No.61 #5902
Changes from all commits
Commits
Show all changes
4 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
23 changes: 23 additions & 0 deletions
23
...del_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.quantile.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,23 @@ | ||
## [torch 参数更多]torch.Tensor.quantile | ||
|
||
### [torch.Tensor.quantile](https://pytorch.org/docs/1.13/generated/torch.Tensor.quantile.html#torch.Tensor.quantile) | ||
|
||
```python | ||
torch.Tensor.quantile(q, dim=None, keepdim=False, *, interpolation='linear') | ||
``` | ||
|
||
### [paddle.Tensor.quantile](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#quantile-q-axis-none-keepdim-false-name-none) | ||
|
||
```python | ||
paddle.Tensor.quantile(q, axis=None, keepdim=False, name=None) | ||
``` | ||
|
||
其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下: | ||
|
||
### 参数映射 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------- | ------------ | ------------------------ | | ||
| q | q |待计算的分位数。 | | ||
| dim | axis |指定对 x 进行计算的轴,仅参数名不一致。| | ||
| keepdim | keepdim |是否在输出 Tensor 中保留减小的维度。| | ||
| interpolation | - |两个数据点的插补取值方法,Paddle 无此参数,暂无转写方式。| |
32 changes: 32 additions & 0 deletions
32
.../model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.round.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 @@ | ||
## [torch 参数更多]torch.Tensor.round | ||
|
||
### [torch.Tensor.round](https://pytorch.org/docs/1.13/generated/torch.Tensor.round.html#torch.Tensor.round) | ||
|
||
```python | ||
torch.Tensor.round(decimals=0) | ||
``` | ||
|
||
### [paddle.Tensor.round](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#round-name-none) | ||
|
||
```python | ||
paddle.Tensor.round(name=None) | ||
``` | ||
|
||
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: | ||
|
||
### 参数映射 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| -------- | ------- | ------- | | ||
| decimals | - | 舍入小数位数 | | ||
|
||
### 转写示例 | ||
#### decimals:要舍入到的小数位数 | ||
```python | ||
# Pytorch 写法 | ||
torch.tensor([3.345, 5.774]).round(decimals=2) | ||
|
||
# Paddle 写法 | ||
(paddle.to_tensor([3.345, 5.774]) * 1e2).round() / 1e2 | ||
|
||
# 注:Paddle 可使用 10 的 decimals 次方来实现 | ||
``` |
32 changes: 32 additions & 0 deletions
32
...model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.round_.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 @@ | ||
## [torch 参数更多]torch.Tensor.round_ | ||
|
||
### [torch.Tensor.round_](https://pytorch.org/docs/1.13/generated/torch.Tensor.round_.html#torch.Tensor.round_) | ||
|
||
```python | ||
torch.Tensor.round_(decimals=0) | ||
``` | ||
|
||
### [paddle.Tensor.round_](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#round-name-none) | ||
|
||
```python | ||
paddle.Tensor.round_(name=None) | ||
``` | ||
|
||
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: | ||
|
||
### 参数映射 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| -------- | ------- | ------- | | ||
| decimals | - | 舍入小数位数 | | ||
|
||
### 转写示例 | ||
#### decimals:要舍入到的小数位数 | ||
```python | ||
# Pytorch 写法 | ||
torch.tensor([3.345, 5.774]).round_(decimals=2) | ||
|
||
# Paddle 写法 | ||
(paddle.to_tensor([3.345, 5.774]) * 1e2).round_() / 1e2 | ||
|
||
# 注:Paddle 可使用 10 的 decimals 次方来实现 | ||
``` |
24 changes: 24 additions & 0 deletions
24
...odel_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter.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.Tensor.scatter | ||
|
||
### [torch.Tensor.scatter](https://pytorch.org/docs/1.13/generated/torch.Tensor.scatter.html#torch.Tensor.scatter) | ||
|
||
```python | ||
torch.Tensor.scatter(dim, index, src) | ||
``` | ||
|
||
### [paddle.Tensor.put_along_axis](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#put-along-axis-arr-index-value-axis-reduce-assign) | ||
|
||
```python | ||
paddle.Tensor.put_along_axis(index, value, axis, reduce="assign") | ||
|
||
``` | ||
|
||
其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: | ||
|
||
### 参数映射 | ||
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. 测试Tensor.put_along_axis 不使用arr参数 |
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------- | ------------ | ------- | | ||
| dim | axis | 表示在哪一个维度 scatter ,仅参数名不一致。 | | ||
| index | index | 表示输入的索引张量,仅参数名不一致。 | | ||
| src | value | 表示需要插入的值,仅参数名不一致。 | | ||
| - | reduce | 归约操作类型,PyTorch 无此参数, Paddle 保持默认即可。 | |
20 changes: 20 additions & 0 deletions
20
..._convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter_add.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,20 @@ | ||
## [组合替代实现]torch.Tensor.scatter_add | ||
|
||
### [torch.Tensor.scatter_add](https://pytorch.org/docs/1.13/generated/torch.Tensor.scatter_add.html#torch.Tensor.scatter_add) | ||
|
||
```python | ||
torch.Tensor.scatter_add(dim, index, src) | ||
``` | ||
|
||
Paddle 无此 API,需要组合实现。 | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# Pytorch 写法 | ||
x.scatter_add(dim, index, src) | ||
|
||
# Paddle 写法 | ||
x2 = paddle.zeros(x.shape) | ||
y = x + x2.put_along_axis(index, value, axis) | ||
``` |
20 changes: 20 additions & 0 deletions
20
.../model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.short.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,20 @@ | ||
## [torch 参数更多]torch.Tensor.short | ||
|
||
### [torch.Tensor.short](https://pytorch.org/docs/1.13/generated/torch.Tensor.short.html#torch.Tensor.short) | ||
|
||
```python | ||
torch.Tensor.short(memory_format=torch.preserve_format) | ||
``` | ||
|
||
### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#put-along-axis-arr-index-value-axis-reduce-assign) | ||
|
||
```python | ||
paddle.Tensor.astype('int16') | ||
``` | ||
|
||
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: | ||
|
||
### 参数映射 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------- | ------- | ------- | | ||
| memory_format | - |表示内存格式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | |
30 changes: 30 additions & 0 deletions
30
...s/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.size.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,30 @@ | ||
## [torch 参数更多]torch.Tensor.size | ||
|
||
### [torch.Tensor.size](https://pytorch.org/docs/1.13/generated/torch.Tensor.size.html#torch.Tensor.size) | ||
|
||
```python | ||
torch.Tensor.size(dim=None) | ||
``` | ||
|
||
### [paddle.Tensor.shape](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#shape) | ||
|
||
```python | ||
paddle.Tensor.shape | ||
``` | ||
|
||
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: | ||
|
||
### 参数映射 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------- | ------------ | ------- | | ||
| dim | - | 表示获取大小的轴,Paddle 无此参数,需要进行转写。 | | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# Pytorch 写法 | ||
torch.tensor([-1, -2, 3]).size(0) | ||
|
||
# Paddle 写法 | ||
paddle.to_tensor([-0.4, -0.2, 0.1, 0.3]).shape[0] | ||
``` |
38 changes: 38 additions & 0 deletions
38
...s/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.stft.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,38 @@ | ||
## [torch 参数更多]torch.Tensor.stft | ||
|
||
### [torch.Tensor.stft](https://pytorch.org/docs/1.13/generated/torch.Tensor.stft.html#torch.Tensor.stft) | ||
|
||
```python | ||
torch.Tensor.stft(n_fft, hop_length=None, win_length=None, window=None, center=True, pad_mode='reflect', normalized=False, onesided=None, return_complex=None) | ||
``` | ||
|
||
### [paddle.signal.stft](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/signal/stft_cn.html) | ||
|
||
```python | ||
paddle.signal.stft(x, n_fft, hop_length=None, win_length=None, window=None, center=True, pad_mode='reflect', normalized=False, onesided=True, name=None) | ||
``` | ||
|
||
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: | ||
|
||
### 参数映射 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ---------- | ------------ | ------- | | ||
| n_fft | n_fft | 离散傅里叶变换的样本点个数。 | | ||
| hop_length | hop_length | 对输入分帧时,相邻两帧偏移的样本点个数。 | | ||
| win_length | win_length | 信号窗的长度。 | | ||
| window | window | 维度为 1D 长度为 win_length 的 Tensor。 | | ||
| center | center | 选择是否将输入信号进行补长。 | | ||
| pad_mode | pad_mode | 当 center 为 True 时,确定 padding 的模式。 | | ||
| normalized | normalized | 是否将傅里叶变换的结果乘以值为 1/sqrt(n) 的缩放系数。 | | ||
| onesided | onesided | 当输入为实信号时,选择是否只返回傅里叶变换结果的一半的频点值。 | | ||
| return_complex | - | 表示当输入为复数时,是否以复数形式返回,还是将实部与虚部分开以实数形式返回。Paddle 目前只支持返回复数,分开返回实部与虚部的情况,需要使用 as_real 进行转写。 | | ||
|
||
### 转写示例 | ||
#### return_complex:是否返回复数 | ||
```python | ||
# Pytorch 写法 | ||
y = torch.rand(512,512).stft(n_fft=512, return_complex=False) | ||
|
||
# Paddle 写法 | ||
y = paddle.as_real(paddle.signal.stft(paddle.rand((512,512)), n_fft=512)) | ||
``` |
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.
另起一行加一个代码块的符号吧 ```