From 75eba6108dcbc9f46c8e9f7fc763a8e138d8329e Mon Sep 17 00:00:00 2001 From: Qiao Longfei Date: Thu, 29 Nov 2018 11:28:05 +0800 Subject: [PATCH] Add scope doc (#14582) * add doc for scope * update doc for force_init_on_cpu test=develop * follow comment test=develop * update format test=develop --- paddle/fluid/pybind/pybind.cc | 21 ++++++++++++++++++++- python/paddle/fluid/initializer.py | 6 ++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/paddle/fluid/pybind/pybind.cc b/paddle/fluid/pybind/pybind.cc index e31c2f21732..1835c064055 100644 --- a/paddle/fluid/pybind/pybind.cc +++ b/paddle/fluid/pybind/pybind.cc @@ -398,7 +398,26 @@ All parameter, weight, gradient are variables in Paddle. }, py::return_value_policy::copy); - py::class_(m, "Scope", "") + py::class_(m, "Scope", R"DOC( + Scope is an association of a name to Variable. All variables belong to Scope. + + Variables in a parent scope can be retrieved from local scope. + + You need to specify a scope to run a Net, i.e., `exe.Run(&scope)`. + One net can run in different scopes and update different variable in the + scope. + + You can create var in a scope and get it from the scope. + + Examples: + .. code-block:: python + + # create tensor from a scope and set value to it. + param = scope.var('Param').get_tensor() + param_array = np.full((height, row_numel), 5.0).astype("float32") + param.set(param_array, place) + + )DOC") .def("var", [](Scope &self, const std::string &name) -> Variable * { return self.Var(name); diff --git a/python/paddle/fluid/initializer.py b/python/paddle/fluid/initializer.py index a26b8df5a24..b37ebbe5179 100644 --- a/python/paddle/fluid/initializer.py +++ b/python/paddle/fluid/initializer.py @@ -33,13 +33,15 @@ def force_init_on_cpu(): """ The flag of whether force to init variables on CPU. - Returns:: + Returns: + bool: the state if we should force init on CPU. Examples: + .. code-block:: python if force_init_on_cpu(): - pass + create_op('force_cpu': force_init_on_cpu()) """ return _force_init_on_cpu_ -- GitLab