mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-30 20:18:08 +00:00
add qdq support of Sigmoid (#10800)
This commit is contained in:
parent
6260733533
commit
33c6819196
2 changed files with 71 additions and 1 deletions
|
|
@ -81,7 +81,8 @@ void UnaryOpQDQRules(SelectorActionRegistry& qdq_selector_action_registry) {
|
|||
qdq_selector_action_registry.RegisterSelectorAndAction(action_name,
|
||||
{{"AveragePool", {}},
|
||||
{"LeakyRelu", {}},
|
||||
{"GlobalAveragePool", {}}},
|
||||
{"GlobalAveragePool", {}},
|
||||
{"Sigmoid", {}}},
|
||||
std::move(selector),
|
||||
std::move(action));
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -1390,6 +1390,75 @@ TEST(QDQTransformerTests, LeakyRelu_U8S8) {
|
|||
QDQTransformerLeakyReluTests<uint8_t, int8_t>();
|
||||
}
|
||||
|
||||
template <typename InputType, typename OutputType>
|
||||
void QDQTransformerSigmoidTests() {
|
||||
auto test_case = [&](const std::vector<int64_t>& input_shape) {
|
||||
auto build_test_case = [&](ModelTestBuilder& builder) {
|
||||
auto* input_arg = builder.MakeInput<float>(input_shape, -1.f, 1.f);
|
||||
auto* output_arg = builder.MakeOutput();
|
||||
// add QDQ + Sigmoid
|
||||
auto* dq_output = AddQDQNodePair<InputType>(builder, input_arg, .0035f, 7);
|
||||
auto* sigmoid_output = builder.MakeIntermediate();
|
||||
builder.AddNode("Sigmoid", {dq_output}, {sigmoid_output});
|
||||
|
||||
// add QDQ output
|
||||
auto* q_output = builder.MakeIntermediate();
|
||||
builder.AddQuantizeLinearNode<OutputType>(sigmoid_output,
|
||||
.0038f,
|
||||
std::numeric_limits<OutputType>::max() / 2,
|
||||
q_output);
|
||||
builder.AddDequantizeLinearNode<OutputType>(q_output,
|
||||
.0039f,
|
||||
std::numeric_limits<OutputType>::max() / 2,
|
||||
output_arg);
|
||||
};
|
||||
|
||||
auto check_graph = [&](InferenceSessionWrapper& session) {
|
||||
auto op_to_count = CountOpsInGraph(session.GetGraph());
|
||||
if constexpr (std::is_same<InputType, OutputType>::value) {
|
||||
EXPECT_EQ(op_to_count["com.microsoft.QLinearSigmoid"], 1);
|
||||
EXPECT_EQ(op_to_count["Sigmoid"], 0);
|
||||
EXPECT_EQ(op_to_count["QuantizeLinear"], 1);
|
||||
EXPECT_EQ(op_to_count["DequantizeLinear"], 1);
|
||||
} else {
|
||||
EXPECT_EQ(op_to_count["com.microsoft.QLinearSigmoid"], 0);
|
||||
EXPECT_EQ(op_to_count["Sigmoid"], 1);
|
||||
EXPECT_EQ(op_to_count["QuantizeLinear"], 2);
|
||||
EXPECT_EQ(op_to_count["DequantizeLinear"], 2);
|
||||
}
|
||||
};
|
||||
|
||||
TransformerTester(build_test_case,
|
||||
check_graph,
|
||||
TransformerLevel::Level1,
|
||||
TransformerLevel::Level2,
|
||||
12 /*opset_version*/,
|
||||
0.01 /*per_sample_tolerance*/,
|
||||
0.01 /*relative_per_sample_tolerance*/,
|
||||
std::make_unique<QDQSelectorActionTransformer>());
|
||||
};
|
||||
|
||||
test_case({1, 12, 37});
|
||||
test_case({1, 23, 13, 13});
|
||||
test_case({1, 22, 11, 13, 15});
|
||||
}
|
||||
|
||||
TEST(QDQTransformerTests, Sigmoid_S8S8) {
|
||||
QDQTransformerSigmoidTests<int8_t, int8_t>();
|
||||
}
|
||||
|
||||
TEST(QDQTransformerTests, Sigmoid_U8U8) {
|
||||
QDQTransformerSigmoidTests<uint8_t, uint8_t>();
|
||||
}
|
||||
|
||||
TEST(QDQTransformerTests, Sigmoid_S8U8) {
|
||||
QDQTransformerSigmoidTests<int8_t, uint8_t>();
|
||||
}
|
||||
|
||||
TEST(QDQTransformerTests, Sigmoid_U8S8) {
|
||||
QDQTransformerSigmoidTests<uint8_t, int8_t>();
|
||||
}
|
||||
|
||||
TEST(QDQTransformerTests, ConvTranspose_QBackward) {
|
||||
auto test_case = [&](const std::vector<int64_t>& input_shape, const std::vector<int64_t>& weights_shape, const std::vector<int64_t>& perms) {
|
||||
auto build_test_case = [&](ModelTestBuilder& builder) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue