-
Notifications
You must be signed in to change notification settings - Fork 5.9k
[PIR] Adaptation of test_zero_dim_no_backward_api, extract init data
#62808
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 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -260,6 +260,9 @@ class TestNoBackwardAPIStatic(unittest.TestCase): | |
| def setUp(self): | ||
| paddle.enable_static() | ||
| self.exe = paddle.static.Executor() | ||
| self.shape = [] | ||
|
|
||
| def init_data(self): | ||
| self.shape = [ | ||
| paddle.full([], 2, 'int32'), | ||
| paddle.full([], 3, 'int32'), | ||
|
|
@@ -312,6 +315,7 @@ def test_arange(self): | |
| np.testing.assert_array_equal(res, [1.0, 2.0, 3.0, 4.0, 5.0]) | ||
|
|
||
| def test_normal(self): | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个单测还有别的问题,下个pr看 |
||
| self.init_data() | ||
| mean = paddle.full([], 0.0) | ||
| std = paddle.full([], 0.0) | ||
| out1 = paddle.normal(mean, std) | ||
|
|
@@ -325,25 +329,35 @@ def test_normal(self): | |
| self.assertEqual(res[1].shape, ()) | ||
| self.assertEqual(res[2].shape, (2, 3, 4)) | ||
|
|
||
| @test_with_pir_api | ||
| def test_rand(self): | ||
| out1 = paddle.rand([]) | ||
| out2 = paddle.rand(self.shape) | ||
| main_program = paddle.static.Program() | ||
| startup_program = paddle.static.Program() | ||
| with paddle.static.program_guard(main_program, startup_program): | ||
| self.init_data() | ||
| out1 = paddle.rand([]) | ||
| out2 = paddle.rand(self.shape) | ||
|
|
||
| res = self.exe.run( | ||
| paddle.static.default_main_program(), fetch_list=[out1, out2] | ||
| ) | ||
| self.assertEqual(res[0].shape, ()) | ||
| self.assertEqual(res[1].shape, (2, 3, 4)) | ||
| res = paddle.static.Executor().run( | ||
| main_program, fetch_list=[out1, out2] | ||
| ) | ||
| self.assertEqual(res[0].shape, ()) | ||
| self.assertEqual(res[1].shape, (2, 3, 4)) | ||
|
|
||
| @test_with_pir_api | ||
| def test_randn(self): | ||
| out1 = paddle.randn([]) | ||
| out2 = paddle.randn(self.shape) | ||
| main_program = paddle.static.Program() | ||
| startup_program = paddle.static.Program() | ||
| with paddle.static.program_guard(main_program, startup_program): | ||
| self.init_data() | ||
| out1 = paddle.randn([]) | ||
| out2 = paddle.randn(self.shape) | ||
|
|
||
| res = self.exe.run( | ||
| paddle.static.default_main_program(), fetch_list=[out1, out2] | ||
| ) | ||
| self.assertEqual(res[0].shape, ()) | ||
| self.assertEqual(res[1].shape, (2, 3, 4)) | ||
| res = paddle.static.Executor().run( | ||
| main_program, fetch_list=[out1, out2] | ||
| ) | ||
| self.assertEqual(res[0].shape, ()) | ||
| self.assertEqual(res[1].shape, (2, 3, 4)) | ||
|
|
||
| @test_with_pir_api | ||
| def test_randint(self): | ||
|
|
@@ -381,76 +395,106 @@ def test_randint_like(self): | |
| self.assertEqual(res[0].shape, ()) | ||
| self.assertEqual(res[1].shape, ()) | ||
|
|
||
| @test_with_pir_api | ||
| def test_standard_normal(self): | ||
| out1 = paddle.standard_normal([]) | ||
| out2 = paddle.standard_normal(self.shape) | ||
| main_program = paddle.static.Program() | ||
| startup_program = paddle.static.Program() | ||
| with paddle.static.program_guard(main_program, startup_program): | ||
| self.init_data() | ||
| out1 = paddle.standard_normal([]) | ||
| out2 = paddle.standard_normal(self.shape) | ||
|
|
||
| res = self.exe.run( | ||
| paddle.static.default_main_program(), fetch_list=[out1, out2] | ||
| ) | ||
| self.assertEqual(res[0].shape, ()) | ||
| self.assertEqual(res[1].shape, (2, 3, 4)) | ||
| res = paddle.static.Executor().run( | ||
| main_program, fetch_list=[out1, out2] | ||
| ) | ||
| self.assertEqual(res[0].shape, ()) | ||
| self.assertEqual(res[1].shape, (2, 3, 4)) | ||
|
|
||
| @test_with_pir_api | ||
| def test_uniform(self): | ||
| out1 = paddle.uniform([]) | ||
| out2 = paddle.uniform(self.shape) | ||
| main_program = paddle.static.Program() | ||
| startup_program = paddle.static.Program() | ||
| with paddle.static.program_guard(main_program, startup_program): | ||
| self.init_data() | ||
| out1 = paddle.uniform([]) | ||
| out2 = paddle.uniform(self.shape) | ||
|
|
||
| res = self.exe.run( | ||
| paddle.static.default_main_program(), fetch_list=[out1, out2] | ||
| ) | ||
| self.assertEqual(res[0].shape, ()) | ||
| self.assertEqual(res[1].shape, (2, 3, 4)) | ||
| res = paddle.static.Executor().run( | ||
| main_program, fetch_list=[out1, out2] | ||
| ) | ||
| self.assertEqual(res[0].shape, ()) | ||
| self.assertEqual(res[1].shape, (2, 3, 4)) | ||
|
|
||
| @test_with_pir_api | ||
| def test_empty_and_empty_like(self): | ||
| out1 = paddle.empty([]) | ||
| out2 = paddle.empty_like(out1) | ||
| out3 = paddle.empty(self.shape) | ||
| main_program = paddle.static.Program() | ||
| startup_program = paddle.static.Program() | ||
| with paddle.static.program_guard(main_program, startup_program): | ||
| self.init_data() | ||
| out1 = paddle.empty([]) | ||
| out2 = paddle.empty_like(out1) | ||
| out3 = paddle.empty(self.shape) | ||
|
|
||
| res = self.exe.run( | ||
| paddle.static.default_main_program(), fetch_list=[out1, out2, out3] | ||
| ) | ||
| self.assertEqual(res[0].shape, ()) | ||
| self.assertEqual(res[1].shape, ()) | ||
| self.assertEqual(res[2].shape, (2, 3, 4)) | ||
| res = paddle.static.Executor().run( | ||
| main_program, fetch_list=[out1, out2, out3] | ||
| ) | ||
| self.assertEqual(res[0].shape, ()) | ||
| self.assertEqual(res[1].shape, ()) | ||
| self.assertEqual(res[2].shape, (2, 3, 4)) | ||
|
|
||
| @test_with_pir_api | ||
| def test_full_and_full_like(self): | ||
| out1 = paddle.full([], 0.5) | ||
| out2 = paddle.full_like(out1, 0.5) | ||
| out3 = paddle.full(self.shape, 0.5) | ||
| out4 = paddle.full(self.shape, paddle.full([], 0.5)) | ||
|
|
||
| res = self.exe.run( | ||
| paddle.static.default_main_program(), | ||
| fetch_list=[out1, out2, out3, out4], | ||
| ) | ||
| self.assertEqual(res[0].shape, ()) | ||
| self.assertEqual(res[1].shape, ()) | ||
| self.assertEqual(res[2].shape, (2, 3, 4)) | ||
| self.assertEqual(res[3].shape, (2, 3, 4)) | ||
| main_program = paddle.static.Program() | ||
| startup_program = paddle.static.Program() | ||
| with paddle.static.program_guard(main_program, startup_program): | ||
| self.init_data() | ||
| out1 = paddle.full([], 0.5) | ||
| out2 = paddle.full_like(out1, 0.5) | ||
| out3 = paddle.full(self.shape, 0.5) | ||
| out4 = paddle.full(self.shape, paddle.full([], 0.5)) | ||
|
|
||
| res = paddle.static.Executor().run( | ||
| main_program, | ||
| fetch_list=[out1, out2, out3, out4], | ||
| ) | ||
| self.assertEqual(res[0].shape, ()) | ||
| self.assertEqual(res[1].shape, ()) | ||
| self.assertEqual(res[2].shape, (2, 3, 4)) | ||
| self.assertEqual(res[3].shape, (2, 3, 4)) | ||
|
|
||
| @test_with_pir_api | ||
| def test_ones_and_ones_like(self): | ||
| out1 = paddle.ones([]) | ||
| out2 = paddle.ones_like(out1) | ||
| out3 = paddle.ones(self.shape) | ||
| main_program = paddle.static.Program() | ||
| startup_program = paddle.static.Program() | ||
| with paddle.static.program_guard(main_program, startup_program): | ||
| self.init_data() | ||
| out1 = paddle.ones([]) | ||
| out2 = paddle.ones_like(out1) | ||
| out3 = paddle.ones(self.shape) | ||
|
|
||
| res = self.exe.run( | ||
| paddle.static.default_main_program(), fetch_list=[out1, out2, out3] | ||
| ) | ||
| self.assertEqual(res[0].shape, ()) | ||
| self.assertEqual(res[1].shape, ()) | ||
| self.assertEqual(res[2].shape, (2, 3, 4)) | ||
| res = paddle.static.Executor().run( | ||
| main_program, fetch_list=[out1, out2, out3] | ||
| ) | ||
| self.assertEqual(res[0].shape, ()) | ||
| self.assertEqual(res[1].shape, ()) | ||
| self.assertEqual(res[2].shape, (2, 3, 4)) | ||
|
|
||
| @test_with_pir_api | ||
| def test_zeros_and_zeros_like(self): | ||
| out1 = paddle.zeros([]) | ||
| out2 = paddle.zeros_like(out1) | ||
| out3 = paddle.zeros(self.shape) | ||
| main_program = paddle.static.Program() | ||
| startup_program = paddle.static.Program() | ||
| with paddle.static.program_guard(main_program, startup_program): | ||
| self.init_data() | ||
| out1 = paddle.zeros([]) | ||
| out2 = paddle.zeros_like(out1) | ||
| out3 = paddle.zeros(self.shape) | ||
|
|
||
| res = self.exe.run( | ||
| paddle.static.default_main_program(), fetch_list=[out1, out2, out3] | ||
| ) | ||
| self.assertEqual(res[0].shape, ()) | ||
| self.assertEqual(res[1].shape, ()) | ||
| self.assertEqual(res[2].shape, (2, 3, 4)) | ||
| res = paddle.static.Executor().run( | ||
| main_program, fetch_list=[out1, out2, out3] | ||
| ) | ||
| self.assertEqual(res[0].shape, ()) | ||
| self.assertEqual(res[1].shape, ()) | ||
| self.assertEqual(res[2].shape, (2, 3, 4)) | ||
|
|
||
| @test_with_pir_api | ||
| def test_embedding(self): | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
这个默认的
self.shape是针对什么情况的?如果所有 case 都有init_data的话,就不存在需要self.shape默认值的情况另外,既然现在是在具体 test case 里调用的,就不要写成带有 side effect 的函数了,直接作为返回值返回即可,能写成纯函数就写成纯函数,函数名改名为
create_dynamic_shapeThere 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.
Done