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.

quantizer.h 2.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_QUANTIZER_H
  17. #define MINDSPORE_LITE_TOOLS_CONVERTER_QUANTIZER_QUANTIZER_H
  18. #include <unordered_map>
  19. #include <utility>
  20. #include <memory>
  21. #include "schema/inner/model_generated.h"
  22. #include "include/errorcode.h"
  23. #include "ir/func_graph.h"
  24. #include "ir/anf.h"
  25. #include "base/base.h"
  26. #include "src/param_value_lite.h"
  27. #include "tools/converter/converter_flags.h"
  28. namespace mindspore::lite::quant {
  29. using STATUS = int;
  30. enum QuantType {
  31. QuantType_QUANT_NONE = 0,
  32. QuantType_AwareTraining = 1,
  33. QuantType_WeightQuant = 2,
  34. QuantType_PostTraining = 3,
  35. QuantType_MIN = QuantType_QUANT_NONE,
  36. QuantType_MAX = QuantType_PostTraining
  37. };
  38. class Quantizer {
  39. public:
  40. explicit Quantizer(FuncGraphPtr graph) : funcGraph(std::move(graph)) {}
  41. ~Quantizer() = default;
  42. virtual STATUS RemoveFakeQuant();
  43. virtual STATUS GenerateQuantParam();
  44. virtual STATUS DetermineNodeQuantType();
  45. virtual STATUS DoQuantize(FuncGraphPtr func_graph) = 0;
  46. mindspore::lite::converter::Flags flags;
  47. protected:
  48. FuncGraphPtr funcGraph = nullptr;
  49. };
  50. class FbQuantizer {
  51. public:
  52. explicit FbQuantizer(schema::MetaGraphT *graph) : graph(graph) {}
  53. virtual ~FbQuantizer() = default;
  54. virtual STATUS RemoveFakeQuant();
  55. virtual STATUS GenerateQuantParam();
  56. virtual STATUS DetermineNodeQuantType();
  57. virtual STATUS DoQuantize() = 0;
  58. protected:
  59. schema::MetaGraphT *graph = nullptr;
  60. };
  61. } // namespace mindspore::lite::quant
  62. #endif