Skip to content

Commit 75eba61

Browse files
jacquesqiaoshanyi15
authored andcommitted
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
1 parent ea47685 commit 75eba61

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

paddle/fluid/pybind/pybind.cc

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,26 @@ All parameter, weight, gradient are variables in Paddle.
398398
},
399399
py::return_value_policy::copy);
400400

401-
py::class_<Scope>(m, "Scope", "")
401+
py::class_<Scope>(m, "Scope", R"DOC(
402+
Scope is an association of a name to Variable. All variables belong to Scope.
403+
404+
Variables in a parent scope can be retrieved from local scope.
405+
406+
You need to specify a scope to run a Net, i.e., `exe.Run(&scope)`.
407+
One net can run in different scopes and update different variable in the
408+
scope.
409+
410+
You can create var in a scope and get it from the scope.
411+
412+
Examples:
413+
.. code-block:: python
414+
415+
# create tensor from a scope and set value to it.
416+
param = scope.var('Param').get_tensor()
417+
param_array = np.full((height, row_numel), 5.0).astype("float32")
418+
param.set(param_array, place)
419+
420+
)DOC")
402421
.def("var",
403422
[](Scope &self, const std::string &name) -> Variable * {
404423
return self.Var(name);

python/paddle/fluid/initializer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ def force_init_on_cpu():
3333
"""
3434
The flag of whether force to init variables on CPU.
3535
36-
Returns::
36+
Returns:
37+
bool: the state if we should force init on CPU.
3738
3839
Examples:
40+
3941
.. code-block:: python
4042
4143
if force_init_on_cpu():
42-
pass
44+
create_op('force_cpu': force_init_on_cpu())
4345
4446
"""
4547
return _force_init_on_cpu_

0 commit comments

Comments
 (0)