MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / load_model

Method load_model

lite/src/mge/network_impl.cpp:554–592  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

552}
553
554void NetworkImplDft::load_model(
555 std::shared_ptr<void> model_mem, size_t size,
556 std::unordered_map<std::string, LiteAny> separate_config_map) {
557 if (!m_loader) {
558 m_input_file =
559 mgb::serialization::InputFile::make_mem_proxy(model_mem, size, false);
560 m_format = mgb::serialization::GraphLoader::identify_graph_dump_format(
561 *m_input_file);
562 if (!m_format.valid()) {
563 LITE_THROW("invalid model format");
564 }
565 m_loader = mgb::serialization::GraphLoader::make(
566 std::move(m_input_file), m_format.val());
567 }
568
569 //! applay the user configration to mge model
570 application_config();
571
572 //! config some flag get from json config file
573 if (separate_config_map.find("device_id") != separate_config_map.end()) {
574 set_device_id(separate_config_map["device_id"].safe_cast<int>());
575 }
576 if (separate_config_map.find("number_threads") != separate_config_map.end() &&
577 separate_config_map["number_threads"].safe_cast<uint32_t>() > 1) {
578 set_cpu_threads_number(
579 separate_config_map["number_threads"].safe_cast<uint32_t>());
580 }
581 if (separate_config_map.find("enable_inplace_model") != separate_config_map.end() &&
582 separate_config_map["enable_inplace_model"].safe_cast<bool>()) {
583 set_cpu_inplace_mode();
584 }
585 if (separate_config_map.find("use_tensorrt") != separate_config_map.end() &&
586 separate_config_map["use_tensorrt"].safe_cast<bool>()) {
587 use_tensorrt();
588 }
589
590 m_load_result = m_loader->load(m_load_config, true);
591 configure_after_loaded();
592}
593
594void NetworkImplDft::configure_after_loaded() {
595 modify_exection_policy();

Callers

nothing calls this directly

Calls 5

makeFunction · 0.50
validMethod · 0.45
findMethod · 0.45
endMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected