From 96ff6103f228eb39c75060a977f712cfb9f2fd98 Mon Sep 17 00:00:00 2001 From: zhangjingwei <57820731+Ainavo@users.noreply.github.com> Date: Tue, 18 Jul 2023 16:48:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9COPY-FROM=20add=5Fexample=5Ff?= =?UTF-8?q?or=5Flazygurd=20(#55411)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add_example_for_lazygurd * fix --- python/paddle/fluid/lazy_init.py | 15 +++++++++++++++ python/paddle/tensor/manipulation.py | 1 + 2 files changed, 16 insertions(+) diff --git a/python/paddle/fluid/lazy_init.py b/python/paddle/fluid/lazy_init.py index 3a577eb9084..36f36161e6f 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 73fc4af9fa4..d71f1b09a2f 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: -- GitLab