diff --git a/python/paddle/incubate/nn/layer/fused_dropout_add.py b/python/paddle/incubate/nn/layer/fused_dropout_add.py index 77874d2944764b453b2dee4b3ffcfa2e6fd08fbe..51cfc18d443b4fe0ab9dda78419d4e35d3d368da 100644 --- a/python/paddle/incubate/nn/layer/fused_dropout_add.py +++ b/python/paddle/incubate/nn/layer/fused_dropout_add.py @@ -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): diff --git a/python/paddle/incubate/nn/layer/fused_dropout_nd.py b/python/paddle/incubate/nn/layer/fused_dropout_nd.py index 156880f73281bc1870f91b47d322afe66b9a1d19..a820654fa9efcb4919bdaab923263fa94bec171b 100644 --- a/python/paddle/incubate/nn/layer/fused_dropout_nd.py +++ b/python/paddle/incubate/nn/layer/fused_dropout_nd.py @@ -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):