Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
856d42b3
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看板
未验证
提交
856d42b3
编写于
3月 27, 2020
作者:
D
Dong Daxiang
提交者:
GitHub
3月 27, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #346 from MRXLT/0.2.0-fix
fix bert demo
上级
5fd1a241
c958028f
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
22 addition
and
17 deletion
+22
-17
python/examples/bert/README.md
python/examples/bert/README.md
+1
-1
python/examples/bert/benchmark_batch.py
python/examples/bert/benchmark_batch.py
+15
-7
python/examples/bert/bert_client.py
python/examples/bert/bert_client.py
+2
-2
python/examples/bert/bert_web_service.py
python/examples/bert/bert_web_service.py
+1
-2
python/examples/criteo_ctr/benchmark_batch.py
python/examples/criteo_ctr/benchmark_batch.py
+1
-2
python/examples/imagenet/benchmark_batch.py
python/examples/imagenet/benchmark_batch.py
+1
-2
python/examples/imdb/benchmark_batch.py
python/examples/imdb/benchmark_batch.py
+1
-1
未找到文件。
python/examples/bert/README.md
浏览文件 @
856d42b3
...
...
@@ -42,7 +42,7 @@ pip install paddle_serving_app
```
执行
```
cat data-c.txt | python bert_client.py
head data-c.txt | python bert_client.py --model bert_seq20_client/serving_client_conf.prototxt
```
启动client读取data-c.txt中的数据进行预测,预测结果为文本的向量表示(由于数据较多,脚本中没有将输出进行打印),server端的地址在脚本中修改。
...
...
python/examples/bert/benchmark_batch.py
浏览文件 @
856d42b3
...
...
@@ -35,21 +35,29 @@ def single_func(idx, resource):
dataset
=
[]
for
line
in
fin
:
dataset
.
append
(
line
.
strip
())
profile_flags
=
False
if
os
.
environ
[
"FLAGS_profile_client"
]:
profile_flags
=
True
if
args
.
request
==
"rpc"
:
reader
=
BertReader
(
vocab_file
=
"vocab.txt"
,
max_seq_len
=
20
)
fetch
=
[
"pooled_output"
]
client
=
Client
()
client
.
load_client_config
(
args
.
model
)
client
.
connect
([
resource
[
"endpoint"
][
idx
%
len
(
resource
[
"endpoint"
])]])
feed_batch
=
[]
for
bi
in
range
(
args
.
batch_size
):
feed_batch
.
append
(
reader
.
process
(
dataset
[
bi
]))
start
=
time
.
time
()
for
i
in
range
(
1000
):
if
args
.
batch_size
>=
1
:
result
=
client
.
batch_predict
(
feed_batch
=
feed_batch
,
fetch
=
fetch
)
feed_batch
=
[]
b_start
=
time
.
time
()
for
bi
in
range
(
args
.
batch_size
):
feed_batch
.
append
(
reader
.
process
(
dataset
[
bi
]))
b_end
=
time
.
time
()
if
profile_flags
:
print
(
"PROFILE
\t
pid:{}
\t
bert+pre_0:{} bert_pre_1:{}"
.
format
(
os
.
getpid
(),
int
(
round
(
b_start
*
1000000
)),
int
(
round
(
b_end
*
1000000
))))
result
=
client
.
predict
(
feed_batch
=
feed_batch
,
fetch
=
fetch
)
else
:
print
(
"unsupport batch size {}"
.
format
(
args
.
batch_size
))
...
...
@@ -62,7 +70,7 @@ def single_func(idx, resource):
if
__name__
==
'__main__'
:
multi_thread_runner
=
MultiThreadRunner
()
endpoint_list
=
[
"127.0.0.1:929
5"
,
"127.0.0.1:9296"
,
"127.0.0.1:9297"
,
"127.0.0.1:9298
"
"127.0.0.1:929
2"
,
"127.0.0.1:9293"
,
"127.0.0.1:9294"
,
"127.0.0.1:9295
"
]
result
=
multi_thread_runner
.
run
(
single_func
,
args
.
thread
,
{
"endpoint"
:
endpoint_list
})
...
...
python/examples/bert/bert_client.py
浏览文件 @
856d42b3
...
...
@@ -29,13 +29,13 @@ from paddle_serving_app import ChineseBertReader
args
=
benchmark_args
()
reader
=
ChineseBertReader
(
max_seq_len
=
20
)
reader
=
ChineseBertReader
(
{
"max_seq_len"
:
20
}
)
fetch
=
[
"pooled_output"
]
endpoint_list
=
[
"127.0.0.1:9292"
]
client
=
Client
()
client
.
load_client_config
(
args
.
model
)
client
.
connect
(
endpoint_list
)
for
line
in
f
in
:
for
line
in
sys
.
std
in
:
feed_dict
=
reader
.
process
(
line
)
result
=
client
.
predict
(
feed
=
feed_dict
,
fetch
=
fetch
)
python/examples/bert/bert_web_service.py
浏览文件 @
856d42b3
...
...
@@ -32,8 +32,7 @@ bert_service = BertService(name="bert")
bert_service
.
load
()
bert_service
.
load_model_config
(
sys
.
argv
[
1
])
gpu_ids
=
os
.
environ
[
"CUDA_VISIBLE_DEVICES"
]
gpus
=
[
int
(
x
)
for
x
in
gpu_ids
.
split
(
","
)]
bert_service
.
set_gpus
(
gpus
)
bert_service
.
set_gpus
(
gpu_ids
)
bert_service
.
prepare_server
(
workdir
=
"workdir"
,
port
=
int
(
sys
.
argv
[
2
]),
device
=
"gpu"
)
bert_service
.
run_server
()
python/examples/criteo_ctr/benchmark_batch.py
浏览文件 @
856d42b3
...
...
@@ -55,8 +55,7 @@ def single_func(idx, resource):
for
i
in
range
(
1
,
27
):
feed_dict
[
"sparse_{}"
.
format
(
i
-
1
)]
=
data
[
0
][
i
]
feed_batch
.
append
(
feed_dict
)
result
=
client
.
batch_predict
(
feed_batch
=
feed_batch
,
fetch
=
fetch
)
result
=
client
.
predict
(
feed_batch
=
feed_batch
,
fetch
=
fetch
)
else
:
print
(
"unsupport batch size {}"
.
format
(
args
.
batch_size
))
...
...
python/examples/imagenet/benchmark_batch.py
浏览文件 @
856d42b3
...
...
@@ -50,8 +50,7 @@ def single_func(idx, resource):
img
=
reader
.
process_image
(
img_list
[
i
])
img
=
img
.
reshape
(
-
1
)
feed_batch
.
append
({
"image"
:
img
})
result
=
client
.
batch_predict
(
feed_batch
=
feed_batch
,
fetch
=
fetch
)
result
=
client
.
predict
(
feed_batch
=
feed_batch
,
fetch
=
fetch
)
else
:
print
(
"unsupport batch size {}"
.
format
(
args
.
batch_size
))
...
...
python/examples/imdb/benchmark_batch.py
浏览文件 @
856d42b3
...
...
@@ -42,7 +42,7 @@ def single_func(idx, resource):
for
bi
in
range
(
args
.
batch_size
):
word_ids
,
label
=
imdb_dataset
.
get_words_and_label
(
line
)
feed_batch
.
append
({
"words"
:
word_ids
})
result
=
client
.
batch_
predict
(
result
=
client
.
predict
(
feed_batch
=
feed_batch
,
fetch
=
[
"prediction"
])
else
:
print
(
"unsupport batch size {}"
.
format
(
args
.
batch_size
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录