aboutsummaryrefslogtreecommitdiff
path: root/ethosu/vela/tflite_graph_optimiser.py
diff options
context:
space:
mode:
authorJohan Gunnarsson <johan.gunnarsson@arm.com>2023-08-10 13:10:44 +0200
committerJohan Gunnarsson <johan.gunnarsson@arm.com>2023-08-29 16:54:41 +0200
commit985563791a811e1ea3b5137f97e5a5fc4dafd4b1 (patch)
treecd1d9a41c9e194e9fcd1fe9ee090d8ef07a640a9 /ethosu/vela/tflite_graph_optimiser.py
parentc02eaa3e25840aee4ff909df263d4d0673227c5d (diff)
downloadethos-u-vela-985563791a811e1ea3b5137f97e5a5fc4dafd4b1.tar.gz
MLBEDSW-7881: Convert Quantize op to Avgpool op in graph optimiser
This convert is already done in the pass packing stage, but doing it in the graph optimiser stage is better. Change-Id: Ib9baa98d115cf88491ce39936972a93467a378ce Signed-off-by: Johan Gunnarsson <johan.gunnarsson@arm.com>
Diffstat (limited to 'ethosu/vela/tflite_graph_optimiser.py')
-rw-r--r--ethosu/vela/tflite_graph_optimiser.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/ethosu/vela/tflite_graph_optimiser.py b/ethosu/vela/tflite_graph_optimiser.py
index ef6b90b5..218f499a 100644
--- a/ethosu/vela/tflite_graph_optimiser.py
+++ b/ethosu/vela/tflite_graph_optimiser.py
@@ -1685,6 +1685,21 @@ def convert_tanh_sigmoid_to_lut(op: Operation, arch, nng) -> Operation:
return op
+def convert_quantize(op: Operation, arch, nng) -> Operation:
+ """Convert Quantize to Avgpool. This conversion only works for int-to-int re-quantization and
+ not to/from floats. Therefor, this rewrite should only run after the supported ops check to
+ avoid rewriting ops that will run on CPU."""
+ if op.type == Op.Quantize:
+ # Create a new AvgPool op and steal its attrs, then reuse the original op with different type
+ avgpool_op = create_avgpool_nop(op.name + "_avgpool")
+ op.type = Op.AvgPool
+ op.attrs = avgpool_op.attrs.copy()
+
+ DebugDatabase.add_optimised(op, op)
+
+ return op
+
+
def fuse_activation_function_with_prev(op, arch, nng):
# if op is a no-op: attempts to move the activation function to the preceding op
if not op.attrs.get("is_nop", False) or op.activation is None:
@@ -2645,6 +2660,7 @@ def tflite_optimise_graph(nng, arch, force_symmetric_int_weights):
fixup_bias_tensors,
fixup_asymmetric_weights,
convert_tanh_sigmoid_to_lut,
+ convert_quantize,
replace_pad_by_hw_pad,
fixup_dilation_gt2,
]