Revert "!5121 Fix the problem of resource clear in r0.7"

This reverts commit a0a6463210, reversing
changes made to 0bcd75bd2b.
This commit is contained in:
simson 2020-08-25 21:03:27 +08:00
parent 1a42811748
commit 556f79d185
3 changed files with 13 additions and 26 deletions

View File

@ -263,13 +263,12 @@ void ExecutorPy::DelNetRes(const std::string &id) {
if (executor_ != nullptr) {
bool flag = false;
auto tmp_info = info_;
for (auto it = tmp_info.begin(); it != tmp_info.end();) {
if (it->first.find(flag) != std::string::npos) {
it->second = nullptr;
it = tmp_info.erase(it);
for (auto &item : tmp_info) {
if (item.first.find(id) != string::npos) {
MS_LOG(DEBUG) << "Delete network res:" << item.first;
item.second = nullptr;
(void)info_.erase(item.first);
flag = true;
} else {
it++;
}
}

View File

@ -1253,24 +1253,17 @@ void PynativeExecutor::GradNetInner(const GradOperationPtr &grad, const py::obje
pipeline::ReclaimOptimizer();
}
template <typename T>
void MapClear(T map, const std::string &flag) {
for (auto it = map.begin(); it != map.end();) {
if (it->first.find(flag) != std::string::npos) {
it->second = nullptr;
it = map.erase(it);
} else {
it++;
}
}
}
void PynativeExecutor::Clear(const std::string &flag) {
if (!flag.empty()) {
MS_LOG(DEBUG) << "Clear res";
MapClear<std::unordered_map<std::string, FuncGraphPtr>>(graph_map_, flag);
MapClear<std::unordered_map<std::string, FuncGraphPtr>>(cell_graph_map_, flag);
MapClear<std::unordered_map<std::string, ResourcePtr>>(cell_resource_map_, flag);
auto key_value = std::find_if(graph_map_.begin(), graph_map_.end(),
[&flag](const auto &item) { return item.first.find(flag) != std::string::npos; });
if (key_value != graph_map_.end()) {
std::string key = key_value->first;
(void)graph_map_.erase(key);
(void)cell_graph_map_.erase(key);
(void)cell_resource_map_.erase(key);
}
Clean();
// Maybe exit in the pynative runing op, so need reset pynative flag.
auto ms_context = MsContext::GetInstance();
@ -1303,9 +1296,6 @@ void PynativeExecutor::Clean() {
}
void PynativeExecutor::ClearRes() {
(void)graph_map_.clear();
(void)cell_graph_map_.clear();
(void)cell_resource_map_.clear();
Clean();
resource_.reset();
}

View File

@ -227,7 +227,6 @@ def dtype_to_pytype(type_):
return {
bool_: bool,
int_: int,
int8: int,
int16: int,
int32: int,
@ -236,7 +235,6 @@ def dtype_to_pytype(type_):
uint16: int,
uint32: int,
uint64: int,
float_: float,
float16: float,
float32: float,
float64: float,