Skip to content

Commit

Permalink
[fix][relay][qnn] Bug fix for 8-bit quantized mul (#14286)
Browse files Browse the repository at this point in the history
* [fix][relay][qnn] Bug fix for 8-bit quantized mul

* Update _annotate.py

Revert black formatting from my text editor, which I had assumed matched TVM's linter
  • Loading branch information
Wheest authored Mar 14, 2023
1 parent eecc02a commit ccc0b91
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions python/tvm/relay/quantize/_annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ def multiply_rewrite(ref_call, new_args, ctx):
rhs_expr = attach_simulated_quantize(rhs_expr, QAnnotateKind.INPUT)
expr = _forward_op(ref_call, [lhs_expr, rhs_expr])
return QAnnotateExpr(expr, QAnnotateKind.ACTIVATION)
if rhs_kind in [QAnnotateKind.ACTIVATION, QAnnotateKind.INPUT] and lhs_kind is None:
# quantize rhs to INPUT field
if rhs_kind == QAnnotateKind.ACTIVATION:
rhs_expr = attach_simulated_quantize(rhs_expr, QAnnotateKind.INPUT)
if _analysis.check_constant(lhs_expr):
lhs_expr = attach_simulated_quantize(lhs_expr, QAnnotateKind.WEIGHT)
else:
lhs_expr = attach_simulated_quantize(lhs_expr, QAnnotateKind.INPUT)
expr = _forward_op(ref_call, [lhs_expr, rhs_expr])
return QAnnotateExpr(expr, QAnnotateKind.ACTIVATION)

raise ValueError

Expand Down
5 changes: 5 additions & 0 deletions python/tvm/relay/quantize/_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ def mul_partition_generic(ref_call, new_args, ctx):
lhs = new_args[0].realize()
return QPartitionExpr(_forward_op(ref_call, [lhs, rhs]))

if rhs_cond:
# introduced by efficientnet
rhs = new_args[1].realize()
return QPartitionExpr(_forward_op(ref_call, [lhs, rhs]))

if not lhs_cond and not rhs_cond:
# trivial case
return None
Expand Down

0 comments on commit ccc0b91

Please sign in to comment.