Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
2fd7675c
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
2fd7675c
编写于
1月 11, 2018
作者:
Y
yangyaming
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add lod checking for forward.
上级
6f79bbc9
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
15 addition
and
11 deletion
+15
-11
python/paddle/v2/fluid/tests/test_dynrnn_static_input.py
python/paddle/v2/fluid/tests/test_dynrnn_static_input.py
+15
-11
未找到文件。
python/paddle/v2/fluid/tests/test_dynrnn_static_input.py
浏览文件 @
2fd7675c
...
...
@@ -56,7 +56,7 @@ class TestDyRnnStaticInput(unittest.TestCase):
ndarray
=
np
.
zeros
(
shape
=
dims
).
astype
(
'float32'
)
for
i
in
xrange
(
np
.
product
(
dims
)):
ndarray
.
ravel
()[
i
]
=
lod_tensor
.
get_float_element
(
i
)
return
ndarray
return
ndarray
,
lod_tensor
.
lod
()
def
build_graph
(
self
,
only_forward
=
False
):
x_tensor
=
fluid
.
layers
.
data
(
...
...
@@ -142,22 +142,28 @@ class TestDyRnnStaticInput(unittest.TestCase):
]
static_step_outs
=
[]
static_step_lods
=
[]
for
i
in
xrange
(
self
.
_max_sequence_len
):
end
=
len
(
x_seq_len
)
-
bisect
.
bisect_left
(
x_seq_len_sorted
,
i
+
1
)
end
=
sum
(
static_seq_len_reordered
[:
end
])
lod
=
[
0
]
for
i
in
xrange
(
end
):
lod
.
append
(
static_seq_len_reordered
[
i
]
+
lod
[
-
1
])
static_step_lods
.
append
([
lod
])
end
=
lod
[
-
1
]
static_step_outs
.
append
(
np
.
array
(
static_reordered
[:
end
]).
astype
(
'float32'
))
return
static_step_outs
return
static_step_outs
,
static_step_lods
def
test_step_out
(
self
):
static_step_outs
=
self
.
build_graph
(
only_forward
=
True
)
self
.
exe
.
run
(
framework
.
default_startup_program
())
expected_
step_out
s
=
self
.
get_expected_static_step_outs
()
expected_
outs
,
expected_lod
s
=
self
.
get_expected_static_step_outs
()
for
i
in
xrange
(
self
.
_max_sequence_len
):
step_out
=
self
.
fetch_value
(
static_step_outs
[
i
])
self
.
assertTrue
(
np
.
allclose
(
step_out
,
expected_step_outs
[
i
]))
step_out
,
lod
=
self
.
fetch_value
(
static_step_outs
[
i
])
self
.
assertTrue
(
np
.
allclose
(
step_out
,
expected_outs
[
i
]))
self
.
assertTrue
(
np
.
allclose
(
lod
,
expected_lods
[
i
]))
def
test_network_gradient
(
self
):
pass
#still have bug (seed doesn't work)
...
...
@@ -165,11 +171,10 @@ class TestDyRnnStaticInput(unittest.TestCase):
static_input_grad, loss = self.build_graph()
self.exe.run(framework.default_startup_program())
actual_gradients = self.fetch_value(static_input_grad)
actual_gradients
, actual_lod
= self.fetch_value(static_input_grad)
static_input_shape = self.static_input_tensor.get_dims()
numeric_gradients = np.zeros(shape=static_input_shape).astype('float32')
#print(actual_gradient)
print(actual_gradients)
# calculate numeric gradients
tensor_size = np.product(static_input_shape)
...
...
@@ -177,13 +182,12 @@ class TestDyRnnStaticInput(unittest.TestCase):
origin = self.static_input_tensor.get_float_element(i)
x_pos = origin + self._delta
self.static_input_tensor.set_float_element(i, x_pos)
y_pos = self.fetch_value(loss)[0]
y_pos = self.fetch_value(loss)[0]
[0]
x_neg = origin - self._delta
self.static_input_tensor.set_float_element(i, x_neg)
y_neg = self.fetch_value(loss)[0]
y_neg = self.fetch_value(loss)[0]
[0]
self.static_input_tensor.set_float_element(i, origin)
numeric_gradients.ravel()[i] = (y_pos - y_neg) / self._delta / 2
print(numeric_gradients)
'''
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录