diff --git a/paddle/fluid/pybind/pybind.cc b/paddle/fluid/pybind/pybind.cc index e31c2f217322be8ef8b131189504b54cf6b4ad80..1835c064055635a4284fc64f4ca4dd8728f933ca 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 a26b8df5a240be8340597b9627866c323fa98a2d..b37ebbe5179ba6e36be70ff936cb8a3ca0d89d13 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_