Skip to content

Commit

Permalink
fix reduce operators consisting of reduce_sum.
Browse files Browse the repository at this point in the history
fix #1193
  • Loading branch information
curioyang committed May 10, 2024
1 parent 7756e29 commit bfab312
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Nncase.Importer/Onnx/Reduce.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ private Expr VisitReduce(in NodeProto op, ReduceOp reduceOp, Expr initValue)
return ReduceCore(op, reduceOp, initValue, expr => expr);
}

private Expr ReduceCore(in NodeProto op, ReduceOp reduceOp, Expr initValue, Func<Expr, Expr> f)
private Expr ReduceCore(in NodeProto op, ReduceOp reduceOp, Expr initValue, Func<Expr, Expr> f, long opVersion = 999)
{
var input = GetInputExpr(op, 0);
Expr axis;
if ((reduceOp == ReduceOp.Sum && GetOpSet(op) < 13) || GetOpSet(op) < 18)

if ((reduceOp == ReduceOp.Sum && opVersion < 13) || (reduceOp != ReduceOp.Sum && GetOpSet(op) < 18))
{
axis = GetAxesAttribute(op, input);
}
Expand Down Expand Up @@ -63,7 +64,9 @@ private Expr ReduceCore(in NodeProto op, ReduceOp reduceOp, Expr initValue, Func

private Expr ReduceSumZero(in NodeProto op, Func<Expr, Expr> f)
{
return ReduceCore(op, ReduceOp.Sum, 0f, f);
// Reduce_sum opVersion 13 == other reduce opVersion 18. Axis is not Attributes.
// If GetOpSet(op) > 13, use reduce_sum opVersion 11. Axis is Attributes.
return ReduceCore(op, ReduceOp.Sum, 0f, f, GetOpSet(op) >= 18 ? 13 : 11);
}

private Expr VisitReduceL1(in NodeProto op)
Expand Down

0 comments on commit bfab312

Please sign in to comment.