Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
be37468f
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
be37468f
编写于
3月 05, 2019
作者:
Z
zhengya01
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add tagspace ce
上级
29c12a62
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
130 addition
and
1 deletion
+130
-1
fluid/PaddleRec/tagspace/.run_ce.sh
fluid/PaddleRec/tagspace/.run_ce.sh
+20
-0
fluid/PaddleRec/tagspace/__init.py__
fluid/PaddleRec/tagspace/__init.py__
+0
-0
fluid/PaddleRec/tagspace/_ce.py
fluid/PaddleRec/tagspace/_ce.py
+66
-0
fluid/PaddleRec/tagspace/train.py
fluid/PaddleRec/tagspace/train.py
+44
-1
未找到文件。
fluid/PaddleRec/tagspace/.run_ce.sh
0 → 100755
浏览文件 @
be37468f
#!/bin/bash
export
MKL_NUM_THREADS
=
1
export
OMP_NUM_THREADS
=
1
export
CPU_NUM
=
1
export
NUM_THREADS
=
1
FLAGS_benchmark
=
true
python train.py
--enable_ce
--train_dir
train_big_data/
--vocab_text_path
big_vocab_text.txt
--vocab_tag_path
big_vocab_tag.txt
--model_dir
big_model
--batch_size
500 | python _ce.py
cudaid
=
${
tagspace
:
=0
}
# use 0-th card as default
export
CUDA_VISIBLE_DEVICES
=
$cudaid
FLAGS_benchmark
=
true
python train.py
--enable_ce
--use_cuda
1
--train_dir
train_big_data/
--vocab_text_path
big_vocab_text.txt
--vocab_tag_path
big_vocab_tag.txt
--model_dir
big_model
--batch_size
500
--parallel
1 | python _ce.py
cudaid
=
${
tagspace_4
:
=0,1,2,3
}
# use 0-th card as default
export
CUDA_VISIBLE_DEVICES
=
$cudaid
FLAGS_benchmark
=
true
python train.py
--enable_ce
--use_cuda
1
--train_dir
train_big_data/
--vocab_text_path
big_vocab_text.txt
--vocab_tag_path
big_vocab_tag.txt
--model_dir
big_model
--batch_size
500
--parallel
1 | python _ce.py
fluid/PaddleRec/tagspace/__init.py__
0 → 100644
浏览文件 @
be37468f
fluid/PaddleRec/tagspace/_ce.py
0 → 100644
浏览文件 @
be37468f
# 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_acc_cpu1_thread1_kpi
=
AccKpi
(
'train_acc_cpu1_thread1'
,
0.08
,
0
)
each_pass_duration_gpu1_kpi
=
DurationKpi
(
'each_pass_duration_gpu1'
,
0.08
,
0
,
actived
=
True
)
train_acc_gpu1_kpi
=
AccKpi
(
'train_acc_gpu1'
,
0.08
,
0
)
each_pass_duration_gpu4_kpi
=
DurationKpi
(
'each_pass_duration_gpu4'
,
0.08
,
0
,
actived
=
True
)
train_acc_gpu4_kpi
=
AccKpi
(
'train_acc_gpu4'
,
0.08
,
0
)
tracking_kpis
=
[
each_pass_duration_cpu1_thread1_kpi
,
train_acc_cpu1_thread1_kpi
,
each_pass_duration_gpu1_kpi
,
train_acc_gpu1_kpi
,
each_pass_duration_gpu4_kpi
,
train_acc_gpu4_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/tagspace/train.py
浏览文件 @
be37468f
...
...
@@ -40,6 +40,10 @@ def parse_args():
'--base_lr'
,
type
=
float
,
default
=
0.01
,
help
=
'learning rate'
)
parser
.
add_argument
(
'--num_devices'
,
type
=
int
,
default
=
1
,
help
=
'Number of GPU devices'
)
parser
.
add_argument
(
'--enable_ce'
,
action
=
'store_true'
,
help
=
'If set, run the task with continuous evaluation logs.'
)
args
=
parser
.
parse_args
()
return
args
...
...
@@ -51,6 +55,9 @@ def get_cards(args):
def
train
():
""" do training """
args
=
parse_args
()
if
args
.
enable_ce
:
fluid
.
default_startup_program
().
random_seed
=
SEED
fluid
.
default_main_program
().
random_seed
=
SEED
train_dir
=
args
.
train_dir
vocab_text_path
=
args
.
vocab_text_path
vocab_tag_path
=
args
.
vocab_tag_path
...
...
@@ -91,6 +98,7 @@ def train():
model_dir
=
args
.
model_dir
fetch_list
=
[
avg_cost
.
name
]
total_time
=
0.0
ce_info
=
[]
for
pass_idx
in
range
(
pass_num
):
epoch_idx
=
pass_idx
+
1
print
(
"epoch_%d start"
%
epoch_idx
)
...
...
@@ -106,6 +114,7 @@ def train():
"neg_tag"
:
lod_neg_tag
},
fetch_list
=
[
avg_cost
.
name
,
correct
.
name
])
ce_info
.
append
(
float
(
np
.
sum
(
correct_val
))
/
(
args
.
num_devices
*
batch_size
))
if
batch_id
%
args
.
print_batch
==
0
:
print
(
"TRAIN --> pass: {} batch_num: {} avg_cost: {}, acc: {}"
.
format
(
pass_idx
,
(
batch_id
+
10
)
*
batch_size
,
...
...
@@ -120,9 +129,43 @@ def train():
feed_var_names
=
[
"text"
,
"pos_tag"
]
fetch_vars
=
[
cos_pos
]
fluid
.
io
.
save_inference_model
(
save_dir
,
feed_var_names
,
fetch_vars
,
train_exe
)
exe
)
# only for ce
if
args
.
enable_ce
:
ce_acc
=
0
try
:
ce_acc
=
ce_info
[
-
2
]
except
:
logger
.
error
(
"ce info error"
)
epoch_idx
=
args
.
pass_num
device
=
get_device
(
args
)
if
args
.
use_cuda
:
gpu_num
=
device
[
1
]
print
(
"kpis
\t
each_pass_duration_gpu%s
\t
%s"
%
(
gpu_num
,
total_time
/
epoch_idx
))
print
(
"kpis
\t
train_acc_gpu%s
\t
%s"
%
(
gpu_num
,
ce_acc
))
else
:
cpu_num
=
device
[
1
]
threads_num
=
device
[
2
]
print
(
"kpis
\t
each_pass_duration_cpu%s_thread%s
\t
%s"
%
(
cpu_num
,
threads_num
,
total_time
/
epoch_idx
))
print
(
"kpis
\t
train_acc_cpu%s_thread%s
\t
%s"
%
(
cpu_num
,
threads_num
,
ce_acc
))
print
(
"finish training"
)
def
get_device
(
args
):
if
args
.
use_cuda
:
gpus
=
os
.
environ
.
get
(
"CUDA_VISIBLE_DEVICES"
,
1
)
gpu_num
=
len
(
gpus
.
split
(
','
))
return
"gpu"
,
gpu_num
else
:
threads_num
=
os
.
environ
.
get
(
'NUM_THREADS'
,
1
)
cpu_num
=
os
.
environ
.
get
(
'CPU_NUM'
,
1
)
return
"cpu"
,
int
(
cpu_num
),
int
(
threads_num
)
if
__name__
==
"__main__"
:
train
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录