Skip to content

Commit

Permalink
Add gradient registration for Abs. (#6139)
Browse files Browse the repository at this point in the history
  • Loading branch information
Derek Murray authored and Sergii Dymchenko committed Dec 16, 2020
1 parent b8c8fe9 commit 279faf1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions orttraining/orttraining/core/graph/gradient_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1506,5 +1506,12 @@ IMPLEMENT_GRADIENT_BUILDER(GetClipGradient) {
return output;
}

IMPLEMENT_GRADIENT_BUILDER(GetAbsGradient) {
return std::vector<NodeDef>{
NodeDef("Sign", {I(0)}, {IA("Sign_Input")}),
NodeDef("Mul", {GO(0), IA("Sign_Input")}, {GI(0)})
};
}

} // namespace training
} // namespace onnxruntime
1 change: 1 addition & 0 deletions orttraining/orttraining/core/graph/gradient_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ DECLARE_GRADIENT_BUILDER(GetExpGradient)
DECLARE_GRADIENT_BUILDER(GetFlattenGradient)
DECLARE_GRADIENT_BUILDER(GetTopKGradient)
DECLARE_GRADIENT_BUILDER(GetClipGradient)
DECLARE_GRADIENT_BUILDER(GetAbsGradient)

} // namespace training
} // namespace onnxruntime
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ void GradientBuilderRegistry::RegisterGradientBuilders() {
REGISTER_GRADIENT_BUILDER("Flatten", GetFlattenGradient);
REGISTER_GRADIENT_BUILDER("TopK", GetTopKGradient);
REGISTER_GRADIENT_BUILDER("Clip", GetClipGradient);
REGISTER_GRADIENT_BUILDER("Abs", GetAbsGradient);
};

} // namespace training
Expand Down
4 changes: 4 additions & 0 deletions orttraining/orttraining/test/gradient/gradient_ops_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,10 @@ TEST(GradientCheckerTest, NegGrad) {
UnaryOpGradientTest("Neg");
}

TEST(GradientCheckerTest, AbsGrad) {
UnaryOpGradientTest("Abs");
}

TEST(GradientCheckerTest, LogGrad) {
TensorShape shape({2, 5, 6});

Expand Down

0 comments on commit 279faf1

Please sign in to comment.