-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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 6th No.30】为 paddle.nn.functional.max_pool1d/max_pool2d /max_pool3d/paddle.signal.stft 进行功能增强 #62975
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
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.
- max_pool1d/2d/3d重点需要检验下在ceil_mode为True/False下的shape是否一致?
paddle.signal.sftf
与torch.sftf
结果做了对比吗,详细对比两者下两者的结果- 设备的问题:正常情况下,API的输入输出的设备是一致的,无需特殊指定配置,这里为何会出现不一致并且要手动指定?
python/paddle/signal.py
Outdated
@@ -362,6 +362,7 @@ def stft( | |||
), f'expected a 1D window tensor of size equal to win_length({win_length}), but got window with shape {window.shape}.' | |||
else: | |||
window = paddle.ones(shape=(win_length,), dtype=x.dtype) | |||
window = paddle.to_tensor(window, place=x.place) |
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.
这里windows的place为何是错的,一般情况下无需针对输出设备进行设置的
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.
这里当用户默认设备是GPU,但是输入的X
指定为CPU上,同时用户没有提供window
输入,这里会创建一个在默认设备(GPU)上的tensor,最后造成输出时result在GPU,这是符合预期的吗?
python/paddle/signal.py
Outdated
@@ -362,6 +362,7 @@ def stft( | |||
), f'expected a 1D window tensor of size equal to win_length({win_length}), but got window with shape {window.shape}.' | |||
else: | |||
window = paddle.ones(shape=(win_length,), dtype=x.dtype) | |||
window = paddle.to_tensor(window, place=x.place) | |||
|
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.
正常情况下:API的输入与输出是在相同设备上的,无需指定,底层执行器会自动设定相应的place
@AndPuQing 另外,该PR合入后,需要提交 API中文文档、API映射文档的修改。 同时需要将PaConvert中 |
Sorry to inform you that 02eb1dc's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually. |
Paddle versioncommit: 02eb1dc336cf650ac3b5c5d2fdbf55f893f7fb02
cuda: 12.0
cudnn: 8.9.1
nccl: 21701
xpu: False
xpu_xccl: False
xpu_xhpc: False
cinn: False Pytorch version2.2.2+cu121
39901f229520a5256505ec24782f716ee7ddc843 input dtype = float32
input dtype = float64
Test Codeimport paddle.cuda_env
import paddle.version
import torch
import paddle
import numpy as np
import torch.version
paddle.version.show()
print(torch.version.__version__)
print(torch.version.git_version)
n_fft = 400
hop_length = 15
normalized = False
onesided = True
inputs_np = np.random.rand(2, 2000).astype('float32')
window_np = np.hamming(n_fft).astype('float32')
# Paddle
x = paddle.to_tensor(inputs_np)
window = paddle.to_tensor(window_np)
res = paddle.signal.stft(
x=x,
n_fft=n_fft,
hop_length=hop_length,
window=window,
normalized=normalized,
onesided=onesided,
)
res_a = paddle.as_real(res)
# PyTorch
x = torch.tensor(inputs_np)
window = torch.tensor(window_np)
res0 = torch.stft(
input=x,
n_fft=n_fft,
hop_length=hop_length,
window=window,
normalized=normalized,
onesided=onesided,
return_complex=True,
)
res_b = torch.view_as_real(res0)
# Compare results
np.testing.assert_allclose(
res.numpy(), res0.numpy(), rtol=1e-20, atol=1e-20, verbose=True
) |
|
也可以单独提PR先把问题1给合入了 @AndPuQing |
|
Sorry to inform you that c1bec1c's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually. |
|
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.
在 paddle/phi/ops/yaml/op_version.yaml
里需要修改下
action:
add_attr
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.
LGTM
PR Category
User Experience
PR Types
New features
Description
修复了在
return_mask=True
模式下,ceil_mode
失效的问题,并添加了相应单测。修复了 stft 在(develop分支无法复现)as_real
后出现的数据不一致问题另外,stft 是否需要根据输入数据 x 所在的设备来决定输出结果的设备,develop分支中,即使
x
在 cpu 上,输出tensor 依然在gpu上(因为window 创建时是根据default_device决定的)