Skip to content

[quant][graphmode][fx] Add support for one value being quantized with different qconfigs#53586

Closed
jerryzh168 wants to merge 24 commits intogh/jerryzh168/570/basefrom
gh/jerryzh168/570/head
Closed

[quant][graphmode][fx] Add support for one value being quantized with different qconfigs#53586
jerryzh168 wants to merge 24 commits intogh/jerryzh168/570/basefrom
gh/jerryzh168/570/head

Conversation

@jerryzh168
Copy link
Copy Markdown
Contributor

@jerryzh168 jerryzh168 commented Mar 9, 2021

Stack from ghstack:

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: D26912676

… different qconfigs

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
jerryzh168 added a commit that referenced this pull request Mar 9, 2021
… different qconfigs

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 3340917
Pull Request resolved: #53586
@facebook-github-bot
Copy link
Copy Markdown
Contributor

facebook-github-bot commented Mar 9, 2021

💊 CI failures summary and remediations

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


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

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.

…ntized with different qconfigs"

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
jerryzh168 added a commit that referenced this pull request Mar 9, 2021
… different qconfigs

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 8d09c22
Pull Request resolved: #53586
Comment thread torch/quantization/fx/quantize.py
Comment thread torch/quantization/fx/quantization_patterns.py Outdated
Comment thread torch/quantization/fx/quantize.py
Comment thread torch/quantization/fx/quantization_patterns.py Outdated
Comment thread torch/quantization/fx/quantize.py
…ntized with different qconfigs"

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
jerryzh168 added a commit that referenced this pull request Mar 10, 2021
… different qconfigs

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 25f2e03
Pull Request resolved: #53586
…ntized with different qconfigs"

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
jerryzh168 added a commit that referenced this pull request Mar 11, 2021
… different qconfigs

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 63e0623
Pull Request resolved: #53586
…ntized with different qconfigs"

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
jerryzh168 added a commit that referenced this pull request Mar 11, 2021
… different qconfigs

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: f1c4408
Pull Request resolved: #53586
…ntized with different qconfigs"

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
jerryzh168 added a commit that referenced this pull request Mar 12, 2021
… different qconfigs

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 05c05b6
Pull Request resolved: #53586
…ntized with different qconfigs"

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
jerryzh168 added a commit that referenced this pull request Mar 12, 2021
… different qconfigs

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: a738021
Pull Request resolved: #53586
…ntized with different qconfigs"

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
jerryzh168 added a commit that referenced this pull request Mar 12, 2021
… different qconfigs

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 6e99e50
Pull Request resolved: #53586
@jerryzh168 jerryzh168 requested a review from vkuzo March 12, 2021 19:29
…ntized with different qconfigs"

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
…ntized with different qconfigs"

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
Copy link
Copy Markdown
Contributor

@vkuzo vkuzo left a comment

Choose a reason for hiding this comment

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

makes sense, accepting to unblock, would be great to undo the additional state in the future. One idea I had when reading this PR...thoughts about this?

# map from (node.name, qconfig) to observer
self.activation_post_process_map: Dict[Tuple(str, QConfig), ObserverBase]

If the only use case for multiple observers for a node is multiple qconfigs, perhaps that can be used to deduplicate, and we wouldn't need to add an additional indices variable? I haven't thought through it deeply, more asking for your early opinion.

Comment thread test/quantization/test_quantize_fx.py Outdated
Comment on lines +97 to +98
if not model.training and isinstance(observer, torch.quantization.FixedQParamsFakeQuantize):
return
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.

just curious, what's the context on this one? Maybe we can add a comment?

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.

Sure I can add a comment. reason is fixedqparams fake quant only needs to be there for training, we can either do this check here or in _find_quant.

…ntized with different qconfigs"

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
…ntized with different qconfigs"

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
…ntized with different qconfigs"

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
…ntized with different qconfigs"

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
…ntized with different qconfigs"

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
…ntized with different qconfigs"

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
…ntized with different qconfigs"

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
…ntized with different qconfigs"

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
…ntized with different qconfigs"

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
…ntized with different qconfigs"

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
…ntized with different qconfigs"

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
…ntized with different qconfigs"

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
…ntized with different qconfigs"

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
…ntized with different qconfigs"

Summary:
Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Reviewers:

Subscribers:

Tasks:

Tags:

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

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

This pull request has been merged in 55544cb.

@facebook-github-bot facebook-github-bot deleted the gh/jerryzh168/570/head branch April 4, 2021 14:17
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
… different qconfigs (pytorch#53586)

Summary:
Pull Request resolved: pytorch#53586

Previously one value can only be quantized to one dtype, this PR adds the support for quantizing one value
in the fx graph with multiple dtypes, e.g. first quantize to int8 and then float16

might do some followup PRs to clean up the hacks and refactor the code.

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_multiple_qconfigs_single_value

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D26912676

fbshipit-source-id: ae3653fd67f05870a3a9e808f491871826c555d5
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.

3 participants