未验证 提交 1274e738 编写于 作者: G gongenlei 提交者: GitHub

【Zero-Dim】support 0D Tensor for alpha_dropout (#49882)

* alpha_dropout supports zero_dim

* add test
上级 0673a54f
......@@ -87,6 +87,7 @@ unary_api_list = [
paddle.nn.functional.softmax,
paddle.nn.functional.log_softmax,
paddle.nn.functional.gumbel_softmax,
paddle.nn.functional.alpha_dropout,
]
inplace_api_list = [
......
......@@ -1436,7 +1436,7 @@ def alpha_dropout(x, p=0.5, training=True, name=None):
random_tensor = paddle.uniform(
input_shape, dtype='float32', min=0.0, max=1.0
)
p = full(shape=[1], fill_value=p, dtype='float32')
p = full(shape=input_shape, fill_value=p, dtype='float32')
keep_mask = paddle.greater_equal(random_tensor, p)
keep_mask = paddle.cast(keep_mask, dtype)
drop_mask = paddle.subtract(
......@@ -1444,7 +1444,7 @@ def alpha_dropout(x, p=0.5, training=True, name=None):
)
# apply mask
b = full(shape=[1], fill_value=b, dtype=dtype)
b = full(shape=input_shape, fill_value=b, dtype=dtype)
y = paddle.add(
paddle.multiply(x, keep_mask),
paddle.scale(drop_mask, scale=alpha_p),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册