From 7ebe23fecf1d19dd33212e192c8020bca9d24b78 Mon Sep 17 00:00:00 2001 From: yujianfeng Date: Tue, 11 Jan 2022 11:52:01 +0800 Subject: [PATCH] Export the bprop mindir when the bprop directory is symbolic link --- mindspore/ccsrc/frontend/optimizer/ad/kprim.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mindspore/ccsrc/frontend/optimizer/ad/kprim.cc b/mindspore/ccsrc/frontend/optimizer/ad/kprim.cc index 71aea7aadfc..ae60a4d8849 100644 --- a/mindspore/ccsrc/frontend/optimizer/ad/kprim.cc +++ b/mindspore/ccsrc/frontend/optimizer/ad/kprim.cc @@ -285,9 +285,14 @@ std::string GetBpropFileHash(const py::function &fn) { static auto bprop_hash_to_file = GetAllBpropFileHash(); // Get the file where the bprop function is defined. auto filename = fn.attr("__code__").attr("co_filename").cast(); + auto realpath = FileUtils::GetRealPath(common::SafeCStr(filename)); + if (!realpath.has_value()) { + MS_LOG(ERROR) << "Failed to get the realpath of file: " << filename; + return ""; + } // Get the hash of the file. auto it = std::find_if(bprop_hash_to_file.begin(), bprop_hash_to_file.end(), - [&filename](const auto &item) { return item.second == filename; }); + [&realpath](const auto &item) { return item.second == realpath.value(); }); if (it != bprop_hash_to_file.end()) { return it->first; }