From e1515e40e60bda6448ded89a89630962f6e1bd7e Mon Sep 17 00:00:00 2001 From: WangZhen <23097963+0x45f@users.noreply.github.com> Date: Wed, 3 Aug 2022 19:53:17 +0800 Subject: [PATCH] Fix Function name error when Load program (#44782) --- paddle/fluid/jit/serializer_utils.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/paddle/fluid/jit/serializer_utils.cc b/paddle/fluid/jit/serializer_utils.cc index 41bfa71b4c..54b0e7831e 100644 --- a/paddle/fluid/jit/serializer_utils.cc +++ b/paddle/fluid/jit/serializer_utils.cc @@ -71,30 +71,31 @@ const std::vector> PdmodelFilePaths( ReplaceAll(&format_path, R"(\\)", "/"); ReplaceAll(&format_path, R"(\)", "/"); - std::string layer_prefix = + std::string layer_name = format_path.substr(format_path.find_last_of("/") + 1); std::string dir_path = - format_path.substr(0, format_path.length() - layer_prefix.length()); + format_path.substr(0, format_path.length() - layer_name.length()); DIR* dir = opendir(dir_path.c_str()); struct dirent* ptr; while ((ptr = readdir(dir)) != nullptr) { std::string file_name = ptr->d_name; - if (StartsWith(file_name, layer_prefix) && + if (StartsWith(file_name, layer_name) && EndsWith(file_name, PDMODEL_SUFFIX)) { std::string prefix = file_name.substr( 0, file_name.length() - std::string(PDMODEL_SUFFIX).length()); - std::string func_name = prefix.substr(prefix.find_first_of(".") + 1); - VLOG(3) << "func_name:" << func_name << "path:" << dir_path + file_name; - if (func_name == layer_prefix) { + if (prefix == layer_name) { pdmodel_paths.emplace_back( std::make_pair("forward", dir_path + file_name)); } else { + std::string func_name = prefix.substr(layer_name.size() + 1); pdmodel_paths.emplace_back( std::make_pair(func_name, dir_path + file_name)); } + VLOG(3) << "func_name: " << pdmodel_paths.back().first + << ", path:" << dir_path + file_name; } } closedir(dir); -- GitLab