Skip to content
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

Merged
merged 1 commit into from
Jul 13, 2017

Conversation

reyoung
Copy link
Collaborator

@reyoung reyoung commented Jul 11, 2017

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.

`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.
@reyoung reyoung force-pushed the feature/scope_default_wrapper branch from d41b811 to d027f47 Compare July 11, 2017 12:22
return __tl_scope__.cur_scope[-1]


def enter_local_scope():
Copy link
Contributor

@Superjomn Superjomn Jul 11, 2017

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

不行么?

Copy link
Collaborator Author

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):
Copy link
Member

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?

Copy link
Collaborator Author

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?

Copy link
Member

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

Copy link
Member

@jacquesqiao jacquesqiao left a 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

@reyoung reyoung merged commit 3c5cc64 into PaddlePaddle:develop Jul 13, 2017
@reyoung reyoung deleted the feature/scope_default_wrapper branch October 28, 2017 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants