Skip to content
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 7th No.36】为 Paddle 代码转换工具新增 API 转换规则(第 3 组) #479

Merged
merged 59 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
28ed535
fix
enkilee Sep 19, 2024
cdc060b
code style
enkilee Sep 19, 2024
131dac1
fix
enkilee Sep 19, 2024
fdd7ae6
fix
enkilee Sep 19, 2024
9eeb83d
fix
enkilee Sep 20, 2024
73e0929
fix
enkilee Sep 24, 2024
9ea271b
Merge branch 'PaddlePaddle:master' into hackathon7-part1
enkilee Sep 24, 2024
9e9cab5
CI
enkilee Sep 24, 2024
7e1675a
Merge remote-tracking branch 'refs/remotes/origin/hackathon7-part1' i…
enkilee Sep 24, 2024
ce46bff
fix
enkilee Sep 25, 2024
70cfd55
fix
enkilee Sep 25, 2024
206980a
fix
enkilee Sep 25, 2024
7c8b49e
fix
enkilee Sep 25, 2024
6a892d0
fix
enkilee Sep 25, 2024
f155669
fix
enkilee Sep 26, 2024
7c8108f
test blackman
enkilee Sep 26, 2024
563a1be
fix
enkilee Sep 26, 2024
4aee5c1
fix
enkilee Sep 26, 2024
f40a61e
fix
enkilee Sep 26, 2024
ecd7677
fix
enkilee Sep 26, 2024
6b22746
fix
enkilee Sep 26, 2024
5aca4f5
test
enkilee Sep 26, 2024
4d9440d
fix
enkilee Sep 26, 2024
fb27f13
fix
enkilee Sep 26, 2024
854bd4c
fix
enkilee Sep 26, 2024
6c0d004
fix
enkilee Sep 26, 2024
2b56f1a
fix
enkilee Sep 26, 2024
3761ca9
fix
enkilee Sep 26, 2024
51f6f81
fix
enkilee Sep 27, 2024
c66d5ed
fix
enkilee Sep 27, 2024
6eef583
fix
enkilee Sep 27, 2024
476edb3
fix
enkilee Sep 27, 2024
9c2aa00
fix
enkilee Sep 27, 2024
67972d8
fix
enkilee Sep 27, 2024
466d826
test
enkilee Sep 27, 2024
3c5e0e4
fix
enkilee Sep 27, 2024
38d7bc8
fix
enkilee Sep 27, 2024
3ce42da
fix
enkilee Sep 27, 2024
a34f023
fix
enkilee Sep 27, 2024
814e9fd
fix
enkilee Sep 27, 2024
d2d0a82
fix
enkilee Sep 27, 2024
fc5b930
fix
enkilee Sep 27, 2024
186c407
Merge branch 'master' into hackathon7-part1
enkilee Oct 9, 2024
9e21303
fix
enkilee Oct 9, 2024
b020daa
Merge branch 'master' into hackathon7-part1
zhwesky2010 Oct 9, 2024
c87d488
fix
enkilee Oct 9, 2024
452781b
Merge remote-tracking branch 'refs/remotes/origin/hackathon7-part1' i…
enkilee Oct 9, 2024
c7f6aa8
fix
enkilee Oct 9, 2024
9e740e4
fix
enkilee Oct 10, 2024
cf14997
fix
enkilee Oct 10, 2024
13090a9
fix
enkilee Oct 12, 2024
4963e99
fix
enkilee Oct 14, 2024
4bbab94
fix
enkilee Oct 14, 2024
b279579
fix
enkilee Oct 15, 2024
2672ed4
fix
enkilee Oct 15, 2024
cea82be
fix
enkilee Oct 15, 2024
874738f
fix
enkilee Oct 16, 2024
167c5a3
Merge branch 'PaddlePaddle:master' into hackathon7-part1
enkilee Oct 16, 2024
d79909e
fix
enkilee Oct 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 189 additions & 0 deletions paconvert/api_mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -14666,6 +14666,195 @@
"input": "x"
}
},
"torch.signal.windows.blackman": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.audio.functional.get_window",
"min_input_args": 1,
"args_list": [
"M",
"*",
"sym",
"dtype",
"layout",
"device",
"requires_grad"
],
"kwargs_change": {
"M": "win_length",
"sym": "fftbins",
"dtype": "dtype"
},
"paddle_default_kwargs": {
"dtype": "'float32'",
"window": "'blackman'"
}
},
"torch.signal.windows.cosine": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.audio.functional.get_window",
"min_input_args": 1,
"args_list": [
"M",
"*",
"sym",
"dtype",
"layout",
"device",
"requires_grad"
],
"kwargs_change": {
"M": "win_length",
"sym": "fftbins",
"dtype": "dtype"
},
"paddle_default_kwargs": {
"dtype": "'float32'",
"window": "'cosine'"
}
},
"torch.signal.windows.exponential": {
"Matcher": "SignalWindowsWatcher",
"paddle_api": "paddle.audio.functional.get_window",
"min_input_args": 1,
"args_list": [
"M",
"*",
"center",
"tau",
enkilee marked this conversation as resolved.
Show resolved Hide resolved
"sym",
"dtype",
"layout",
"device",
"requires_grad"
],
"unsupport_args": [
"center"
],
"kwargs_change": {
"M": "win_length",
"sym": "fftbins",
"dtype": "dtype"
},
"paddle_default_kwargs": {
"dtype": "'float32'"
}
},
"torch.signal.windows.gaussian": {
"Matcher": "SignalWindowsWatcher",
"paddle_api": "paddle.audio.functional.get_window",
"min_input_args": 1,
"args_list": [
"M",
"*",
"std",
"sym",
"dtype",
"layout",
"device",
"requires_grad"
],
"kwargs_change": {
"M": "win_length",
"sym": "fftbins",
"dtype": "dtype"
},
"paddle_default_kwargs": {
"dtype": "'float32'"
}
},
"torch.signal.windows.general_cosine": {
"Matcher": "SignalWindowsWatcher",
"paddle_api": "paddle.audio.functional.get_window",
"min_input_args": 1,
"args_list": [
"M",
"*",
"a",
"sym",
"dtype",
"layout",
"device",
"requires_grad"
],
"kwargs_change": {
"M": "win_length",
"a": "",
enkilee marked this conversation as resolved.
Show resolved Hide resolved
"sym": "fftbins",
"dtype": "dtype"
},
"paddle_default_kwargs": {
"dtype": "'float32'"
}
},
"torch.signal.windows.general_hamming": {
"Matcher": "SignalWindowsWatcher",
"paddle_api": "paddle.audio.functional.get_window",
"min_input_args": 1,
"args_list": [
"M",
"*",
"alpha",
"sym",
"dtype",
"layout",
"device",
"requires_grad"
],
"kwargs_change": {
"M": "win_length",
"sym": "fftbins",
"dtype": "dtype"
},
"paddle_default_kwargs": {
"dtype": "'float32'"
}
},
"torch.signal.windows.hamming": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.audio.functional.get_window",
"min_input_args": 1,
"args_list": [
"M",
"*",
"sym",
"dtype",
"layout",
"device",
"requires_grad"
],
"kwargs_change": {
"M": "win_length",
"sym": "fftbins",
"dtype": "dtype"
},
"paddle_default_kwargs": {
"dtype": "'float32'",
"window": "'hamming'"
}
},
"torch.signal.windows.hann": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.audio.functional.get_window",
"min_input_args": 1,
"args_list": [
"M",
"*",
"sym",
"dtype",
"layout",
"device",
"requires_grad"
],
"kwargs_change": {
"M": "win_length",
"sym": "fftbins",
"dtype": "dtype"
},
"paddle_default_kwargs": {
"dtype": "'float32'",
"window": "'hann'"
}
},
"torch.signbit": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.signbit",
Expand Down
34 changes: 34 additions & 0 deletions paconvert/api_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,40 @@ def generate_code(self, kwargs):
return super().generate_code(kwargs)


