You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

weight_quantizer.h 1.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * Copyright 2020 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. #ifndef MINDSPORE_LITE_TOOLS_CONVERTER_QUANTIZER_WEIGHT_QUANTIZER_H
  17. #define MINDSPORE_LITE_TOOLS_CONVERTER_QUANTIZER_WEIGHT_QUANTIZER_H
  18. #include <memory>
  19. #include <list>
  20. #include <string>
  21. #include "tools/converter/quantizer/quantizer.h"
  22. #include "tools/converter/quantizer/quantize_util.h"
  23. #include "ir/func_graph.h"
  24. #include "ir/anf.h"
  25. #include "include/model.h"
  26. #include "base/base.h"
  27. #include "abstract/dshape.h"
  28. namespace mindspore {
  29. namespace lite {
  30. namespace quant {
  31. class WeightQuantizer : public Quantizer {
  32. public:
  33. WeightQuantizer(FuncGraphPtr graph, const std::string &weightSize, const std::string &covWeightChannelThreshold,
  34. const std::string &bitNum);
  35. ~WeightQuantizer() = default;
  36. STATUS DoQuantize(FuncGraphPtr funcGraph) override;
  37. STATUS DoConvQuantize(const std::list<CNodePtr> &nodes);
  38. STATUS DoMulQuantize(const std::list<CNodePtr> &nodes);
  39. static STATUS WeightQuantInputCheck(const converter::Flags *config);
  40. static bool IsPosNum(const std::string &str);
  41. int quant_max;
  42. int quant_min;
  43. TypeId type_id{kTypeUnknown};
  44. private:
  45. std::unique_ptr<QuantStrategy> mStrategy;
  46. size_t bitNum;
  47. };
  48. } // namespace quant
  49. } // namespace lite
  50. } // namespace mindspore
  51. #endif