[go: nahoru, domu]

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

add onnxifi quantization support #2617

Merged
merged 4 commits into from
Mar 29, 2019

Conversation

zrphercule
Copy link
Contributor
@zrphercule zrphercule commented Mar 28, 2019

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.

@yinghai
Copy link
Contributor
yinghai commented Mar 28, 2019

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;
Copy link
Contributor

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.

@@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

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

revert this

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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.

@rdzhabarov
Copy link
Contributor

Also, make tests passing ;)

Copy link
Contributor
@bertmaher bertmaher left a 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>
Copy link
Contributor

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.

@bertmaher
Copy link
Contributor

Huh, what's this in the CI builds:

error: no member named 'bias' in 'onnxTensorDescriptorV1'

@yinghai
Copy link
Contributor
yinghai commented Mar 28, 2019

Need to update Foxi tp

@zrphercule
Copy link
Contributor Author

Huh, what's this in the CI builds:

error: no member named 'bias' in 'onnxTensorDescriptorV1'

Yeah because we need to update foxi first. foxi update has already been merged in OSS, we are pushing it in fbcode as well.

@rdzhabarov
Copy link
Contributor

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, please remove

@yinghai
Copy link
Contributor
yinghai commented Mar 29, 2019

houseroad/foxi#9 is merged. Let's update tp in this PR.

Copy link
Contributor
@rdzhabarov rdzhabarov left a 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);
Copy link
Contributor

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);

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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);
}

Copy link
Contributor

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.

Copy link
Contributor Author

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

@zrphercule
Copy link
Contributor Author

Ready to go, anymore comments?

@rdzhabarov
Copy link
Contributor

I'll merge once the format nit fixed.

Copy link
Contributor
@rdzhabarov rdzhabarov left a comment

Choose a reason for hiding this comment

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

Looks great!

@rdzhabarov rdzhabarov merged commit 036071a into pytorch:master Mar 29, 2019
@zrphercule zrphercule deleted the quantization_onnxifi branch March 29, 2019 22:19
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.

None yet

5 participants