Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
7e0e08a8
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看板
提交
7e0e08a8
编写于
3月 01, 2019
作者:
Z
zhengya01
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add word2vec ce
上级
d700b813
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
107 addition
and
1 deletion
+107
-1
fluid/PaddleRec/word2vec/.run_ce.sh
fluid/PaddleRec/word2vec/.run_ce.sh
+13
-0
fluid/PaddleRec/word2vec/_ce.py
fluid/PaddleRec/word2vec/_ce.py
+62
-0
fluid/PaddleRec/word2vec/train.py
fluid/PaddleRec/word2vec/train.py
+32
-1
未找到文件。
fluid/PaddleRec/word2vec/.run_ce.sh
0 → 100755
浏览文件 @
7e0e08a8
#!/bin/bash
export
MKL_NUM_THREADS
=
1
export
OMP_NUM_THREADS
=
1
export
CPU_NUM
=
1
FLAGS_benchmark
=
true
python train.py
--train_data_path
./data/1-billion-word-language-modeling-benchmark-r13output/training-monolingual.tokenized.shuffled
--dict_path
data/1-billion_dict
--with_hs
--is_local
--num_passes
10
--enable_ce
| python _ce.py
export
CPU_NUM
=
8
FLAGS_benchmark
=
true
python train.py
--train_data_path
./data/1-billion-word-language-modeling-benchmark-r13output/training-monolingual.tokenized.shuffled
--dict_path
data/1-billion_dict
--with_hs
--is_local
--num_passes
10
--enable_ce
| python _ce.py
fluid/PaddleRec/word2vec/_ce.py
0 → 100644
浏览文件 @
7e0e08a8
# this file is only used for continuous evaluation test!
import
os
import
sys
sys
.
path
.
append
(
os
.
environ
[
'ceroot'
])
from
kpi
import
CostKpi
from
kpi
import
DurationKpi
from
kpi
import
AccKpi
each_pass_duration_cpu1_thread1_kpi
=
DurationKpi
(
'each_pass_duration_cpu1_thread1'
,
0.08
,
0
,
actived
=
True
)
train_loss_cpu1_thread1_kpi
=
CostKpi
(
'train_loss_cpu1_thread1'
,
0.08
,
0
)
each_pass_duration_cpu8_thread8_kpi
=
DurationKpi
(
'each_pass_duration_cpu8_thread8'
,
0.08
,
0
,
actived
=
True
)
train_loss_cpu8_thread8_kpi
=
CostKpi
(
'train_loss_cpu8_thread8'
,
0.08
,
0
)
tracking_kpis
=
[
each_pass_duration_cpu1_thread1_kpi
,
train_loss_cpu1_thread1_kpi
,
each_pass_duration_cpu8_thread8_kpi
,
train_loss_cpu8_thread8_kpi
,
]
def
parse_log
(
log
):
'''
This method should be implemented by model developers.
The suggestion:
each line in the log should be key, value, for example:
"
train_cost
\t
1.0
test_cost
\t
1.0
train_cost
\t
1.0
train_cost
\t
1.0
train_acc
\t
1.2
"
'''
for
line
in
log
.
split
(
'
\n
'
):
fs
=
line
.
strip
().
split
(
'
\t
'
)
print
(
fs
)
if
len
(
fs
)
==
3
and
fs
[
0
]
==
'kpis'
:
kpi_name
=
fs
[
1
]
kpi_value
=
float
(
fs
[
2
])
yield
kpi_name
,
kpi_value
def
log_to_ce
(
log
):
kpi_tracker
=
{}
for
kpi
in
tracking_kpis
:
kpi_tracker
[
kpi
.
name
]
=
kpi
for
(
kpi_name
,
kpi_value
)
in
parse_log
(
log
):
print
(
kpi_name
,
kpi_value
)
kpi_tracker
[
kpi_name
].
add_record
(
kpi_value
)
kpi_tracker
[
kpi_name
].
persist
()
if
__name__
==
'__main__'
:
log
=
sys
.
stdin
.
read
()
log_to_ce
(
log
)
fluid/PaddleRec/word2vec/train.py
浏览文件 @
7e0e08a8
...
@@ -129,6 +129,11 @@ def parse_args():
...
@@ -129,6 +129,11 @@ def parse_args():
default
=
4
,
default
=
4
,
help
=
"find rank_num-nearest result for test (default: 4)"
)
help
=
"find rank_num-nearest result for test (default: 4)"
)
parser
.
add_argument
(
'--enable_ce'
,
action
=
'store_true'
,
help
=
'If set, run the task with continuous evaluation logs.'
)
return
parser
.
parse_args
()
return
parser
.
parse_args
()
...
@@ -198,6 +203,8 @@ def train_loop(args, train_program, reader, py_reader, loss, trainer_id):
...
@@ -198,6 +203,8 @@ def train_loop(args, train_program, reader, py_reader, loss, trainer_id):
profiler_step_start
=
20
profiler_step_start
=
20
profiler_step_end
=
30
profiler_step_end
=
30
total_time
=
0
ce_info
=
[]
for
pass_id
in
range
(
args
.
num_passes
):
for
pass_id
in
range
(
args
.
num_passes
):
py_reader
.
start
()
py_reader
.
start
()
time
.
sleep
(
10
)
time
.
sleep
(
10
)
...
@@ -206,11 +213,14 @@ def train_loop(args, train_program, reader, py_reader, loss, trainer_id):
...
@@ -206,11 +213,14 @@ def train_loop(args, train_program, reader, py_reader, loss, trainer_id):
start
=
time
.
time
()
start
=
time
.
time
()
try
:
try
:
while
True
:
start_time
=
time
.
time
()
loss_val
=
train_exe
.
run
(
fetch_list
=
[
loss
.
name
])
loss_val
=
train_exe
.
run
(
fetch_list
=
[
loss
.
name
])
loss_val
=
np
.
mean
(
loss_val
)
loss_val
=
np
.
mean
(
loss_val
)
total_time
+=
time
.
time
()
-
start_time
ce_info
.
append
(
loss_val
.
mean
())
if
batch_id
%
50
==
0
:
if
batch_id
%
50
==
0
:
logger
.
info
(
logger
.
info
(
"TRAIN --> pass: {} batch: {} loss: {} reader queue:{}"
.
"TRAIN --> pass: {} batch: {} loss: {} reader queue:{}"
.
...
@@ -250,6 +260,27 @@ def train_loop(args, train_program, reader, py_reader, loss, trainer_id):
...
@@ -250,6 +260,27 @@ def train_loop(args, train_program, reader, py_reader, loss, trainer_id):
fluid
.
io
.
save_persistables
(
executor
=
exe
,
dirname
=
model_dir
)
fluid
.
io
.
save_persistables
(
executor
=
exe
,
dirname
=
model_dir
)
with
open
(
model_dir
+
"/_success"
,
'w+'
)
as
f
:
with
open
(
model_dir
+
"/_success"
,
'w+'
)
as
f
:
f
.
write
(
str
(
pass_id
))
f
.
write
(
str
(
pass_id
))
# only for ce
if
args
.
enable_ce
:
threads_num
,
cpu_num
=
get_cards
(
args
)
epoch_idx
=
args
.
num_passes
ce_loss
=
0
try
:
ce_loss
=
ce_info
[
-
1
]
except
:
logger
.
error
(
"ce info error"
)
print
(
"kpis
\t
each_pass_duration_cpu%s_thread%s
\t
%s"
%
(
cpu_num
,
threads_num
,
total_time
/
epoch_idx
))
print
(
"kpis
\t
train_loss_cpu%s_thread%s
\t
%s"
%
(
cpu_num
,
threads_num
,
ce_loss
))
def
get_cards
(
args
):
threads_num
=
os
.
environ
.
get
(
'CPU_NUM'
,
1
)
cpu_num
=
os
.
environ
.
get
(
'CPU_NUM'
,
1
)
return
int
(
threads_num
),
int
(
cpu_num
)
def
GetFileList
(
data_path
):
def
GetFileList
(
data_path
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录