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

GNNE-1714:add norm op name #1127

Merged
merged 3 commits into from
Nov 15, 2023
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
25 changes: 19 additions & 6 deletions src/Nncase.Passes/Rules/Neutral/AddPreProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,26 @@
// Normalization
if (mean.Length != 0)
{
newInput = mean.Length switch
Expr meanCall;
Expr stdCall;
switch (mean.Length)
{
3 when inputShape.Length == 4 => (newInput - Tensor.From(mean, new[] { 1, mean.Length, 1, 1 })) /
Tensor.From(std, new[] { 1, std.Length, 1, 1 }),
_ => (newInput - Tensor.From(new float[] { mean[0] }, new[] { 1 })) /
Tensor.From(new float[] { std[0] }, new[] { 1 }),
};
case 3 when inputShape.Length == 4:
meanCall = (Expr)Tensor.From(mean, new[] { 1, mean.Length, 1, 1 });
stdCall = (Expr)Tensor.From(std, new[] { 1, std.Length, 1, 1 });
break;

Check warning on line 185 in src/Nncase.Passes/Rules/Neutral/AddPreProcess.cs

View check run for this annotation

Codecov / codecov/patch

src/Nncase.Passes/Rules/Neutral/AddPreProcess.cs#L183-L185

Added lines #L183 - L185 were not covered by tests

default:
meanCall = (Expr)Tensor.From(new float[] { mean[0] }, new[] { 1 });
stdCall = (Expr)Tensor.From(new float[] { std[0] }, new[] { 1 });

Check warning on line 189 in src/Nncase.Passes/Rules/Neutral/AddPreProcess.cs

View check run for this annotation

Codecov / codecov/patch

src/Nncase.Passes/Rules/Neutral/AddPreProcess.cs#L188-L189

Added lines #L188 - L189 were not covered by tests
break;
}

meanCall.Metadata.OutputNames = new[] { "Mean" };
stdCall.Metadata.OutputNames = new[] { "Std" };

Check warning on line 194 in src/Nncase.Passes/Rules/Neutral/AddPreProcess.cs

View check run for this annotation

Codecov / codecov/patch

src/Nncase.Passes/Rules/Neutral/AddPreProcess.cs#L193-L194

Added lines #L193 - L194 were not covered by tests
var subMean = (newInput - meanCall).With(metadata: new IRMetadata() { OutputNames = new[] { input.Metadata.OutputNames?[0] + "_SubMean" } });
var divStd = (subMean / stdCall).With(metadata: new IRMetadata() { OutputNames = new[] { input.Metadata.OutputNames?[0] + "_DivStd" } });
newInput = divStd;

Check warning on line 197 in src/Nncase.Passes/Rules/Neutral/AddPreProcess.cs

View check run for this annotation

Codecov / codecov/patch

src/Nncase.Passes/Rules/Neutral/AddPreProcess.cs#L197

Added line #L197 was not covered by tests

// newInput = Binary(BinaryOp.Div, Binary(BinaryOp.Sub, newInput, Tensor.From(mean, new []{1,3,1,1})), Const.FromTensor(std) );
}
Expand Down
Loading