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
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6a3f47b
[quant] Support aten::embedding_bag quantization in graph mode
supriyar 9d51358
Update on "[quant][pyper] Support aten::embedding_bag quantization in…
supriyar 7960f7b
Update on "[quant][pyper] Support aten::embedding_bag quantization in…
supriyar 119b273
Update on "[quant][pyper] Support aten::embedding_bag quantization in…
supriyar File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ std::vector<std::string> _dynamic_quantizable_call_funcs = { | |
|
||
std::vector<std::string> _dynamic_quantizable_aten_funcs = { | ||
"linear", | ||
"embedding_bag", | ||
}; | ||
|
||
// These are the prim::CallFunctions that doesn't require observation and | ||
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
// %mode_enum, %sparse, %per_sample_weights, %include_last_offset) | ||
AtenFuncArgs({{"conv1d", 1}, | ||
{"conv2d", 1}, | ||
{"conv3d", 1}, | ||
{"linear", 1}, | ||
{"embedding_bag", 0}}), | ||
// embedding_bag - prim::CallFunction(%func, %input.1, %weight, | ||
// %offsets.1, %7, %8, %9, %10, %9, %per_sample_weights.1, %13) | ||
// %offsets.1, %max_norm, %norm_type, %scale_grad_by_freq, %mode, %sparse, | ||
// %per_sample_weights.1, %include_last_offset) | ||
CallFuncArgs({{"linear", 2}, {"embedding_bag", 2}})); | ||
return result; | ||
} | ||
|
@@ -276,6 +283,14 @@ bool isBiasOfConvOrLinear(Value* v) { | |
return result; | ||
} | ||
|
||
bool isEmbeddingBagNonInput(Value* v) { | ||
bool result = matchArgPattern( | ||
v, | ||
AtenFuncArgs({{"embedding_bag", 2}, {"embedding_bag", 6}}), | ||
CallFuncArgs({})); | ||
return result; | ||
} | ||
|
||
c10::optional<Use> getClampScalarInputUse(Value* v) { | ||
for (const auto& use : v->uses()) { | ||
for (const auto& aten_func : _clamp_funcs) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.