Unverified Commit 69d8d789 authored by Umang Yadav's avatar Umang Yadav Committed by GitHub
Browse files

Add options to set tolerances inside MIGraphX driver (#2213)

MIGraphX verification by default uses normalized RMS error as the basis for the verification.  This change adds some logic to allow migraphx to do "np.allclose" type of elementwise verification using atol and rtol.

Commit also includes changes to consistently pass "gold" or "expected" results as the second argument for "verify_range()" calls.  Default RMS tolerance inside driver is set to 0.001 which IMO is high for FP32 compared to what we had earlier. Need better defaults
parent e12032fb
...@@ -68,7 +68,7 @@ TEST_CASE(eval_run_on_target) ...@@ -68,7 +68,7 @@ TEST_CASE(eval_run_on_target)
std::vector<float> results_vector(3); std::vector<float> results_vector(3);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); }); result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {0.5, 0.25, 0.125}; std::vector<float> gold = {0.5, 0.25, 0.125};
EXPECT(migraphx::verify::verify_range(results_vector, gold)); EXPECT(migraphx::verify::verify_rms_range(results_vector, gold));
} }
int main(int argc, const char* argv[]) { test::run(argc, argv); } int main(int argc, const char* argv[]) { test::run(argc, argv); }
...@@ -956,13 +956,13 @@ TEST_CASE(test_with_type) ...@@ -956,13 +956,13 @@ TEST_CASE(test_with_type)
TEST_CASE(test_multi_index) TEST_CASE(test_multi_index)
{ {
migraphx::shape s{migraphx::shape::float_type, {2, 4, 6}}; migraphx::shape s{migraphx::shape::float_type, {2, 4, 6}};
EXPECT(migraphx::verify::verify_range(s.multi(0), std::vector<size_t>{0, 0, 0})); EXPECT(migraphx::verify::verify_rms_range(s.multi(0), std::vector<size_t>{0, 0, 0}));
EXPECT(migraphx::verify::verify_range(s.multi(4), std::vector<size_t>{0, 0, 4})); EXPECT(migraphx::verify::verify_rms_range(s.multi(4), std::vector<size_t>{0, 0, 4}));
EXPECT(migraphx::verify::verify_range(s.multi(6), std::vector<size_t>{0, 1, 0})); EXPECT(migraphx::verify::verify_rms_range(s.multi(6), std::vector<size_t>{0, 1, 0}));
EXPECT(migraphx::verify::verify_range(s.multi(8), std::vector<size_t>{0, 1, 2})); EXPECT(migraphx::verify::verify_rms_range(s.multi(8), std::vector<size_t>{0, 1, 2}));
EXPECT(migraphx::verify::verify_range(s.multi(24), std::vector<size_t>{1, 0, 0})); EXPECT(migraphx::verify::verify_rms_range(s.multi(24), std::vector<size_t>{1, 0, 0}));
EXPECT(migraphx::verify::verify_range(s.multi(30), std::vector<size_t>{1, 1, 0})); EXPECT(migraphx::verify::verify_rms_range(s.multi(30), std::vector<size_t>{1, 1, 0}));
EXPECT(migraphx::verify::verify_range(s.multi(34), std::vector<size_t>{1, 1, 4})); EXPECT(migraphx::verify::verify_rms_range(s.multi(34), std::vector<size_t>{1, 1, 4}));
} }
TEST_CASE(find_permutation_2d_standard) TEST_CASE(find_permutation_2d_standard)
......
...@@ -479,11 +479,11 @@ TEST_CASE(conv_pooling_dot) ...@@ -479,11 +479,11 @@ TEST_CASE(conv_pooling_dot)
auto q1 = add_quantize_op(m1, "quantizelinear", input, scale, zero); auto q1 = add_quantize_op(m1, "quantizelinear", input, scale, zero);
auto d5 = add_quantize_op(m1, "dequantizelinear", q1, scale, zero); auto d5 = add_quantize_op(m1, "dequantizelinear", q1, scale, zero);
auto c1 = m1.add_instruction(migraphx::make_op("convolution", auto c1 = m1.add_instruction(migraphx::make_op("convolution",
{{"padding", {0, 0, 0, 0}}, {{"padding", {0, 0, 0, 0}},
{"stride", {1, 1}}, {"stride", {1, 1}},
{"dilation", {1, 1}}, {"dilation", {1, 1}},
{"group", 1}, {"group", 1},
{"padding_mode", 0}}), {"padding_mode", 0}}),
d5, d5,
d1); d1);
auto bc1 = m1.add_instruction( auto bc1 = m1.add_instruction(
...@@ -526,11 +526,11 @@ TEST_CASE(conv_pooling_dot) ...@@ -526,11 +526,11 @@ TEST_CASE(conv_pooling_dot)
auto d3 = add_quantize_op(m2, "dequantizelinear", ab, scale, zero); auto d3 = add_quantize_op(m2, "dequantizelinear", ab, scale, zero);
auto q1 = add_quantize_op(m2, "quantizelinear", input, scale, zero); auto q1 = add_quantize_op(m2, "quantizelinear", input, scale, zero);
auto c1 = m2.add_instruction(migraphx::make_op("quant_convolution", auto c1 = m2.add_instruction(migraphx::make_op("quant_convolution",
{{"padding", {0, 0, 0, 0}}, {{"padding", {0, 0, 0, 0}},
{"stride", {1, 1}}, {"stride", {1, 1}},
{"dilation", {1, 1}}, {"dilation", {1, 1}},
{"group", 1}, {"group", 1},
{"padding_mode", 0}}), {"padding_mode", 0}}),
q1, q1,
weights); weights);
auto d5 = add_quantize_op(m2, "dequantizelinear", c1, scale1); auto d5 = add_quantize_op(m2, "dequantizelinear", c1, scale1);
...@@ -585,11 +585,11 @@ TEST_CASE(mobilenet_snippet) ...@@ -585,11 +585,11 @@ TEST_CASE(mobilenet_snippet)
auto q1 = add_quantize_op(mm, "quantizelinear", input, scale, zero); auto q1 = add_quantize_op(mm, "quantizelinear", input, scale, zero);
auto d5 = add_quantize_op(mm, "dequantizelinear", q1, scale, zero); auto d5 = add_quantize_op(mm, "dequantizelinear", q1, scale, zero);
auto c1 = mm.add_instruction(migraphx::make_op("convolution", auto c1 = mm.add_instruction(migraphx::make_op("convolution",
{{"padding", {0, 0, 0, 0}}, {{"padding", {0, 0, 0, 0}},
{"stride", {1, 1}}, {"stride", {1, 1}},
{"dilation", {1, 1}}, {"dilation", {1, 1}},
{"group", 1}, {"group", 1},
{"padding_mode", 0}}), {"padding_mode", 0}}),
d5, d5,
d1); d1);
auto bc1 = mm.add_instruction( auto bc1 = mm.add_instruction(
...@@ -700,7 +700,7 @@ TEST_CASE(conv_correctness) ...@@ -700,7 +700,7 @@ TEST_CASE(conv_correctness)
auto result2 = p2.eval({{"input", input}, {"weights", weights}}).back(); auto result2 = p2.eval({{"input", input}, {"weights", weights}}).back();
std::vector<float> rv2(16); std::vector<float> rv2(16);
result2.visit([&](auto output) { rv2.assign(output.begin(), output.end()); }); result2.visit([&](auto output) { rv2.assign(output.begin(), output.end()); });
EXPECT(migraphx::verify::verify_range(rv1, rv2)); EXPECT(migraphx::verify::verify_rms_range(rv1, rv2));
} }
TEST_CASE(dot_correctness) TEST_CASE(dot_correctness)
...@@ -750,7 +750,7 @@ TEST_CASE(dot_correctness) ...@@ -750,7 +750,7 @@ TEST_CASE(dot_correctness)
auto result2 = p2.eval({{"a", a}, {"b", b}}).back(); auto result2 = p2.eval({{"a", a}, {"b", b}}).back();
std::vector<float> rv2(sh3.elements()); std::vector<float> rv2(sh3.elements());
result2.visit([&](auto output) { rv2.assign(output.begin(), output.end()); }); result2.visit([&](auto output) { rv2.assign(output.begin(), output.end()); });
EXPECT(migraphx::verify::verify_range(rv1, rv2)); EXPECT(migraphx::verify::verify_rms_range(rv1, rv2));
} }
int main(int argc, const char* argv[]) { test::run(argc, argv); } int main(int argc, const char* argv[]) { test::run(argc, argv); }
...@@ -251,7 +251,8 @@ void run_verify::verify(const std::string& name, ...@@ -251,7 +251,8 @@ void run_verify::verify(const std::string& name,
std::size_t num = gold.size(); std::size_t num = gold.size();
for(std::size_t i = 0; ((i < num) and passed); ++i) for(std::size_t i = 0; ((i < num) and passed); ++i)
{ {
passed &= migraphx::verify_args(tname, gold[i], result[i]); passed &= migraphx::verify_args_with_tolerance(
tname, result[i], migraphx::verify::expected{gold[i]});
} }
if(not passed or migraphx::enabled(MIGRAPHX_TRACE_TEST{})) if(not passed or migraphx::enabled(MIGRAPHX_TRACE_TEST{}))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment