-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
change: NewVar() to Var() #4725
Conversation
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.
LGTM++
paddle/framework/block_desc.cc
Outdated
@@ -18,7 +18,7 @@ limitations under the License. */ | |||
namespace paddle { | |||
namespace framework { | |||
|
|||
VarDescBind *BlockDescBind::NewVar(const std::string &name) { | |||
VarDescBind *BlockDescBind::GetOrCreateVar(const std::string &name) { |
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 the issue is related to Scope::NewVar
. BlockDescBind::NewVar
should not be changed.
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.
It's the same with Scope
, also do the same logic of find or create. Which we want to make it more clearly.
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.
agree that NewVar
is not resonable.
may be the implementation is wrong, an function called NewVar
should just create a new var, raise error or return false if an variable exists.
We can add a new interface called GetOrCreateVar
, and update the implementation of NewVar
.
not just delete it.
FindVar
matches NewVar
grammerly
but not GetOrCreateVar
@Superjom @dzhwinter From my understanding some of the current cpp implementations rely on |
I think, most of the current usage of |
We should only provide one interface to create a variable. Otherwise, the user's code may be ugly mixed with |
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.
LGTM
This PR depends #4728 |
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.
LGTM!
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.
LGTM
paddle/framework/block_desc.cc
Outdated
@@ -18,7 +18,7 @@ limitations under the License. */ | |||
namespace paddle { | |||
namespace framework { | |||
|
|||
VarDescBind *BlockDescBind::NewVar(const std::string &name) { | |||
VarDescBind *BlockDescBind::Var(const std::string &name) { | |||
need_update_ = true; | |||
auto it = vars_.find(name); | |||
PADDLE_ENFORCE(it == vars_.end(), "Duplicated variable %s", name); |
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.
var should mean getOrCreate
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.
Done.
So many conflicts, I will merge it ASAP.
fix #4722
fix #4778