Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
0fdd3656
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
0fdd3656
编写于
12月 11, 2020
作者:
L
Leo Chen
提交者:
GitHub
12月 11, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add fast path for dropout when p == 0 (#29553)
* add fast path for p == 0 in dropout * add ut
上级
917a1149
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
19 addition
and
2 deletion
+19
-2
python/paddle/fluid/dygraph/nn.py
python/paddle/fluid/dygraph/nn.py
+3
-0
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+3
-0
python/paddle/fluid/tests/unittests/test_dropout_op.py
python/paddle/fluid/tests/unittests/test_dropout_op.py
+9
-2
python/paddle/nn/functional/common.py
python/paddle/nn/functional/common.py
+4
-0
未找到文件。
python/paddle/fluid/dygraph/nn.py
浏览文件 @
0fdd3656
...
...
@@ -1476,6 +1476,9 @@ class Dropout(layers.Layer):
self
.
_is_test
=
is_test
def
forward
(
self
,
input
):
# fast return for p == 0
if
self
.
_dropout_prob
==
0
:
return
input
prog
=
default_main_program
()
if
(
self
.
_seed
is
None
or
self
.
_seed
==
0
)
and
prog
.
random_seed
!=
0
:
self
.
_seed
=
prog
.
random_seed
...
...
python/paddle/fluid/layers/nn.py
浏览文件 @
0fdd3656
...
...
@@ -1007,6 +1007,9 @@ def dropout(x,
x = fluid.data(name="data", shape=[None, 32, 32], dtype="float32")
dropped = fluid.layers.dropout(x, dropout_prob=0.5)
"""
# fast return for p == 0
if dropout_prob == 0:
return x
def get_attrs(prog, dropout_prob, is_test, seed):
if (seed is None or seed == 0) and prog.random_seed != 0:
...
...
python/paddle/fluid/tests/unittests/test_dropout_op.py
浏览文件 @
0fdd3656
...
...
@@ -302,13 +302,16 @@ class TestDropoutFAPI(unittest.TestCase):
training
=
False
,
mode
=
'downscale_in_infer'
)
res10
=
paddle
.
nn
.
functional
.
dropout
(
x
=
input
,
p
=
1.
,
training
=
True
)
res11
=
paddle
.
fluid
.
layers
.
dropout
(
x
=
input
,
dropout_prob
=
0.
)
in_np
=
np
.
random
.
random
([
40
,
40
]).
astype
(
"float32"
)
res_np
=
in_np
res_np2
=
np
.
zeros_like
(
in_np
)
exe
=
fluid
.
Executor
(
place
)
res_list
=
[
res1
,
res2
,
res3
,
res4
,
res5
,
res6
,
res7
,
res8
,
res9
]
res_list
=
[
res1
,
res2
,
res3
,
res4
,
res5
,
res6
,
res7
,
res8
,
res9
,
res11
]
for
res
in
res_list
:
fetches
=
exe
.
run
(
fluid
.
default_main_program
(),
feed
=
{
"input"
:
in_np
},
...
...
@@ -383,8 +386,12 @@ class TestDropoutFAPI(unittest.TestCase):
mode
=
'downscale_in_infer'
)
res10
=
paddle
.
nn
.
functional
.
dropout
(
x
=
input
,
p
=
1.
,
training
=
True
)
dropout
=
paddle
.
fluid
.
dygraph
.
Dropout
(
p
=
0
,
)
res11
=
dropout
(
input
)
res_list
=
[
res1
,
res2
,
res3
,
res4
,
res5
,
res6
,
res7
,
res8
,
res9
]
res_list
=
[
res1
,
res2
,
res3
,
res4
,
res5
,
res6
,
res7
,
res8
,
res9
,
res11
]
for
res
in
res_list
:
self
.
assertTrue
(
np
.
allclose
(
res
.
numpy
(),
res_np
))
self
.
assertTrue
(
np
.
allclose
(
res10
.
numpy
(),
res_np2
))
...
...
python/paddle/nn/functional/common.py
浏览文件 @
0fdd3656
...
...
@@ -887,6 +887,10 @@ def dropout(x,
print(y_01)
"""
# fast return for p == 0
if
p
==
0
:
return
x
if
not
isinstance
(
p
,
(
float
,
int
)):
raise
TypeError
(
"p argument should be a number"
)
if
p
<
0
or
p
>
1
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录