-
Notifications
You must be signed in to change notification settings - Fork 24.4k
cleanup tmp name generation #25065
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cleanup tmp name generation #25065
Conversation
Using global atomic variables is bad because sending the same AST through the compiler twice will produce different graphs. This makes it a member of the translation struct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good
torch/csrc/jit/script/compiler.cpp
Outdated
@@ -522,6 +522,10 @@ struct to_ir { | |||
// `next` that points to the most immediate enclosing scope's value. | |||
std::shared_ptr<Environment> environment_stack; | |||
std::vector<DefContext> def_stack_; | |||
size_t temp_name_count_ = 0; | |||
std::string createTempName(const std::string& prefix) { | |||
return prefix + std::to_string(temp_name_count_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think you dropped a ++
torch/csrc/jit/script/compiler.cpp
Outdated
static std::atomic<size_t> tmp_count{0}; | ||
const auto tmp_name = | ||
std::string("___list_acc") + std::to_string(tmp_count++); | ||
const auto tmp_name = createTempName("___list_acc"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated to your diff but it's better practice to prefix the names with $
so that there is no possibility of user collision
cleanup tmp name generation Using global atomic variables is bad because sending the same AST through the compiler twice will produce different graphs. This makes it a member of the translation struct. gh-metadata: pytorch pytorch 25065 gh/zdevito/93/head
Stack from ghstack:
Using global atomic variables is bad because sending the same AST through
the compiler twice will produce different graphs. This makes it a
member of the translation struct.
Differential Revision: D16975355