Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
飞不过沧海
Paddle
提交
4caf60df
P
Paddle
项目概览
飞不过沧海
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
4caf60df
编写于
8月 06, 2021
作者:
J
Jack Zhou
提交者:
GitHub
8月 06, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix simple_rnn_cell, gru_cell and lstm_cell zero_div_error (#34627)
上级
21beef91
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
33 addition
and
0 deletion
+33
-0
python/paddle/fluid/tests/unittests/rnn/test_rnn_cells.py
python/paddle/fluid/tests/unittests/rnn/test_rnn_cells.py
+21
-0
python/paddle/nn/layer/rnn.py
python/paddle/nn/layer/rnn.py
+12
-0
未找到文件。
python/paddle/fluid/tests/unittests/rnn/test_rnn_cells.py
浏览文件 @
4caf60df
...
...
@@ -60,9 +60,16 @@ class TestSimpleRNNCell(unittest.TestCase):
y2
,
h2
=
rnn2
(
paddle
.
to_tensor
(
x
))
np
.
testing
.
assert_allclose
(
h1
,
h2
.
numpy
(),
atol
=
1e-8
,
rtol
=
1e-5
)
def
test_errors
(
self
):
def
test_zero_hidden_size
():
cell
=
paddle
.
nn
.
SimpleRNNCell
(
-
1
,
0
)
self
.
assertRaises
(
ValueError
,
test_zero_hidden_size
)
def
runTest
(
self
):
self
.
test_with_initial_state
()
self
.
test_with_zero_state
()
self
.
test_errors
()
class
TestGRUCell
(
unittest
.
TestCase
):
...
...
@@ -103,9 +110,16 @@ class TestGRUCell(unittest.TestCase):
y2
,
h2
=
rnn2
(
paddle
.
to_tensor
(
x
))
np
.
testing
.
assert_allclose
(
h1
,
h2
.
numpy
(),
atol
=
1e-8
,
rtol
=
1e-5
)
def
test_errors
(
self
):
def
test_zero_hidden_size
():
cell
=
paddle
.
nn
.
GRUCell
(
-
1
,
0
)
self
.
assertRaises
(
ValueError
,
test_zero_hidden_size
)
def
runTest
(
self
):
self
.
test_with_initial_state
()
self
.
test_with_zero_state
()
self
.
test_errors
()
class
TestLSTMCell
(
unittest
.
TestCase
):
...
...
@@ -150,9 +164,16 @@ class TestLSTMCell(unittest.TestCase):
np
.
testing
.
assert_allclose
(
h1
,
h2
.
numpy
(),
atol
=
1e-8
,
rtol
=
1e-5
)
np
.
testing
.
assert_allclose
(
c1
,
c2
.
numpy
(),
atol
=
1e-8
,
rtol
=
1e-5
)
def
test_errors
(
self
):
def
test_zero_hidden_size
():
cell
=
paddle
.
nn
.
LSTMCell
(
-
1
,
0
)
self
.
assertRaises
(
ValueError
,
test_zero_hidden_size
)
def
runTest
(
self
):
self
.
test_with_initial_state
()
self
.
test_with_zero_state
()
self
.
test_errors
()
def
load_tests
(
loader
,
tests
,
pattern
):
...
...
python/paddle/nn/layer/rnn.py
浏览文件 @
4caf60df
...
...
@@ -332,6 +332,10 @@ class SimpleRNNCell(RNNCellBase):
bias_hh_attr
=
None
,
name
=
None
):
super
(
SimpleRNNCell
,
self
).
__init__
()
if
hidden_size
<=
0
:
raise
ValueError
(
"hidden_size of {} must be greater than 0, but now equals to {}"
.
format
(
self
.
__class__
.
__name__
,
hidden_size
))
std
=
1.0
/
math
.
sqrt
(
hidden_size
)
self
.
weight_ih
=
self
.
create_parameter
(
(
hidden_size
,
input_size
),
...
...
@@ -480,6 +484,10 @@ class LSTMCell(RNNCellBase):
bias_hh_attr
=
None
,
name
=
None
):
super
(
LSTMCell
,
self
).
__init__
()
if
hidden_size
<=
0
:
raise
ValueError
(
"hidden_size of {} must be greater than 0, but now equals to {}"
.
format
(
self
.
__class__
.
__name__
,
hidden_size
))
std
=
1.0
/
math
.
sqrt
(
hidden_size
)
self
.
weight_ih
=
self
.
create_parameter
(
(
4
*
hidden_size
,
input_size
),
...
...
@@ -627,6 +635,10 @@ class GRUCell(RNNCellBase):
bias_hh_attr
=
None
,
name
=
None
):
super
(
GRUCell
,
self
).
__init__
()
if
hidden_size
<=
0
:
raise
ValueError
(
"hidden_size of {} must be greater than 0, but now equals to {}"
.
format
(
self
.
__class__
.
__name__
,
hidden_size
))
std
=
1.0
/
math
.
sqrt
(
hidden_size
)
self
.
weight_ih
=
self
.
create_parameter
(
(
3
*
hidden_size
,
input_size
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录