Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
a4a5704a
S
Serving
项目概览
PaddlePaddle
/
Serving
大约 1 年 前同步成功
通知
186
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看板
提交
a4a5704a
编写于
3月 15, 2020
作者:
M
MRXLT
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove bert_rpc_client
上级
7abe8a1c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
0 addition
and
124 deletion
+0
-124
python/examples/bert/bert_rpc_client.py
python/examples/bert/bert_rpc_client.py
+0
-124
未找到文件。
python/examples/bert/bert_rpc_client.py
已删除
100644 → 0
浏览文件 @
7abe8a1c
# coding:utf-8
# pylint: disable=doc-string-missing
import
os
import
sys
import
numpy
as
np
import
paddlehub
as
hub
import
ujson
import
random
import
time
from
paddlehub.common.logger
import
logger
import
socket
from
paddle_serving_client
import
Client
from
paddle_serving_client.utils
import
MultiThreadRunner
from
paddle_serving_client.utils
import
benchmark_args
from
bert_reader
import
BertReader
args
=
benchmark_args
()
_ver
=
sys
.
version_info
is_py2
=
(
_ver
[
0
]
==
2
)
is_py3
=
(
_ver
[
0
]
==
3
)
if
is_py2
:
import
httplib
if
is_py3
:
import
http.client
as
httplib
class
BertService
():
def
__init__
(
self
,
max_seq_len
=
128
,
model_name
=
"bert_uncased_L-12_H-768_A-12"
,
show_ids
=
False
,
do_lower_case
=
True
,
process_id
=
0
,
retry
=
3
):
self
.
process_id
=
process_id
self
.
reader_flag
=
False
self
.
batch_size
=
0
self
.
max_seq_len
=
max_seq_len
self
.
model_name
=
model_name
self
.
show_ids
=
show_ids
self
.
do_lower_case
=
do_lower_case
self
.
retry
=
retry
self
.
pid
=
os
.
getpid
()
self
.
profile
=
True
if
(
"FLAGS_profile_client"
in
os
.
environ
and
os
.
environ
[
"FLAGS_profile_client"
])
else
False
self
.
reader
=
BertReader
(
vocab_file
=
"vocab.txt"
,
max_seq_len
=
20
)
self
.
reader_flag
=
True
def
load_client
(
self
,
config_file
,
server_addr
):
self
.
client
=
Client
()
self
.
client
.
load_client_config
(
config_file
)
self
.
client
.
connect
(
server_addr
)
def
run_general
(
self
,
text
,
fetch
):
result
=
[]
prepro_start
=
time
.
time
()
feed
=
self
.
reader
.
process
(
text
)
if
self
.
profile
:
print
(
"PROFILE
\t
pid:{}
\t
bert_pre_0:{} bert_pre_1:{}"
.
format
(
self
.
pid
,
int
(
round
(
prepro_start
*
1000000
)),
int
(
round
(
prepro_end
*
1000000
))))
fetch_map
=
self
.
client
.
predict
(
feed
=
feed
,
fetch
=
fetch
)
return
fetch_map
def
run_batch_general
(
self
,
text
,
fetch
):
self
.
batch_size
=
len
(
text
)
result
=
[]
prepro_start
=
time
.
time
()
feed_batch
=
[]
for
si
in
range
(
self
.
batch_size
):
feed
=
self
.
reader
.
process
(
text
[
si
])
feed_batch
.
append
(
feed
)
prepro_end
=
time
.
time
()
if
self
.
profile
:
print
(
"PROFILE
\t
pid:{}
\t
bert_pre_0:{} bert_pre_1:{}"
.
format
(
self
.
pid
,
int
(
round
(
prepro_start
*
1000000
)),
int
(
round
(
prepro_end
*
1000000
))))
fetch_map_batch
=
self
.
client
.
batch_predict
(
feed_batch
=
feed_batch
,
fetch
=
fetch
)
return
fetch_map_batch
def
single_func
(
idx
,
resource
):
bc
=
BertService
(
model_name
=
'bert_chinese_L-12_H-768_A-12'
,
max_seq_len
=
20
,
show_ids
=
False
,
do_lower_case
=
True
)
config_file
=
'./serving_client_conf/serving_client_conf.prototxt'
fetch
=
[
"pooled_output"
]
server_addr
=
[
resource
[
"endpoint"
][
idx
%
len
(
resource
[
"endpoint"
])]]
bc
.
load_client
(
config_file
,
server_addr
)
batch_size
=
1
use_batch
=
False
if
batch_size
==
1
else
True
feed_batch
=
[]
start
=
time
.
time
()
fin
=
open
(
"data-c.txt"
)
for
line
in
fin
:
if
not
use_batch
:
result
=
bc
.
run_general
(
line
.
strip
(),
fetch
)
else
:
if
len
(
feed_batch
)
==
batch_size
:
result
=
bc
.
run_batch_general
(
feed_batch
,
fetch
)
feed_batch
=
[]
else
:
feed_batch
.
append
(
line
.
strip
())
if
use_batch
and
len
(
feed_batch
)
>
0
:
result
=
bc
.
run_batch_general
(
feed_batch
,
fetch
)
feed_batch
=
[]
end
=
time
.
time
()
return
[[
end
-
start
]]
if
__name__
==
'__main__'
:
multi_thread_runner
=
MultiThreadRunner
()
result
=
multi_thread_runner
.
run
(
single_func
,
args
.
thread
,
{
"endpoint"
:
[
"127.0.0.1:9292"
]})
print
(
"time cost for each thread {}"
.
format
(
result
))
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录