-
Notifications
You must be signed in to change notification settings - Fork 5.9k
【Hackathon 9th Sprint No.1】add api compatibility for paddle.unique - part #76387
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
20 commits
Select commit
Hold shift + click to select a range
ac045fd
add api compatibility for paddle.unique
co63oc 8e5e6ac
fix
co63oc 80764fd
fix
co63oc 7a1d555
fix
co63oc fb311dd
fix
co63oc 8b6e2d7
Merge branch 'develop' into m31
co63oc 46814a0
fix
co63oc 68fca13
fix
co63oc 379a6ea
fix
co63oc d8cc756
fix
co63oc 8be342b
fix
co63oc c9b57aa
Merge branch 'develop' into m31
co63oc f5c9c30
fix
co63oc 659bfee
fix
co63oc f845a1f
fix
co63oc 76f6321
Merge branch 'develop' into m31
co63oc dd247c8
fix
co63oc ea1c1f1
fix
co63oc 71af57d
Update python/paddle/compat/__init__.py
co63oc 6d41363
fix
co63oc 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| # Copyright (c) 2025 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 base | ||
|
|
||
|
|
||
| class TestCompatUniqueAPI(unittest.TestCase): | ||
| def test_basic(self): | ||
| paddle.disable_static() | ||
| x = paddle.to_tensor([2, 3, 3, 1, 5, 3]) | ||
| result = paddle.compat.unique(x) | ||
| expected = paddle.to_tensor([1, 2, 3, 5], dtype='int64') | ||
| np.testing.assert_allclose(result.numpy(), expected.numpy()) | ||
|
|
||
| _, inverse_indices, counts = paddle.compat.unique( | ||
| x, return_inverse=True, return_counts=True | ||
| ) | ||
| expected_indices = paddle.to_tensor([1, 2, 2, 0, 3, 2], dtype='int64') | ||
| expected_counts = paddle.to_tensor([1, 1, 3, 1], dtype='int64') | ||
| np.testing.assert_allclose( | ||
| inverse_indices.numpy(), expected_indices.numpy() | ||
| ) | ||
| np.testing.assert_allclose(counts.numpy(), expected_counts.numpy()) | ||
|
|
||
| x = paddle.to_tensor([[2, 1, 3], [3, 0, 1], [2, 1, 3]]) | ||
| result = paddle.compat.unique(x) | ||
| expected = paddle.to_tensor([0, 1, 2, 3], dtype='int64') | ||
| np.testing.assert_allclose(result.numpy(), expected.numpy()) | ||
| paddle.enable_static() | ||
|
|
||
| def test_static(self): | ||
| paddle.enable_static() | ||
|
|
||
| with paddle.static.program_guard( | ||
| paddle.static.Program(), paddle.static.Program() | ||
| ): | ||
| x = paddle.static.data(name='input', shape=[6], dtype='int64') | ||
| out, inverse_indices, counts = paddle.compat.unique( | ||
| x, return_inverse=True, return_counts=True | ||
| ) | ||
|
|
||
| exe = base.Executor(base.CPUPlace()) | ||
| x_data = np.array([2, 3, 3, 1, 5, 3], dtype='int64') | ||
| result = exe.run( | ||
| feed={'input': x_data}, | ||
| fetch_list=[out, inverse_indices, counts], | ||
| ) | ||
|
|
||
| np.testing.assert_allclose(result[1], [1, 2, 2, 0, 3, 2]) | ||
| np.testing.assert_allclose(result[2], [1, 1, 3, 1]) | ||
|
|
||
| with paddle.static.program_guard( | ||
| paddle.static.Program(), paddle.static.Program() | ||
| ): | ||
| x = paddle.static.data(name='input', shape=[3, 3], dtype='int64') | ||
| out = paddle.compat.unique(x) | ||
|
|
||
| exe = base.Executor(base.CPUPlace()) | ||
| x_data = np.array([[2, 1, 3], [3, 0, 1], [2, 1, 3]], dtype='int64') | ||
| result = exe.run(feed={'input': x_data}, fetch_list=[out]) | ||
|
|
||
| expected = np.array([0, 1, 2, 3], dtype='int64') | ||
| np.testing.assert_allclose(result[0], expected) | ||
|
|
||
| paddle.disable_static() | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() |
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
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.
这个目前应该无法实现 API完全一致吧,参数顺序不同。
group_norm也有这个问题。不过这个没法判断数据类型了,只能新增加一个paddle.compat.unique了?
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.compat.unique
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.
@zhwesky2010 已增加paddle.compat.unique CI完成,PaConvert PaddlePaddle/PaConvert#758 修改测试通过