Skip to content

[quant][graphmode] Fix add_relu patterns for scripting and tracing#39455

Closed
jerryzh168 wants to merge 8 commits intogh/jerryzh168/332/basefrom
gh/jerryzh168/332/head
Closed

[quant][graphmode] Fix add_relu patterns for scripting and tracing#39455
jerryzh168 wants to merge 8 commits intogh/jerryzh168/332/basefrom
gh/jerryzh168/332/head

Conversation

@jerryzh168
Copy link
Copy Markdown
Contributor

@jerryzh168 jerryzh168 commented Jun 3, 2020

Stack from ghstack:

Summary:

  1. enable filters in PatternInfo
  2. add aten_add_alpha_is_one filter
  3. add is_functional_relu filter
  4. add is_relu_module filter
  5. fix the relu module method call matching in traced modules with regex
  6. add aten::add - aten::relu patterns for traced modules

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: D21917118

Summary:
1. enable filters in PatternInfo
2. add aten_add_alpha_is_one filter
3. add is_functional_relu filter
4. add is_relu_module filter
5. fix the relu module method call matching in traced modules with regex
6. add aten::add - aten::relu patterns for traced modules

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
… tracing"

Summary:
1. enable filters in PatternInfo
2. add aten_add_alpha_is_one filter
3. add is_functional_relu filter
4. add is_relu_module filter
5. fix the relu module method call matching in traced modules with regex
6. add aten::add - aten::relu patterns for traced modules

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
jerryzh168 added a commit that referenced this pull request Jun 3, 2020
Summary:
1. enable filters in PatternInfo
2. add aten_add_alpha_is_one filter
3. add is_functional_relu filter
4. add is_relu_module filter
5. fix the relu module method call matching in traced modules with regex
6. add aten::add - aten::relu patterns for traced modules

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 2134605
Pull Request resolved: #39455
@dr-ci
Copy link
Copy Markdown

dr-ci Bot commented Jun 3, 2020

💊 CI failures summary and remediations

As of commit afd7a8b (more details on the Dr. CI page):


  • 2/2 failures possibly* introduced in this PR
    • 2/2 non-CircleCI failure(s)

Extra GitHub checks: 1 failed


ci.pytorch.org: 1 failed


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group.

See how this bot performed.

This comment has been revised 13 times.

Comment thread test/quantization/test_quantize_script.py
Comment thread torch/csrc/jit/passes/quantization/insert_observers.cpp Outdated
Comment thread torch/quantization/quantize_script.py Outdated
Comment thread test/quantization/test_quantize_script.py
… tracing"

Summary:
1. enable filters in PatternInfo
2. add aten_add_alpha_is_one filter
3. add is_functional_relu filter
4. add is_relu_module filter
5. fix the relu module method call matching in traced modules with regex
6. add aten::add - aten::relu patterns for traced modules

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
jerryzh168 added a commit that referenced this pull request Jun 3, 2020
Summary:
1. enable filters in PatternInfo
2. add aten_add_alpha_is_one filter
3. add is_functional_relu filter
4. add is_relu_module filter
5. fix the relu module method call matching in traced modules with regex
6. add aten::add - aten::relu patterns for traced modules

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: fb340e5
Pull Request resolved: #39455
… tracing"

Summary:
1. enable filters in PatternInfo
2. add aten_add_alpha_is_one filter
3. add is_functional_relu filter
4. add is_relu_module filter
5. fix the relu module method call matching in traced modules with regex
6. add aten::add - aten::relu patterns for traced modules

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
… tracing"

Summary:
1. enable filters in PatternInfo
2. add aten_add_alpha_is_one filter
3. add is_functional_relu filter
4. add is_relu_module filter
5. fix the relu module method call matching in traced modules with regex
6. add aten::add - aten::relu patterns for traced modules

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
data = [(torch.rand((1, 3, 10, 10), dtype=torch.float),
torch.rand((1, 3, 10, 10), dtype=torch.float),
torch.randint(0, 1, (1,), dtype=torch.long)) for _ in range(2)]
for m_orig in [AddRelu(True), AddRelu(False),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a way to make the model set smaller? As we have more operations similar to this (sub/mul etc), it feel clunky to have a lot of models? Would a single model performing all the operation types here be better?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we can try to see if we can refactor this test with some python features, but I feel it's likely not supported in JIT.

regarding single model vs multiple model: I feel it's better to keep them separate since it's easier to see what is failing.

Comment thread torch/csrc/jit/passes/quantization/helper.h Outdated
// =========== helper functions for Module ==========

// ==================== filter functions for matches ==============
auto aten_add_alpha_is_one =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How about a general matcher that checks if a particular argument is hardcoded to an integer value?

    auto check_constant_argument =
[](const Match& match,
       const std::unordered_map<std::string, Value*>& vmap, std::string argument_name, int argument_value) {
      const auto& match_vmap = match.values_map;
      auto alpha = toIValue(match_vmap.at(vmap.at(argument_name)));
      return alpha && alpha->isInt() && alpha->toInt() == argument_value;
    };

Comment thread torch/csrc/jit/passes/quantization/insert_observers.cpp Outdated
%first_output = aten::add_(%a, %b, %one)
%relu = prim::Constant[name="relu"]()
%second_output = prim::CallFunction(%relu, %first_output, %inplace)
const PatternInfo inplace_add_aten_relu_ = PatternInfo::parse_from_str(R"(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we generate these patterns to make the code readable? If you iterate over the patterns (add, add_) and (relu, relu_) can you simplify this part?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is the third starter task for my intern, so let's land this asap

Copy link
Copy Markdown
Contributor

@raghuramank100 raghuramank100 left a comment

Choose a reason for hiding this comment

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

Please see comments

… tracing"

Summary:
1. enable filters in PatternInfo
2. add aten_add_alpha_is_one filter
3. add is_functional_relu filter
4. add is_relu_module filter
5. fix the relu module method call matching in traced modules with regex
6. add aten::add - aten::relu patterns for traced modules

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
… tracing"

Summary:
1. enable filters in PatternInfo
2. add aten_add_alpha_is_one filter
3. add is_functional_relu filter
4. add is_relu_module filter
5. fix the relu module method call matching in traced modules with regex
6. add aten::add - aten::relu patterns for traced modules

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
… tracing"

Summary:
1. enable filters in PatternInfo
2. add aten_add_alpha_is_one filter
3. add is_functional_relu filter
4. add is_relu_module filter
5. fix the relu module method call matching in traced modules with regex
6. add aten::add - aten::relu patterns for traced modules

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: [D21917118](https://our.internmc.facebook.com/intern/diff/D21917118)

[ghstack-poisoned]
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request has been merged in e4627e5.

@facebook-github-bot facebook-github-bot deleted the gh/jerryzh168/332/head branch June 10, 2020 15:33
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
…ytorch#39455)

Summary:
Pull Request resolved: pytorch#39455

1. enable filters in PatternInfo
2. add aten_add_alpha_is_one filter
3. add is_functional_relu filter
4. add is_relu_module filter
5. fix the relu module method call matching in traced modules with regex
6. add aten::add - aten::relu patterns for traced modules

Test Plan: Imported from OSS

Differential Revision: D21917118

fbshipit-source-id: e67b55cd1c070fd4238f563d933a6f10a3582ae3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants