Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 22 additions & 35 deletions onnxruntime/test/optimizer/qdq_transformer_fastmath_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ TEST(QDQTransformerTests, MatMul_S8S8U8_DisableFastMath) {

template <typename Input1Type, typename Input2Type, typename OutputType, typename BiasType = int32_t>
void QDQTransformerGemmTests(bool has_output_q, bool has_bias, bool beta_not_one = false,
bool disable_fastmath = false, bool alpha_not_one = false) {
bool disable_fastmath = false, bool alpha_not_one = false, int opset_version = 0) {
auto test_case = [&](const std::vector<int64_t>& input1_shape, const std::vector<int64_t>& input2_shape,
Comment thread
tianleiwu marked this conversation as resolved.
bool use_contrib_qdq = false) {
auto build_test_case = [&](ModelTestBuilder& builder) {
Expand Down Expand Up @@ -435,33 +435,19 @@ void QDQTransformerGemmTests(bool has_output_q, bool has_bias, bool beta_not_one
kOrtSessionOptionsMlasGemmFastMathArm64Bfloat16, "1"));
};

TransformerTester(build_test_case,
check_binary_op_graph,
TransformerLevel::Level1,
TransformerLevel::Level2,
12 /*opset_version*/,
NAN /*per_sample_tolerance*/,
NAN /*relative_per_sample_tolerance*/,
std::make_unique<QDQSelectorActionTransformer>(QDQIsInt8Allowed()),
add_session_options);
TransformerTester(build_test_case,
check_binary_op_graph,
TransformerLevel::Level1,
TransformerLevel::Level2,
18 /*opset_version*/,
NAN /*per_sample_tolerance*/,
NAN /*relative_per_sample_tolerance*/,
std::make_unique<QDQSelectorActionTransformer>(QDQIsInt8Allowed()),
add_session_options);
TransformerTester(build_test_case,
check_binary_op_graph,
TransformerLevel::Level1,
TransformerLevel::Level2,
19 /*opset_version*/,
NAN /*per_sample_tolerance*/,
NAN /*relative_per_sample_tolerance*/,
std::make_unique<QDQSelectorActionTransformer>(QDQIsInt8Allowed()),
add_session_options);
const auto opset_versions = opset_version == 0 ? std::vector<int>{12, 18, 19}
: std::vector<int>{opset_version};
for (int current_opset_version : opset_versions) {
TransformerTester(build_test_case,
check_binary_op_graph,
TransformerLevel::Level1,
TransformerLevel::Level2,
current_opset_version,
NAN /*per_sample_tolerance*/,
NAN /*relative_per_sample_tolerance*/,
std::make_unique<QDQSelectorActionTransformer>(QDQIsInt8Allowed()),
add_session_options);
}

if (disable_fastmath) {
auto add_session_options = [&](SessionOptions& so) {
Expand Down Expand Up @@ -498,17 +484,18 @@ void QDQTransformerGemmTests() {
QDQTransformerGemmTests<Input1Type, Input2Type, OutputType, BiasType>(false, true, true);
QDQTransformerGemmTests<Input1Type, Input2Type, OutputType, BiasType>(true, false, true);
QDQTransformerGemmTests<Input1Type, Input2Type, OutputType, BiasType>(true, true, true);
if constexpr (std::is_same_v<Input1Type, uint8_t> && std::is_same_v<Input2Type, uint8_t> &&
std::is_same_v<OutputType, uint8_t> && std::is_same_v<BiasType, int32_t>) {
QDQTransformerGemmTests<Input1Type, Input2Type, OutputType, BiasType>(false, false, false, false, true);
QDQTransformerGemmTests<Input1Type, Input2Type, OutputType, BiasType>(false, true, false, false, true);
QDQTransformerGemmTests<Input1Type, Input2Type, OutputType, BiasType>(true, false, false, false, true);
QDQTransformerGemmTests<Input1Type, Input2Type, OutputType, BiasType>(true, true, false, false, true);
}
// dummy test to disable the fastmath session
QDQTransformerGemmTests<Input1Type, Input2Type, OutputType, BiasType>(true, true, true, true);
}

TEST(QDQTransformerTests, Gemm_AlphaNotOne_U8U8U8_FastMath) {
constexpr int opset_version = 19;
QDQTransformerGemmTests<uint8_t, uint8_t, uint8_t>(false, false, false, false, true, opset_version);
QDQTransformerGemmTests<uint8_t, uint8_t, uint8_t>(false, true, false, false, true, opset_version);
QDQTransformerGemmTests<uint8_t, uint8_t, uint8_t>(true, false, false, false, true, opset_version);
QDQTransformerGemmTests<uint8_t, uint8_t, uint8_t>(true, true, false, false, true, opset_version);
}

TEST(QDQTransformerTests, Gemm_U8U8U8_FastMath) {
QDQTransformerGemmTests<uint8_t, uint8_t, uint8_t>();
QDQTransformerGemmTests<uint8_t, uint8_t, uint8_t, uint8_t>();
Expand Down
53 changes: 21 additions & 32 deletions onnxruntime/test/optimizer/qdq_transformer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ TEST(QDQTransformerTests, MatMul_S8S8U8) {

template <typename Input1Type, typename Input2Type, typename OutputType, typename BiasType = int32_t>
void QDQTransformerGemmTests(bool has_output_q, bool has_bias, bool beta_not_one = false,
bool alpha_not_one = false) {
bool alpha_not_one = false, int opset_version = 0) {
auto test_case = [&](const std::vector<int64_t>& input1_shape, const std::vector<int64_t>& input2_shape,
Comment thread
tianleiwu marked this conversation as resolved.
bool use_contrib_qdq = false) {
auto build_test_case = [&](ModelTestBuilder& builder) {
Expand Down Expand Up @@ -825,30 +825,18 @@ void QDQTransformerGemmTests(bool has_output_q, bool has_bias, bool beta_not_one
}
};

TransformerTester(build_test_case,
check_binary_op_graph,
TransformerLevel::Level1,
TransformerLevel::Level2,
12 /*opset_version*/,
0.01 /*per_sample_tolerance*/,
0.01 /*relative_per_sample_tolerance*/,
std::make_unique<QDQSelectorActionTransformer>(QDQIsInt8Allowed()));
TransformerTester(build_test_case,
check_binary_op_graph,
TransformerLevel::Level1,
TransformerLevel::Level2,
18 /*opset_version*/,
0.01 /*per_sample_tolerance*/,
0.01 /*relative_per_sample_tolerance*/,
std::make_unique<QDQSelectorActionTransformer>(QDQIsInt8Allowed()));
TransformerTester(build_test_case,
check_binary_op_graph,
TransformerLevel::Level1,
TransformerLevel::Level2,
19 /*opset_version*/,
0.01 /*per_sample_tolerance*/,
0.01 /*relative_per_sample_tolerance*/,
std::make_unique<QDQSelectorActionTransformer>(QDQIsInt8Allowed()));
const auto opset_versions = opset_version == 0 ? std::vector<int>{12, 18, 19}
: std::vector<int>{opset_version};
for (int current_opset_version : opset_versions) {
TransformerTester(build_test_case,
check_binary_op_graph,
TransformerLevel::Level1,
TransformerLevel::Level2,
current_opset_version,
0.01 /*per_sample_tolerance*/,
0.01 /*relative_per_sample_tolerance*/,
std::make_unique<QDQSelectorActionTransformer>(QDQIsInt8Allowed()));
}
};

test_case({2, 2}, {2, 4});
Expand All @@ -868,13 +856,14 @@ void QDQTransformerGemmTests() {
QDQTransformerGemmTests<Input1Type, Input2Type, OutputType, BiasType>(false, true, true);
QDQTransformerGemmTests<Input1Type, Input2Type, OutputType, BiasType>(true, false, true);
QDQTransformerGemmTests<Input1Type, Input2Type, OutputType, BiasType>(true, true, true);
if constexpr (std::is_same_v<Input1Type, uint8_t> && std::is_same_v<Input2Type, uint8_t> &&
std::is_same_v<OutputType, uint8_t> && std::is_same_v<BiasType, int32_t>) {
QDQTransformerGemmTests<Input1Type, Input2Type, OutputType, BiasType>(false, false, false, true);
QDQTransformerGemmTests<Input1Type, Input2Type, OutputType, BiasType>(false, true, false, true);
QDQTransformerGemmTests<Input1Type, Input2Type, OutputType, BiasType>(true, false, false, true);
QDQTransformerGemmTests<Input1Type, Input2Type, OutputType, BiasType>(true, true, false, true);
}
}

TEST(QDQTransformerTests, Gemm_AlphaNotOne_U8U8U8) {
constexpr int opset_version = 19;
QDQTransformerGemmTests<uint8_t, uint8_t, uint8_t>(false, false, false, true, opset_version);
QDQTransformerGemmTests<uint8_t, uint8_t, uint8_t>(false, true, false, true, opset_version);
QDQTransformerGemmTests<uint8_t, uint8_t, uint8_t>(true, false, false, true, opset_version);
QDQTransformerGemmTests<uint8_t, uint8_t, uint8_t>(true, true, false, true, opset_version);
}

TEST(QDQTransformerTests, Gemm_U8U8U8) {
Expand Down
Loading