class SignalWindowsWatcher(BaseMatcher):
enkilee marked this conversation as resolved.
Show resolved Hide resolved
def generate_code(self, kwargs):
new_kwargs = {}
if "exponential" in self.torch_api:
enkilee marked this conversation as resolved.
Show resolved Hide resolved
if "sym" in kwargs and kwargs["sym"] == "(False)":
if "tau" in kwargs:
tau_value = float(str(kwargs.pop("tau")).strip("()"))
new_kwargs["window"] = ("exponential", None, tau_value)
else:
enkilee marked this conversation as resolved.
Show resolved Hide resolved
new_kwargs["window"] = ("exponential", None, 1.0)
else:
if "tau" in kwargs:
tau_value = float(str(kwargs.pop("tau")).strip("()"))
new_kwargs["window"] = ("exponential", tau_value)
else:
new_kwargs["window"] = ("exponential", 1.0)
if "gaussian" in self.torch_api:
if "std" in kwargs:
std_value = float(str(kwargs.pop("std")).strip("()"))
new_kwargs["window"] = ("gaussian", std_value)
else:
new_kwargs["window"] = ("gaussian", 1.0)
enkilee marked this conversation as resolved.
Show resolved Hide resolved
if "general_hamming" in self.torch_api:
if "alpha" in kwargs:
alpha_value = float(str(kwargs.pop("alpha")).strip("()"))
new_kwargs["window"] = ("general_hamming", alpha_value)
else:
new_kwargs["window"] = ("general_hamming", 0.54)
enkilee marked this conversation as resolved.
Show resolved Hide resolved
if "general_cosine" in self.torch_api:
new_kwargs["window"] = ("general_cosine", kwargs.pop("a"))
new_kwargs.update(kwargs)
return GenericMatcher.generate_code(self, new_kwargs)


