Skip to content
2 changes: 1 addition & 1 deletion lite/backends/arm/math/reduce_max.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ inline void reduce_third_of_three(
const T* src, T* dst, int first_in, int second_in, int third_in) {
for (int i = 0; i < first_in; i++) {
for (int j = 0; j < second_in; j++) {
dst[i * second_in + j] = src[i * second_in * third_in + j * second_in];
dst[i * second_in + j] = src[i * second_in * third_in + j * third_in];
for (int k = 0; k < third_in; k++) {
dst[i * second_in + j] =
src[i * second_in * third_in + j * third_in + k] >
Expand Down
37 changes: 29 additions & 8 deletions lite/tests/unittest_py/op/test_reduce_max_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@
class TestReduceMaxOp(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])
opencl_places = [
Place(TargetType.OpenCL, PrecisionType.FP16,
DataLayoutType.ImageDefault), Place(
Expand Down Expand Up @@ -69,13 +74,25 @@ 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 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]]))

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):
Expand Down Expand Up @@ -113,18 +130,22 @@ def _teller2(program_config, predictor_config):
in_shape = list(program_config.inputs["input_data"].shape)
axis = program_config.ops[0].attrs["dim"]
keep_dim = program_config.ops[0].attrs["keep_dim"]
if target_type == TargetType.OpenCL:
Comment thread
chenjiaoAngel marked this conversation as resolved.
Outdated
if len(in_shape) < 4:
return True
if target_type == TargetType.Metal:
if keep_dim == False or axis[0] != 1 or in_shape[0] != 1:
if keep_dim == False or axis[0] != 1 or in_shape[
0] != 1 or len(in_shape) < 4:
return True

self.add_ignore_check_case(
_teller2, IgnoreReasons.PADDLELITE_NOT_SUPPORT,
"The op output has diff in a specific case on metal. We need to fix it as soon as possible."
"The op output has diff in a specific case on metal/opencl. We need to fix it as soon as possible."
Comment thread
chenjiaoAngel marked this conversation as resolved.
Outdated
)

def test(self, *args, **kwargs):
target_str = self.get_target()
max_examples = 100
max_examples = 300
if target_str == "Metal":
# Make sure to generate enough valid cases for Metal
max_examples = 3000
Expand Down
5 changes: 2 additions & 3 deletions lite/tests/unittest_py/op/test_reduce_mean_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

axis_list 也可以是 0,1,2 等情况吧?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有呀, [0], [1], [2]
axis 这个传进去的必须是list,不能是单独的数值。这个可以看paddle/paddle-lite OP 定义

Copy link
Copy Markdown
Collaborator

@zhaoyang-star zhaoyang-star Mar 22, 2022

Choose a reason for hiding this comment

The 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):
Expand Down
28 changes: 22 additions & 6 deletions lite/tests/unittest_py/op/test_reduce_min_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]]))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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):
Expand Down
97 changes: 97 additions & 0 deletions lite/tests/unittest_py/op/test_reduce_prod_op.py
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=[''])
97 changes: 97 additions & 0 deletions lite/tests/unittest_py/op/test_reduce_sum_op.py
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=[''])