未验证 提交 bd4ce23e 编写于 作者: L Leo Chen 提交者: GitHub

Increase the threshold of softmax and imperative qat UT (#45819)

上级 36046a89
...@@ -56,7 +56,10 @@ class TestImperativeQat(unittest.TestCase): ...@@ -56,7 +56,10 @@ class TestImperativeQat(unittest.TestCase):
self.activation_quantize_type = 'moving_average_abs_max' self.activation_quantize_type = 'moving_average_abs_max'
self.onnx_format = False self.onnx_format = False
self.check_export_model_accuracy = True self.check_export_model_accuracy = True
self.diff_threshold = 0.01 # The original model and quantized model may have different prediction.
# There are 32 test data and we allow at most one is different.
# Hence, the diff_threshold is 1 / 32 = 0.03125
self.diff_threshold = 0.03125
self.fuse_conv_bn = False self.fuse_conv_bn = False
def func_qat(self): def func_qat(self):
...@@ -207,7 +210,7 @@ class TestImperativeQat(unittest.TestCase): ...@@ -207,7 +210,7 @@ class TestImperativeQat(unittest.TestCase):
quant_acc = fluid.layers.accuracy(quant_out, label).numpy() quant_acc = fluid.layers.accuracy(quant_out, label).numpy()
paddle.enable_static() paddle.enable_static()
delta_value = fp32_acc - quant_acc delta_value = fp32_acc - quant_acc
self.assertLess(delta_value, self.diff_threshold) self.assertLessEqual(delta_value, self.diff_threshold)
def test_qat(self): def test_qat(self):
with _test_eager_guard(): with _test_eager_guard():
...@@ -221,7 +224,7 @@ class TestImperativeQatONNXFormat(unittest.TestCase): ...@@ -221,7 +224,7 @@ class TestImperativeQatONNXFormat(unittest.TestCase):
self.weight_quantize_type = 'abs_max' self.weight_quantize_type = 'abs_max'
self.activation_quantize_type = 'moving_average_abs_max' self.activation_quantize_type = 'moving_average_abs_max'
self.onnx_format = True self.onnx_format = True
self.diff_threshold = 0.025 self.diff_threshold = 0.03125
self.fuse_conv_bn = False self.fuse_conv_bn = False
......
...@@ -43,7 +43,7 @@ class TestImperativeQatChannelWise(TestImperativeQat): ...@@ -43,7 +43,7 @@ class TestImperativeQatChannelWise(TestImperativeQat):
def set_vars(self): def set_vars(self):
self.weight_quantize_type = 'channel_wise_abs_max' self.weight_quantize_type = 'channel_wise_abs_max'
self.activation_quantize_type = 'moving_average_abs_max' self.activation_quantize_type = 'moving_average_abs_max'
self.diff_threshold = 0.01 self.diff_threshold = 0.03125
self.onnx_format = False self.onnx_format = False
self.fuse_conv_bn = False self.fuse_conv_bn = False
print('weight_quantize_type', self.weight_quantize_type) print('weight_quantize_type', self.weight_quantize_type)
...@@ -55,7 +55,7 @@ class TestImperativeQatChannelWiseONNXFormat(TestImperativeQat): ...@@ -55,7 +55,7 @@ class TestImperativeQatChannelWiseONNXFormat(TestImperativeQat):
self.weight_quantize_type = 'channel_wise_abs_max' self.weight_quantize_type = 'channel_wise_abs_max'
self.activation_quantize_type = 'moving_average_abs_max' self.activation_quantize_type = 'moving_average_abs_max'
self.onnx_format = True self.onnx_format = True
self.diff_threshold = 0.025 self.diff_threshold = 0.03125
self.fuse_conv_bn = False self.fuse_conv_bn = False
print('weight_quantize_type', self.weight_quantize_type) print('weight_quantize_type', self.weight_quantize_type)
......
...@@ -43,7 +43,7 @@ class TestImperativeQatfuseBN(TestImperativeQat): ...@@ -43,7 +43,7 @@ class TestImperativeQatfuseBN(TestImperativeQat):
def set_vars(self): def set_vars(self):
self.weight_quantize_type = 'abs_max' self.weight_quantize_type = 'abs_max'
self.activation_quantize_type = 'moving_average_abs_max' self.activation_quantize_type = 'moving_average_abs_max'
self.diff_threshold = 0.01 self.diff_threshold = 0.03125
self.onnx_format = False self.onnx_format = False
self.fuse_conv_bn = True self.fuse_conv_bn = True
......
...@@ -126,7 +126,7 @@ class TrtConvertSoftmaxTest(TrtLayerAutoScanTest): ...@@ -126,7 +126,7 @@ class TrtConvertSoftmaxTest(TrtLayerAutoScanTest):
attrs, False), 1e-5 attrs, False), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num( yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), 1e-5 attrs, False), 1e-3
# for dynamic_shape # for dynamic_shape
generate_dynamic_shape(attrs) generate_dynamic_shape(attrs)
...@@ -135,7 +135,7 @@ class TrtConvertSoftmaxTest(TrtLayerAutoScanTest): ...@@ -135,7 +135,7 @@ class TrtConvertSoftmaxTest(TrtLayerAutoScanTest):
attrs, True), 1e-5 attrs, True), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num( yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), 1e-5 attrs, True), 1e-3
def test(self): def test(self):
self.run_test() self.run_test()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册