Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
f0a09c3a
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
f0a09c3a
编写于
2月 20, 2020
作者:
Z
zhengya01
提交者:
GitHub
2月 20, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add ce for dygraph_lac (#4327)
上级
837489ed
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
27 addition
and
5 deletion
+27
-5
dygraph/lac/train.py
dygraph/lac/train.py
+27
-5
未找到文件。
dygraph/lac/train.py
浏览文件 @
f0a09c3a
...
@@ -44,10 +44,11 @@ def do_train(args):
...
@@ -44,10 +44,11 @@ def do_train(args):
with
fluid
.
dygraph
.
guard
(
place
):
with
fluid
.
dygraph
.
guard
(
place
):
if
args
.
use_data_parallel
:
if
args
.
use_data_parallel
:
strategy
=
fluid
.
dygraph
.
parallel
.
prepare_context
()
strategy
=
fluid
.
dygraph
.
parallel
.
prepare_context
()
#fluid.default_startup_program().random_seed = 102
if
args
.
enable_ce
:
#fluid.default_main_program().random_seed = 102
fluid
.
default_startup_program
().
random_seed
=
102
#np.random.seed(102)
fluid
.
default_main_program
().
random_seed
=
102
#random.seed(102)
np
.
random
.
seed
(
102
)
random
.
seed
(
102
)
train_loader
=
reader
.
create_dataloader
(
train_loader
=
reader
.
create_dataloader
(
args
,
args
,
file_name
=
args
.
train_data
,
file_name
=
args
.
train_data
,
...
@@ -102,6 +103,8 @@ def do_train(args):
...
@@ -102,6 +103,8 @@ def do_train(args):
(
precision
,
recall
,
f1
,
end_time
-
start_time
))
(
precision
,
recall
,
f1
,
end_time
-
start_time
))
model
.
train
()
model
.
train
()
ce_time
=
[]
ce_infor
=
[]
for
epoch_id
in
range
(
args
.
epoch
):
for
epoch_id
in
range
(
args
.
epoch
):
for
batch
in
train_loader
():
for
batch
in
train_loader
():
words
,
targets
,
length
=
batch
words
,
targets
,
length
=
batch
...
@@ -129,6 +132,8 @@ def do_train(args):
...
@@ -129,6 +132,8 @@ def do_train(args):
print
(
"[train] step = %d, loss = %.5f, P: %.5f, R: %.5f, F1: %.5f, elapsed time %.5f"
%
(
print
(
"[train] step = %d, loss = %.5f, P: %.5f, R: %.5f, F1: %.5f, elapsed time %.5f"
%
(
step
,
avg_cost
,
precision
,
recall
,
f1_score
,
end_time
-
start_time
))
step
,
avg_cost
,
precision
,
recall
,
f1_score
,
end_time
-
start_time
))
ce_time
.
append
(
end_time
-
start_time
)
ce_infor
.
append
([
precision
,
recall
,
f1_score
])
if
step
%
args
.
validation_steps
==
0
:
if
step
%
args
.
validation_steps
==
0
:
test_process
(
test_loader
,
chunk_evaluator
)
test_process
(
test_loader
,
chunk_evaluator
)
...
@@ -139,7 +144,24 @@ def do_train(args):
...
@@ -139,7 +144,24 @@ def do_train(args):
paddle
.
fluid
.
save_dygraph
(
model
.
state_dict
(),
save_path
)
paddle
.
fluid
.
save_dygraph
(
model
.
state_dict
(),
save_path
)
step
+=
1
step
+=
1
if
args
.
enable_ce
and
fluid
.
dygraph
.
parallel
.
Env
().
local_rank
==
0
:
card_num
=
fluid
.
core
.
get_cuda_device_count
()
_p
=
0
_r
=
0
_f1
=
0
_time
=
0
try
:
_time
=
ce_time
[
-
1
]
_p
=
ce_infor
[
-
1
][
0
]
_r
=
ce_infor
[
-
1
][
1
]
_f1
=
ce_infor
[
-
1
][
2
]
except
:
print
(
"ce info error"
)
print
(
"kpis
\t
train_duration_card%s
\t
%s"
%
(
card_num
,
_time
))
print
(
"kpis
\t
train_p_card%s
\t
%f"
%
(
card_num
,
_p
))
print
(
"kpis
\t
train_r_card%s
\t
%f"
%
(
card_num
,
_r
))
print
(
"kpis
\t
train_f1_card%s
\t
%f"
%
(
card_num
,
_f1
))
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
# 参数控制可以根据需求使用argparse,yaml或者json
# 参数控制可以根据需求使用argparse,yaml或者json
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录