forked from mindspore-Ecosystem/mindspore
!24363 [MS][LITE] add quant params check
Merge pull request !24363 from jianghui58/quant_check_mas
This commit is contained in:
commit
ad88cfcafb
|
@ -79,16 +79,19 @@ int ArithmeticInt8CPUKernel::Init() {
|
||||||
|
|
||||||
auto *input0_tensor = in_tensors_.at(0);
|
auto *input0_tensor = in_tensors_.at(0);
|
||||||
auto in0_quant_args = input0_tensor->quant_params();
|
auto in0_quant_args = input0_tensor->quant_params();
|
||||||
|
CHECK_LESS_RETURN(in0_quant_args.size(), 1);
|
||||||
quant_args_.in0_args_.scale_ = in0_quant_args.front().scale;
|
quant_args_.in0_args_.scale_ = in0_quant_args.front().scale;
|
||||||
quant_args_.in0_args_.zp_ = in0_quant_args.front().zeroPoint;
|
quant_args_.in0_args_.zp_ = in0_quant_args.front().zeroPoint;
|
||||||
|
|
||||||
auto *input1_tensor = in_tensors_.at(1);
|
auto *input1_tensor = in_tensors_.at(1);
|
||||||
auto in1_quant_args = input1_tensor->quant_params();
|
auto in1_quant_args = input1_tensor->quant_params();
|
||||||
|
CHECK_LESS_RETURN(in1_quant_args.size(), 1);
|
||||||
quant_args_.in1_args_.scale_ = in1_quant_args.front().scale;
|
quant_args_.in1_args_.scale_ = in1_quant_args.front().scale;
|
||||||
quant_args_.in1_args_.zp_ = in1_quant_args.front().zeroPoint;
|
quant_args_.in1_args_.zp_ = in1_quant_args.front().zeroPoint;
|
||||||
|
|
||||||
auto *out_tensor = out_tensors_.at(kOutputIndex);
|
auto *out_tensor = out_tensors_.at(kOutputIndex);
|
||||||
auto out_quant_args = out_tensor->quant_params();
|
auto out_quant_args = out_tensor->quant_params();
|
||||||
|
CHECK_LESS_RETURN(out_quant_args.size(), 1);
|
||||||
quant_args_.out_args_.scale_ = out_quant_args.front().scale;
|
quant_args_.out_args_.scale_ = out_quant_args.front().scale;
|
||||||
quant_args_.out_args_.zp_ = out_quant_args.front().zeroPoint;
|
quant_args_.out_args_.zp_ = out_quant_args.front().zeroPoint;
|
||||||
if (!InferShapeDone()) {
|
if (!InferShapeDone()) {
|
||||||
|
|
|
@ -32,11 +32,13 @@ int ArithmeticSelfInt8CPUKernel::Init() {
|
||||||
auto *input_tensor = in_tensors_.at(kInputIndex);
|
auto *input_tensor = in_tensors_.at(kInputIndex);
|
||||||
CHECK_NULL_RETURN(input_tensor);
|
CHECK_NULL_RETURN(input_tensor);
|
||||||
auto in_quant_args = input_tensor->quant_params();
|
auto in_quant_args = input_tensor->quant_params();
|
||||||
|
CHECK_LESS_RETURN(in_quant_args.size(), 1);
|
||||||
para_->quant_arg_.in_args_.scale_ = in_quant_args.front().scale;
|
para_->quant_arg_.in_args_.scale_ = in_quant_args.front().scale;
|
||||||
para_->quant_arg_.in_args_.zp_ = in_quant_args.front().zeroPoint * (-1);
|
para_->quant_arg_.in_args_.zp_ = in_quant_args.front().zeroPoint * (-1);
|
||||||
|
|
||||||
auto *out_tensor = out_tensors_.at(kOutputIndex);
|
auto *out_tensor = out_tensors_.at(kOutputIndex);
|
||||||
auto out_quant_args = out_tensor->quant_params();
|
auto out_quant_args = out_tensor->quant_params();
|
||||||
|
CHECK_LESS_RETURN(out_quant_args.size(), 1);
|
||||||
para_->quant_arg_.out_args_.scale_ = out_quant_args.front().scale;
|
para_->quant_arg_.out_args_.scale_ = out_quant_args.front().scale;
|
||||||
para_->quant_arg_.out_args_.zp_ = out_quant_args.front().zeroPoint;
|
para_->quant_arg_.out_args_.zp_ = out_quant_args.front().zeroPoint;
|
||||||
|
|
||||||
|
|
|
@ -94,9 +94,11 @@ int ResizeInt8CPUKernel::Init() {
|
||||||
return RET_ERROR;
|
return RET_ERROR;
|
||||||
}
|
}
|
||||||
auto input = in_tensors_.at(0);
|
auto input = in_tensors_.at(0);
|
||||||
|
CHECK_LESS_RETURN(input->quant_params().size(), 1);
|
||||||
quant_in_->zp_ = input->quant_params().front().zeroPoint;
|
quant_in_->zp_ = input->quant_params().front().zeroPoint;
|
||||||
quant_in_->scale_ = input->quant_params().front().scale;
|
quant_in_->scale_ = input->quant_params().front().scale;
|
||||||
auto output = out_tensors_.at(0);
|
auto output = out_tensors_.at(0);
|
||||||
|
CHECK_LESS_RETURN(output->quant_params().size(), 1);
|
||||||
quant_out_->zp_ = output->quant_params().front().zeroPoint;
|
quant_out_->zp_ = output->quant_params().front().zeroPoint;
|
||||||
quant_out_->scale_ = output->quant_params().front().scale;
|
quant_out_->scale_ = output->quant_params().front().scale;
|
||||||
|
|
||||||
|
|
|
@ -172,6 +172,9 @@ int ScaleInt8CPUKernel::InitQuantArgs() {
|
||||||
auto input = in_tensors_.at(0);
|
auto input = in_tensors_.at(0);
|
||||||
auto scale = in_tensors_.at(1);
|
auto scale = in_tensors_.at(1);
|
||||||
auto output = out_tensors_.at(0);
|
auto output = out_tensors_.at(0);
|
||||||
|
CHECK_LESS_RETURN(input->quant_params().size(), 1);
|
||||||
|
CHECK_LESS_RETURN(scale->quant_params().size(), 1);
|
||||||
|
CHECK_LESS_RETURN(output->quant_params().size(), 1);
|
||||||
auto input_scale = input->quant_params().front().scale;
|
auto input_scale = input->quant_params().front().scale;
|
||||||
auto scale_scale = scale->quant_params().front().scale;
|
auto scale_scale = scale->quant_params().front().scale;
|
||||||
auto output_scale = output->quant_params().front().scale;
|
auto output_scale = output->quant_params().front().scale;
|
||||||
|
@ -188,6 +191,7 @@ int ScaleInt8CPUKernel::InitQuantArgs() {
|
||||||
|
|
||||||
if (in_tensors_.size() == kScaleBiasInputsSize) {
|
if (in_tensors_.size() == kScaleBiasInputsSize) {
|
||||||
auto offset = in_tensors_.at(kOffsetIndex);
|
auto offset = in_tensors_.at(kOffsetIndex);
|
||||||
|
CHECK_LESS_RETURN(offset->quant_params().size(), 1);
|
||||||
auto offset_scale = offset->quant_params().front().scale;
|
auto offset_scale = offset->quant_params().front().scale;
|
||||||
scale_param_->offset_zp_ = offset->quant_params().front().zeroPoint;
|
scale_param_->offset_zp_ = offset->quant_params().front().zeroPoint;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue