Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
54230dca
S
Serving
项目概览
PaddlePaddle
/
Serving
大约 2 年 前同步成功
通知
187
Star
833
Fork
253
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
105
列表
看板
标记
里程碑
合并请求
10
Wiki
2
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Serving
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
105
Issue
105
列表
看板
标记
里程碑
合并请求
10
合并请求
10
Pages
分析
分析
仓库分析
DevOps
Wiki
2
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
54230dca
编写于
4月 05, 2021
作者:
W
wangjiawei04
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bert
上级
22c3047c
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
85 addition
and
0 deletion
+85
-0
python/examples/bert/bert_web_service.py
python/examples/bert/bert_web_service.py
+1
-0
python/examples/bert/new_benchmark.py
python/examples/bert/new_benchmark.py
+59
-0
python/examples/bert/new_benchmark.sh
python/examples/bert/new_benchmark.sh
+25
-0
未找到文件。
python/examples/bert/bert_web_service.py
浏览文件 @
54230dca
...
@@ -30,6 +30,7 @@ class BertService(WebService):
...
@@ -30,6 +30,7 @@ class BertService(WebService):
def
preprocess
(
self
,
feed
=
[],
fetch
=
[]):
def
preprocess
(
self
,
feed
=
[],
fetch
=
[]):
feed_res
=
[]
feed_res
=
[]
is_batch
=
True
is_batch
=
True
print
(
feed
)
for
ins
in
feed
:
for
ins
in
feed
:
feed_dict
=
self
.
reader
.
process
(
ins
[
"words"
].
encode
(
"utf-8"
))
feed_dict
=
self
.
reader
.
process
(
ins
[
"words"
].
encode
(
"utf-8"
))
for
key
in
feed_dict
.
keys
():
for
key
in
feed_dict
.
keys
():
...
...
python/examples/bert/new_benchmark.py
0 → 100644
浏览文件 @
54230dca
import
sys
import
os
import
yaml
import
requests
import
time
import
json
import
ast
from
paddle_serving_client.utils
import
MultiThreadRunner
from
paddle_serving_client.utils
import
benchmark_args
,
show_latency
def
parse_benchmark
(
filein
,
fileout
):
with
open
(
filein
,
"r"
)
as
fin
:
res
=
yaml
.
load
(
fin
)
del_list
=
[]
for
key
in
res
[
"DAG"
].
keys
():
if
"call"
in
key
:
del_list
.
append
(
key
)
for
key
in
del_list
:
del
res
[
"DAG"
][
key
]
with
open
(
fileout
,
"w"
)
as
fout
:
yaml
.
dump
(
res
,
fout
,
default_flow_style
=
False
)
def
run_http
(
idx
,
batch_size
):
"""
{"feed":[{"words": "hello"}], "fetch":["pooled_output"]}
"""
print
(
"start thread ({})"
.
format
(
idx
))
url
=
"http://127.0.0.1:9292/bert/prediction"
start
=
time
.
time
()
with
open
(
"data-c.txt"
,
'r'
)
as
fin
:
start
=
time
.
time
()
lines
=
fin
.
readlines
()
start_idx
=
0
while
start_idx
<
len
(
lines
):
end_idx
=
min
(
len
(
lines
),
start_idx
+
batch_size
)
feed
=
{}
feed_lst
=
[{
"words"
:
lines
[
i
]}
for
i
in
range
(
start_idx
,
end_idx
)]
data
=
{
"feed"
:
feed_lst
,
"fetch"
:
[
"pooled_output"
]}
r
=
requests
.
post
(
url
=
url
,
data
=
json
.
dumps
(
data
),
headers
=
{
"Content-Type"
:
"application/json"
})
start_idx
+=
batch_size
end
=
time
.
time
()
if
end
-
start
>
40
:
break
end
=
time
.
time
()
return
[[
end
-
start
]]
def
multithread_http
(
thread
,
batch_size
):
multi_thread_runner
=
MultiThreadRunner
()
result
=
multi_thread_runner
.
run
(
run_http
,
thread
,
batch_size
)
if
__name__
==
"__main__"
:
if
sys
.
argv
[
1
]
==
"run"
:
thread
=
int
(
sys
.
argv
[
2
])
batch_size
=
int
(
sys
.
argv
[
3
])
multithread_http
(
thread
,
batch_size
)
if
sys
.
argv
[
1
]
==
"dump"
:
filein
=
sys
.
argv
[
2
]
fileout
=
sys
.
argv
[
3
]
parse_benchmark
(
filein
,
fileout
)
python/examples/bert/new_benchmark.sh
0 → 100644
浏览文件 @
54230dca
modelname
=
"bert"
# HTTP
ps
-ef
|
grep
web_service |
awk
'{print $2}'
| xargs
kill
-9
sleep
3
rm
-rf
profile_log_
$modelname
for
thread_num
in
1 8 16
do
for
batch_size
in
1 10 100
do
python3.7 bert_web_service.py bert_seq128_model/ 9292 &
sleep
3
echo
"----Bert thread num:
$thread_num
batch size:
$batch_size
mode:http ----"
>>
profile_log_
$modelname
nvidia-smi
--id
=
2
--query-compute-apps
=
used_memory
--format
=
csv
-lms
100
>
gpu_use.log 2>&1 &
nvidia-smi
--id
=
2
--query-gpu
=
utilization.gpu
--format
=
csv
-lms
100
>
gpu_utilization.log 2>&1 &
echo
"import psutil
\n
cpu_utilization=psutil.cpu_percent(1,False)
\n
print('CPU_UTILIZATION:', cpu_utilization)
\n
"
>
cpu_utilization.py
python3.7 new_benchmark.py run
$thread_num
$batch_size
python3.7 cpu_utilization.py
>>
profile_log_
$modelname
ps
-ef
|
grep
web_service |
awk
'{print $2}'
| xargs
kill
-9
python3.7 new_benchmark.py dump benchmark.log benchmark.tmp
mv
benchmark.tmp benchmark.log
awk
'BEGIN {max = 0} {if(NR>1){if ($modelname > max) max=$modelname}} END {print "MAX_GPU_MEMORY:", max}'
gpu_use.log
>>
profile_log_
$modelname
awk
'BEGIN {max = 0} {if(NR>1){if ($modelname > max) max=$modelname}} END {print "GPU_UTILIZATION:", max}'
gpu_utilization.log
>>
profile_log_
$modelname
cat
benchmark.log
>>
profile_log_
$modelname
done
done
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录