Support Sum opset6 for ONNX 1.2 models (#1447)

The NCHWc transform was missing support for the Sum_6 operator from ONNX 1.2. Older models would add unnecessary reorder ops and also would not use the Conv/Add fusion.
This commit is contained in:
Tracy Sharpe 2019-07-19 20:00:59 -07:00 committed by GitHub
parent 9e2fa69785
commit 414a07a85b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View file

@ -637,7 +637,7 @@ void NchwcTransformerImpl::Transform(Node& node) {
// needed for correct operation. This avoids doing extra string checks for
// nodes unrelated to this transformer.
if (graph_utils::IsSupportedOptypeVersionAndDomain(node, "Add", {7}) ||
graph_utils::IsSupportedOptypeVersionAndDomain(node, "Sum", {8})) {
graph_utils::IsSupportedOptypeVersionAndDomain(node, "Sum", {6, 8})) {
TransformAdd(node);
} else if (graph_utils::IsSupportedOptypeVersionAndDomain(node, "Concat", {4})) {
TransformConcat(node);

View file

@ -139,14 +139,17 @@ struct NchwcTestHelper {
};
void NchwcOptimizerTester(const std::function<void(NchwcTestHelper& helper)>& build_test_case,
const std::function<void(NchwcInferenceSession& session)>& check_nchwc_graph) {
const std::function<void(NchwcInferenceSession& session)>& check_nchwc_graph,
int opset_version = 10) {
// Ignore the test if NCHWc is not supported by the platform.
if (MlasNchwcGetBlockSize() <= 1) {
return;
}
// Build the model for this test.
Model model("nchwc");
std::unordered_map<std::string, int> domain_to_version;
domain_to_version[kOnnxDomain] = opset_version;
Model model("nchwc", false, ModelMetaData(), IOnnxRuntimeOpSchemaRegistryList(), domain_to_version);
NchwcTestHelper helper(model.MainGraph());
build_test_case(helper);
ASSERT_TRUE(model.MainGraph().Resolve().IsOK());
@ -486,7 +489,7 @@ TEST(NchwcOptimizerTests, ConvGlobalPool) {
}
TEST(NchwcOptimizerTests, ConvAddFusion) {
auto test_case = [&](const std::string& op_type, bool do_relu) {
auto test_case = [&](const std::string& op_type, int opset_version, bool do_relu) {
auto build_test_case = [&](NchwcTestHelper& helper) {
auto* input_arg = helper.MakeInput({1, 32, 28, 28});
auto* conv1_output_arg = helper.MakeIntermediate();
@ -514,15 +517,18 @@ TEST(NchwcOptimizerTests, ConvAddFusion) {
EXPECT_EQ(op_to_count["Relu"], 0);
};
NchwcOptimizerTester(build_test_case, check_nchwc_graph);
NchwcOptimizerTester(build_test_case, check_nchwc_graph, opset_version);
};
// Verify that Add or Sum can be fused into a preceding NCHWc Conv node,
// with an optional Relu node following.
std::vector<std::string> op_types = {"Add", "Sum"};
static const int opset_versions[] = {7, 10};
for (auto& op_type : op_types) {
test_case(op_type, false);
test_case(op_type, true);
for (auto opset_version : opset_versions) {
test_case(op_type, opset_version, false);
test_case(op_type, opset_version, true);
}
}
}