MCPcopy Create free account
hub / github.com/alibaba/MNN / save

Method save

express/Expr.cpp:1108–1315  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1106blob->dataType = DataType_DT_##TYPE;
1107
1108void Variable::save(const std::vector<VARP>& vars, NetT* dest) {
1109 auto executeOrder = getExecuteOrder(vars);
1110 // Search subgraphs
1111 std::map<std::string, std::shared_ptr<Executor::SubGraph>> subgraphs;
1112 auto exe = ExecutorScope::Current();
1113#ifndef MNN_REDUCE_SIZE
1114 for (int index = 0; index < executeOrder.size(); ++index) {
1115 auto expr = executeOrder[index];
1116 auto op = expr->get();
1117 if (nullptr == op || op->type() != OpType_While) {
1118 continue;
1119 }
1120 if (op->main_type() != OpParameter_WhileParam) {
1121 continue;
1122 }
1123 auto whileParam = op->main_as_WhileParam();
1124 auto name = whileParam->body_graph()->str();
1125 auto subgraph = exe->findSubGraph(name);
1126 if (nullptr == subgraph) {
1127#ifdef MNN_EXPRESS_ERROR_REPORT
1128 MNN_ERROR("Variable::save: Invalid subgraph name: %s\n", name.c_str());
1129#endif
1130 continue;
1131 }
1132 MNN_ASSERT(subgraph->depends.size() == 0);
1133 subgraphs.insert(std::make_pair(name, subgraph));
1134 }
1135 // Save Subgraphs
1136 dest->subgraphs.clear();
1137 for (auto& graphIter : subgraphs) {
1138 // Copy Subgraph info
1139 flatbuffers::FlatBufferBuilder builder;
1140 builder.Finish(MNN::SubGraphProto::Pack(builder, graphIter.second->info.get()));
1141 std::unique_ptr<MNN::SubGraphProtoT> subgraph(flatbuffers::GetRoot<MNN::SubGraphProto>(builder.GetBufferPointer())->UnPack());
1142 dest->subgraphs.emplace_back(std::move(subgraph));
1143 }
1144#endif
1145 // Get Expr - TensorOffset Map
1146 std::map<EXPRP, int> varIndexInfo;
1147 {
1148 int tensorOffset = 0;
1149 for (int i=0; i<executeOrder.size(); ++i) {
1150 auto expr = executeOrder[i];
1151 auto outputSize = executeOrder[i]->outputSize();
1152 varIndexInfo[expr] = tensorOffset;
1153 tensorOffset += outputSize;
1154 }
1155 dest->tensorName.resize(tensorOffset);
1156 }
1157
1158 // Create All Op
1159 for (int index = 0; index < executeOrder.size(); ++index) {
1160 auto expr = executeOrder[index];
1161 auto mOp = expr->get();
1162 std::unique_ptr<OpT> op;
1163 if (nullptr != mOp) {
1164 op.reset(mOp->UnPack());
1165 } else {

Callers 8

train_funcFunction · 0.45
demoFunction · 0.45
grad_loss.pyFile · 0.45
test_save.pyFile · 0.45
grad_test.pyFile · 0.45
train_funcFunction · 0.45
demoFunction · 0.45
saveFunction · 0.45

Calls 15

convertFormatFunction · 0.85
EnumNameOpTypeFunction · 0.85
numberToStringFunction · 0.85
writeFunction · 0.85
findSubGraphMethod · 0.80
AsInputMethod · 0.80
createFunction · 0.50
saveFunction · 0.50
sizeMethod · 0.45
getMethod · 0.45
typeMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected