-
Notifications
You must be signed in to change notification settings - Fork 5.9k
【Hackathon 6th No.3】为 Paddle 新增 ZeroPad1D / ZeroPad3D / block_diag API -part #63728
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 22 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
03a43c3
add api
ADream-ki 05e6050
update zeropad1 test
ADream-ki ab0762c
test
ADream-ki 5088dbe
update block_diag example
ADream-ki 7854d91
update test
ADream-ki cbf4594
test
ADream-ki edae11d
update
ADream-ki 319e0c5
add block_diag
ADream-ki e7a7625
update
ADream-ki db8fce8
Merge branch 'PaddlePaddle:develop' into task2
ADream-ki 3f3cc8b
Merge branch 'PaddlePaddle:develop' into task2
ADream-ki 28e80b7
Zeropad
ADream-ki d9fccd4
finish
ADream-ki 7bd3ffe
update test
ADream-ki 2cb256d
Merge branch 'PaddlePaddle:develop' into task2
ADream-ki cda4dca
update cpu/gpu
ADream-ki d8e24e3
Merge branch 'task2' of https://github.com/Chen-Lun-Hao/Paddle into t…
ADream-ki b382c5e
update
ADream-ki 9dddaa5
update file
ADream-ki 940d365
update
ADream-ki 832059f
update
ADream-ki 569ded4
Merge branch 'PaddlePaddle:develop' into task2
ADream-ki 333f225
update
ADream-ki 0375e5f
Merge branch 'task2' of https://github.com/Chen-Lun-Hao/Paddle into t…
ADream-ki 8fd3aeb
update
ADream-ki 97bfa5f
update
ADream-ki c8b7a84
finish
ADream-ki d05dd19
update
ADream-ki 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
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
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
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
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
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
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,90 @@ | ||
| # 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 unittest | ||
|
|
||
| import numpy as np | ||
|
|
||
| import paddle | ||
| from paddle import to_tensor | ||
| from paddle.nn import ZeroPad1D | ||
|
|
||
|
|
||
| class TestZeroPad1dAPI(unittest.TestCase): | ||
| def setUp(self): | ||
| if paddle.is_compiled_with_cuda(): | ||
| paddle.device.set_device('gpu:0') | ||
| else: | ||
| paddle.device.set_device('cpu') | ||
| self.shape = [4, 6, 6] | ||
| self.support_dtypes = ['float32', 'float64', 'int32', 'int64'] | ||
|
|
||
| def test_support_dtypes(self): | ||
| for dtype in self.support_dtypes: | ||
| pad = 2 | ||
| x = np.random.randint(-255, 255, size=self.shape).astype(dtype) | ||
| expect_res = np.pad( | ||
| x, | ||
| [[0, 0], [0, 0], [pad, pad]], | ||
| mode='constant', | ||
| constant_values=0, | ||
| ) | ||
|
|
||
| x_tensor = to_tensor(x).astype(dtype) | ||
| zeropad1d = ZeroPad1D(padding=pad) | ||
| ret_res = zeropad1d(x_tensor).numpy() | ||
| np.testing.assert_allclose(expect_res, ret_res, rtol=1e-05) | ||
|
|
||
| def test_support_pad2(self): | ||
| pad = [1, 2] | ||
| x = np.random.randint(-255, 255, size=self.shape) | ||
| expect_res = np.pad( | ||
| x, [[0, 0], [0, 0], pad], mode='constant', constant_values=0 | ||
| ) | ||
|
|
||
| x_tensor = to_tensor(x) | ||
| zeropad1d = ZeroPad1D(padding=pad) | ||
| ret_res = zeropad1d(x_tensor).numpy() | ||
| np.testing.assert_allclose(expect_res, ret_res, rtol=1e-05) | ||
|
|
||
| def test_support_pad3(self): | ||
| pad = (1, 2) | ||
| x = np.random.randint(-255, 255, size=self.shape) | ||
| expect_res = np.pad(x, [[0, 0], [0, 0], [pad[0], pad[1]]]) | ||
|
|
||
| x_tensor = to_tensor(x) | ||
| zeropad1d = ZeroPad1D(padding=pad) | ||
| ret_res = zeropad1d(x_tensor).numpy() | ||
| np.testing.assert_allclose(expect_res, ret_res, rtol=1e-05) | ||
|
|
||
| def test_support_pad4(self): | ||
| pad = [1, 2] | ||
| x = np.random.randint(-255, 255, size=self.shape) | ||
| expect_res = np.pad(x, [[0, 0], [0, 0], [pad[0], pad[1]]]) | ||
|
|
||
| x_tensor = to_tensor(x) | ||
| pad_tensor = to_tensor(pad, dtype='int32') | ||
| zeropad1d = ZeroPad1D(padding=pad_tensor) | ||
| ret_res = zeropad1d(x_tensor).numpy() | ||
| np.testing.assert_allclose(expect_res, ret_res, rtol=1e-05) | ||
|
|
||
| def test_repr(self): | ||
| pad = [1, 2] | ||
| zeropad1d = ZeroPad1D(padding=pad) | ||
| name_str = zeropad1d.extra_repr() | ||
| assert name_str == 'padding=[1, 2], data_format=NCL' | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() |
Oops, something went wrong.
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.
According to the current specification of PaddlePaddle, when the input may be multiple tensors, the parameters cannot be passed in this way. You need to put multiple tensors into a list or tuple before passing in. Please refer to the broadcast_tensors API