Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
d2cb2841
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看板
提交
d2cb2841
编写于
12月 28, 2017
作者:
Y
Yang Yu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix ALL RNN error
上级
96bc3352
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
17 addition
and
9 deletion
+17
-9
paddle/operators/while_op.cc
paddle/operators/while_op.cc
+11
-1
paddle/pybind/tensor_py.h
paddle/pybind/tensor_py.h
+4
-4
python/paddle/v2/fluid/tests/test_dynrnn_gradient_check.py
python/paddle/v2/fluid/tests/test_dynrnn_gradient_check.py
+2
-4
未找到文件。
paddle/operators/while_op.cc
浏览文件 @
d2cb2841
...
...
@@ -12,6 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include <cmath>
#include <vector>
#include "paddle/framework/executor.h"
#include "paddle/framework/lod_tensor_array.h"
...
...
@@ -201,6 +202,15 @@ class WhileGradOp : public framework::OperatorBase {
VLOG
(
10
)
<<
"Checking "
<<
var_name
;
PADDLE_ENFORCE
(
!
framework
::
HasNAN
(
var
->
Get
<
framework
::
LoDTensor
>
()),
"%s has NAN"
,
var_name
);
if
(
var
->
Get
<
framework
::
LoDTensor
>
().
type
()
==
typeid
(
float
))
{
// NOLINT
auto
&
tensor
=
var
->
Get
<
framework
::
LoDTensor
>
();
auto
*
buf
=
tensor
.
data
<
float
>
();
for
(
int64_t
i
=
0
;
i
<
tensor
.
numel
();
++
i
)
{
PADDLE_ENFORCE
(
!
std
::
isnan
(
buf
[
i
]));
}
VLOG
(
10
)
<<
buf
[
0
];
}
}
};
check_var_no_nan
(
cur_scope
,
inside_grad_name
);
...
...
@@ -210,7 +220,7 @@ class WhileGradOp : public framework::OperatorBase {
"sum"
,
{{
"X"
,
{
pg_names
[
param_id
],
new_inside_name
}}},
{{
"Out"
,
{
pg_names
[
param_id
]}}},
framework
::
AttributeMap
{});
sum_op
->
Run
(
cur_scope
,
dev_place
);
check_var_no_nan
(
cur_
scope
,
pg_names
[
param_id
]);
check_var_no_nan
(
scope
,
pg_names
[
param_id
]);
cur_scope
.
Rename
(
new_inside_name
,
inside_grad_name
);
}
}
...
...
paddle/pybind/tensor_py.h
浏览文件 @
d2cb2841
...
...
@@ -77,10 +77,10 @@ struct CastToPyBufferImpl<true, I, ARGS...> {
}
else
if
(
paddle
::
platform
::
is_cpu_place
(
tensor
.
place
()))
{
dst_tensor
=
tensor
;
}
return
py
::
buffer_info
(
dst_tensor
.
mutable_data
<
CUR_TYPE
>
(
dst_tensor
.
place
()
),
sizeof
(
CUR_TYPE
),
py
::
format_descriptor
<
CUR_TYPE
>::
format
(
),
(
size_t
)
framework
::
arity
(
dst_tensor
.
dims
()),
dims_outside
,
strides
);
return
py
::
buffer_info
(
dst_tensor
.
data
<
CUR_TYPE
>
(),
sizeof
(
CUR_TYPE
),
py
::
format_descriptor
<
CUR_TYPE
>::
format
(
),
(
size_t
)
framework
::
arity
(
dst_tensor
.
dims
()
),
dims_outside
,
strides
);
}
else
{
constexpr
bool
less
=
I
+
1
<
std
::
tuple_size
<
std
::
tuple
<
ARGS
...
>>::
value
;
return
CastToPyBufferImpl
<
less
,
I
+
1
,
ARGS
...
>
()(
tensor
);
...
...
python/paddle/v2/fluid/tests/test_dynrnn_gradient_check.py
浏览文件 @
d2cb2841
...
...
@@ -294,7 +294,7 @@ class TestSimpleMulWithMemory(unittest.TestCase):
assert
isinstance
(
Out
,
Output
)
Out
.
out
(
o
)
#
@many_times(10)
@
many_times
(
10
)
@
prog_scope
()
def
test_forward_backward
(
self
):
py_rnn
=
TestSimpleMulWithMemory
.
SimpleMulWithMemory
()
...
...
@@ -330,10 +330,8 @@ class TestSimpleMulWithMemory(unittest.TestCase):
],
return_numpy
=
False
))
last_by_py
,
=
py_rnn
.
exe
().
values
()
print
w_g
[
0
]
self
.
assertTrue
(
numpy
.
allclose
(
last_np
,
last_by_py
))
w_g_num
=
py_rnn
.
get_numeric_gradient_of_param
(
self
.
PARAM_NAME
)
# print w_g_num[0], w_g[0]
self
.
assertTrue
(
numpy
.
allclose
(
last_np
,
last_by_py
))
self
.
assertTrue
(
numpy
.
allclose
(
w_g_num
,
w_g
,
rtol
=
0.1
))
i_g_num
=
py_rnn
.
get_numeric_gradient_of_input
(
self
.
DATA_NAME
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录