mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-29 20:14:01 +00:00
constrain inputs for min/max grad UT (#8632)
* fix inputs for min/max grad UT * use random inputs (truncated)
This commit is contained in:
parent
1ce4328846
commit
a56e325eb8
1 changed files with 8 additions and 8 deletions
|
|
@ -2494,27 +2494,27 @@ void GradientCheckerMinMaxGradHelper(const std::string op) {
|
|||
float max_error;
|
||||
GradientChecker<float, float, float> 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<float(float)> x1_transformer = [](float x) { return (int)(x * 100) / 100.f; };
|
||||
std::function<float(float)> 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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue