-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Default scope function #2808
Default scope function #2808
Conversation
`Paddle` manages Scope as programming language's scope. It just a thread-local stack of Scope. Top of that stack is current scope, the bottom of that stack is all scopes' parent. Invoking `create_var/get_var` can `create/get` variable in current scope. Invoking `enter_local_scope/leave_local_scope` can create or destroy local scope. A `scoped_function` will take a `function` as input. That function will be invoked in a new local scope.
d41b811
to
d027f47
Compare
return __tl_scope__.cur_scope[-1] | ||
|
||
|
||
def enter_local_scope(): |
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.
scope 必须是连续么?
scopeA:
xxx
scope B:
xxxx
scopeA:
xxxx
不行么?
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.
不是特别清楚什么是『必须连续』?
但是,举的例子可以做到。
enter_local_scope() # scope A
xxx
enter_local_scope() # scope B
xxx
leave_local_scope()
xxx
leave_local_scope() # leave scope A
return get_cur_scope().get_var(name) | ||
|
||
|
||
def scoped_function(func): |
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.
what is the situation to use this function?
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.
Maybe used to define an RNN step net?
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.
But the scope of stepnet is create inside RnnOP as far as know
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 with a small question
Paddle
manages Scope as programming language's scope. It just athread-local stack of Scope. Top of that stack is current scope, the
bottom of that stack is all scopes' parent.
Invoking
create_var/get_var
cancreate/get
variable in currentscope. Invoking
enter_local_scope/leave_local_scope
can create ordestroy local scope.
A
scoped_function
will take afunction
as input. That function willbe invoked in a new local scope.