Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix reduce sum opset condition #1203

Merged
merged 3 commits into from
May 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 (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
Loading