From 3c7a1df83aeb8d1d61cfe6c52a767eaf58f2b39e Mon Sep 17 00:00:00 2001 From: Feiyue Chen Date: Tue, 9 Jan 2024 08:35:54 +0000 Subject: [PATCH] Fixed layout infer bug when some op is not in op_vector_ Backgroud: instance_norm models run crash after latest lay out code refine Reason: erase() function will delete the last element if the param is vector.end() Solution: Check iterator validtion before erase. Type: Bug Fix Issue: 37449 Signed-off-by: Feiyue Chen --- src/tim/transform/mean_stddev_normalize_fusion.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tim/transform/mean_stddev_normalize_fusion.cc b/src/tim/transform/mean_stddev_normalize_fusion.cc index eeb55dff3..3227a3408 100644 --- a/src/tim/transform/mean_stddev_normalize_fusion.cc +++ b/src/tim/transform/mean_stddev_normalize_fusion.cc @@ -109,12 +109,14 @@ void RemoveTensorsAndOps( std::shared_ptr& graph, const std::vector>& norm_ops) { for (uint32_t i = 0; i < norm_ops.size(); i++) { - auto it = + auto it = std::remove_if(graph->OpVector().begin(), graph->OpVector().end(), [norm_ops, i](std::shared_ptr oper) { return oper == norm_ops[i]; }); - graph->OpVector().erase(it); //Remove current op from op_vector_ + if (it != graph->OpVector().end()) { + graph->OpVector().erase(it); + } // Remove current op from op_vector_ auto input_tensors = norm_ops[i]->impl()->InputsTensor(); auto output_tensors = norm_ops[i]->impl()->OutputsTensor();