[Relay] Improved `multiply_rewrite` for gluoncv_ssd quantization (#2848)
authorLiangfu Chen <liangfu.chen@icloud.com>
Wed, 20 Mar 2019 17:02:10 +0000 (01:02 +0800)
committerTianqi Chen <tqchen@users.noreply.github.com>
Wed, 20 Mar 2019 17:02:10 +0000 (10:02 -0700)
* improved `multiply_rewrite` for gluoncv_ssd quantization

* 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

index c757468..08d56a3 100644 (file)
@@ -166,9 +166,10 @@ 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)
+        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])