test_imperative_qat_channelwise.py 1.7 KB
Newer Older
1
#   copyright (c) 2022 paddlepaddle authors. all rights reserved.
H
huangxu96 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#
# 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 os
import unittest
17 18

from test_imperative_qat import TestImperativeQat
H
huangxu96 已提交
19

20 21 22
import paddle
from paddle.framework import core, set_flags

P
pangyoki 已提交
23 24
paddle.enable_static()

H
huangxu96 已提交
25 26
os.environ["CPU_NUM"] = "1"
if core.is_compiled_with_cuda():
27
    set_flags({"FLAGS_cudnn_deterministic": True})
H
huangxu96 已提交
28 29


30 31 32 33
class TestImperativeQatChannelWise(TestImperativeQat):
    def set_vars(self):
        self.weight_quantize_type = 'channel_wise_abs_max'
        self.activation_quantize_type = 'moving_average_abs_max'
34
        self.diff_threshold = 0.03125
35
        self.onnx_format = False
36
        self.fuse_conv_bn = False
37 38 39 40 41 42 43 44
        print('weight_quantize_type', self.weight_quantize_type)


class TestImperativeQatChannelWiseONNXFormat(TestImperativeQat):
    def set_vars(self):
        self.weight_quantize_type = 'channel_wise_abs_max'
        self.activation_quantize_type = 'moving_average_abs_max'
        self.onnx_format = True
45
        self.diff_threshold = 0.03125
46
        self.fuse_conv_bn = False
47
        print('weight_quantize_type', self.weight_quantize_type)
H
huangxu96 已提交
48 49 50 51


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