[quant][graphmode] Fix add_relu patterns for scripting and tracing#39455
[quant][graphmode] Fix add_relu patterns for scripting and tracing#39455jerryzh168 wants to merge 8 commits intogh/jerryzh168/332/basefrom
Conversation
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]
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
💊 CI failures summary and remediationsAs of commit afd7a8b (more details on the Dr. CI page):
Extra GitHub checks: 1 failed
ci.pytorch.org: 1 failedThis 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. This comment has been revised 13 times. |
… 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]
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), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
| // =========== helper functions for Module ========== | ||
|
|
||
| // ==================== filter functions for matches ============== | ||
| auto aten_add_alpha_is_one = |
There was a problem hiding this comment.
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;
};| %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"( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
this is the third starter task for my intern, so let's land this asap
raghuramank100
left a comment
There was a problem hiding this comment.
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]
|
This pull request has been merged in e4627e5. |
…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
Stack from ghstack:
ifin insert_observers #39615 [quant][graphmode] Fix a corner case in handlingifin insert_observersSummary:
Test Plan:
Reviewers:
Subscribers:
Tasks:
Tags:
Differential Revision: D21917118