MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle-Lite / LoadModelNaive

Function LoadModelNaive

lite/model_parser/model_parser.cc:646–698  ·  view source on GitHub ↗

////////////////////////////////////////////////////////////////////////// Old Method of loading and saving model, before V2.3.0 */ Warning: this is an old inference and will be abandened in release/v3.0.0 */ //////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

644/* Warning: this is an old inference and will be abandened in release/v3.0.0 */
645///////////////////////////////////////////////////////////////////////////////
646void LoadModelNaive(const std::string &model_dir,
647 Scope *scope,
648 cpp::ProgramDesc *cpp_prog,
649 bool combined) {
650 CHECK(cpp_prog);
651 CHECK(scope);
652 cpp_prog->ClearBlocks();
653
654 LOG(WARNING)
655 << "WARNING: MobileConfig::set_model_dir and "
656 "MobileConfig::set_model_buffer are deprecated APIs "
657 "and will be removed in latter release. \n"
658 " MobileConfig::set_model_from_file(const std::string& model_file)"
659 " and MobileConfig::set_model_from_buffer(const std::string& "
660 "model_buffer) are recommended.";
661 // Load model
662 const std::string prog_path = model_dir + "/__model__.nb";
663 naive_buffer::BinaryTable table;
664 table.LoadFromFile(prog_path);
665 naive_buffer::proto::ProgramDesc nb_proto_prog(&table);
666 nb_proto_prog.Load();
667 naive_buffer::ProgramDesc nb_prog(&nb_proto_prog);
668
669 // Transform to cpp::ProgramDesc
670 TransformProgramDescAnyToCpp(nb_prog, cpp_prog);
671
672 // Load Params
673 // NOTE: Only main block be used now.
674 if (combined) {
675 const std::string combined_params_path = model_dir + "/param.nb";
676 LoadCombinedParamsNaive(combined_params_path, 0, scope, *cpp_prog, false);
677 } else {
678 auto &prog = *cpp_prog;
679 auto &main_block_desc = *prog.GetBlock<cpp::BlockDesc>(0);
680 for (size_t i = 0; i < main_block_desc.VarsSize(); ++i) {
681 auto &var = *main_block_desc.GetVar<cpp::VarDesc>(i);
682 if (!IsParamVarDesc(var)) continue;
683
684 std::string file_path = model_dir + "/" + var.Name() + ".nb";
685 VLOG(4) << "reading weight " << var.Name();
686
687 switch (var.GetType()) {
688 case VarDescAPI::Type::LOD_TENSOR:
689 LoadParamNaive(file_path, scope, var.Name());
690 break;
691 default:
692 CHECK(false) << "unknown weight type";
693 }
694 }
695 }
696
697 VLOG(4) << "Load naive buffer model in '" << model_dir << "' successfully";
698}
699
700void LoadModelNaiveFromMemory(const std::string &model_buffer,
701 const std::string &param_buffer,

Callers 1

BuildMethod · 0.85

Calls 9

LoadCombinedParamsNaiveFunction · 0.85
LoadParamNaiveFunction · 0.85
LoadFromFileMethod · 0.80
LoadMethod · 0.60
IsParamVarDescFunction · 0.50
ClearBlocksMethod · 0.45
VarsSizeMethod · 0.45
NameMethod · 0.45
GetTypeMethod · 0.45

Tested by

no test coverage detected