From c4bcdb5f29c8017479eb0439c519db7d8598ff4c Mon Sep 17 00:00:00 2001 From: nicologhielmetti Date: Fri, 8 Nov 2024 09:49:37 +0100 Subject: [PATCH 1/3] Added transformation to remove successive and identical Quant nodes in the graph --- src/qonnx/transformation/remove.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/qonnx/transformation/remove.py b/src/qonnx/transformation/remove.py index 0f7f38f7..3bc09495 100644 --- a/src/qonnx/transformation/remove.py +++ b/src/qonnx/transformation/remove.py @@ -144,3 +144,17 @@ def apply(self, model): break model = model.transform(InferShapes()) return (model, graph_modified) + +class RemoveSuccessiveIdenticalQuant(Transformation): + def apply(self, model): + graph = model.graph + graph_modified = False + for n in graph.node: + if n.op_type == "Quant": + successors = model.find_direct_successors(n) + if successors is not None and len(successors) == 1 and successors[0].op_type == "Quant": + init_node = [model.get_initializer(i) for i in n.input] + init_succ = [model.get_initializer(i) for i in successors[0].input] + if init_node == init_succ: + remove_node_and_rewire(model, n) + return (model, graph_modified) \ No newline at end of file From cd69110694b5fdb0d703060e63630b7e0ef1f9f9 Mon Sep 17 00:00:00 2001 From: nicologhielmetti Date: Fri, 8 Nov 2024 09:52:59 +0100 Subject: [PATCH 2/3] Aesthetic fix --- src/qonnx/transformation/remove.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/qonnx/transformation/remove.py b/src/qonnx/transformation/remove.py index 3bc09495..b6a57be6 100644 --- a/src/qonnx/transformation/remove.py +++ b/src/qonnx/transformation/remove.py @@ -157,4 +157,5 @@ def apply(self, model): init_succ = [model.get_initializer(i) for i in successors[0].input] if init_node == init_succ: remove_node_and_rewire(model, n) - return (model, graph_modified) \ No newline at end of file + return (model, graph_modified) + \ No newline at end of file From 7747a6da70c0940169e5f144e5f47a5d9efcba25 Mon Sep 17 00:00:00 2001 From: nicologhielmetti Date: Fri, 8 Nov 2024 10:02:40 +0100 Subject: [PATCH 3/3] Aesthetic fix --- src/qonnx/transformation/remove.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qonnx/transformation/remove.py b/src/qonnx/transformation/remove.py index b6a57be6..22dbd6eb 100644 --- a/src/qonnx/transformation/remove.py +++ b/src/qonnx/transformation/remove.py @@ -145,6 +145,7 @@ def apply(self, model): model = model.transform(InferShapes()) return (model, graph_modified) + class RemoveSuccessiveIdenticalQuant(Transformation): def apply(self, model): graph = model.graph @@ -158,4 +159,3 @@ def apply(self, model): if init_node == init_succ: remove_node_and_rewire(model, n) return (model, graph_modified) - \ No newline at end of file