From 4ce996cae9433b8b146c36936e36ced362576105 Mon Sep 17 00:00:00 2001 From: Liangfu Chen Date: Tue, 19 Mar 2019 16:36:44 +0800 Subject: [PATCH 1/2] improved `multiply_rewrite` for gluoncv_ssd quantization --- python/tvm/relay/quantize/_annotate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/tvm/relay/quantize/_annotate.py b/python/tvm/relay/quantize/_annotate.py index c75746812ecc..40c9a967ce83 100644 --- a/python/tvm/relay/quantize/_annotate.py +++ b/python/tvm/relay/quantize/_annotate.py @@ -166,7 +166,7 @@ def multiply_rewrite(ref_call, new_args, ctx): if lhs_kind is None and rhs_kind is None: return None - if lhs_kind == QAnnotateKind.ACTIVATION and rhs_kind is None: + if lhs_kind in [QAnnotateKind.ACTIVATION, QAnnotateKind.INPUT] and rhs_kind is None: # quantize lhs to INPUT field lhs_expr = attach_simulated_quantize(lhs_expr, QAnnotateKind.INPUT) # quantize rhs to WEIGHT field From 486ad4ffb801ecef210dbb0c6b1bef8e66d3392a Mon Sep 17 00:00:00 2001 From: Liangfu Chen Date: Wed, 20 Mar 2019 15:34:06 +0800 Subject: [PATCH 2/2] add a check to attach_simulated_quantize below to prevent quantizing lhs to INPUT if lhs_kind is INPUT; --- python/tvm/relay/quantize/_annotate.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/tvm/relay/quantize/_annotate.py b/python/tvm/relay/quantize/_annotate.py index 40c9a967ce83..08d56a3ca23f 100644 --- a/python/tvm/relay/quantize/_annotate.py +++ b/python/tvm/relay/quantize/_annotate.py @@ -168,7 +168,8 @@ def multiply_rewrite(ref_call, new_args, ctx): return None if lhs_kind in [QAnnotateKind.ACTIVATION, QAnnotateKind.INPUT] and rhs_kind is None: # quantize lhs to INPUT field - lhs_expr = attach_simulated_quantize(lhs_expr, QAnnotateKind.INPUT) + if lhs_kind == QAnnotateKind.ACTIVATION: + lhs_expr = attach_simulated_quantize(lhs_expr, QAnnotateKind.INPUT) # quantize rhs to WEIGHT field rhs_expr = attach_simulated_quantize(rhs_expr, QAnnotateKind.WEIGHT) expr = _forward_op(ref_call, [lhs_expr, rhs_expr])