未验证 提交 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):
Examples:
.. code-block:: python
# required: gpu
import paddle
from paddle.incubate.nn.layer.fused_dropout_add import FusedDropoutAdd
>>> # doctest: +REQUIRES(env:GPU)
>>> import paddle
>>> 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")
y = 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")
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):
......
......@@ -53,23 +53,23 @@ class FusedDropout(paddle.nn.Layer):
Examples:
.. code-block:: python
import paddle
x = paddle.to_tensor([[1, 2, 3], [4, 5, 6]], dtype="float32")
m = paddle.incubate.nn.FusedDropout(p=0.5)
y_train = m(x)
print(y_train)
# Tensor(shape=[2, 3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
# [[2., 0., 6.],
# [0., 0., 0.]])
m.eval() # switch the model to test phase
y_test = m(x)
print(y_test)
# Tensor(shape=[2, 3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
# [[1., 2., 3.],
# [4., 5., 6.]])
>>> import paddle
>>> x = paddle.to_tensor([[1, 2, 3], [4, 5, 6]], dtype="float32")
>>> m = paddle.incubate.nn.FusedDropout(p=0.5)
>>> y_train = m(x)
>>> print(y_train)
Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
[[2., 0., 6.],
[0., 0., 0.]])
>>> m.eval() # switch the model to test phase
>>> y_test = m(x)
>>> print(y_test)
Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
[[1., 2., 3.],
[4., 5., 6.]])
"""
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.
先完成此消息的编辑!
想要评论请 注册