| 83 | } |
| 84 | |
| 85 | void 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 | |
| 122 | void TensorToStream(std::ostream &os, const lite::Tensor &tensor) { |
| 123 | LITE_MODEL_INTERFACE_NOT_IMPLEMENTED; |