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.

model_options.cpp 3.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * \file lite/load_and_run/src/options/model_options.cpp
  3. *
  4. * This file is part of MegEngine, a deep learning framework developed by
  5. * Megvii.
  6. *
  7. * \copyright Copyright (c) 2020-2021 Megvii Inc. All rights reserved.
  8. */
  9. #include "model_options.h"
  10. #include "device_options.h"
  11. #include "lite/pack_model.h"
  12. #include "megbrain/opr/search_policy/algo_chooser.h"
  13. #include "megbrain/utils/infile_persistent_cache.h"
  14. #include "misc.h"
  15. #include "models/model_lite.h"
  16. #include "models/model_mdl.h"
  17. #include "network_impl_base.h"
  18. namespace lar {
  19. template <typename ModelImpl>
  20. void PackModelOption::config_model_internel(
  21. RuntimeParam& runtime_param, std::shared_ptr<ModelImpl> model) {
  22. if (runtime_param.stage == RunStage::AFTER_MODEL_RUNNING) {
  23. lite::ModelPacker packer(
  24. model->get_model_path(), packed_model_dump, pack_info_json, pack_cache,
  25. pack_binary_cache);
  26. packer.set_header(pack_info_cryption, pack_model_cryption, is_fast_run_cache);
  27. packer.pack_model();
  28. }
  29. }
  30. } // namespace lar
  31. using namespace lar;
  32. ////////////////////// PackModel options ////////////////////////
  33. PackModelOption::PackModelOption() {
  34. m_option_name = "pack_model";
  35. if (!FLAGS_packed_model_dump.empty())
  36. packed_model_dump = FLAGS_packed_model_dump;
  37. if (!FLAGS_pack_info_json.empty())
  38. pack_info_json = FLAGS_pack_info_json;
  39. if (!FLAGS_pack_cache.empty())
  40. pack_cache = FLAGS_pack_cache;
  41. if (!FLAGS_pack_info_cryption.empty())
  42. pack_info_cryption = FLAGS_pack_info_cryption;
  43. if (!FLAGS_pack_model_cryption.empty())
  44. pack_model_cryption = FLAGS_pack_model_cryption;
  45. }
  46. bool PackModelOption::is_valid() {
  47. return !FLAGS_packed_model_dump.empty();
  48. }
  49. std::shared_ptr<OptionBase> PackModelOption::create_option() {
  50. static std::shared_ptr<PackModelOption> option(new PackModelOption);
  51. if (PackModelOption::is_valid()) {
  52. return std::static_pointer_cast<OptionBase>(option);
  53. } else {
  54. return nullptr;
  55. }
  56. }
  57. void PackModelOption::config_model(
  58. RuntimeParam& runtime_param, std::shared_ptr<ModelBase> model) {
  59. CONFIG_MODEL_FUN;
  60. }
  61. ////////////////////// PackModel gflags ////////////////////////
  62. DEFINE_string(packed_model_dump, "", "The output file path of packed model.");
  63. DEFINE_string(
  64. pack_info_json, "",
  65. "An encrypted or not encrypted json format file to pack into the model.");
  66. DEFINE_string(pack_cache, "", "Pack the fastrun cache or algo policy into the model.");
  67. DEFINE_string(
  68. pack_info_cryption, "NONE",
  69. "The info data encryption method name, this is used to find the right "
  70. "decryption method. --pack-info-cryption [ AES_default | RC4_default | "
  71. "SIMPLE_FAST_RC4_default ], default is NONE. See "
  72. "https://megengine.megvii-inc.com/user-guide/deployment/lite/advance/"
  73. "pack-lite-model.html for more details.");
  74. DEFINE_string(
  75. pack_model_cryption, "NONE",
  76. "The model encryption method name, this is used to find the right decryption "
  77. "method. --pack-model-cryption [ AES_default | RC4_default | "
  78. "SIMPLE_FAST_RC4_default ], default is NONE. See "
  79. "https://megengine.megvii-inc.com/user-guide/deployment/lite/advance/"
  80. "pack-lite-model.html for more details.");
  81. REGIST_OPTION_CREATOR(pack_model, lar::PackModelOption::create_option);