| 1449 | } |
| 1450 | |
| 1451 | void FleetWrapper::LoadFromPaddleModel(Scope& scope, |
| 1452 | const uint64_t table_id, |
| 1453 | std::vector<std::string> var_list, |
| 1454 | std::string model_path, |
| 1455 | std::string model_proto_file, |
| 1456 | std::vector<std::string> table_var_list, |
| 1457 | bool load_combine) { |
| 1458 | #ifdef PADDLE_WITH_PSLIB |
| 1459 | // load ProgramDesc from model file |
| 1460 | auto read_proto_func = [](const std::string& filename) -> ProgramDesc { |
| 1461 | std::string contents; |
| 1462 | std::ifstream fin(filename, std::ios::in | std::ios::binary); |
| 1463 | fin.seekg(0, std::ios::end); |
| 1464 | contents.resize(fin.tellg()); |
| 1465 | fin.seekg(0, std::ios::beg); |
| 1466 | fin.read(&contents[0], contents.size()); |
| 1467 | fin.close(); |
| 1468 | ProgramDesc program_desc(contents); |
| 1469 | return program_desc; |
| 1470 | }; |
| 1471 | const ProgramDesc old_program = read_proto_func(model_proto_file); |
| 1472 | Scope* old_scope = new Scope(); |
| 1473 | auto& old_block = old_program.Block(0); |
| 1474 | auto place = phi::CPUPlace(); |
| 1475 | std::vector<std::string> old_param_list; |
| 1476 | |
| 1477 | for (auto& t : var_list) { |
| 1478 | VarDesc* old_var_desc = old_block.FindVar(t); |
| 1479 | if (old_var_desc == nullptr) { |
| 1480 | continue; |
| 1481 | } |
| 1482 | // init variable in scope |
| 1483 | Variable* old_var = old_scope->Var(old_var_desc->Name()); |
| 1484 | InitializeVariable(old_var, old_var_desc->GetType()); |
| 1485 | old_param_list.push_back(t); |
| 1486 | if (load_combine) { |
| 1487 | continue; |
| 1488 | } |
| 1489 | // load variable from model |
| 1490 | paddle::framework::AttributeMap attrs; |
| 1491 | attrs.insert({"file_path", model_path + "/" + old_var_desc->Name()}); |
| 1492 | auto load_op = paddle::framework::OpRegistry::CreateOp( |
| 1493 | "load", {}, {{"Out", {old_var_desc->Name()}}}, attrs); |
| 1494 | load_op->Run(*old_scope, place); |
| 1495 | } |
| 1496 | |
| 1497 | if (load_combine) { |
| 1498 | std::sort(old_param_list.begin(), old_param_list.end()); |
| 1499 | paddle::framework::AttributeMap attrs; |
| 1500 | attrs.insert({"file_path", model_path}); |
| 1501 | auto load_op = paddle::framework::OpRegistry::CreateOp( |
| 1502 | "load_combine", {}, {{"Out", old_param_list}}, attrs); |
| 1503 | load_op->Run(*old_scope, place); |
| 1504 | } |
| 1505 | |
| 1506 | for (auto& t : old_param_list) { |
| 1507 | Variable* old_var = old_scope->Var(t); |
| 1508 | // old model data, here we assume data type is float |
nothing calls this directly
no test coverage detected