From a56e325eb823ac6ffc9406b7608159fa29d5686e Mon Sep 17 00:00:00 2001 From: mindest <30493312+mindest@users.noreply.github.com> Date: Sat, 7 Aug 2021 18:29:06 +0800 Subject: [PATCH] constrain inputs for min/max grad UT (#8632) * fix inputs for min/max grad UT * use random inputs (truncated) --- .../test/gradient/gradient_ops_test.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/orttraining/orttraining/test/gradient/gradient_ops_test.cc b/orttraining/orttraining/test/gradient/gradient_ops_test.cc index 29b18dbfef..37ba6d5dec 100644 --- a/orttraining/orttraining/test/gradient/gradient_ops_test.cc +++ b/orttraining/orttraining/test/gradient/gradient_ops_test.cc @@ -2494,27 +2494,27 @@ void GradientCheckerMinMaxGradHelper(const std::string op) { float max_error; GradientChecker gradient_checker; OpDef op_def{op, kOnnxDomain, 11}; + // Ensure the gap between x1 and x2 is greater than 1e-3f, otherwise the result of NumericJacobian + // will be incorrect. This also excludes equal inputs case, where Min/Max is not smooth. + std::function x1_transformer = [](float x) { return (int)(x * 100) / 100.f; }; + std::function x2_transformer = [](float x) { return (int)(x * 100) / 100.f + 0.002f; }; + TensorInfo x1_info({2, 3}, true, &x1_transformer); + TensorInfo y_info({2, 3}, true); - // Exclude equal inputs, since Min/Max is not smooth in such case { TensorInfo x_info({2, 3}, true); - TensorInfo y_info({2, 3}, true); gradient_checker.ComputeGradientError(op_def, {x_info}, {y_info}, &max_error); EXPECT_IS_TINY(max_error); } { - TensorInfo x1_info({2, 3}, true); - TensorInfo x2_info({2, 3}, true); - TensorInfo y_info({2, 3}, true); + TensorInfo x2_info({2, 3}, true, &x2_transformer); gradient_checker.ComputeGradientError(op_def, {x1_info, x2_info}, {y_info}, &max_error); EXPECT_IS_TINY(max_error); } { - TensorInfo x1_info({2, 3}, true); - TensorInfo x2_info({3}, true); - TensorInfo y_info({2, 3}, true); + TensorInfo x2_info({3}, true, &x2_transformer); gradient_checker.ComputeGradientError(op_def, {x1_info, x2_info}, {y_info}, &max_error); EXPECT_IS_TINY(max_error); }