Skip to content

Commit 28ffaa8

Browse files
authored
Add fp16 configs for reduce and add test of all, any. (#1184)
* Update some configs. * Add test scripts of all and any. * Change the approve ids. * Fix the case when the length of axis is 1. * Fix a bug of string comparison in shell.
1 parent 8e36c2f commit 28ffaa8

File tree

11 files changed

+195
-20
lines changed

11 files changed

+195
-20
lines changed

api/common/special_op_list.py

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"logical_not",
5656
"logical_and",
5757
"logical_or",
58+
"logical_xor",
5859
"not_equal",
5960
"one_hot",
6061
"scale",
@@ -64,6 +65,7 @@
6465

6566
# paddle v2 apis
6667
"add_n",
68+
"all",
6769
"any",
6870
"bernoulli",
6971
"empty",

api/common/utils.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ def _compare(self, output, target, atol):
7676

7777
def _check_type(output, target):
7878
def _is_numpy_dtype(value):
79-
if type(value
80-
) in [np.float32, np.float16, np.int32, np.int64, np.bool]:
79+
if type(value) in [
80+
np.float32, np.float16, np.int32, np.int64, np.bool, np.bool_
81+
]:
8182
return True
8283
else:
8384
return False

api/dynamic_tests_v2/elementwise.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(self, op_type="elementwise"):
2929
self.feed_spec = [{"range": [-1, 1]}, {"range": [-1, 1]}]
3030

3131
def disabled(self):
32-
if self.api_name in ["pow", "maximum", "minimum", "divide"
32+
if self.api_name in ["pow", "maximum", "minimum"
3333
] and self.x_dtype == "float16":
3434
print(
3535
"Warning:\n"

api/dynamic_tests_v2/reduce.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def compute_flop_and_byte(self, config):
5656
class TorchReduce(PytorchAPIBenchmarkBase):
5757
def build_graph(self, config):
5858
x = self.variable(name='x', shape=config.x_shape, dtype=config.x_dtype)
59-
if len(config.axis) == 0:
59+
if isinstance(config.axis, list) and len(config.axis) == 0:
6060
result = self.layers(config.api_name, input=x)
6161
else:
6262
result = self.layers(
+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from common_import import *
16+
17+
18+
class ReduceAllAnyConfig(APIConfig):
19+
def __init__(self):
20+
super(ReduceAllAnyConfig, self).__init__('reduce_all_any')
21+
self.feed_spec = {"range": [-1, 1]}
22+
self.api_name = 'all'
23+
self.api_list = {'all': 'all', 'any': 'any'}
24+
25+
def init_from_json(self, filename, config_id=3, unknown_dim=16):
26+
super(ReduceAllAnyConfig, self).init_from_json(filename, config_id,
27+
unknown_dim)
28+
if self.axis == None:
29+
self.axis = []
30+
31+
def squeeze_shape(self):
32+
if len(self.axis) == 1:
33+
return self.axis[0], self.x_shape
34+
elif len(self.axis) > 1:
35+
is_continuous = True
36+
for i in range(1, len(self.axis)):
37+
if self.axis[i] != self.axis[i - 1] + 1:
38+
is_continuous = False
39+
break
40+
if is_continuous:
41+
begin_axis = self.axis[0]
42+
end_axis = self.axis[-1]
43+
new_x_shape = [1] * (len(self.x_shape) + begin_axis - end_axis)
44+
for i in range(len(self.x_shape)):
45+
if i < begin_axis:
46+
new_x_shape[i] = self.x_shape[i]
47+
elif i < end_axis + 1:
48+
new_x_shape[begin_axis] = new_x_shape[
49+
begin_axis] * self.x_shape[i]
50+
else:
51+
new_x_shape[i + begin_axis - end_axis] = self.x_shape[
52+
i]
53+
return begin_axis, new_x_shape
54+
return self.axis, self.x_shape
55+
56+
57+
class PDReduceAllAny(PaddleDynamicAPIBenchmarkBase):
58+
def build_graph(self, config):
59+
x = self.variable(name='x', shape=config.x_shape, dtype=config.x_dtype)
60+
result = self.layers(
61+
config.api_name, x=x, axis=config.axis, keepdim=config.keepdim)
62+
63+
self.feed_list = [x]
64+
self.fetch_list = [result]
65+
66+
67+
class TorchReduceAllAny(PytorchAPIBenchmarkBase):
68+
def build_graph(self, config):
69+
x = self.variable(name='x', shape=config.x_shape, dtype=config.x_dtype)
70+
axis, x_shape = config.squeeze_shape()
71+
if x_shape != config.x_shape:
72+
x = torch.reshape(x=x, shape=x_shape)
73+
if isinstance(axis, list) and len(axis) == 0:
74+
result = self.layers(config.api_name, input=x)
75+
else:
76+
result = self.layers(
77+
config.api_name, input=x, dim=axis, keepdim=config.keepdim)
78+
79+
self.feed_list = [x]
80+
self.fetch_list = [result]
81+
82+
83+
if __name__ == '__main__':
84+
test_main(
85+
pd_dy_obj=PDReduceAllAny(),
86+
torch_obj=TorchReduceAllAny(),
87+
config=ReduceAllAnyConfig())

api/run_op_benchmark.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ install_package() {
2121
import_status=$?
2222
if [ ${import_status} -eq 0 ]; then
2323
installed_version=`python -c "import ${package_name}; print(${package_name}.__version__)"`
24-
if [ "${installed_version}" > "${package_version}" ]; then
24+
if [[ "${installed_version}" > "${package_version}" ]]; then
2525
echo "-- ${package_name} ${installed_version} (newer than ${package_version}) is already installed."
2626
elif [ "${installed_version}" == "${package_version}" ]; then
2727
echo "-- ${package_name} ${package_version} is already installed."

api/tests_v2/any.py

+1-10
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,7 @@
1818
class AnyConfig(APIConfig):
1919
def __init__(self):
2020
super(AnyConfig, self).__init__('any')
21-
self.alias_name = "reduce"
22-
23-
def init_from_json(self, filename, config_id=0, unknown_dim=16):
24-
super(AnyConfig, self).init_from_json(filename, config_id, unknown_dim)
25-
self.x_dtype = "bool"
26-
# Update the parameters information. It will be removed and reimplemented
27-
# in api_param.py.
28-
for var in self.variable_list:
29-
if var.type == "Variable" and var.name == "x":
30-
var.dtype = "bool"
21+
self.alias_name = "reduce_all_any"
3122

3223

3324
class PDAny(PaddleAPIBenchmarkBase):

api/tests_v2/configs/elementwise.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,6 @@
184184
"type": "Variable"
185185
}
186186
},
187-
"atol": 1E-5,
187+
"atol": 1E-1,
188188
"repeat": 10000
189189
}]

api/tests_v2/configs/reduce.json

+41-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,25 @@
1515
"value": "True"
1616
}
1717
},
18+
"atol": 1E-3,
19+
"repeat": 10000
20+
}, {
21+
"op": "reduce",
22+
"param_info": {
23+
"axis": {
24+
"type": "list",
25+
"value": "[2, 3]"
26+
},
27+
"x": {
28+
"dtype": "float16",
29+
"shape": "[-1L, 2048L, 33L, 33L]",
30+
"type": "Variable"
31+
},
32+
"keepdim": {
33+
"type": "bool",
34+
"value": "True"
35+
}
36+
},
1837
"atol": 0.0001,
1938
"repeat": 10000
2039
}, {
@@ -39,11 +58,11 @@
3958
"param_info": {
4059
"axis": {
4160
"type": "list",
42-
"value": "[0]"
61+
"value": "[1]"
4362
},
4463
"x": {
45-
"dtype": "float32",
46-
"shape": "[-1L, -1L, 1L, 1L]",
64+
"dtype": "float16",
65+
"shape": "[-1L, 8L, 128L]",
4766
"type": "Variable"
4867
},
4968
"keepdim": {
@@ -70,4 +89,23 @@
7089
},
7190
"atol": 0.01,
7291
"repeat": 10000
92+
}, {
93+
"op": "reduce",
94+
"param_info": {
95+
"axis": {
96+
"type": "string",
97+
"value": "None"
98+
},
99+
"x": {
100+
"dtype": "float16",
101+
"shape": "[30522L, 1024L]",
102+
"type": "Variable"
103+
},
104+
"keepdim": {
105+
"type": "bool",
106+
"value": "False"
107+
}
108+
},
109+
"atol": 0.01,
110+
"repeat": 10000
73111
}]
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
[{
2+
"op": "reduce_all_any",
3+
"param_info": {
4+
"axis": {
5+
"type": "list",
6+
"value": "[2, 3]"
7+
},
8+
"x": {
9+
"dtype": "bool",
10+
"shape": "[-1L, 2048L, 33L, 33L]",
11+
"type": "Variable"
12+
},
13+
"keepdim": {
14+
"type": "bool",
15+
"value": "True"
16+
}
17+
},
18+
"atol": 0.0001,
19+
"repeat": 10000
20+
}, {
21+
"op": "reduce_all_any",
22+
"param_info": {
23+
"axis": {
24+
"type": "list",
25+
"value": "[1]"
26+
},
27+
"x": {
28+
"dtype": "bool",
29+
"shape": "[-1L, 8L, 128L]",
30+
"type": "Variable"
31+
},
32+
"keepdim": {
33+
"type": "bool",
34+
"value": "False"
35+
}
36+
}
37+
}, {
38+
"op": "reduce_all_any",
39+
"param_info": {
40+
"axis": {
41+
"type": "string",
42+
"value": "None"
43+
},
44+
"x": {
45+
"dtype": "bool",
46+
"shape": "[30522L, 1024L]",
47+
"type": "Variable"
48+
},
49+
"keepdim": {
50+
"type": "bool",
51+
"value": "False"
52+
}
53+
},
54+
"atol": 0.01,
55+
"repeat": 10000
56+
}]

ci/scripts/check_approval.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ BENCHMARK_ROOT=$(cd $(dirname $0)/../../ && pwd)
2525

2626
declare -A FILE_APPROVAL_USER_MAP
2727
FILE_APPROVAL_USER_MAP=(
28-
["api/common/special_op_list.py"]="GaoWei8 wangchaochaohu zhangting2020"
28+
["api/common/special_op_list.py"]="JamesLim-sy ZzSean zhangting2020"
2929
)
3030

3131
LOG "[INFO] Get approval list ..."

0 commit comments

Comments
 (0)