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

[quant][graphmode][fx] Scope support for call_method in QuantizationTracer #50173

Closed
wants to merge 8 commits into from

Conversation

jerryzh168
Copy link
Contributor

@jerryzh168 jerryzh168 commented Jan 7, 2021

Stack from ghstack:

Summary:
Previously we did not set the qconfig for call_method node correctly since it requires us to know
the scope (module path and type of the module whose forward graph contains the node) of the node. This
PR modifies the QuantizationTracer to record the scope information and build a map from call_method
Node to (module_path, module_type), which will be used when we construct qconfig_map

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_qconfig_for_call_method
Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: D25818132

…racer

Summary:
Previously we did not set the qconfig for call_method node correctly since it requires us to know
the scope (module path of the module whose forward graph contains the node) of the node. This
PR modifies the QuantizationTracer to record the scope information and build a map from call_method
Node to module path, which will be used when we construct qconfig_map

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_qconfig_for_call_method
Reviewers:

Subscribers:

Tasks:

Tags:

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

facebook-github-bot commented Jan 7, 2021

💊 CI failures summary and remediations

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


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

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 to the (internal) Dr. CI Users group.

This comment has been revised 32 times.

@jerryzh168 jerryzh168 requested review from vkuzo, z-a-f, jamesr66a, raghuramank100 and supriyar and removed request for vkuzo January 7, 2021 01:04
…antizationTracer"

Summary:
Previously we did not set the qconfig for call_method node correctly since it requires us to know
the scope (module path of the module whose forward graph contains the node) of the node. This
PR modifies the QuantizationTracer to record the scope information and build a map from call_method
Node to module path, which will be used when we construct qconfig_map

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_qconfig_for_call_method
Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
…antizationTracer"

Summary:
Previously we did not set the qconfig for call_method node correctly since it requires us to know
the scope (module path of the module whose forward graph contains the node) of the node. This
PR modifies the QuantizationTracer to record the scope information and build a map from call_method
Node to module path, which will be used when we construct qconfig_map

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_qconfig_for_call_method
Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
…antizationTracer"

Summary:
Previously we did not set the qconfig for call_method node correctly since it requires us to know
the scope (module path of the module whose forward graph contains the node) of the node. This
PR modifies the QuantizationTracer to record the scope information and build a map from call_method
Node to module path, which will be used when we construct qconfig_map

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_qconfig_for_call_method
Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
jerryzh168 added a commit that referenced this pull request Jan 7, 2021
…racer

Summary:
Previously we did not set the qconfig for call_method node correctly since it requires us to know
the scope (module path of the module whose forward graph contains the node) of the node. This
PR modifies the QuantizationTracer to record the scope information and build a map from call_method
Node to module path, which will be used when we construct qconfig_map

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_qconfig_for_call_method
Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 811f46cb9cbbcab1d79b670f36f4987be7f3982b
Pull Request resolved: #50173
…antizationTracer"

Summary:
Previously we did not set the qconfig for call_method node correctly since it requires us to know
the scope (module path of the module whose forward graph contains the node) of the node. This
PR modifies the QuantizationTracer to record the scope information and build a map from call_method
Node to module path, which will be used when we construct qconfig_map

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_qconfig_for_call_method
Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
jerryzh168 added a commit that referenced this pull request Jan 7, 2021
…racer

Summary:
Previously we did not set the qconfig for call_method node correctly since it requires us to know
the scope (module path of the module whose forward graph contains the node) of the node. This
PR modifies the QuantizationTracer to record the scope information and build a map from call_method
Node to module path, which will be used when we construct qconfig_map

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_qconfig_for_call_method
Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: f30902dc69be9c263d31a851b07f757efe5ac2e1
Pull Request resolved: #50173
Copy link
Collaborator

@jamesr66a jamesr66a left a comment

Choose a reason for hiding this comment

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

LGTM

…antizationTracer"


Summary:
Previously we did not set the qconfig for call_method node correctly since it requires us to know
the scope (module path and type of the module whose forward graph contains the node) of the node. This
PR modifies the QuantizationTracer to record the scope information and build a map from call_method
Node to (module_path, module_type), which will be used when we construct qconfig_map

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_qconfig_for_call_method
Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
jerryzh168 added a commit that referenced this pull request Jan 7, 2021
…racer

Summary:
Previously we did not set the qconfig for call_method node correctly since it requires us to know
the scope (module path of the module whose forward graph contains the node) of the node. This
PR modifies the QuantizationTracer to record the scope information and build a map from call_method
Node to module path, which will be used when we construct qconfig_map

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_qconfig_for_call_method
Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 69417ef56dab0f487d68d262eccadaa857c8d069
Pull Request resolved: #50173
torch/quantization/quantize_fx.py Outdated Show resolved Hide resolved
test/quantization/test_quantize_fx.py Outdated Show resolved Hide resolved
qconfig_dict: Any) -> None:
global_qconfig = qconfig_dict.get('', None)
qconfig_dict: Any,
node_name_to_scope: Dict[str, Tuple[str, Any]]) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

any chance we can clarify Any further to the real type? Motivation: if someone other than the code author is debugging this, as written there is no way to deduce the type other than looking up this PR and tracing what's happening. If the type was specified, the code reader has a lower burden.

if it's challening to define the type for some reason, can we add a comment with an example value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

torch/quantization/quantize_fx.py Outdated Show resolved Hide resolved
not isinstance(m, torch.nn.Sequential)) or \
module_qualified_name in self.skipped_module_names or \
type(m) in self.skipped_module_classes or \
isinstance(m, _FusedModule)

def call_module(self, m: torch.nn.Module, forward: Callable[..., Any], args : Tuple[Any, ...], kwargs : Dict[str, Any]) -> Any:
module_qualified_name = self.path_of_module(m)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jamesr66a this is copied from default call_module code, would it be a problem if the default code changes? do you think it's better to provide an API in call_module to allow this kind of extension?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the future-proofed way to do this is to instantiate the guard and call super().call_module

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, sg

…antizationTracer"


Summary:
Previously we did not set the qconfig for call_method node correctly since it requires us to know
the scope (module path and type of the module whose forward graph contains the node) of the node. This
PR modifies the QuantizationTracer to record the scope information and build a map from call_method
Node to (module_path, module_type), which will be used when we construct qconfig_map

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_qconfig_for_call_method
Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
…antizationTracer"


Summary:
Previously we did not set the qconfig for call_method node correctly since it requires us to know
the scope (module path and type of the module whose forward graph contains the node) of the node. This
PR modifies the QuantizationTracer to record the scope information and build a map from call_method
Node to (module_path, module_type), which will be used when we construct qconfig_map

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_qconfig_for_call_method
Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
@codecov
Copy link

codecov bot commented Jan 9, 2021

Codecov Report

Merging #50173 (3e9560f) into gh/jerryzh168/528/base (49bb0a3) will decrease coverage by 0.08%.
The diff coverage is 100.00%.

@@                    Coverage Diff                     @@
##           gh/jerryzh168/528/base   #50173      +/-   ##
==========================================================
- Coverage                   80.68%   80.59%   -0.09%     
==========================================================
  Files                        1904     1904              
  Lines                      206561   206587      +26     
==========================================================
- Hits                       166667   166508     -159     
- Misses                      39894    40079     +185     

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in f10e7aa.

@facebook-github-bot facebook-github-bot deleted the gh/jerryzh168/528/head branch January 15, 2021 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants