未验证 提交 3c22b174 编写于 作者: C Chen Long 提交者: GitHub

[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: NWenyu <wenyu.lyu@gmail.com>
上级 d5225145
...@@ -87,8 +87,6 @@ def get_default_dtype(): ...@@ -87,8 +87,6 @@ def get_default_dtype():
@contextmanager @contextmanager
def set_grad_enabled(mode): def set_grad_enabled(mode):
""" """
:api_attr: imperative
Create a context which enables or disables dygraph gradient calculation. Create a context which enables or disables dygraph gradient calculation.
Args: Args:
...@@ -96,11 +94,13 @@ def set_grad_enabled(mode): ...@@ -96,11 +94,13 @@ def set_grad_enabled(mode):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle
x = paddle.ones([3, 2]) x = paddle.ones([3, 2])
x.stop_gradient = False x.stop_gradient = False
with torch.set_grad_enabled(False): with paddle.set_grad_enabled(False):
y = x * 2 y = x * 2
with torch.set_grad_enabled(True): with paddle.set_grad_enabled(True):
z = x * 2 z = x * 2
print(y.stop_gradient) # True print(y.stop_gradient) # True
print(z.stop_gradient) # False print(z.stop_gradient) # False
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册