1 /** 2 * Copyright 2022 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef MINDSPORE_LITE_TOOLS_CONVERTER_QUANTIZER_DYNAMIC_QUANTIZER_H_ 18 #define MINDSPORE_LITE_TOOLS_CONVERTER_QUANTIZER_DYNAMIC_QUANTIZER_H_ 19 20 #include <future> 21 #include <memory> 22 #include <unordered_map> 23 #include <map> 24 #include <list> 25 #include <string> 26 #include <utility> 27 #include <vector> 28 #include <set> 29 #include "tools/converter/quantizer/quantizer.h" 30 #include "tools/converter/quantizer/quantize_util.h" 31 #include "tools/converter/quantizer/quant_params.h" 32 #include "tools/converter/quantizer/quant_strategy.h" 33 #include "tools/converter/preprocess/preprocess_param.h" 34 #include "ir/func_graph.h" 35 #include "ir/anf.h" 36 #include "include/model.h" 37 #include "base/base.h" 38 #include "abstract/dshape.h" 39 #include "src/common/quant_utils.h" 40 41 namespace mindspore::lite::quant { 42 class DynamicQuantizer : public Quantizer { 43 public: DynamicQuantizer(const std::shared_ptr<ConverterPara> & param)44 explicit DynamicQuantizer(const std::shared_ptr<ConverterPara> ¶m) : Quantizer(param) { 45 bit_num_ = param->commonQuantParam.bit_num; 46 activation_channel_weight_layer_ = 47 (param->dynamicQuantParam.quant_strategy == quant::ACTIVATION_CHANNEL_WEIGHT_LAYER); 48 } 49 ~DynamicQuantizer() = default; 50 51 int DoQuantize(FuncGraphPtr func_graph) override; 52 53 private: 54 size_t bit_num_{8}; 55 int quant_max_{127}; 56 int quant_min_{-128}; 57 TypeId type_id_{kNumberTypeInt8}; 58 bool activation_channel_weight_layer_ = false; 59 }; 60 } // namespace mindspore::lite::quant 61 #endif // MINDSPORE_LITE_TOOLS_CONVERTER_QUANTIZER_WEIGHT_QUANTIZER_H_ 62