예제 #1
0
    def sample_program_configs(self, draw):

        elementwise_type = draw(
            st.sampled_from(
                ["elementwise_add", "elementwise_sub", "elementwise_mul"]))
        in_shape_x = draw(
            st.lists(st.integers(min_value=1, max_value=20),
                     min_size=2,
                     max_size=5))
        in_shape_y = draw(
            st.lists(st.integers(min_value=1, max_value=20),
                     min_size=2,
                     max_size=5))

        axis = draw(
            st.integers(min_value=-1,
                        max_value=max(len(in_shape_x), len(in_shape_y))))

        assume(
            check_input_shape_available(in_shape_x=in_shape_x,
                                        in_shape_y=in_shape_y,
                                        axis=axis) == True)

        elementwise_op = OpConfig(type=elementwise_type,
                                  inputs={
                                      "X": ["input_data_x"],
                                      "Y": ["input_data_y"]
                                  },
                                  outputs={"Out": ["elementwise_output_data"]},
                                  attrs={
                                      "data_format": 'nchw',
                                      "axis": axis
                                  })

        act_type = draw(st.sampled_from(['relu']))

        def generate_act_attrs(act_type_str):
            attrs = {}
            if act_type_str == 'relu':
                attrs = {}
            return attrs

        active_op = OpConfig(type=act_type,
                             inputs={"X": ["elementwise_output_data"]},
                             outputs={"Out": ["output_data"]},
                             attrs=generate_act_attrs(act_type))

        ops = [elementwise_op, active_op]
        self.ops = ops
        program_config = ProgramConfig(ops=ops,
                                       weights={},
                                       inputs={
                                           "input_data_x":
                                           TensorConfig(shape=in_shape_x),
                                           "input_data_y":
                                           TensorConfig(shape=in_shape_y)
                                       },
                                       outputs=["output_data"])
        return program_config
예제 #2
0
    def sample_program_configs(self, draw):
        in_shape_x = draw(
            st.lists(
                st.integers(
                    min_value=1, max_value=20), min_size=2, max_size=5))
        in_shape_y = draw(
            st.lists(
                st.integers(
                    min_value=1, max_value=20), min_size=2, max_size=5))

        axis = draw(
            st.integers(
                min_value=-1, max_value=max(len(in_shape_x), len(in_shape_y))))

        assume(
            check_input_shape_available(
                in_shape_x=in_shape_x, in_shape_y=in_shape_y, axis=axis) ==
            True)

        #scale param
        scale = draw(st.floats(min_value=0.5, max_value=5))
        bias = draw(st.floats(min_value=0, max_value=1))
        bias_after_scale = draw(st.sampled_from([False, True]))

        elementwise_op = OpConfig(
            type='elementwise_mul',
            inputs={"X": ["input_data_x"],
                    "Y": ["input_data_y"]},
            outputs={"Out": ["elementwise_output_data"]},
            attrs={"data_format": 'nchw',
                   "axis": axis})

        scale_op = OpConfig(
            type='scale',
            inputs={"X": ["elementwise_output_data"]},
            outputs={"Out": ["output_data"]},
            attrs={
                "scale": scale,
                "bias": bias,
                "bias_after_scale": bias_after_scale
            })

        ops = [elementwise_op, scale_op]
        program_config = ProgramConfig(
            ops=ops,
            weights={},
            inputs={
                "input_data_x": TensorConfig(shape=in_shape_x),
                "input_data_y": TensorConfig(shape=in_shape_y)
            },
            outputs=["output_data"])
        return program_config
    def sample_program_configs(self, draw):
        in_shape = draw(
            st.lists(st.integers(min_value=1, max_value=20),
                     min_size=2,
                     max_size=5))
        fill_constant_shape = draw(
            st.lists(st.integers(min_value=1, max_value=20),
                     min_size=2,
                     max_size=5))

        axis = draw(
            st.integers(min_value=-1,
                        max_value=max(len(in_shape),
                                      len(fill_constant_shape))))

        out_shape = []
        assume(
            check_input_shape_available(in_shape_x=in_shape,
                                        in_shape_y=fill_constant_shape,
                                        axis=axis,
                                        out_shape=out_shape) == True)
        assume(out_shape == in_shape)

        threshold = draw(st.floats(min_value=0, max_value=1))
        scale = draw(st.floats(min_value=0.5, max_value=5))
        offset = draw(st.floats(min_value=0, max_value=1))

        hard_swish_op0 = OpConfig(type="hard_swish",
                                  inputs={"X": ["input_data"]},
                                  outputs={"Out": ["hard_swish_output_data"]},
                                  attrs={
                                      "threshold": threshold,
                                      "scale": scale,
                                      "offset": offset
                                  })

        fill_constant_op = OpConfig(
            type="fill_constant",
            inputs={},
            outputs={"Out": ["fill_constant_output_data"]},
            attrs={
                "dtype": 5,
                "shape": fill_constant_shape,
                "value": 1.,
                "force_cpu": False,
                "place_type": -1
            })

        elementwise_mul_op = OpConfig(
            type="elementwise_mul",
            inputs={
                "X": ["hard_swish_output_data"],
                "Y": ["fill_constant_output_data"]
            },
            outputs={"Out": ["elementwise_mul_output_data"]},
            attrs={"axis": axis})

        hard_swish_op1 = OpConfig(
            type="hard_swish",
            inputs={"X": ["elementwise_mul_output_data"]},
            outputs={"Out": ["output_data"]},
            attrs={
                "threshold": threshold,
                "scale": scale,
                "offset": offset
            })

        ops = [
            hard_swish_op0, fill_constant_op, elementwise_mul_op,
            hard_swish_op1
        ]
        program_config = ProgramConfig(
            ops=ops,
            weights={},
            inputs={"input_data": TensorConfig(shape=in_shape)},
            outputs=["output_data"])
        return program_config