From ad28f8afd9cde6f22b8fb33c8a15154fb415629f Mon Sep 17 00:00:00 2001 From: Wanming Lin Date: Mon, 2 Sep 2024 16:20:11 +0800 Subject: [PATCH 1/2] Fixed a minor bug in layout transformation for Resize Since opset 18, 'scales' and 'sizes' constant inputs can be 2D tensors, transpose for 2D tensors are not supported at current implementation, fix it by only allowing 4D constant inputs. --- .../layout_transformation/layout_transformation.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/onnxruntime/core/optimizer/layout_transformation/layout_transformation.cc b/onnxruntime/core/optimizer/layout_transformation/layout_transformation.cc index 7953cde6686c0..38e60f656a9a8 100644 --- a/onnxruntime/core/optimizer/layout_transformation/layout_transformation.cc +++ b/onnxruntime/core/optimizer/layout_transformation/layout_transformation.cc @@ -177,7 +177,11 @@ Status TransformLayoutForEP(Graph& graph, bool& modified, const IExecutionProvid for (size_t i = 2; i < node->Inputs().size(); i++) { auto constant = api_graph->GetConstant(node->Inputs()[i]); if (constant != nullptr && constant->Data().size() > 0) { - input_perms.push_back(&input_perm); + // Starting from opset version 18, 'scales' and 'sizes' can be 2D tensors. + // However, our current implementation only supports the transposition of 4D tensors. + if (constant->NumElements() == 4) { + input_perms.push_back(&input_perm); + } } else { // TODO: Fix inconsistency. We should Transpose the non-const inputs so that the result of our changes // is consistent - all layout specific inputs are in NHWC format when we're done. From 22d05c4f0510a6723d66cf383e4f5407bc80a60e Mon Sep 17 00:00:00 2001 From: Wanming Lin Date: Wed, 23 Oct 2024 13:37:58 +0800 Subject: [PATCH 2/2] Improve the comment --- .../optimizer/layout_transformation/layout_transformation.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxruntime/core/optimizer/layout_transformation/layout_transformation.cc b/onnxruntime/core/optimizer/layout_transformation/layout_transformation.cc index 38e60f656a9a8..56f7d28cd5b77 100644 --- a/onnxruntime/core/optimizer/layout_transformation/layout_transformation.cc +++ b/onnxruntime/core/optimizer/layout_transformation/layout_transformation.cc @@ -177,7 +177,7 @@ Status TransformLayoutForEP(Graph& graph, bool& modified, const IExecutionProvid for (size_t i = 2; i < node->Inputs().size(); i++) { auto constant = api_graph->GetConstant(node->Inputs()[i]); if (constant != nullptr && constant->Data().size() > 0) { - // Starting from opset version 18, 'scales' and 'sizes' can be 2D tensors. + // Starting from opset version 18, the 'scales' and 'sizes' can be any length up to the input rank. // However, our current implementation only supports the transposition of 4D tensors. if (constant->NumElements() == 4) { input_perms.push_back(&input_perm);