Browse Source

fix(lite): fix exception bug for load and run

GitOrigin-RevId: 339a343a80
HuaHua404-patch-4
Megvii Engine Team 3 years ago
parent
commit
ba1508e33a
4 changed files with 17 additions and 15 deletions
  1. +1
    -0
      lite/load_and_run/BUILD
  2. +2
    -2
      lite/load_and_run/src/models/model_mdl.cpp
  3. +13
    -12
      lite/load_and_run/src/strategys/strategy_fitting.cpp
  4. +1
    -1
      lite/load_and_run/src/strategys/strategy_normal.cpp

+ 1
- 0
lite/load_and_run/BUILD View File

@@ -5,6 +5,7 @@ cc_library(
hdrs = glob(["src/**/*.h"]), hdrs = glob(["src/**/*.h"]),
includes = ["src"], includes = ["src"],
features = if_opt([ features = if_opt([
"no_exceptions",
"no_rtti", "no_rtti",
]), ]),




+ 2
- 2
lite/load_and_run/src/models/model_mdl.cpp View File

@@ -7,7 +7,7 @@ DECLARE_bool(share_param_mem);
using namespace lar; using namespace lar;


ModelMdl::ModelMdl(const std::string& path) : model_path(path) { ModelMdl::ModelMdl(const std::string& path) : model_path(path) {
mgb_log_warn("creat mdl model use XPU as default comp node");
mgb_log("creat mdl model use XPU as default comp node");
m_load_config.comp_graph = mgb::ComputingGraph::make(); m_load_config.comp_graph = mgb::ComputingGraph::make();
m_load_config.comp_graph->options().graph_opt_level = 0; m_load_config.comp_graph->options().graph_opt_level = 0;
testcase_num = 0; testcase_num = 0;
@@ -16,7 +16,7 @@ ModelMdl::ModelMdl(const std::string& path) : model_path(path) {
void ModelMdl::load_model() { void ModelMdl::load_model() {
//! read dump file //! read dump file
if (share_model_mem) { if (share_model_mem) {
mgb_log_warn("enable share model memory");
mgb_log("enable share model memory");
FILE* fin = fopen(model_path.c_str(), "rb"); FILE* fin = fopen(model_path.c_str(), "rb");
mgb_assert(fin, "failed to open %s: %s", model_path.c_str(), strerror(errno)); mgb_assert(fin, "failed to open %s: %s", model_path.c_str(), strerror(errno));
fseek(fin, 0, SEEK_END); fseek(fin, 0, SEEK_END);


+ 13
- 12
lite/load_and_run/src/strategys/strategy_fitting.cpp View File

@@ -170,7 +170,7 @@ void OptionsTimeProfiler::profile_with_given_options(
auto start = timer.get_msecs(); auto start = timer.get_msecs();
model->run_model(); model->run_model();
model->wait(); model->wait();
mgb_log_warn("warm up %ld time %f ms", i, timer.get_msecs() - start);
mgb_log("warm up %ld time %f ms", i, timer.get_msecs() - start);
} }
}; };
double inference_time = 0.0; double inference_time = 0.0;
@@ -180,7 +180,7 @@ void OptionsTimeProfiler::profile_with_given_options(
model->run_model(); model->run_model();
model->wait(); model->wait();
auto end = timer.get_msecs(); auto end = timer.get_msecs();
mgb_log_warn("run iter %ld time %f ms", i, end - start);
mgb_log("run iter %ld time %f ms", i, end - start);
inference_time += end - start; inference_time += end - start;
mgb_throw_if( mgb_throw_if(
inference_time > TIME_OUT, mgb::TimeoutError, inference_time > TIME_OUT, mgb::TimeoutError,
@@ -213,7 +213,7 @@ void OptionsTimeProfiler::profile_with_given_options(
auto start = timer.get_msecs(); auto start = timer.get_msecs();
config_model_before_runing(); config_model_before_runing();
auto end = timer.get_msecs(); auto end = timer.get_msecs();
mgb_log_warn("config model time %f ms", end - start);
mgb_log("config model time %f ms", end - start);
warm_up(); warm_up();
run_iter(); run_iter();
} }
@@ -228,9 +228,10 @@ void OptionsTimeProfiler::profile_with_given_options(
auto average = inference_time / runtime_param.run_iter; auto average = inference_time / runtime_param.run_iter;
if (exception_state) { if (exception_state) {
average = TIME_OUT; average = TIME_OUT;
printf("out of time (this may be caused by some exception, please checkout the "
"log) when profile option:\n%s\n",
option_code.c_str());
mgb_log_error(
"out of time (this may be caused by some exception, please checkout "
"the log) when profile option:\n%s\n",
option_code.c_str());
} else { } else {
printf("profile option:\n%s\naverage time = %.2f\n", option_code.c_str(), printf("profile option:\n%s\naverage time = %.2f\n", option_code.c_str(),
average); average);
@@ -369,7 +370,7 @@ void UserInfoParser::parse_info(std::shared_ptr<OptionsFastManager>& manager) {
FittingStrategy::FittingStrategy(std::string model_path) { FittingStrategy::FittingStrategy(std::string model_path) {
m_manager = std::make_shared<OptionsFastManager>(); m_manager = std::make_shared<OptionsFastManager>();
m_dumped_model = FLAGS_dump_fitting_model; m_dumped_model = FLAGS_dump_fitting_model;
mgb::set_log_level(mgb::LogLevel::WARN);
mgb::set_log_level(mgb::LogLevel::INFO);
m_options = std::make_shared<OptionMap>(); m_options = std::make_shared<OptionMap>();
m_model_path = model_path; m_model_path = model_path;
auto option_creator_map = OptionFactory::get_Instance().get_option_creator_map(); auto option_creator_map = OptionFactory::get_Instance().get_option_creator_map();
@@ -458,10 +459,10 @@ void FittingStrategy::dump_best_options_with_model() {
model->run_model(); model->run_model();
model->wait(); model->wait();
std::vector<uint8_t> model_data = model->get_model_data(); std::vector<uint8_t> model_data = model->get_model_data();
mgb_log_warn("model_data size=%zu", model_data.size());
mgb_log_warn("json_info size=%zu", json_info.size());
mgb_log_warn("info_algo_policy_data size=%zu", info_algo_policy_data.size());
mgb_log_warn("info_binary_cache_data size=%zu", info_binary_cache_data.size());
mgb_log("model_data size=%zu", model_data.size());
mgb_log("json_info size=%zu", json_info.size());
mgb_log("info_algo_policy_data size=%zu", info_algo_policy_data.size());
mgb_log("info_binary_cache_data size=%zu", info_binary_cache_data.size());
lite::ModelPacker packer( lite::ModelPacker packer(
model_data, m_dumped_model, json_info, info_algo_policy_data, model_data, m_dumped_model, json_info, info_algo_policy_data,
info_binary_cache_data); info_binary_cache_data);
@@ -508,7 +509,7 @@ void FittingStrategy::AutoCleanFile::dump_model() {
model->wait(); model->wait();


std::vector<uint8_t> model_data = model->get_model_data(); std::vector<uint8_t> model_data = model->get_model_data();
mgb_log_warn("dumped model_data size=%zu\n", model_data.size());
mgb_log("dumped model_data size=%zu\n", model_data.size());
auto fp = fopen(m_filename.c_str(), "wb"); auto fp = fopen(m_filename.c_str(), "wb");
fwrite(model_data.data(), 1, model_data.size(), fp); fwrite(model_data.data(), 1, model_data.size(), fp);
fclose(fp); fclose(fp);


+ 1
- 1
lite/load_and_run/src/strategys/strategy_normal.cpp View File

@@ -109,7 +109,7 @@ void NormalStrategy::run_subline() {
//! config model //! config model
config_after_load(); config_after_load();
//! config when running model //! config when running model
mgb_log_warn("run testcase: %zu ", idx);
mgb_log("run testcase: %zu ", idx);
m_runtime_param.stage = RunStage::MODEL_RUNNING; m_runtime_param.stage = RunStage::MODEL_RUNNING;
stage_config_model(); stage_config_model();




Loading…
Cancel
Save