1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 #ifndef TENSORFLOW_COMPILER_MLIR_LITE_QUANTIZATION_LITE_QUANTIZE_MODEL_H_ 16 #define TENSORFLOW_COMPILER_MLIR_LITE_QUANTIZATION_LITE_QUANTIZE_MODEL_H_ 17 18 #include <memory> 19 #include <string> 20 #include <unordered_set> 21 22 #include "absl/container/flat_hash_set.h" 23 #include "tensorflow/lite/core/api/error_reporter.h" 24 #include "tensorflow/lite/model.h" 25 #include "tensorflow/lite/schema/schema_generated.h" 26 27 namespace mlir { 28 namespace lite { 29 30 using StringSet = absl::flat_hash_set<std::string>; 31 32 // Quantize the `input_model` and write the result to a flatbuffer `builder`. 33 // The `input_type`, `output_type` and `inference_type` can be 34 // float32/qint8/int8/int16. 35 // Return partially quantized model if `fully_quantize` is false. 36 // When `verify_numeric` is true, the model will have it's original float ops 37 // and NumericVerify ops to compare output values from the quantized and float 38 // ops. When `legacy_float_scale` is true, the quantizer will use float scale 39 // instead of double, and call TOCO's quantization routines to maintain 40 // bit-exactness of the values with the TOCO quantizer. 41 TfLiteStatus QuantizeModel( 42 const tflite::ModelT& input_model, const tflite::TensorType& input_type, 43 const tflite::TensorType& output_type, 44 const tflite::TensorType& inference_type, 45 const std::unordered_set<std::string>& operator_names, 46 bool disable_per_channel, bool fully_quantize, 47 flatbuffers::FlatBufferBuilder* builder, 48 tflite::ErrorReporter* error_reporter, bool verify_numeric = false, 49 bool whole_model_verify = false, bool legacy_float_scale = true, 50 const StringSet& denylisted_ops = {}, 51 const StringSet& denylisted_nodes = {}); 52 } // namespace lite 53 } // namespace mlir 54 55 #endif // TENSORFLOW_COMPILER_MLIR_LITE_QUANTIZATION_LITE_QUANTIZE_MODEL_H_ 56