Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mish fusion transformation #1399

Merged

Conversation

iimironov
Copy link
Contributor

@iimironov iimironov commented Jul 20, 2020

Description: Mish nGraph transformation and MO implementation

JIRA: 32954, 33715

Code:

  • Comments
  • Code style (PEP8)
  • Transformation generates reshape-able IR
  • Transformation preserves original framework node names

Validation:

  • Unit tests: Not added, we use simple eltwise shape inference and value propagation functions
  • Framework operation tests: 33719
  • Transformation tests: No new transformation added
  • e2e model test with an update of ./tests/e2e_oss/utils/reshape_utils.py: No new supported models
  • Model Optimizer IR Reader check: Done

Documentation:

  • Supported frameworks operations list: Done, operation was supported via transformation, now it supported directly
  • Supported public models list: No new supported models
  • New operations specification: Done, PR Added mish layer doc opset #1149
  • Guide on how to convert the public model: No new supported models
  • User guide update: Nothing to update

@ilyachur
Copy link
Contributor

Please fix CI.

Also I guess you should add a call of your transformation pass and integrate it to the PassManager, add new tests and etc.

@ilya-lavrenov ilya-lavrenov added the category: transformations OpenVINO Runtime library - Transformations label Jul 21, 2020
@iimironov iimironov requested review from a team July 23, 2020 10:56
@iimironov iimironov force-pushed the imironov/CVS-33715-fuse-mish-op branch 2 times, most recently from 70c02bb to fbb96c9 Compare July 28, 2020 08:39
@iimironov iimironov force-pushed the imironov/CVS-33715-fuse-mish-op branch from 0b3e23c to 0bdb0e2 Compare July 29, 2020 16:54
@GlebKazantaev
Copy link
Contributor

GlebKazantaev commented Jul 30, 2020

@iimironov Please replace your code with this and check that it works.

    auto input = ngraph::pattern::any_input();
    auto exp = std::make_shared<ngraph::opset4::Exp>(input);
    auto add = std::make_shared<ngraph::opset4::Add>(exp, ngraph::pattern::wrap_type<ngraph::opset4::Constant>());
    auto log = std::make_shared<ngraph::opset4::Log>(add);
    auto tanh = std::make_shared<ngraph::opset4::Tanh>(log);
    auto mul = std::make_shared<ngraph::opset4::Multiply>(input, tanh);

    ngraph::graph_rewrite_callback callback = [=](ngraph::pattern::Matcher& m) {
        auto & pattern_to_output = m.get_pattern_value_map();
        auto exp_input = pattern_to_output.at(input);
        
        auto mish = std::make_shared<ngraph::opset4::Mish>(exp_input);
        
        mish->set_friendly_name(m.get_match_root()->get_friendly_name());
        ngraph::copy_runtime_info({pattern_to_output.at(mul).get_node_shared_ptr(),
                                   pattern_to_output.at(tanh).get_node_shared_ptr(),
                                   pattern_to_output.at(log).get_node_shared_ptr(),
                                   pattern_to_output.at(add).get_node_shared_ptr(),
                                   pattern_to_output.at(exp).get_node_shared_ptr()}, mish);
        ngraph::replace_node(m.get_match_root(), mish);
        return true;
    };

    auto m = std::make_shared<ngraph::pattern::Matcher>(mul, "MishFusion");
    register_matcher(m, callback);

And dont forget to fix my other comments

@iimironov iimironov force-pushed the imironov/CVS-33715-fuse-mish-op branch from a011a73 to 22f8dc1 Compare July 30, 2020 12:39
@iimironov iimironov requested a review from GlebKazantaev July 30, 2020 17:20
@iimironov iimironov requested a review from a team August 3, 2020 08:57
@iimironov iimironov force-pushed the imironov/CVS-33715-fuse-mish-op branch 2 times, most recently from b42ba36 to 0fe86ae Compare August 4, 2020 08:41
@iimironov iimironov force-pushed the imironov/CVS-33715-fuse-mish-op branch from 0fe86ae to 0aae3b3 Compare August 5, 2020 12:01
Copy link
Contributor

@lazarevevgeny lazarevevgeny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MO part looks good to me.

@GlebKazantaev, please, approve the IE changes part or provide other comments.

@lazarevevgeny lazarevevgeny merged commit 7e856c3 into openvinotoolkit:master Aug 6, 2020
RomanZm pushed a commit to RomanZm/openvino that referenced this pull request Aug 28, 2020
* Add mish fusion transformation

* Add mish op to python api
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: transformations OpenVINO Runtime library - Transformations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants