From be1e51af2aa458c08dd41d0e4172fd3d3852e821 Mon Sep 17 00:00:00 2001 From: Kaz Nishimura Date: Sat, 7 Oct 2023 04:06:13 +0900 Subject: [PATCH] Add length checks to fusion_transpose.py (#17608) This change adds list length checks to node's inputs in fusion_transpose.py. It bypasses the optimization if not applicable. ### Motivation and Context Unsqueeze in opset (<13) has only one input and cause runtime exceptions. --- onnxruntime/python/tools/transformers/fusion_transpose.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/onnxruntime/python/tools/transformers/fusion_transpose.py b/onnxruntime/python/tools/transformers/fusion_transpose.py index 2762d95dd7..ca699903a7 100644 --- a/onnxruntime/python/tools/transformers/fusion_transpose.py +++ b/onnxruntime/python/tools/transformers/fusion_transpose.py @@ -128,7 +128,9 @@ class FusionInsertTranspose(Fusion): return if not ( - self.model.get_constant_value(unsqueeze_3.input[1]) == 3 + len(unsqueeze_3.input) == 2 + and self.model.get_constant_value(unsqueeze_3.input[1]) == 3 + and len(unsqueeze_2.input) == 2 and self.model.get_constant_value(unsqueeze_2.input[1]) == 2 and len(self.model.get_children(gemm, input_name_to_nodes)) == 1 and len(self.model.get_children(unsqueeze_3, input_name_to_nodes)) == 1