class Num2TensorBinaryWithAlphaMatcher(BaseMatcher):
def generate_code(self, kwargs):
kwargs_change = self.api_mapping.get("kwargs_change", {})
Expand Down
151 changes: 151 additions & 0 deletions tests/test_signal_windows_blackman.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import textwrap

from apibase import APIBase

obj = APIBase("torch.signal.windows.blackman")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch
result = torch.signal.windows.blackman(5)
"""
)
obj.run(pytorch_code, ["result"], check_value=False)
enkilee marked this conversation as resolved.
Show resolved Hide resolved


def test_case_2():
pytorch_code = textwrap.dedent(
"""
import torch
result = torch.signal.windows.blackman(5, dtype=torch.float64)
"""
)
obj.run(pytorch_code, ["result"], check_value=False)


def test_case_3():
pytorch_code = textwrap.dedent(
"""
import torch
a = 5
result = torch.signal.windows.blackman(a)
"""
)
obj.run(pytorch_code, ["result"], check_value=False)


def test_case_4():
pytorch_code = textwrap.dedent(
"""
import torch
a = 5
result = torch.signal.windows.blackman(M = a, dtype=torch.float32)
"""
)
obj.run(pytorch_code, ["result"], check_value=False)


def test_case_5():
pytorch_code = textwrap.dedent(
"""
import torch
result = torch.signal.windows.blackman(5, dtype=torch.float64, requires_grad=True)
"""
)
obj.run(pytorch_code, ["result"], check_value=False)


def test_case_6():
pytorch_code = textwrap.dedent(
"""
import torch
result = torch.signal.windows.blackman(5, dtype=torch.float64, layout=torch.strided, requires_grad=True)
"""
)
obj.run(pytorch_code, ["result"], check_value=False)


def test_case_7():
pytorch_code = textwrap.dedent(
"""
import torch
result = torch.signal.windows.blackman(5, dtype=torch.float64, layout=torch.strided, device=torch.device('cpu'), requires_grad=True)
enkilee marked this conversation as resolved.
Show resolved Hide resolved
"""
)
obj.run(pytorch_code, ["result"], check_value=False)


def test_case_8():
pytorch_code = textwrap.dedent(
"""
import torch
result = torch.signal.windows.blackman(5, sym=False)
"""
)
obj.run(pytorch_code, ["result"], check_value=False)


def test_case_9():
pytorch_code = textwrap.dedent(
"""
import torch
result = torch.signal.windows.blackman(M=5, sym=False, dtype=torch.float64)
"""
)
obj.run(pytorch_code, ["result"], check_value=False)


def test_case_10():
pytorch_code = textwrap.dedent(
"""
import torch
result = torch.signal.windows.blackman(M=5, sym=False, dtype=torch.float64, requires_grad=True)
"""
)
obj.run(pytorch_code, ["result"], check_value=False)


def test_case_11():
pytorch_code = textwrap.dedent(
"""
import torch
result = torch.signal.windows.blackman(M=5, sym=False, dtype=torch.float64, layout=torch.strided, requires_grad=True)
"""
)
obj.run(pytorch_code, ["result"], check_value=False)


def test_case_12():
pytorch_code = textwrap.dedent(
"""
import torch
result = torch.signal.windows.blackman(M=5, sym=False, dtype=torch.float64, layout=torch.strided, device=torch.device('cpu'), requires_grad=True)
"""
)
obj.run(pytorch_code, ["result"], check_value=False)


def test_case_13():
pytorch_code = textwrap.dedent(
"""
import torch
result = torch.signal.windows.blackman(dtype=torch.float64, M=5, layout=torch.strided, device=torch.device('cpu'), requires_grad=True, sym=False)
"""
)
obj.run(pytorch_code, ["result"], check_value=False)
Loading