Esempio n. 1
0
    def is_program_valid(self, program_config: ProgramConfig) -> bool:
        inputs = program_config.inputs
        weights = program_config.weights
        attrs = [
            program_config.ops[i].attrs for i in range(len(program_config.ops))
        ]

        if inputs['input_data'].shape[
                1] != weights['conv2d_weight'].shape[1] * attrs[0]['groups']:
            return False

        if inputs['input_data'].shape[1] != weights['conv2d_weight'].shape[1]:
            return False

        if inputs['input_data'].shape[1] != attrs[0]['groups']:
            return False

        if attrs[0]['dilations'][0] != 1 or attrs[0]['dilations'][1] != 1:
            return False

        ver = paddle_infer.get_trt_compile_version()
        if ver[0] * 1000 + ver[1] * 100 + ver[2] * 10 < 7000:
            return False

        return True
Esempio n. 2
0
        def generate_trt_nodes_num(attrs, dynamic_shape):
            inputs = program_config.inputs

            if not dynamic_shape:
                return 0, 3
            ver = paddle_infer.get_trt_compile_version()
            if ver[0] * 1000 + ver[1] * 100 + ver[2] * 10 < 7000:
                return 0, 3
            return 1, 2
 def generate_trt_nodes_num(attrs, dynamic_shape):
     ver = paddle_infer.get_trt_compile_version()
     if ver[0] * 1000 + ver[1] * 100 + ver[0] * 10 >= 7000:
         if dynamic_shape == True:
             return 0, 3
         else:
             return 1, 2
     else:
         return 0, 3
Esempio n. 4
0
 def test_apis(self):
     print('trt compile version:', get_trt_compile_version())
     print('trt runtime version:', get_trt_runtime_version())
     program, params = get_sample_model()
     config = self.get_config(program, params)
     predictor = create_predictor(config)
     in_names = predictor.get_input_names()
     in_handle = predictor.get_input_handle(in_names[0])
     in_data = np.ones((1, 6, 32, 32)).astype(np.float32)
     in_handle.copy_from_cpu(in_data)
     predictor.run()
Esempio n. 5
0
    def add_skip_trt_case(self):
        ver = paddle_infer.get_trt_compile_version()
        if ver[0] * 1000 + ver[1] * 100 + ver[0] * 10 < 7000:

            def teller(program_config, predictor_config):
                if not predictor_config.tensorrt_dynamic_shape_enabled():
                    return True
                return False

            self.add_skip_case(
                teller, SkipReasons.TRT_NOT_IMPLEMENTED,
                "Need to repair the case: the output of GPU and tensorrt has diff in trt6, the prelu static plugin has bug."
            )
Esempio n. 6
0
        def generate_trt_nodes_num(attrs, dynamic_shape):
            ver = paddle_infer.get_trt_compile_version()
            if ver[0] * 1000 + ver[1] * 100 + ver[0] * 10 >= 7130:
                if attrs[0]['axis'] == 1:
                    return 1, 2
                else:
                    return 0, 3
            else:
                if dynamic_shape:
                    return 0, 3

                if attrs[0]['axis'] == 1:
                    return 1, 2
                else:
                    return 0, 3
        def generate_trt_nodes_num(attrs, dynamic_shape):
            inputs = program_config.inputs

            if dynamic_shape:
                for i in range(len(attrs[0]["starts"])):
                    if attrs[0]["starts"][i] < 0 or attrs[0]["ends"][i] < 0:
                        return 0, 3
            if not dynamic_shape:
                for x in attrs[0]["axes"]:
                    if x == 0:
                        return 0, 3
            ver = paddle_infer.get_trt_compile_version()
            if ver[0] * 1000 + ver[1] * 100 + ver[2] * 10 < 7000:
                return 0, 3
            return 1, 2
Esempio n. 8
0
 def generate_trt_nodes_num(attrs, dynamic_shape):
     valid_version = (7, 0, 0)
     compile_version = paddle_infer.get_trt_compile_version()
     runtime_version = paddle_infer.get_trt_runtime_version()
     self.assertTrue(compile_version == runtime_version)
     # Dimension one only runs on Paddle OP
     if self.dims == 1:
         return 0, 3
     if compile_version >= valid_version:
         return 1, 2
     else:
         if attrs[0]['approximate'] == True:
             return 0, 3
         else:
             return 1, 2
 def is_paddings_valid(self, program_config: ProgramConfig) -> bool:
     exclusive = program_config.ops[0].attrs['exclusive']
     paddings = program_config.ops[0].attrs['paddings']
     ksize = program_config.ops[0].attrs['ksize']
     pooling_type = program_config.ops[0].attrs['pooling_type']
     global_pooling = program_config.ops[0].attrs['global_pooling']
     if global_pooling == False:
         if pooling_type == 'avg':
             for index in range(len(ksize)):
                 if ksize[index] <= paddings[index]:
                     return False
     ver = paddle_infer.get_trt_compile_version()
     if ver[0] * 1000 + ver[1] * 100 + ver[0] * 10 < 7000:
         if program_config.ops[0].attrs['pooling_type'] == 'avg':
             return False
     return True
Esempio n. 10
0
    def add_skip_trt_case(self):
        ver = paddle_infer.get_trt_compile_version()
        if ver[0] * 1000 + ver[1] * 100 + ver[0] * 10 < 7000:

            def teller1(program_config, predictor_config):
                if len(self.dynamic_shape.min_input_shape) != 0:
                    inputs = program_config.inputs
                    if len(inputs['input_data'].shape) == 1 or len(
                            inputs['index_data'].shape) == 1:
                        return True
                return False

            self.add_skip_case(
                teller1, SkipReasons.TRT_NOT_SUPPORT,
                "Need to repair the case: trt reshape out failed for dynamic shape mode when inputs' dims==1. under trt7.0 "
            )
    def is_program_valid(self, program_config: ProgramConfig) -> bool:
        inputs = program_config.inputs
        weights = program_config.weights
        attrs = [
            program_config.ops[i].attrs for i in range(len(program_config.ops))
        ]

        if inputs['input_data'].shape[
                1] != weights['conv2d_weight'].shape[1] * attrs[0]['groups']:
            return False

        ver = paddle_infer.get_trt_compile_version()
        if ver[0] * 1000 + ver[1] * 100 + ver[0] * 10 < 7000:
            if attrs[0]['padding_algorithm'] == 'SAME' and (
                    attrs[0]['strides'][0] > 1 or attrs[0]['strides'][1] > 1):
                return False

        return True
Esempio n. 12
0
    def is_program_valid(self, program_config: ProgramConfig) -> bool:
        inputs = program_config.inputs
        attrs = [
            program_config.ops[i].attrs for i in range(len(program_config.ops))
        ]

        ## dim should be in (-rank, rank), and not NONE
        rank = len(inputs['input_data'].shape)
        for x in attrs[0]["dim"]:
            if x >= rank or x <= -rank:
                return False
        if len(attrs[0]["dim"]) == 0:
            return False

        ver = paddle_infer.get_trt_compile_version()
        if ver[0] * 1000 + ver[1] * 100 + ver[0] * 10 < 7000:
            if attrs[0]['out_dtype'] == 2:
                return False

        return True