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 all 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
196 changes: 196 additions & 0 deletions paconvert/api_mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -15024,6 +15024,202 @@
"input": "x"
}
},
"torch.signal.windows.blackman": {
"Matcher": "SignalWindowsWatcher",
"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'",
"fftbins": "False",
"window": "'blackman'"
}
},
"torch.signal.windows.cosine": {
"Matcher": "SignalWindowsWatcher",
"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'",
"fftbins": "False",
"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'",
"fftbins": "False"
}
},
"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'",
"fftbins": "False"
}
},
"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",
"sym": "fftbins",
"dtype": "dtype"
},
"paddle_default_kwargs": {
"dtype": "'float32'",
"fftbins": "False"
}
},
"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'",
"fftbins": "False"
}
},
"torch.signal.windows.hamming": {
"Matcher": "SignalWindowsWatcher",
"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'",
"fftbins": "False",
"window": "'hamming'"
}
},
"torch.signal.windows.hann": {
"Matcher": "SignalWindowsWatcher",
"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'",
"fftbins": "False",
"window": "'hann'"
}
},
"torch.signbit": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.signbit",
Expand Down
36 changes: 33 additions & 3 deletions paconvert/api_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,36 @@ 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 "sym" in kwargs:
kwargs["fftbins"] = "not " + kwargs.pop("sym")
if "exponential" in self.torch_api:
enkilee marked this conversation as resolved.
Show resolved Hide resolved
if "tau" in kwargs:
new_kwargs["window"] = "('exponential', None, {})".format(
kwargs.pop("tau")
)
else:
new_kwargs["window"] = "('exponential', None, 1.0)"
if "gaussian" in self.torch_api:
if "std" in kwargs:
new_kwargs["window"] = "('gaussian', {})".format(kwargs.pop("std"))
else:
new_kwargs["window"] = "('gaussian', 1.0)"
if "general_hamming" in self.torch_api:
if "alpha" in kwargs:
new_kwargs["window"] = "('general_hamming', {})".format(
kwargs.pop("alpha")
)
else:
new_kwargs["window"] = "('general_hamming', 0.54)"
if "general_cosine" in self.torch_api:
new_kwargs["window"] = "('general_cosine', {})".format(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 Expand Up @@ -832,7 +862,7 @@ def get_paddle_nodes(self, args, kwargs):
else:
shape = self.parse_args(args)[0]
kwargs = {"shape": str(shape).replace("'", ""), **kwargs}

if "dtype" not in kwargs:
kwargs["dtype"] = "float32"

Expand All @@ -841,7 +871,7 @@ def get_paddle_nodes(self, args, kwargs):

if "high" not in kwargs:
kwargs["high"] = 1

if "requires_grad" not in kwargs.keys():
API_TEMPLATE = textwrap.dedent(
"""
Expand Down Expand Up @@ -871,7 +901,7 @@ def get_paddle_nodes(self, args, kwargs):
kwargs["device"],
kwargs["requires_grad"],
)

return ast.parse(code).body


Expand Down
Loading