From 3c22b1742cc9778f959c879a661147edb54557fa Mon Sep 17 00:00:00 2001 From: Chen Long <1300851984@qq.com> Date: Tue, 8 Jun 2021 10:47:00 +0800 Subject: [PATCH] [cherry-pick] Fix code examples #32861 #33395 (#33396) * Fix comments in framework (#32861) * Fix comments in framework * Update framework.py * fix code style Co-authored-by: Wenyu --- python/paddle/framework/framework.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/paddle/framework/framework.py b/python/paddle/framework/framework.py index 17eaa82cd8..d5fa45f768 100644 --- a/python/paddle/framework/framework.py +++ b/python/paddle/framework/framework.py @@ -87,8 +87,6 @@ def get_default_dtype(): @contextmanager def set_grad_enabled(mode): """ - :api_attr: imperative - Create a context which enables or disables dygraph gradient calculation. Args: @@ -96,11 +94,13 @@ def set_grad_enabled(mode): Examples: .. code-block:: python + + import paddle x = paddle.ones([3, 2]) x.stop_gradient = False - with torch.set_grad_enabled(False): + with paddle.set_grad_enabled(False): y = x * 2 - with torch.set_grad_enabled(True): + with paddle.set_grad_enabled(True): z = x * 2 print(y.stop_gradient) # True print(z.stop_gradient) # False -- GitLab