"git@developer.sourcefind.cn:gaoqiong/migraphx.git" did not exist on "579c925a7113f9eda2dacd8ceec6fa95dcb76dea"
Unverified Commit ca300bd6 authored by Chris Austen's avatar Chris Austen Committed by GitHub
Browse files

Merge branch 'develop' into blas_tuning

parents 5adb597c e7486577
...@@ -538,6 +538,70 @@ TEST_CASE(gemm_half_test) ...@@ -538,6 +538,70 @@ TEST_CASE(gemm_half_test)
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold)); EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
} }
template <typename T = float>
std::vector<T> norm_test(const std::vector<size_t>& x_dims,
std::vector<T>& scale,
std::vector<T>& bias,
const std::string& onnx_file)
{
migraphx::program p = migraphx::parse_onnx(onnx_file);
p.compile(migraphx::make_target("ref"));
migraphx::shape s_x{migraphx::shape::get_type<T>{}, x_dims};
migraphx::shape s_s{migraphx::shape::get_type<T>{}, {scale.size()}};
migraphx::shape s_b{migraphx::shape::get_type<T>{}, {scale.size()}};
std::vector<T> x(s_x.elements());
std::iota(std::begin(x), std::end(x), 1);
migraphx::parameter_map pp;
pp["x"] = migraphx::argument(s_x, x.data());
pp["scale"] = migraphx::argument(s_s, scale.data());
pp["bias"] = migraphx::argument(s_b, bias.data());
auto result = p.eval(pp).back();
std::vector<T> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
return result_vector;
}
TEST_CASE(group_norm_test)
{
std::vector<float> scale{1.2, 0.8};
std::vector<float> bias{0.5, 0.2};
std::vector<float> result_vector =
norm_test<float>({1, 4, 2}, scale, bias, "group_norm_3d_test.onnx");
std::vector<float> gold = {-1.10996256,
-0.0366542,
1.0366542,
2.10996256,
-0.87330837,
-0.15776947,
0.55776947,
1.27330837};
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
TEST_CASE(group_norm_half_test)
{
using migraphx::half;
std::vector<half> scale{half{1.2}, half{0.8}};
std::vector<half> bias{half{0.5}, half{0.2}};
std::vector<half> result_vector =
norm_test<half>({1, 4, 2}, scale, bias, "group_norm_3d_half_test.onnx");
std::vector<half> gold = {half{-1.10996256},
half{-0.0366542},
half{1.0366542},
half{2.10996256},
half{-0.87330837},
half{-0.15776947},
half{0.55776947},
half{1.27330837}};
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
TEST_CASE(greaterorequal_test) TEST_CASE(greaterorequal_test)
{ {
migraphx::program p = migraphx::parse_onnx("greaterorequal_test.onnx"); migraphx::program p = migraphx::parse_onnx("greaterorequal_test.onnx");
...@@ -950,6 +1014,41 @@ TEST_CASE(instance_norm_3d_test) ...@@ -950,6 +1014,41 @@ TEST_CASE(instance_norm_3d_test)
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold)); EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
} }
TEST_CASE(layer_norm_test)
{
std::vector<float> scale{1.2, 0.8};
std::vector<float> bias{0.5, 0.2};
std::vector<float> result_vector =
norm_test<float>({1, 4, 2}, scale, bias, "layer_norm_3d_test.onnx");
std::vector<float> gold = {-0.69997597,
0.99998398,
-0.69997597,
0.99998398,
-0.69997597,
0.99998398,
-0.69997597,
0.99998398};
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
TEST_CASE(layer_norm_half_test)
{
using migraphx::half;
std::vector<half> scale{half{1.2}, half{0.8}};
std::vector<half> bias{half{0.5}, half{0.2}};
std::vector<half> result_vector =
norm_test<half>({1, 4, 2}, scale, bias, "layer_norm_3d_half_test.onnx");
std::vector<half> gold = {half{-0.69997597},
half{0.99998398},
half{-0.69997597},
half{0.99998398},
half{-0.69997597},
half{0.99998398},
half{-0.69997597},
half{0.99998398}};
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
TEST_CASE(lessorequal_test) TEST_CASE(lessorequal_test)
{ {
migraphx::program p = migraphx::parse_onnx("lessorequal_test.onnx"); migraphx::program p = migraphx::parse_onnx("lessorequal_test.onnx");
...@@ -1708,6 +1807,112 @@ TEST_CASE(selu_test) ...@@ -1708,6 +1807,112 @@ TEST_CASE(selu_test)
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold)); EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
} }
TEST_CASE(shrink_hard_test)
{
migraphx::program p = migraphx::parse_onnx("shrink_hard_test.onnx");
p.compile(migraphx::make_target("ref"));
migraphx::shape s{migraphx::shape::float_type, {5}};
std::vector<float> data{-2, -1, 0, 1, 2};
migraphx::parameter_map pp;
pp["x"] = migraphx::argument(s, data.data());
auto result = p.eval(pp).back();
std::vector<float> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {-2, 0, 0, 0, 2};
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
TEST_CASE(shrink_soft_test)
{
migraphx::program p = migraphx::parse_onnx("shrink_soft_test.onnx");
p.compile(migraphx::make_target("ref"));
migraphx::shape s{migraphx::shape::float_type, {5}};
std::vector<float> data{-2, -1, 0, 1, 2};
migraphx::parameter_map pp;
pp["x"] = migraphx::argument(s, data.data());
auto result = p.eval(pp).back();
std::vector<float> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {-0.5, 0, 0, 0, 0.5};
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
TEST_CASE(shrink_verify_test)
{
migraphx::program p = migraphx::parse_onnx("shrink_verify_test.onnx");
p.compile(migraphx::make_target("ref"));
migraphx::shape s{migraphx::shape::half_type, {5}};
std::vector<float> tmp = {-10.0, -5.0, 0.0, 5.0, 10.0};
std::vector<migraphx::half> data{tmp.cbegin(), tmp.cend()};
migraphx::parameter_map pp;
pp["x"] = migraphx::argument(s, data.data());
auto result = p.eval(pp).back();
std::vector<migraphx::half> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
tmp = {-9.0, -4.0, 1.0, 4.0, 9.0};
std::vector<migraphx::half> gold{tmp.cbegin(), tmp.cend()};
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
TEST_CASE(shrink_verify2_test)
{
migraphx::program p = migraphx::parse_onnx("shrink_verify2_test.onnx");
p.compile(migraphx::make_target("ref"));
migraphx::shape s{migraphx::shape::half_type, {5}};
std::vector<float> tmp = {-10.0, -5.0, 0.0, 5.0, 10.0};
std::vector<migraphx::half> data{tmp.cbegin(), tmp.cend()};
migraphx::parameter_map pp;
pp["x"] = migraphx::argument(s, data.data());
auto result = p.eval(pp).back();
std::vector<migraphx::half> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
tmp = {-5.0, 0.0, 5.0, 10.0, 5.0};
std::vector<migraphx::half> gold{tmp.cbegin(), tmp.cend()};
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
TEST_CASE(shrink_int8_test)
{
migraphx::program p = migraphx::parse_onnx("shrink_int8_test.onnx");
p.compile(migraphx::make_target("ref"));
migraphx::shape s{migraphx::shape::int8_type, {3, 3}};
std::vector<int8_t> data{-4, -3, -2, -1, 0, 1, 2, 3, 4};
migraphx::parameter_map pp;
pp["x"] = migraphx::argument(s, data.data());
auto result = p.eval(pp).back();
std::vector<int8_t> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<int8_t> gold = {-2, -1, 0, 0, 0, 0, 0, 1, 2};
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
TEST_CASE(shrink_uint8_test)
{
migraphx::program p = migraphx::parse_onnx("shrink_uint8_test.onnx");
p.compile(migraphx::make_target("ref"));
migraphx::shape s{migraphx::shape::uint8_type, {3, 3}};
std::vector<uint8_t> data{1, 2, 3, 4, 5, 6, 7, 8, 9};
migraphx::parameter_map pp;
pp["x"] = migraphx::argument(s, data.data());
auto result = p.eval(pp).back();
std::vector<uint8_t> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<uint8_t> gold = {0, 0, 0, 0, 0, 10, 11, 12, 13};
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
TEST_CASE(size_verify_test) TEST_CASE(size_verify_test)
{ {
migraphx::program p = migraphx::parse_onnx("size_verify_test.onnx"); migraphx::program p = migraphx::parse_onnx("size_verify_test.onnx");
......
...@@ -249,8 +249,6 @@ def disabled_tests_onnx_1_7_0(backend_test): ...@@ -249,8 +249,6 @@ def disabled_tests_onnx_1_7_0(backend_test):
backend_test.exclude(r'test_reversesequence_time_cpu') backend_test.exclude(r'test_reversesequence_time_cpu')
backend_test.exclude(r'test_scan9_sum_cpu') backend_test.exclude(r'test_scan9_sum_cpu')
backend_test.exclude(r'test_scan_sum_cpu') backend_test.exclude(r'test_scan_sum_cpu')
backend_test.exclude(r'test_shrink_hard_cpu')
backend_test.exclude(r'test_shrink_soft_cpu')
backend_test.exclude(r'test_slice_cpu') backend_test.exclude(r'test_slice_cpu')
backend_test.exclude(r'test_slice_default_axes_cpu') backend_test.exclude(r'test_slice_default_axes_cpu')
backend_test.exclude(r'test_slice_default_steps_cpu') backend_test.exclude(r'test_slice_default_steps_cpu')
...@@ -463,7 +461,6 @@ def disabled_tests_onnx_1_7_0(backend_test): ...@@ -463,7 +461,6 @@ def disabled_tests_onnx_1_7_0(backend_test):
backend_test.exclude(r'test_sequence_model6_cpu') backend_test.exclude(r'test_sequence_model6_cpu')
backend_test.exclude(r'test_sequence_model7_cpu') backend_test.exclude(r'test_sequence_model7_cpu')
backend_test.exclude(r'test_sequence_model8_cpu') backend_test.exclude(r'test_sequence_model8_cpu')
backend_test.exclude(r'test_shrink_cpu')
backend_test.exclude(r'test_strnorm_model_monday_casesensintive_lower_cpu') backend_test.exclude(r'test_strnorm_model_monday_casesensintive_lower_cpu')
backend_test.exclude( backend_test.exclude(
r'test_strnorm_model_monday_casesensintive_nochangecase_cpu') r'test_strnorm_model_monday_casesensintive_nochangecase_cpu')
......
...@@ -54,7 +54,7 @@ struct allocate_no_out : migraphx::auto_register_op<allocate_no_out> ...@@ -54,7 +54,7 @@ struct allocate_no_out : migraphx::auto_register_op<allocate_no_out>
const migraphx::shape& output_shape, const migraphx::shape& output_shape,
const std::vector<migraphx::argument>&) const const std::vector<migraphx::argument>&) const
{ {
return {output_shape}; return migraphx::argument{output_shape};
} }
}; };
...@@ -78,7 +78,7 @@ struct allocate_with_out : migraphx::auto_register_op<allocate_with_out> ...@@ -78,7 +78,7 @@ struct allocate_with_out : migraphx::auto_register_op<allocate_with_out>
const migraphx::shape& output_shape, const migraphx::shape& output_shape,
const std::vector<migraphx::argument>&) const const std::vector<migraphx::argument>&) const
{ {
return {output_shape}; return migraphx::argument{output_shape};
} }
}; };
......
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/op/common.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/common.hpp>
template <migraphx::shape::type_t T>
struct test_shrink : verify_program<test_shrink<T>>
{
migraphx::program create_program() const
{
migraphx::program p;
float bias = 1.5;
float lambd = 1.5;
auto* mm = p.get_main_module();
migraphx::shape is{T, {2, 3}};
std::vector<float> data;
migraphx::shape::visit(T, [&](auto as) {
as.is_signed() ? data.assign({-3.0, -2.0, -1.0, 0.0, 1.0, 2.0})
: data.assign({3.0, 2.0, 1.0, 0.0, 1.0, 2.0});
});
auto x = mm->add_literal(migraphx::literal{is, data});
auto lit_bias = mm->add_literal(migraphx::literal{migraphx::shape::float_type, {bias}});
auto lit_neg_lambd =
mm->add_literal(migraphx::literal{migraphx::shape::float_type, {-lambd}});
auto lit_lambd = mm->add_literal(migraphx::literal{migraphx::shape::float_type, {lambd}});
auto x_plus_bias = add_common_op(*mm, migraphx::make_op("add"), {x, lit_bias});
auto x_min_bias = add_common_op(*mm, migraphx::make_op("sub"), {x, lit_bias});
auto cond1 = add_common_op(*mm, migraphx::make_op("less"), {x, lit_neg_lambd});
auto cond2_a = add_common_op(*mm, migraphx::make_op("not"), {cond1});
auto cond2_b = add_common_op(*mm, migraphx::make_op("greater"), {x, lit_lambd});
auto cond2 = add_common_op(*mm, migraphx::make_op("logical_and"), {cond2_a, cond2_b});
auto mul1 = mm->add_instruction(migraphx::make_op("convert", {{"target_type", T}}), cond1);
auto mul2 = mm->add_instruction(migraphx::make_op("convert", {{"target_type", T}}), cond2);
auto first = add_common_op(*mm, migraphx::make_op("mul"), {mul1, x_plus_bias});
auto second = add_common_op(*mm, migraphx::make_op("mul"), {mul2, x_min_bias});
auto ret = add_common_op(*mm, migraphx::make_op("add"), {first, second});
if(ret->get_shape().type() != T)
{
mm->add_instruction(migraphx::make_op("convert", {{"target_type", T}}), ret);
}
return p;
}
};
template struct test_shrink<migraphx::shape::double_type>;
template struct test_shrink<migraphx::shape::float_type>;
template struct test_shrink<migraphx::shape::half_type>;
template struct test_shrink<migraphx::shape::int64_type>;
template struct test_shrink<migraphx::shape::int32_type>;
template struct test_shrink<migraphx::shape::int16_type>;
template struct test_shrink<migraphx::shape::int8_type>;
template struct test_shrink<migraphx::shape::uint64_type>;
template struct test_shrink<migraphx::shape::uint32_type>;
template struct test_shrink<migraphx::shape::uint16_type>;
template struct test_shrink<migraphx::shape::uint8_type>;
...@@ -220,10 +220,16 @@ def main(): ...@@ -220,10 +220,16 @@ def main():
else: else:
test_input = np.zeros(in_shape).astype(get_np_datatype(in_type)) test_input = np.zeros(in_shape).astype(get_np_datatype(in_type))
test_inputs[name] = test_input test_inputs[name] = test_input
params[name] = migraphx.argument(test_input) migraphx_arg = migraphx.argument(test_input)
if not args.offload_copy:
migraphx_arg = migraphx.to_gpu(migraphx_arg)
params[name] = migraphx_arg
if not args.ort_run: if not args.ort_run:
pred_migx = np.array(model.run(params)[-1]) if not args.offload_copy:
pred_migx = np.array(migraphx.from_gpu(model.run(params)[-1]))
else:
pred_migx = np.array(model.run(params)[-1])
if use_onnx: if use_onnx:
sess_op = ort.SessionOptions() sess_op = ort.SessionOptions()
......
...@@ -22,4 +22,4 @@ ...@@ -22,4 +22,4 @@
# THE SOFTWARE. # THE SOFTWARE.
##################################################################################### #####################################################################################
numpy==1.21.6 numpy==1.21.6
onnxruntime==1.10.0 onnxruntime==1.16.1
...@@ -40,4 +40,4 @@ echo 'InferenceSessionTests.CheckRunProfilerWithSessionOptions' >> ../../../tool ...@@ -40,4 +40,4 @@ echo 'InferenceSessionTests.CheckRunProfilerWithSessionOptions' >> ../../../tool
echo 'InferenceSessionTests.CheckRunProfilerWithSessionOptions2' >> ../../../tools/ci_build/github/pai/migraphx-excluded-tests.txt echo 'InferenceSessionTests.CheckRunProfilerWithSessionOptions2' >> ../../../tools/ci_build/github/pai/migraphx-excluded-tests.txt
echo 'InferenceSessionTests.Test3LayerNestedSubgraph' >> ../../../tools/ci_build/github/pai/migraphx-excluded-tests.txt echo 'InferenceSessionTests.Test3LayerNestedSubgraph' >> ../../../tools/ci_build/github/pai/migraphx-excluded-tests.txt
echo 'InferenceSessionTests.Test2LayerNestedSubgraph' >> ../../../tools/ci_build/github/pai/migraphx-excluded-tests.txt echo 'InferenceSessionTests.Test2LayerNestedSubgraph' >> ../../../tools/ci_build/github/pai/migraphx-excluded-tests.txt
../../../tools/ci_build/github/pai/migraphx_test_launcher.sh || (gdb ./onnxruntime_test_all core -batch -ex bt && exit 1) ../../../tools/ci_build/github/pai/pai_test_launcher.sh || (gdb ./onnxruntime_test_all core -batch -ex bt && exit 1)
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