From 9ba3f4297fbac6992c485a0753909a0dec744ef7 Mon Sep 17 00:00:00 2001 From: TTerror Date: Mon, 14 Feb 2022 10:36:38 +0800 Subject: [PATCH] update xpu test build script and fix get_test_cover_info, *test=kunlun (#39235) --- paddle/scripts/paddle_build.sh | 4 +- .../unittests/xpu/get_test_cover_info.py | 68 +++++++++++++++---- .../unittests/xpu/test_refactor_op_xpu.py | 4 +- 3 files changed, 60 insertions(+), 16 deletions(-) diff --git a/paddle/scripts/paddle_build.sh b/paddle/scripts/paddle_build.sh index af78b6d21eb..7f2ad893f67 100755 --- a/paddle/scripts/paddle_build.sh +++ b/paddle/scripts/paddle_build.sh @@ -1759,11 +1759,11 @@ set +x set -x ut_endTime_s=`date +%s` echo "XPU testCase Time: $[ $ut_endTime_s - $ut_startTime_s ]s" + python ${PADDLE_ROOT}/build/python/paddle/fluid/tests/unittests/xpu/get_test_cover_info.py + unset XPU_OP_LIST_DIR if [[ "$EXIT_CODE" != "0" ]]; then exit 8; fi - python ${PADDLE_ROOT}/build/python/paddle/fluid/tests/unittests/xpu/get_test_cover_info.py - unset XPU_OP_LIST_DIR fi } diff --git a/python/paddle/fluid/tests/unittests/xpu/get_test_cover_info.py b/python/paddle/fluid/tests/unittests/xpu/get_test_cover_info.py index 31246436efa..4eae44846ef 100644 --- a/python/paddle/fluid/tests/unittests/xpu/get_test_cover_info.py +++ b/python/paddle/fluid/tests/unittests/xpu/get_test_cover_info.py @@ -17,6 +17,7 @@ from __future__ import print_function import inspect import os import fcntl +import numpy as np import paddle import paddle.fluid.core as core @@ -29,28 +30,61 @@ type_dict_paddle_to_str = { paddle.int32: 'int32', paddle.int64: 'int64', paddle.float16: 'float16', + paddle.bfloat16: 'bfloat16', paddle.float32: 'float32', paddle.float64: 'float64', paddle.complex128: 'complex128', paddle.complex64: 'complex64', } +type_dict_paddle_to_numpy = { + paddle.bool: np.bool_, + paddle.uint8: np.uint8, + paddle.int8: np.int8, + paddle.int16: np.int16, + paddle.int32: np.int32, + paddle.int64: np.int64, + paddle.bfloat16: np.uint16, + paddle.float16: np.float16, + paddle.float32: np.float32, + paddle.float64: np.float64, + paddle.complex128: np.complex128, + paddle.complex64: np.complex64, +} + type_dict_str_to_paddle = { + 'uint8': paddle.uint8, + 'int8': paddle.int8, + 'int16': paddle.int16, 'int32': paddle.int32, 'int64': paddle.int64, - 'float32': paddle.float32, + 'bfloat16': paddle.bfloat16, 'float16': paddle.float16, + 'float32': paddle.float32, + 'float64': paddle.float64, 'bool': paddle.bool, - 'uint8': paddle.uint8, - 'int8': paddle.int8, - 'complex128': paddle.complex128, 'complex64': paddle.complex64, - 'int16': paddle.int16, + 'complex128': paddle.complex128, +} + +type_dict_str_to_numpy = { + 'uint8': np.uint8, + 'int8': np.int8, + 'int16': np.int16, + 'int32': np.int32, + 'int64': np.int64, + 'bfloat16': np.uint16, + 'float16': np.float16, + 'float32': np.float32, + 'float64': np.float64, + 'bool': np.bool_, + 'complex64': np.complex64, + 'complex128': np.complex128, } xpu_test_op_white_list = [] xpu_test_type_white_list = [] -xpu_test_op_type_white_list = [] +xpu_test_op_type_white_list = ['float64'] xpu_test_device_op_white_list = [] xpu_test_device_op_type_white_list = [] @@ -122,6 +156,8 @@ def make_xpu_op_list(xpu_version): if op_name in op_white_list or device_op_name in device_op_white_list: continue for op_type in type_list: + if op_type == paddle.bfloat16: + op_type = paddle.bfloat16 if op_type in type_white_list or op_type not in type_dict_paddle_to_str.keys( ): continue @@ -143,10 +179,17 @@ def get_xpu_op_support_types(op_name, dev_id=0): xpu_version = core.get_xpu_device_version(dev_id) support_type_list = core.get_xpu_device_op_support_types(op_name, xpu_version) - support_type_str_list = [ - type_dict_paddle_to_str[x] for x in support_type_list + support_type_str_list = [] + for stype in support_type_list: + if stype == paddle.bfloat16: + support_type_str_list.append(type_dict_paddle_to_str[ + paddle.bfloat16]) + else: + support_type_str_list.append(type_dict_paddle_to_str[stype]) + type_white_list = get_op_type_white_list() + return [ + stype for stype in support_type_str_list if stype not in type_white_list ] - return support_type_str_list def record_op_test(op_name, test_type): @@ -196,8 +239,9 @@ def create_test_class(func_globals, continue class_obj = test_class[1] cls_name = "{0}_{1}".format(test_class[0], str(test_type)) - func_globals[cls_name] = type(cls_name, (class_obj, ), - {'in_type': test_type}) + func_globals[cls_name] = type( + cls_name, (class_obj, ), + {'in_type': type_dict_str_to_numpy[test_type]}) if hasattr(test_class_obj, 'use_dynamic_create_class' ) and test_class_obj.use_dynamic_create_class: @@ -205,7 +249,7 @@ def create_test_class(func_globals, for dy_class in dynamic_classes: cls_name = "{0}_{1}".format(dy_class[0], str(test_type)) attr_dict = dy_class[1] - attr_dict['in_type'] = test_type + attr_dict['in_type'] = type_dict_str_to_numpy[test_type] func_globals[cls_name] = type(cls_name, (base_class, ), attr_dict) record_op_test(op_name, test_type) diff --git a/python/paddle/fluid/tests/unittests/xpu/test_refactor_op_xpu.py b/python/paddle/fluid/tests/unittests/xpu/test_refactor_op_xpu.py index a1eb0af2bc9..e7ee89c567f 100644 --- a/python/paddle/fluid/tests/unittests/xpu/test_refactor_op_xpu.py +++ b/python/paddle/fluid/tests/unittests/xpu/test_refactor_op_xpu.py @@ -69,7 +69,7 @@ class XPUTestArgsortOp1(XPUOpTestWrapper): self.descending = False if not hasattr( self, 'init_descending') else self.init_descending - if self.in_type == 'float32': + if self.in_type == np.float32: self.x = np.random.random(self.input_shape).astype(self.dtype) else: self.x = np.random.randint( @@ -118,7 +118,7 @@ class XPUTestArgsortOp2(XPUOpTestWrapper): self.init_axis() self.init_direction() - if self.in_type == 'float32': + if self.in_type == np.float32: self.x = np.random.random(self.input_shape).astype(self.dtype) else: self.x = np.random.randint( -- GitLab