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

Function LoadCombinedParamsPb

lite/model_parser/model_parser.cc:85–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85void LoadCombinedParamsPb(const std::string &path,
86 lite::Scope *scope,
87 const cpp::ProgramDesc &cpp_prog,
88 const lite_api::CxxModelBuffer &model_buffer) {
89 CHECK(scope) << "The input argument scope is nullptr.";
90 auto &prog = cpp_prog;
91 auto &main_block_desc = *prog.GetBlock<cpp::BlockDesc>(0);
92
93 // Get vars
94 std::vector<std::string> paramlist;
95 for (size_t i = 0; i < main_block_desc.VarsSize(); ++i) {
96 auto &var = *main_block_desc.GetVar<cpp::VarDesc>(i);
97 if (!IsPersistable(var)) continue;
98 paramlist.push_back(var.Name());
99 }
100 std::stable_sort(paramlist.begin(), paramlist.end());
101
102 std::unique_ptr<model_parser::ByteReader> reader;
103 if (!model_buffer.is_empty()) {
104 reader.reset(
105 new model_parser::StringBufferReader(model_buffer.get_params()));
106 } else {
107 reader.reset(new model_parser::BinaryFileReader(path));
108 }
109 model_parser::pb::LoDTensorDeserializer loader;
110 if (!paramlist.empty()) {
111 CHECK(reader->length())
112 << "The model needs weights but the weight file is not existed.";
113 }
114 for (size_t i = 0; i < paramlist.size(); ++i) {
115 auto *var = scope->Var(paramlist[i]);
116 LoadLoDTensor(&loader, reader.get(), var);
117 }
118 CHECK(reader->ReachEnd()) << "You are not allowed to load partial data via"
119 << " LoadCombinedParamsPb, use LoadParam instead.";
120}
121
122void TensorToStream(std::ostream &os, const lite::Tensor &tensor) {
123 LITE_MODEL_INTERFACE_NOT_IMPLEMENTED;

Callers 2

LoadNonCombinedParamsPbFunction · 0.85
LoadModelPbFunction · 0.85

Calls 14

IsPersistableFunction · 0.85
LoadLoDTensorFunction · 0.85
is_emptyMethod · 0.80
VarsSizeMethod · 0.45
NameMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
resetMethod · 0.45
emptyMethod · 0.45
lengthMethod · 0.45
sizeMethod · 0.45
VarMethod · 0.45

Tested by

no test coverage detected