-
Notifications
You must be signed in to change notification settings - Fork 683
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
add onnxifi quantization support #2617
Conversation
Please fix your summary. |
@@ -40,54 +40,66 @@ inline llvm::Error loadWeight(const onnxTensorDescriptorV1 &in, Tensor *T) { | |||
RETURN_ERR("Only support CPU memory tensors."); | |||
} | |||
|
|||
// This is a caffe2 offset shift. | |||
const int32_t OFFSETSHIFT = 128; |
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.
would be good to have this in one place. C2ModelLoader.cpp has the same.
lib/Importer/Caffe2ModelLoader.cpp
Outdated
@@ -1179,8 +1219,8 @@ llvm::Error Caffe2ModelLoader::loadWeight(const caffe2::OperatorDef &op) { | |||
arg { | |||
name: "values" | |||
s: | |||
"\000\377\152\232\115\072\000\000\200\077\000\377\050\132\215\073\063\063\023\100\000\377\314\063\232\073\000\000\220\100" | |||
} | |||
"\000\377\152\232\115\072\000\000\200\077\000\377\050\132\215\073\063\063\023\100\000\377\314\063\232\073\000\000\220\100" |
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.
revert this
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 can be reverted by the clang format fix tool in Glow?
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.
@zrphercule that was not reverted.
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 can be reverted by the clang format fix tool in Glow?
it's inside a comment, not sure if it can be fixed by clang format.
Also, make tests passing ;) |
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.
Looking good to me, just needs to address @rdzhabarov's comments.
@@ -1047,38 +1066,59 @@ llvm::Error Caffe2ModelLoader::loadOperator(const caffe2::OperatorDef &op) { | |||
|
|||
RETURN_ERR(unexpectedNodeErrorMessage(op, "Unsupported operator.")); | |||
} | |||
template <class TensorProtoType> |
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.
nitpick, add a blank line here before template
to separate top-level defs.
Huh, what's this in the CI builds:
|
Need to update Foxi tp |
Yeah because we need to update foxi first. foxi update has already been merged in OSS, we are pushing it in fbcode as well. |
You need to update sha of 'foxi' submodule used in glow to make it work |
for (size_t i = 0; i < TH.size(); ++i) { | ||
constexpr uint8_t OFFSETSHIFT = 128; | ||
TH.raw(i) = static_cast<int8_t>((((uint8_t)data[i]) - OFFSETSHIFT)); | ||
if (in.is_quantized == 1) { |
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 is this not boolean?
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.
@rdzhabarov because onnxifi is C API, and it is an uint8 instead of bool (Actually it is supposed to be char at first...)
} else if (in.dataType == ONNXIFI_DATATYPE_UINT64 || | ||
in.dataType == ONNXIFI_DATATYPE_INT64) { | ||
const bool inDataSigned = in.dataType == ONNXIFI_DATATYPE_INT64; | ||
(void)inDataSigned; |
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.
inDataSigned seems to be used later, why this?
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.
hmmm that's interesting, I didnt write this, the change here is only lint problem.
But I am wondering as well, this seems can be removed, no objection?
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.
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.
yes, please remove
houseroad/foxi#9 is merged. Let's update tp in this PR. |
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.
LGTM. Please, address pending comments.
} | ||
|
||
if (in.data_type() == caffe2::TensorProto::UINT8) { | ||
T->reset(ElemKind::Int8QTy, dim, in.scale(), in.bias() - OFFSETSHIFT); |
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.
what is the use case for what's checked in line 72?
else if (in.data_type() == caffe2::TensorProto::UINT8) {
T->reset(ElemKind::Int8QTy, dim, 1.0, 0);
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.
@rdzhabarov These are two different branches, in #72 we assume the incoming tensor is a non-quantized tensor, and only use Int8QTy to represent a int8 tensor. Here we know it is a quantized tensor (by knowing protobuf is a QTensorProto), we treated it like real quantized tensor.
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.
linked PR seems to be unrelated.
What is the case when tensor is int8 and non quantized?
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.
oh it is not the pr I want to link, it is the 72nd line in this file...
I think you have the point, right now glow takes all int8 input as Int8QTy. do we have normal int8ty as well?
@@ -60,7 +60,6 @@ llvm::Error setTensorType(const caffe2::TensorProto &in, Tensor *T) { | |||
} | |||
dim.push_back(d); | |||
} | |||
|
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.
sorry, not your change, but
line 46 does not have a correct comment.
Could you fix [-128, 127] and <=255.
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.
I wont bother having one more line of credit lol
Ready to go, anymore comments? |
I'll merge once the format nit fixed. |
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.
Looks great!
Description:
This the onnxifi quantization support in glow side, we accept two quantized tensors, intQ32ty and int8Qty.
Testing:
Only internal test is supported now, using resnet50_quantized.