Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
aa2635fe
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看板
提交
aa2635fe
编写于
5月 09, 2018
作者:
K
Kexin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clean code
上级
cbf502e5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
1 addition
and
14 deletion
+1
-14
paddle/fluid/operators/load_op.cc
paddle/fluid/operators/load_op.cc
+1
-10
paddle/fluid/operators/save_load_op_test.cc
paddle/fluid/operators/save_load_op_test.cc
+0
-4
未找到文件。
paddle/fluid/operators/load_op.cc
浏览文件 @
aa2635fe
...
@@ -12,7 +12,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
@@ -12,7 +12,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#include <fstream>
#include <fstream>
#include <iostream>
#include "paddle/fluid/framework/data_type_transform.h"
#include "paddle/fluid/framework/data_type_transform.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/framework/op_registry.h"
...
@@ -53,9 +52,6 @@ class LoadOp : public framework::OperatorBase {
...
@@ -53,9 +52,6 @@ class LoadOp : public framework::OperatorBase {
auto
in_dtype
=
framework
::
ToDataType
(
tensor
->
type
());
auto
in_dtype
=
framework
::
ToDataType
(
tensor
->
type
());
auto
out_dtype
=
load_as_fp16
?
framework
::
proto
::
VarType
::
FP16
:
in_dtype
;
auto
out_dtype
=
load_as_fp16
?
framework
::
proto
::
VarType
::
FP16
:
in_dtype
;
std
::
cout
<<
"In load op: "
<<
std
::
endl
;
std
::
cout
<<
"before conversion block"
<<
std
::
endl
;
if
(
in_dtype
!=
out_dtype
)
{
if
(
in_dtype
!=
out_dtype
)
{
// convert to float16 tensor
// convert to float16 tensor
auto
in_kernel_type
=
framework
::
OpKernelType
(
in_dtype
,
place
);
auto
in_kernel_type
=
framework
::
OpKernelType
(
in_dtype
,
place
);
...
@@ -63,20 +59,15 @@ class LoadOp : public framework::OperatorBase {
...
@@ -63,20 +59,15 @@ class LoadOp : public framework::OperatorBase {
framework
::
LoDTensor
fp16_tensor
;
framework
::
LoDTensor
fp16_tensor
;
// copy LoD info to the new tensor
// copy LoD info to the new tensor
fp16_tensor
.
set_lod
(
tensor
->
lod
());
fp16_tensor
.
set_lod
(
tensor
->
lod
());
std
::
cout
<<
"before TransDataType"
<<
std
::
endl
;
framework
::
TransDataType
(
in_kernel_type
,
out_kernel_type
,
*
tensor
,
framework
::
TransDataType
(
in_kernel_type
,
out_kernel_type
,
*
tensor
,
&
fp16_tensor
);
&
fp16_tensor
);
std
::
cout
<<
"after TransDataType"
<<
std
::
endl
;
// reset output tensor
// reset output tensor
out_var
->
Clear
();
out_var
->
Clear
();
tensor
=
out_var
->
GetMutable
<
framework
::
LoDTensor
>
();
tensor
=
out_var
->
GetMutable
<
framework
::
LoDTensor
>
();
tensor
->
set_lod
(
fp16_tensor
.
lod
());
tensor
->
set_lod
(
fp16_tensor
.
lod
());
std
::
cout
<<
"before TransDataType"
<<
std
::
endl
;
tensor
->
ShareDataWith
(
fp16_tensor
);
tensor
->
ShareDataWith
(
fp16_tensor
);
std
::
cout
<<
"after TransDataType"
<<
std
::
endl
;
}
}
std
::
cout
<<
"Out of load op: "
<<
std
::
endl
;
}
}
};
};
...
...
paddle/fluid/operators/save_load_op_test.cc
浏览文件 @
aa2635fe
...
@@ -127,17 +127,13 @@ TEST(LoadFP16Op, CPU) {
...
@@ -127,17 +127,13 @@ TEST(LoadFP16Op, CPU) {
auto
load_var
=
scope
.
Var
(
"out_var"
);
auto
load_var
=
scope
.
Var
(
"out_var"
);
auto
load_op
=
paddle
::
framework
::
OpRegistry
::
CreateOp
(
auto
load_op
=
paddle
::
framework
::
OpRegistry
::
CreateOp
(
"load"
,
{},
{{
"Out"
,
{
"out_var"
}}},
attrs
);
"load"
,
{},
{{
"Out"
,
{
"out_var"
}}},
attrs
);
LOG
(
INFO
)
<<
"before load op run"
;
load_op
->
Run
(
scope
,
place
);
load_op
->
Run
(
scope
,
place
);
LOG
(
INFO
)
<<
"after load op run"
;
auto
target
=
load_var
->
Get
<
paddle
::
framework
::
LoDTensor
>
();
auto
target
=
load_var
->
Get
<
paddle
::
framework
::
LoDTensor
>
();
paddle
::
platform
::
float16
*
actual
=
target
.
data
<
paddle
::
platform
::
float16
>
();
paddle
::
platform
::
float16
*
actual
=
target
.
data
<
paddle
::
platform
::
float16
>
();
LOG
(
INFO
)
<<
"after target->data"
;
for
(
int64_t
i
=
0
;
i
<
tensor
->
numel
();
++
i
)
{
for
(
int64_t
i
=
0
;
i
<
tensor
->
numel
();
++
i
)
{
EXPECT_EQ
(
expect
[
i
],
static_cast
<
float
>
(
actual
[
i
]));
EXPECT_EQ
(
expect
[
i
],
static_cast
<
float
>
(
actual
[
i
]));
}
}
LOG
(
INFO
)
<<
"after expect equal"
;
auto
&
actual_lod
=
target
.
lod
();
auto
&
actual_lod
=
target
.
lod
();
EXPECT_EQ
(
expect_lod
.
size
(),
actual_lod
.
size
());
EXPECT_EQ
(
expect_lod
.
size
(),
actual_lod
.
size
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录