diff --git a/python/paddle/fluid/lazy_init.py b/python/paddle/fluid/lazy_init.py index 3a577eb908432b1abcf94525fdea12f10ca281f5..36f36161e6f27d60fb203f3ab1b8c6887c5d50e0 100644 --- a/python/paddle/fluid/lazy_init.py +++ b/python/paddle/fluid/lazy_init.py @@ -93,6 +93,21 @@ class LazyGuard: LazyGuard is a wrapper interface for nn.Layer, it forwards the construct process of user defined Layer. Meanwhile, it provides necessary API to trigger EagerParamBase Lazy Initialization and get startup Program. + + Examples: + + .. code-block:: python + + from paddle import LazyGuard + from paddle.nn import Linear + + with LazyGuard(): + # w and b are initialized lazily and have no memory. + net = Linear(10, 10) + + for param in net.parameters(): + # Initialize param and allocate memory explicitly. + param.initialize() """ def __enter__(self): diff --git a/python/paddle/tensor/manipulation.py b/python/paddle/tensor/manipulation.py index 73fc4af9fa4d14d07a64f62e119eae2d717e0892..d71f1b09a2f9da55a329bb4115961b18b585063d 100644 --- a/python/paddle/tensor/manipulation.py +++ b/python/paddle/tensor/manipulation.py @@ -2851,6 +2851,7 @@ def scatter(x, index, updates, overwrite=True, name=None): Output is obtained by updating the input on selected indices based on updates. .. code-block:: python + :name: code-example1 import paddle #input: