未验证 提交 8746e230 编写于 作者: K KongAKun 提交者: GitHub

[xdoctest] reformat example code with google style in No. 264-265 (#56907)

* Fix styles of code

* update the GPU option

* add the GPU setup

* remove the note

* update the code
上级 3e36271e
...@@ -44,16 +44,17 @@ class FusedDropoutAdd(Layer): ...@@ -44,16 +44,17 @@ class FusedDropoutAdd(Layer):
Examples: Examples:
.. code-block:: python .. code-block:: python
# required: gpu >>> # doctest: +REQUIRES(env:GPU)
import paddle >>> import paddle
from paddle.incubate.nn.layer.fused_dropout_add import FusedDropoutAdd >>> paddle.device.set_device('gpu')
>>> from paddle.incubate.nn.layer.fused_dropout_add import FusedDropoutAdd
x = paddle.to_tensor([[1,2,3], [4,5,6]], dtype="float32") >>> x = paddle.to_tensor([[1,2,3], [4,5,6]], dtype="float32")
y = paddle.to_tensor([[1,2,3], [4,5,6]], dtype="float32") >>> y = paddle.to_tensor([[1,2,3], [4,5,6]], dtype="float32")
m = FusedDropoutAdd(p=0.5) >>> m = FusedDropoutAdd(p=0.5)
out = m(x, y) >>> out = m(x, y)
""" """
def __init__(self, p=0.5, mode="upscale_in_train", name=None): def __init__(self, p=0.5, mode="upscale_in_train", name=None):
......
...@@ -53,23 +53,23 @@ class FusedDropout(paddle.nn.Layer): ...@@ -53,23 +53,23 @@ class FusedDropout(paddle.nn.Layer):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle >>> import paddle
x = paddle.to_tensor([[1, 2, 3], [4, 5, 6]], dtype="float32") >>> x = paddle.to_tensor([[1, 2, 3], [4, 5, 6]], dtype="float32")
m = paddle.incubate.nn.FusedDropout(p=0.5) >>> m = paddle.incubate.nn.FusedDropout(p=0.5)
y_train = m(x) >>> y_train = m(x)
print(y_train) >>> print(y_train)
# Tensor(shape=[2, 3], dtype=float32, place=Place(gpu:0), stop_gradient=True, Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
# [[2., 0., 6.], [[2., 0., 6.],
# [0., 0., 0.]]) [0., 0., 0.]])
m.eval() # switch the model to test phase >>> m.eval() # switch the model to test phase
y_test = m(x) >>> y_test = m(x)
print(y_test) >>> print(y_test)
# Tensor(shape=[2, 3], dtype=float32, place=Place(gpu:0), stop_gradient=True, Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
# [[1., 2., 3.], [[1., 2., 3.],
# [4., 5., 6.]]) [4., 5., 6.]])
""" """
def __init__(self, p=0.5, axis=None, mode="upscale_in_train", name=None): def __init__(self, p=0.5, axis=None, mode="upscale_in_train", name=None):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册