From 6eb2530643435a1bbb1dcab1a2daca5364d3426b Mon Sep 17 00:00:00 2001 From: Joshua Lochner Date: Wed, 19 Jun 2024 14:35:05 +0200 Subject: [PATCH 1/2] Update optimizer.py --- onnxslim/core/optimizer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxslim/core/optimizer.py b/onnxslim/core/optimizer.py index 25fbf9b..5070782 100644 --- a/onnxslim/core/optimizer.py +++ b/onnxslim/core/optimizer.py @@ -157,8 +157,8 @@ def graph_constant_fold_inplace(graph): delete_node(node, idx) logger.debug(f"removing Add op: {node.name}") elif node.op == "Expand": - idx, constant_variable = get_constant_variable(node, return_idx=True) if len(node.inputs) > 1 and isinstance(node.inputs[1], Constant) and np.all(node.inputs[1].values == 1): + idx, constant_variable = get_constant_variable(node, return_idx=True) idx = 0 if idx == 1 else 1 delete_node(node, idx) logger.debug(f"removing Expand op: {node.name}") From 92245d5f680ce903cd1338b4c8d8c8d7065b32a2 Mon Sep 17 00:00:00 2001 From: inisis Date: Wed, 19 Jun 2024 13:26:28 +0000 Subject: [PATCH 2/2] simplify code --- onnxslim/core/optimizer.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/onnxslim/core/optimizer.py b/onnxslim/core/optimizer.py index 5070782..f511059 100644 --- a/onnxslim/core/optimizer.py +++ b/onnxslim/core/optimizer.py @@ -158,9 +158,7 @@ def graph_constant_fold_inplace(graph): logger.debug(f"removing Add op: {node.name}") elif node.op == "Expand": if len(node.inputs) > 1 and isinstance(node.inputs[1], Constant) and np.all(node.inputs[1].values == 1): - idx, constant_variable = get_constant_variable(node, return_idx=True) - idx = 0 if idx == 1 else 1 - delete_node(node, idx) + delete_node(node) logger.debug(f"removing Expand op: {node.name}") elif node.op == "Concat": if len(node.inputs) == 1: