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][pyper] Support aten::embedding_bag quantization in graph mode #43989

Closed
wants to merge 4 commits into from

Conversation

supriyar
Copy link
Contributor

@supriyar supriyar commented Sep 1, 2020

Stack from ghstack:

Summary:
When we trace the model it produces aten::embedding_bag node in the graph,
Add necessary passes in graph mode to help support quantizing it as well

Test Plan:
python test/test_quantization.py TestQuantizeDynamicJitOps.test_embedding_bag

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: D23460485

Summary:
When we trace the model it produces aten::embedding_bag node in the graph,
Add necessary passes in graph mode to help support quantizing it as well

Test Plan:
python test/test_quantization.py TestQuantizeDynamicJitOps.test_embedding_bag

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Sep 1, 2020
@dr-ci
Copy link

dr-ci bot commented Sep 1, 2020

💊 CI failures summary and remediations

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


  • 2/3 failures possibly* introduced in this PR
    • 2/2 non-CircleCI failure(s)
  • 1/3 broken upstream at merge base 6474057 on Sep 04 from 3:37am to 11:28am PDT (13 commits; f8f35fd - 0c2bc4f)

🚧 1 fixed upstream failure:

These were probably caused by upstream breakages that were already fixed.

Please rebase on the viable/strict branch (expand for instructions)

If your commit is newer than viable/strict, you can try basing on an older, stable commit:

git fetch https://github.com/pytorch/pytorch viable/strict
git rebase --onto FETCH_HEAD $(git merge-base origin/master HEAD)

If your commit is older than viable/strict:

git fetch https://github.com/pytorch/pytorch viable/strict
git rebase FETCH_HEAD

Check out the recency history of this "viable master" tracking branch.


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 18 times.

@supriyar supriyar changed the title [quant] Support aten::embedding_bag quantization in graph mode [quant][pyper] Support aten::embedding_bag quantization in graph mode Sep 1, 2020
… graph mode"

Summary:
When we trace the model it produces aten::embedding_bag node in the graph,
Add necessary passes in graph mode to help support quantizing it as well

Test Plan:
python test/test_quantization.py TestQuantizeDynamicJitOps.test_embedding_bag

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
supriyar added a commit that referenced this pull request Sep 1, 2020
Summary:
When we trace the model it produces aten::embedding_bag node in the graph,
Add necessary passes in graph mode to help support quantizing it as well

Test Plan:
python test/test_quantization.py TestQuantizeDynamicJitOps.test_embedding_bag

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 1686d1ba8c2eac1cc750b771f4fd542a473c2bd3
Pull Request resolved: #43989
… graph mode"

Summary:
When we trace the model it produces aten::embedding_bag node in the graph,
Add necessary passes in graph mode to help support quantizing it as well

Test Plan:
python test/test_quantization.py TestQuantizeDynamicJitOps.test_embedding_bag

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
@codecov
Copy link

codecov bot commented Sep 2, 2020

Codecov Report

❗ No coverage uploaded for pull request base (gh/supriyar/170/base@6474057). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@                   Coverage Diff                   @@
##             gh/supriyar/170/base   #43989   +/-   ##
=======================================================
  Coverage                        ?   69.27%           
=======================================================
  Files                           ?      381           
  Lines                           ?    47239           
  Branches                        ?        0           
=======================================================
  Hits                            ?    32724           
  Misses                          ?    14515           
  Partials                        ?        0           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6474057...119b273. Read the comment docs.

Copy link
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.

lg, feel free to wait for @jerryzh168 if a deeper review is needed

@@ -259,10 +260,16 @@ bool matchArgPattern(
bool isWeight(Value* v) {
bool result = matchArgPattern(
v,
AtenFuncArgs(
{{"conv1d", 1}, {"conv2d", 1}, {"conv3d", 1}, {"linear", 1}}),
// ate::embedding_bag(%weight, %input, %offsets, %scale_grad_by_freq,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: aten?

from torch.quantization import QConfigDynamic, PlaceholderObserver
int4_dynamic_qconfig = QConfigDynamic(activation=PlaceholderObserver.with_args(dtype=torch.float,
custom_op_name="embedding_bag_4bit"),
weight=PlaceholderObserver.with_args(custom_op_name="embedding_bag_4bit"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have a placeholder observer for weights?. My understanding is that we can use real observers for 8 bit but not for 4 bit currently. Is that correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We currently use real observers and torchbind classes for eager mode 8-bit embedding quant currently. For graph mode we implemented this initially using the custom prepack ops for PyPer for 8bit and 4bit, to be consistent with C2.
Going forward, in fx we can implement embeddingbag quantization using observers. I feel it is a bit of an overkill to update this code to use observers for 8-bit and placeholder observers for 4-bit. Let me know your thoughts.

… graph mode"

Summary:
When we trace the model it produces aten::embedding_bag node in the graph,
Add necessary passes in graph mode to help support quantizing it as well

Test Plan:
python test/test_quantization.py TestQuantizeDynamicJitOps.test_embedding_bag

Reviewers:

Subscribers:

Tasks:

Tags:

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

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

This pull request has been merged in a0ae416.

@facebook-github-bot facebook-github-bot deleted the gh/supriyar/170/head branch September 9, 2020 14:18
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.

None yet

5 participants