Created by: NHZlX
PR types
Bug fixes
PR changes
Others
Describe
The passes for inference do a lot of fuse operation during graph analysis. During this period, The delete ops、vars, insert new ops or new vars operation will be carried out during this period . When adding new variables, the variable name is determined by https://github.com/PaddlePaddle/Paddle/blob/a7944904d3b50aeffcaae61f00ecd5d6920805b3/paddle/fluid/framework/ir/graph_pattern_detector.h#L357 .
static std::string PDNodeName(const std::string& name_scope,
const std::string& repr) {
return string::Sprintf("%s/%s/%d", name_scope, repr,
KeyCounter::Instance().IncCounter(repr));
}
We can see, the name is generated by KeyCounter::Instance().IncCounter
, which is a singleton instance.
struct KeyCounter {
static KeyCounter& Instance() {
static KeyCounter x;
return x;
}
int IncCounter(const std::string& key) { return dic_[key]++; }
private:
std::unordered_map<std::string, size_t> dic_;
};
So,two identical models produce variables with different names during pass optimization.
We should avoid using this method to generate internal variable names