diff --git a/paddle/fluid/API.spec b/paddle/fluid/API.spec index c33b9391dc9839bb837f8ad2f236a3cd7c4e9b88..ede5c02e3f4e3b4a866d44282cdf7c9434c3c00a 100755 --- a/paddle/fluid/API.spec +++ b/paddle/fluid/API.spec @@ -34,7 +34,7 @@ paddle.fluid.Executor.infer_from_dataset (ArgSpec(args=['self', 'program', 'data paddle.fluid.Executor.run (ArgSpec(args=['self', 'program', 'feed', 'fetch_list', 'feed_var_name', 'fetch_var_name', 'scope', 'return_numpy', 'use_program_cache'], varargs=None, keywords=None, defaults=(None, None, None, 'feed', 'fetch', None, True, False)), ('document', '4cfcd9c15b766a51b584cc46d38f1ad8')) paddle.fluid.Executor.train_from_dataset (ArgSpec(args=['self', 'program', 'dataset', 'scope', 'thread', 'debug', 'fetch_list', 'fetch_info', 'print_period', 'fetch_handler'], varargs=None, keywords=None, defaults=(None, None, None, 0, False, None, None, 100, None)), ('document', '73024c79f46b4f14f1060edeaa4919c8')) paddle.fluid.global_scope (ArgSpec(args=[], varargs=None, keywords=None, defaults=None), ('document', 'f65788d9ead293ada47551339df12203')) -paddle.fluid.scope_guard (ArgSpec(args=['scope'], varargs=None, keywords=None, defaults=None), ('document', 'e6c073ed237001aaba7bff976b62b122')) +paddle.fluid.scope_guard (ArgSpec(args=['scope'], varargs=None, keywords=None, defaults=None), ('document', '02fcfc1eda07c03a84ed62422366239c')) paddle.fluid.DistributeTranspiler ('paddle.fluid.transpiler.distribute_transpiler.DistributeTranspiler', ('document', 'b2b19821c5dffcd11473d6a4eef089af')) paddle.fluid.DistributeTranspiler.__init__ (ArgSpec(args=['self', 'config'], varargs=None, keywords=None, defaults=(None,)), ('document', '6adf97f83acf6453d4a6a4b1070f3754')) paddle.fluid.DistributeTranspiler.get_pserver_program (ArgSpec(args=['self', 'endpoint'], varargs=None, keywords=None, defaults=None), ('document', 'b1951949c6d21698290aa8ac69afee32')) diff --git a/python/paddle/fluid/executor.py b/python/paddle/fluid/executor.py index 460f1eae741b7c61a542453cb5eef95fa1f8202b..679de3ccc6bff79d20eaa8f0d0f013b64cb86078 100644 --- a/python/paddle/fluid/executor.py +++ b/python/paddle/fluid/executor.py @@ -66,11 +66,21 @@ def _switch_scope(scope): @signature_safe_contextmanager def scope_guard(scope): """ - Change the global/default scope instance by Python `with` statement. All - variable in runtime will assigned to the new scope. + This function switches scope through python `with` statement. + Scope records the mapping between variable names and variables ( :ref:`api_guide_Variable` ), + similar to brackets in programming languages. + If this function is not invoked, all variables and variable names are recorded in the default global scope. + When users need to create variables with the same name, + they need to switch scopes through this function + if they do not want the mapping of variables with the same name to be overwritten. + After switching through the `with` statement, + all variables created in the `with` block will be assigned to a new scope. + + Parameters: + scope: The new scope. - Args: - scope: The new global/default scope. + Returns: + None Examples: .. code-block:: python