test_identity_clean_pass.py 2.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# Copyright (c) 2022 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 unittest
16

17
import hypothesis.strategies as st
18 19 20
from auto_scan_test import PassAutoScanTest
from program_config import OpConfig, ProgramConfig, TensorConfig

21 22 23

class TestIdentityScaleCleanPass(PassAutoScanTest):
    def sample_predictor_configs(self, program_config):
24
        config = self.create_inference_config(use_gpu=True)
25 26 27 28 29 30 31 32 33
        yield config, ['relu'], (1e-5, 1e-5)

    def sample_program_config(self, draw):
        bias_after_scale = draw(st.booleans())
        n = draw(st.integers(min_value=1, max_value=4))
        c = draw(st.integers(min_value=1, max_value=20))
        h = draw(st.integers(min_value=1, max_value=20))
        w = draw(st.integers(min_value=1, max_value=20))

34 35 36 37 38 39 40 41 42 43 44
        relu_op = OpConfig(
            "relu", inputs={"X": ["relu_x"]}, outputs={"Out": ["relu_out"]}
        )
        scale_op = OpConfig(
            "scale",
            inputs={"X": ["relu_out"]},
            outputs={"Out": ["scale_out"]},
            bias=0.0,
            scale=1.0,
            bias_after_scale=True,
        )
45 46 47 48
        program_config = ProgramConfig(
            ops=[relu_op, scale_op],
            weights={},
            inputs={"relu_x": TensorConfig(shape=[n, c, h, w])},
49 50
            outputs=["scale_out"],
        )
51 52 53
        return program_config

    def test(self):
54
        self.run_and_statis(max_examples=25, passes=["identity_op_clean_pass"])
55 56 57 58


if __name__ == "__main__":
    unittest.main()