-
Notifications
You must be signed in to change notification settings - Fork 827
【Hackathon 7th No.36】为 Paddle 代码转换工具新增 API 转换规则(第 3 组)2 -part #6890
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
Changes from all commits
Commits
Show all changes
8 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
66 changes: 66 additions & 0 deletions
66
...odel_convert/convert_from_pytorch/api_difference/torch/torch.blackman_window.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,66 @@ | ||
## [ torch 参数更多 ] torch.blackman_window | ||
|
||
### [torch.blackman_window](https://pytorch.org/docs/stable/generated/torch.blackman_window.html) | ||
|
||
```python | ||
torch.blackman_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) | ||
``` | ||
|
||
### [paddle.audio.functional.get_window](https://www.paddlepaddle.org.cn/documentation/docs/zh/2.6/api/paddle/audio/functional/get_window_cn.html#get-window) | ||
|
||
```python | ||
paddle.audio.functional.get_window(window, win_length, fftbins=True, dtype='float64') | ||
``` | ||
|
||
PyTorch 相比 Paddle 支持更多其他参数,具体如下: | ||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| - | window | 窗函数类型,Pytorch 无此参数,Paddle 需设置为 `blackman`。 | | ||
| window_length | win_length | 输入窗口的长度,仅参数名不同。 | | ||
| periodic | fftbins | 判断是否返回适用于过滤器设计的对称窗口,功能相反,Pytorch 默认值为 True 时,Paddle 须设置为 False,需要转写。 | | ||
| dtype | dtype | 返回 Tensor 的数据类型。 | | ||
| layout | -| 表示布局方式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | | ||
| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | | ||
| requires_grad | - | 表示是否计算梯度, Paddle 无此参数,需要转写。 | | ||
|
||
### 转写示例 | ||
|
||
#### window:窗函数类型 | ||
```python | ||
# PyTorch 写法 | ||
torch.blackman_window(5) | ||
|
||
# Paddle 写法 | ||
paddle.audio.functional.get_window('blackman', 5, fftbins = False) | ||
``` | ||
|
||
#### periodic:判断是否返回适用于过滤器设计的对称窗口 | ||
```python | ||
# PyTorch 写法 | ||
torch.blackman_window(5, periodic = False) | ||
|
||
# Paddle 写法 | ||
paddle.audio.functional.get_window('blackman', 5, fftbins = True) | ||
``` | ||
|
||
#### requires_grad:是否需要求反向梯度,需要修改该 Tensor 的 stop_gradient 属性 | ||
```python | ||
# PyTorch 写法 | ||
torch.blackman_window(5, requires_grad = True) | ||
|
||
# Paddle 写法 | ||
x = paddle.audio.functional.get_window('blackman', 5, fftbins = False) | ||
x.stop_gradient = False | ||
``` | ||
|
||
#### device: Tensor 的设备 | ||
```python | ||
# PyTorch 写法 | ||
torch.blackman_window(5, device = torch.device('cpu')) | ||
|
||
# Paddle 写法 | ||
y = paddle.audio.functional.get_window('blackman', 5, fftbins = False) | ||
y.cpu() | ||
``` |
19 changes: 19 additions & 0 deletions
19
...des/model_convert/convert_from_pytorch/api_difference/torch/torch.frombuffer.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,19 @@ | ||
## [ 组合替代实现 ]torch.frombuffer | ||
|
||
### [torch.frombuffer](https://pytorch.org/docs/stable/generated/torch.frombuffer.html) | ||
|
||
```python | ||
torch.frombuffer(buffer, *, dtype, count=-1, offset=0, requires_grad=False) | ||
``` | ||
|
||
把 Python 缓冲区创建的的对象变成一维 Tensor,Paddle 无此 API,需要组合实现。 | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# PyTorch 写法 | ||
torch.frombuffer(a, dtype=torch.int32) | ||
|
||
# Paddle 写法 | ||
paddle.to_tensor(np.frombuffer(a, dtype='int32')) | ||
``` |
19 changes: 19 additions & 0 deletions
19
...vert/convert_from_pytorch/api_difference/torch/torch.get_num_interop_threads.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,19 @@ | ||
## [ 组合替代实现 ]torch.get_num_interop_threads | ||
|
||
### [torch.get_num_interop_threads](https://pytorch.org/docs/stable/generated/torch.get_num_interop_threads.html) | ||
|
||
```python | ||
torch.get_num_interop_threads() | ||
enkilee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
返回 CPU 上用于操作间并行的线程数 (例如,在 JIT 解释器中),Paddle 无此 API,需要组合实现。 | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# PyTorch 写法 | ||
torch.get_num_interop_threads() | ||
|
||
# Paddle 写法 | ||
os.environ['OMP_NUM_THREADS'] | ||
``` |
19 changes: 19 additions & 0 deletions
19
...odel_convert/convert_from_pytorch/api_difference/torch/torch.get_num_threads.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,19 @@ | ||
## [ 组合替代实现 ]torch.get_num_threads | ||
|
||
### [torch.get_num_threads](https://pytorch.org/docs/stable/generated/torch.get_num_threads.html) | ||
|
||
```python | ||
torch.get_num_threads() | ||
``` | ||
|
||
返回用于并行化 CPU 操作的线程数,Paddle 无此 API,需要组合实现。 | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# PyTorch 写法 | ||
torch.get_num_threads() | ||
|
||
# Paddle 写法 | ||
os.environ['CPU_NUM'] | ||
``` |
67 changes: 67 additions & 0 deletions
67
...model_convert/convert_from_pytorch/api_difference/torch/torch.hamming_window.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,67 @@ | ||
## [ torch 参数更多 ]torch.hamming_window | ||
### [torch.hamming_window](https://pytorch.org/docs/stable/generated/torch.hamming_window.html) | ||
|
||
```python | ||
torch.hamming_window(window_length, periodic=True, alpha=0.54, beta=0.46, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) | ||
``` | ||
|
||
### [paddle.audio.functional.get_window](https://www.paddlepaddle.org.cn/documentation/docs/zh/2.6/api/paddle/audio/functional/get_window_cn.html#get-window) | ||
|
||
```python | ||
paddle.audio.functional.get_window(window, win_length, fftbins=True, dtype='float64') | ||
``` | ||
|
||
PyTorch 相比 Paddle 支持更多其他参数,具体如下: | ||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| - | window | 窗函数类型,Pytorch 无此参数,Paddle 需设置为 `hamming`。 | | ||
| window_length | win_length | 输入窗口的长度,仅参数名不同。 | | ||
| periodic | fftbins | 判断是否返回适用于过滤器设计的对称窗口,功能相反,Pytorch 默认值为 True 时,Paddle 须设置为 False,需要转写。 | | ||
| alpha | - | 窗函数中非线性部分的衰减速度,Paddle 无此参数,暂无转写方式。 | | ||
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. 这个没有转写方式吗?看其他的窗函数std、alpha都能转写 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. paddle: def _hamming(M: int, sym: bool = True, dtype: str = 'float64') -> Tensor:
"""Compute a Hamming window.
The Hamming window is a taper formed by using a raised cosine with
non-zero endpoints, optimized to minimize the nearest side lobe.
"""
return _general_hamming(M, 0.54, sym, dtype=dtype) 参数固定了。 |
||
| beta | - | 窗函数中线性部分的衰减速度,Paddle 无此参数,暂无转写方式。 | | ||
| dtype | dtype | 返回 Tensor 的数据类型。 | | ||
| layout | - | 表示布局方式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | | ||
| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | | ||
| requires_grad | - | 表示是否计算梯度, Paddle 无此参数,需要转写。 | | ||
|
||
### 转写示例 | ||
|
||
#### window:窗函数类型 | ||
```python | ||
# PyTorch 写法 | ||
torch.hamming_window(10, periodic = True) | ||
|
||
# Paddle 写法 | ||
paddle.audio.functional.get_window('hamming', 10, fftbins = False) | ||
``` | ||
|
||
#### periodic:判断是否返回适用于过滤器设计的对称窗口 | ||
```python | ||
# PyTorch 写法 | ||
torch.hamming_window(10, periodic = False) | ||
|
||
# Paddle 写法 | ||
paddle.audio.functional.get_window('hamming', 10, fftbins = True) | ||
``` | ||
|
||
#### requires_grad:是否需要求反向梯度,需要修改该 Tensor 的 stop_gradient 属性 | ||
```python | ||
# PyTorch 写法 | ||
torch.hamming_window(10, requires_grad=True) | ||
|
||
# Paddle 写法 | ||
x = paddle.audio.functional.get_window('hamming', 10, fftbins = False) | ||
x.stop_gradient = False | ||
``` | ||
|
||
#### device: Tensor 的设备 | ||
```python | ||
# PyTorch 写法 | ||
torch.hamming_window(10, device=torch.device('cpu')) | ||
|
||
# Paddle 写法 | ||
y = paddle.audio.functional.get_window('hamming', 10, fftbins = False) | ||
y.cpu() | ||
``` |
65 changes: 65 additions & 0 deletions
65
...es/model_convert/convert_from_pytorch/api_difference/torch/torch.hann_window.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,65 @@ | ||
## [ torch 参数更多 ]torch.hann_window | ||
### [torch.hann_window](https://pytorch.org/docs/stable/generated/torch.hann_window.html) | ||
|
||
```python | ||
torch.hann_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) | ||
``` | ||
|
||
### [paddle.audio.functional.get_window](https://www.paddlepaddle.org.cn/documentation/docs/zh/2.6/api/paddle/audio/functional/get_window_cn.html#get-window) | ||
|
||
```python | ||
paddle.audio.functional.get_window(window, win_length, fftbins=True, dtype='float64') | ||
``` | ||
|
||
PyTorch 相比 Paddle 支持更多其他参数,具体如下: | ||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| - | window | 窗函数类型,Pytorch 无此参数,Paddle 需设置为 `hann`。 | | ||
| window_length | win_length | 输入窗口的长度,仅参数名不同。 | | ||
| periodic | fftbins | 判断是否返回适用于过滤器设计的对称窗口,功能相反,Pytorch 默认值为 True 时,Paddle 须设置为 False,需要转写。 | | ||
| dtype | dtype | 返回 Tensor 的数据类型。 | | ||
| layout | - | 表示布局方式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | | ||
| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | | ||
| requires_grad | - | 表示是否计算梯度, Paddle 无此参数,需要转写。 | | ||
|
||
### 转写示例 | ||
|
||
#### window:窗函数类型 | ||
```python | ||
# PyTorch 写法 | ||
torch.hann_window(5) | ||
|
||
# Paddle 写法 | ||
paddle.audio.functional.get_window('hann', 5, fftbins = False) | ||
``` | ||
|
||
#### periodic:判断是否返回适用于过滤器设计的对称窗口 | ||
```python | ||
# PyTorch 写法 | ||
torch.blackman_window(10, periodic = False) | ||
|
||
# Paddle 写法 | ||
paddle.audio.functional.get_window('hann', 10, fftbins = True) | ||
``` | ||
|
||
#### requires_grad:是否需要求反向梯度,需要修改该 Tensor 的 stop_gradient 属性 | ||
```python | ||
# PyTorch 写法 | ||
torch.hann_window(10, requires_grad=True) | ||
|
||
# Paddle 写法 | ||
x = paddle.audio.functional.get_window('hann', 10, fftbins = False) | ||
x.stop_gradient = False | ||
``` | ||
|
||
#### device: Tensor 的设备 | ||
```python | ||
# PyTorch 写法 | ||
torch.hann_window(10, device=torch.device('cpu')) | ||
|
||
# Paddle 写法 | ||
y = paddle.audio.functional.get_window('hann', 10, fftbins = False) | ||
y.cpu() | ||
``` |
19 changes: 19 additions & 0 deletions
19
...vert/convert_from_pytorch/api_difference/torch/torch.set_num_interop_threads.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,19 @@ | ||
## [ 组合替代实现 ]torch.set_num_interop_threads | ||
|
||
### [torch.set_num_interop_threads](https://pytorch.org/docs/stable/generated/torch.set_num_interop_threads.html) | ||
|
||
```python | ||
torch.set_num_interop_threads() | ||
``` | ||
|
||
设置 CPU 上用于操作间并行的线程数 (例如,在 JIT 解释器中),Paddle 无此 API,需要组合实现。 | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# PyTorch 写法 | ||
torch.set_num_interop_threads(2) | ||
|
||
# Paddle 写法 | ||
os.environ['OMP_NUM_THREADS'] = '2' | ||
``` |
19 changes: 19 additions & 0 deletions
19
...odel_convert/convert_from_pytorch/api_difference/torch/torch.set_num_threads.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,19 @@ | ||
## [ 组合替代实现 ]torch.set_num_threads | ||
|
||
### [torch.set_num_threads](https://pytorch.org/docs/stable/generated/torch.set_num_threads.html) | ||
|
||
```python | ||
torch.set_num_threads(int) | ||
``` | ||
|
||
设置用于 CPU 上的内部操作并行性的线程数,Paddle 无此 API,需要组合实现。 | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# PyTorch 写法 | ||
torch.set_num_threads(2) | ||
|
||
# Paddle 写法 | ||
os.environ['CPU_NUM'] = '2' | ||
``` |
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.