Skip to content

Conversation

@supriyar
Copy link
Contributor

@supriyar supriyar commented Sep 4, 2020

Stack from ghstack:

Summary:
Add quantized module in static quantization namespace. Embedding
quantization requires only weights to be quantized so it is static.
Internally it calls the embedding_bag_byte op with the offsets set corresponding to the
indices.

Future PR will move EmbeddingBag quantization from dynamic to static as well.

Test Plan:
python test/test_quantization.py test_embedding_api

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: D23547384

Summary:
Add quantized module in static quantization namespace. Embedding
quantization requires only weights to be quantized so it is static.
Internally it calls the embedding_bag_byte op with the offsets set corresponding to the
indices.

Future PR will move EmbeddingBag quantization from dynamic to static as well.

Test Plan:
python test/test_quantization.py test_embedding_api

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
@dr-ci
Copy link

dr-ci bot commented Sep 4, 2020

💊 CI failures summary and remediations

As of commit b4a14f7 (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 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.

Summary:
Add quantized module in static quantization namespace. Embedding
quantization requires only weights to be quantized so it is static.
Internally it calls the embedding_bag_byte op with the offsets set corresponding to the
indices.

Future PR will move EmbeddingBag quantization from dynamic to static as well.

Test Plan:
python test/test_quantization.py test_embedding_api

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
Summary:
Add quantized module in static quantization namespace. Embedding
quantization requires only weights to be quantized so it is static.
Internally it calls the embedding_bag_byte op with the offsets set corresponding to the
indices.

Future PR will move EmbeddingBag quantization from dynamic to static as well.

Test Plan:
python test/test_quantization.py test_embedding_api

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
Comment on lines +103 to +104
scales = torch.ones(num_embeddings, dtype=torch.float)
zero_points = torch.ones(num_embeddings, dtype=torch.float)
Copy link
Contributor

Choose a reason for hiding this comment

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

seems like this is the same code as in packed params, perhaps we can only do it once?

def set_weight(self, weight):
# type: (torch.Tensor) -> None
if self.dtype == torch.quint8:
self._packed_weight = torch.ops.quantized.embedding_bag_prepack(weight)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we support per tensor quantization for packed params?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not atm, we only have per-row quantization support with float qparams.

# |--- _packed_weight : Tensor representing weight of EmbeddingPackedParamsBase
# |--- dtype : torch.dtype

def _save_to_state_dict(self, destination, prefix, keep_vars):
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also have a field for bitwidth?

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 can use the tensor dtype to determine the bitwidth, right? Currently it only supports 8bit, but once we add 4-bit qtensor it should be encoded in the dtype.

super(Embedding, self).__init__()
self.num_embeddings = num_embeddings
self.embedding_dim = embedding_dim
self.sparse = sparse
Copy link
Contributor

Choose a reason for hiding this comment

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

For my understanding: What does self.sparse do ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently it doesn't do anything for the quantized module. I'll remove it from here.
It is used in the float module for sparse gradients for weight tensor.

@codecov
Copy link

codecov bot commented Sep 5, 2020

Codecov Report

Merging #44208 into gh/supriyar/174/base will increase coverage by 0.06%.
The diff coverage is 91.54%.

Impacted file tree graph

@@                   Coverage Diff                    @@
##           gh/supriyar/174/base   #44208      +/-   ##
========================================================
+ Coverage                 69.24%   69.31%   +0.06%     
========================================================
  Files                       381      382       +1     
  Lines                     47573    47714     +141     
========================================================
+ Hits                      32943    33072     +129     
- Misses                    14630    14642      +12     
Impacted Files Coverage Δ
torch/quantization/default_mappings.py 100.00% <ø> (ø)
torch/testing/_internal/common_quantization.py 89.58% <90.56%> (+0.04%) ⬆️
torch/nn/quantized/modules/embedding.py 92.04% <92.04%> (ø)
torch/nn/quantized/modules/__init__.py 96.96% <100.00%> (+0.09%) ⬆️

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 3e137ea...b4a14f7. Read the comment docs.

Summary:
Add quantized module in static quantization namespace. Embedding
quantization requires only weights to be quantized so it is static.
Internally it calls the embedding_bag_byte op with the offsets set corresponding to the
indices.

Future PR will move EmbeddingBag quantization from dynamic to static as well.

Test Plan:
python test/test_quantization.py test_embedding_api

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
Summary:
Add quantized module in static quantization namespace. Embedding
quantization requires only weights to be quantized so it is static.
Internally it calls the embedding_bag_byte op with the offsets set corresponding to the
indices.

Future PR will move EmbeddingBag quantization from dynamic to static as well.

Test Plan:
python test/test_quantization.py test_embedding_api

Reviewers:

Subscribers:

Tasks:

Tags:

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

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

This pull request has been merged in 57b87aa.

@facebook-github-bot facebook-github-bot deleted the gh/supriyar/174/head branch September 12, 2020 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants