Fixed layout infer bug when some op is not in op_vector_ (#676)

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 <Feiyue.Chen@verisilicon.com>
This commit is contained in:
Chen Feiyue 2024-01-11 15:58:29 +08:00 committed by GitHub
parent 394cedcfe6
commit 0d8ca44377
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -109,12 +109,14 @@ void RemoveTensorsAndOps(
std::shared_ptr<vx::Graph>& graph,
const std::vector<std::shared_ptr<vx::Operation>>& 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<vx::Operation> 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();