提交 75eba610 编写于 作者: Q Qiao Longfei 提交者: Cheerego

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
上级 ea47685f
...@@ -398,7 +398,26 @@ All parameter, weight, gradient are variables in Paddle. ...@@ -398,7 +398,26 @@ All parameter, weight, gradient are variables in Paddle.
}, },
py::return_value_policy::copy); py::return_value_policy::copy);
py::class_<Scope>(m, "Scope", "") py::class_<Scope>(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", .def("var",
[](Scope &self, const std::string &name) -> Variable * { [](Scope &self, const std::string &name) -> Variable * {
return self.Var(name); return self.Var(name);
......
...@@ -33,13 +33,15 @@ def force_init_on_cpu(): ...@@ -33,13 +33,15 @@ def force_init_on_cpu():
""" """
The flag of whether force to init variables 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: Examples:
.. code-block:: python .. code-block:: python
if force_init_on_cpu(): if force_init_on_cpu():
pass create_op('force_cpu': force_init_on_cpu())
""" """
return _force_init_on_cpu_ return _force_init_on_cpu_
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册