-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[arm_ut_py] fix reduce_max compute error and add reduce_* ut_py #8649
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
Changes from 5 commits
ffd085b
f1ca90c
5b189ec
5d1db4a
cd2dd23
7fe6608
8e13d2f
6fb46e8
c19c40b
d90e5f5
e0fd690
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,14 +64,13 @@ def sample_program_configs(self, draw): | |
| axis_type = draw(st.sampled_from(["int", "list"])) | ||
| axis_int = draw(st.integers(min_value=-1, max_value=3)) | ||
| axis_list = draw( | ||
| st.sampled_from([[2, 3], [1, 2], [0, 1], [1, 2, 3], [0, 1, 2]])) | ||
| st.sampled_from([[0], [1], [2], [3], [0, 1], [1, 2], [2, 3]])) | ||
|
Collaborator
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. axis_list 也可以是 0,1,2 等情况吧?
Collaborator
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. 有呀, [0], [1], [2]
Collaborator
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. [0,1,2]这种情况 |
||
| assume(axis < len(in_shape)) | ||
|
|
||
| if axis_type == "int": | ||
| axis = axis_int | ||
| else: | ||
| axis = axis_list | ||
| if isinstance(axis, int): | ||
| axis = [axis] | ||
| reduce_all_data = True if axis == None or axis == [] else False | ||
|
|
||
| def generate_input(*args, **kwargs): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,11 +31,16 @@ | |
| class TestReduceMinOp(AutoScanTest): | ||
| def __init__(self, *args, **kwargs): | ||
| AutoScanTest.__init__(self, *args, **kwargs) | ||
| self.enable_testing_on_place( | ||
| TargetType.ARM, | ||
| PrecisionType.FP32, | ||
| DataLayoutType.NCHW, | ||
| thread=[1, 4]) | ||
| self.enable_testing_on_place( | ||
| TargetType.X86, | ||
| PrecisionType.FP32, | ||
| DataLayoutType.NCHW, | ||
| thread=[1, 2]) | ||
| thread=[1, 4]) | ||
|
|
||
| def is_program_valid(self, | ||
| program_config: ProgramConfig, | ||
|
|
@@ -46,13 +51,24 @@ def sample_program_configs(self, draw): | |
| in_shape = draw( | ||
| st.lists( | ||
| st.integers( | ||
| min_value=1, max_value=10), min_size=4, max_size=4)) | ||
| min_value=1, max_value=10), min_size=1, max_size=4)) | ||
| keep_dim = draw(st.booleans()) | ||
| axis = draw(st.integers(min_value=-1, max_value=3)) | ||
| axis_type = draw(st.sampled_from(["int", "list"])) | ||
| axis_int = draw(st.integers(min_value=-1, max_value=3)) | ||
| axis_list = [0] | ||
| assume(axis < len(in_shape)) | ||
|
|
||
| if isinstance(axis, int): | ||
| axis = [axis] | ||
| if len(in_shape) == 2: | ||
| axis_list = draw(st.sampled_from([[0], [1]])) | ||
| elif len(in_shape) == 3: | ||
| axis_list = draw(st.sampled_from([[0], [1], [2]])) | ||
| elif len(in_shape) == 4: | ||
| axis_list = draw( | ||
| st.sampled_from([[0], [1], [2], [3], [0, 1], [1, 2], [2, 3]])) | ||
|
Collaborator
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. 同上,也可以是三个数 |
||
|
|
||
| if axis_type == "int": | ||
| axis = axis_int | ||
| else: | ||
| axis = axis_list | ||
| reduce_all_data = True if axis == None or axis == [] else False | ||
|
|
||
| def generate_input(*args, **kwargs): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| # Copyright (c) 2021 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 sys | ||
| sys.path.append('../') | ||
|
|
||
| from auto_scan_test import AutoScanTest, IgnoreReasons | ||
| from program_config import TensorConfig, ProgramConfig, OpConfig, CxxConfig, TargetType, PrecisionType, DataLayoutType, Place | ||
| import unittest | ||
|
|
||
| import hypothesis | ||
| from hypothesis import given, settings, seed, example, assume | ||
| import hypothesis.strategies as st | ||
|
|
||
| from functools import partial | ||
| import numpy as np | ||
| import argparse | ||
|
|
||
|
|
||
| class TestReduceMeanOp(AutoScanTest): | ||
| def __init__(self, *args, **kwargs): | ||
| AutoScanTest.__init__(self, *args, **kwargs) | ||
| self.enable_testing_on_place(TargetType.X86, PrecisionType.FP32, | ||
| DataLayoutType.NCHW) | ||
| self.enable_testing_on_place( | ||
| TargetType.ARM, | ||
| PrecisionType.FP32, | ||
| DataLayoutType.NCHW, | ||
| thread=[1, 4]) | ||
|
|
||
| def is_program_valid(self, | ||
| program_config: ProgramConfig, | ||
| predictor_config: CxxConfig) -> bool: | ||
| return True | ||
|
|
||
| def sample_program_configs(self, draw): | ||
| in_shape = draw( | ||
| st.lists( | ||
| st.integers( | ||
| min_value=1, max_value=10), min_size=4, max_size=4)) | ||
| keep_dim = draw(st.booleans()) | ||
| axis_type = draw(st.sampled_from(["int", "list"])) | ||
| axis_int = draw(st.integers(min_value=-1, max_value=3)) | ||
| axis_list = draw( | ||
| st.sampled_from([[0], [1], [2], [3], [0, 1], [1, 2], [2, 3]])) | ||
| assume(axis < len(in_shape)) | ||
|
|
||
| if axis_type == "int": | ||
| axis = axis_int | ||
| else: | ||
| axis = axis_list | ||
| reduce_all_data = True if axis == None or axis == [] else False | ||
|
|
||
| def generate_input(*args, **kwargs): | ||
| return np.random.random(in_shape).astype(np.float32) | ||
|
|
||
| build_ops = OpConfig( | ||
| type="reduce_prod", | ||
| inputs={"X": ["input_data"], }, | ||
| outputs={"Out": ["output_data"], }, | ||
| attrs={ | ||
| "dim": axis, | ||
| "keep_dim": keep_dim, | ||
| "reduce_all": reduce_all_data, | ||
| }) | ||
| program_config = ProgramConfig( | ||
| ops=[build_ops], | ||
| weights={}, | ||
| inputs={ | ||
| "input_data": TensorConfig(data_gen=partial(generate_input)), | ||
| }, | ||
| outputs=["output_data"]) | ||
| return program_config | ||
|
|
||
| def sample_predictor_configs(self): | ||
| return self.get_predictor_configs(), ["reduce_prod"], (1e-2, 1e-2) | ||
|
|
||
| def add_ignore_pass_case(self): | ||
| pass | ||
|
|
||
| def test(self, *args, **kwargs): | ||
| self.run_and_statis(quant=False, max_examples=100) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main(argv=['']) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| # Copyright (c) 2021 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 sys | ||
| sys.path.append('../') | ||
|
|
||
| from auto_scan_test import AutoScanTest, IgnoreReasons | ||
| from program_config import TensorConfig, ProgramConfig, OpConfig, CxxConfig, TargetType, PrecisionType, DataLayoutType, Place | ||
| import unittest | ||
|
|
||
| import hypothesis | ||
| from hypothesis import given, settings, seed, example, assume | ||
| import hypothesis.strategies as st | ||
|
|
||
| from functools import partial | ||
| import numpy as np | ||
| import argparse | ||
|
|
||
|
|
||
| class TestReduceMeanOp(AutoScanTest): | ||
| def __init__(self, *args, **kwargs): | ||
| AutoScanTest.__init__(self, *args, **kwargs) | ||
| self.enable_testing_on_place(TargetType.X86, PrecisionType.FP32, | ||
| DataLayoutType.NCHW) | ||
| self.enable_testing_on_place( | ||
| TargetType.ARM, | ||
| PrecisionType.FP32, | ||
| DataLayoutType.NCHW, | ||
| thread=[1, 4]) | ||
|
|
||
| def is_program_valid(self, | ||
| program_config: ProgramConfig, | ||
| predictor_config: CxxConfig) -> bool: | ||
| return True | ||
|
|
||
| def sample_program_configs(self, draw): | ||
| in_shape = draw( | ||
| st.lists( | ||
| st.integers( | ||
| min_value=1, max_value=10), min_size=4, max_size=4)) | ||
| keep_dim = draw(st.booleans()) | ||
| axis_type = draw(st.sampled_from(["int", "list"])) | ||
| axis_int = draw(st.integers(min_value=-1, max_value=3)) | ||
| axis_list = draw( | ||
| st.sampled_from([[0], [1], [2], [3], [0, 1], [1, 2], [2, 3]])) | ||
| assume(axis < len(in_shape)) | ||
|
|
||
| if axis_type == "int": | ||
| axis = axis_int | ||
| else: | ||
| axis = axis_list | ||
| reduce_all_data = True if axis == None or axis == [] else False | ||
|
|
||
| def generate_input(*args, **kwargs): | ||
| return np.random.random(in_shape).astype(np.float32) | ||
|
|
||
| build_ops = OpConfig( | ||
| type="reduce_sum", | ||
| inputs={"X": ["input_data"], }, | ||
| outputs={"Out": ["output_data"], }, | ||
| attrs={ | ||
| "dim": axis, | ||
| "keep_dim": keep_dim, | ||
| "reduce_all": reduce_all_data, | ||
| }) | ||
| program_config = ProgramConfig( | ||
| ops=[build_ops], | ||
| weights={}, | ||
| inputs={ | ||
| "input_data": TensorConfig(data_gen=partial(generate_input)), | ||
| }, | ||
| outputs=["output_data"]) | ||
| return program_config | ||
|
|
||
| def sample_predictor_configs(self): | ||
| return self.get_predictor_configs(), ["reduce_sum"], (1e-2, 1e-2) | ||
|
|
||
| def add_ignore_pass_case(self): | ||
| pass | ||
|
|
||
| def test(self, *args, **kwargs): | ||
| self.run_and_statis(quant=False, max_examples=100) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main(argv=['']) |
Uh oh!
There was an error while loading. Please reload this page.