Skip to content

Commit b94f784

Browse files
authored
Merge pull request #11531 from reyoung/feature/non_layer_api_doc
Polish Non-Layer API
2 parents 8d5ab1f + d1203e3 commit b94f784

File tree

8 files changed

+545
-93
lines changed

8 files changed

+545
-93
lines changed

python/paddle/fluid/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
import transpiler
4545
from param_attr import ParamAttr, WeightNormParamAttr
4646
from data_feeder import DataFeeder
47-
from core import LoDTensor, CPUPlace, CUDAPlace, CUDAPinnedPlace
47+
from core import LoDTensor, CPUPlace, CUDAPlace, CUDAPinnedPlace, Scope
4848
from transpiler import DistributeTranspiler, InferenceTranspiler, \
4949
memory_optimize, release_memory
5050
from concurrency import (Go, make_channel, channel_send, channel_recv,
@@ -83,6 +83,7 @@
8383
'profiler',
8484
'unique_name',
8585
'recordio_writer',
86+
'Scope',
8687
]
8788

8889

python/paddle/fluid/executor.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@
2525

2626

2727
def global_scope():
28+
"""
29+
Get the global/default scope instance. There are a lot of APIs use
30+
:code:`global_scope` as its default value, e.g., :code:`Executor.run`
31+
32+
Returns:
33+
Scope: The global/default scope instance.
34+
"""
2835
return g_scope
2936

3037

@@ -37,6 +44,19 @@ def switch_scope(scope):
3744

3845
@contextlib.contextmanager
3946
def scope_guard(scope):
47+
"""
48+
Change the global/default scope instance by Python `with` statement. All
49+
variable in runtime will assigned to the new scope.
50+
51+
Examples:
52+
>>> import paddle.fluid as fluid
53+
>>> new_scope = fluid.Scope()
54+
>>> with fluid.scope_guard(new_scope):
55+
>>> ...
56+
57+
Args:
58+
scope: The new global/default scope.
59+
"""
4060
ex = switch_scope(scope)
4161
yield
4262
switch_scope(ex)

0 commit comments

Comments
 (0)