From 22f6939be9cc23d14610c3e21fd30f7345c1b125 Mon Sep 17 00:00:00 2001 From: Feng Liu Date: Mon, 22 Jun 2020 09:43:32 -0700 Subject: [PATCH] Apply default quantization parameter before quantization pass By this order, the default quantization parameter is only applied on the activations and the weight quantization parameter will use the parameters from the weight content. PiperOrigin-RevId: 317672365 Change-Id: Ib7b02ae19105db124721242ea51a5ccc1d5aa68e --- tensorflow/compiler/mlir/lite/tf_tfl_passes.cc | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/tensorflow/compiler/mlir/lite/tf_tfl_passes.cc b/tensorflow/compiler/mlir/lite/tf_tfl_passes.cc index fed2896035b..3fa2eae42f2 100644 --- a/tensorflow/compiler/mlir/lite/tf_tfl_passes.cc +++ b/tensorflow/compiler/mlir/lite/tf_tfl_passes.cc @@ -39,22 +39,18 @@ namespace tensorflow { void AddQuantizationPasses(const mlir::TFL::QuantizationSpecs& quant_specs, mlir::OpPassManager* pass_manager) { pass_manager->addPass(mlir::TFL::CreatePrepareQuantizePass(quant_specs)); - pass_manager->addPass(mlir::TFL::CreateQuantizePass()); - bool emit_quant_adaptor_ops = - quant_specs.inference_type != quant_specs.inference_input_type; - pass_manager->addPass( - mlir::TFL::CreatePostQuantizePass(emit_quant_adaptor_ops)); - if (quant_specs.default_ranges.first.hasValue() || quant_specs.default_ranges.second.hasValue()) { pass_manager->addPass(mlir::TFL::CreateDefaultQuantParamsPass( quant_specs.default_ranges.first.getValueOr(0.0), quant_specs.default_ranges.second.getValueOr(0.0), quant_specs.IsSignedInferenceType())); - pass_manager->addPass(mlir::TFL::CreateQuantizePass()); - pass_manager->addPass( - mlir::TFL::CreatePostQuantizePass(emit_quant_adaptor_ops)); } + pass_manager->addPass(mlir::TFL::CreateQuantizePass()); + bool emit_quant_adaptor_ops = + quant_specs.inference_type != quant_specs.inference_input_type; + pass_manager->addPass( + mlir::TFL::CreatePostQuantizePass(emit_quant_adaptor_ops)); } void AddTFToTFLConversionPasses(const mlir::TFL::PassConfig& pass_config,