Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
f7ee7b16
S
Serving
项目概览
PaddlePaddle
/
Serving
接近 2 年 前同步成功
通知
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看板
未验证
提交
f7ee7b16
编写于
12月 09, 2020
作者:
T
TeslaZhao
提交者:
GitHub
12月 09, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #907 from TeslaZhao/develop
Predicting on multi-devices in local predictor
上级
41ed402e
15b22346
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
98 addition
and
37 deletion
+98
-37
python/examples/pipeline/imdb_model_ensemble/README.md
python/examples/pipeline/imdb_model_ensemble/README.md
+19
-0
python/examples/pipeline/simple_web_service/web_service.py
python/examples/pipeline/simple_web_service/web_service.py
+13
-5
python/pipeline/analyse.py
python/pipeline/analyse.py
+1
-1
python/pipeline/channel.py
python/pipeline/channel.py
+29
-18
python/pipeline/local_service_handler.py
python/pipeline/local_service_handler.py
+21
-4
python/pipeline/operator.py
python/pipeline/operator.py
+5
-4
python/pipeline/pipeline_client.py
python/pipeline/pipeline_client.py
+10
-5
未找到文件。
python/examples/pipeline/imdb_model_ensemble/README.md
0 → 100644
浏览文件 @
f7ee7b16
# IMDB model ensemble examples
## Get models
```
sh get_data.sh
```
## Start servers
```
python -m paddle_serving_server.serve --model imdb_cnn_model --port 9292 &> cnn.log &
python -m paddle_serving_server.serve --model imdb_bow_model --port 9393 &> bow.log &
python test_pipeline_server.py &>pipeline.log &
```
## Start clients
```
python test_pipeline_client.py
```
python/examples/pipeline/simple_web_service/web_service.py
浏览文件 @
f7ee7b16
...
@@ -17,6 +17,7 @@ except ImportError:
...
@@ -17,6 +17,7 @@ except ImportError:
from
paddle_serving_server.web_service
import
WebService
,
Op
from
paddle_serving_server.web_service
import
WebService
,
Op
import
logging
import
logging
import
numpy
as
np
import
numpy
as
np
import
sys
_LOGGER
=
logging
.
getLogger
()
_LOGGER
=
logging
.
getLogger
()
...
@@ -31,11 +32,18 @@ class UciOp(Op):
...
@@ -31,11 +32,18 @@ class UciOp(Op):
log_id
,
input_dict
))
log_id
,
input_dict
))
x_value
=
input_dict
[
"x"
]
x_value
=
input_dict
[
"x"
]
proc_dict
=
{}
proc_dict
=
{}
if
isinstance
(
x_value
,
(
str
,
unicode
)):
if
sys
.
version_info
.
major
==
2
:
input_dict
[
"x"
]
=
np
.
array
(
if
isinstance
(
x_value
,
(
str
,
unicode
)):
[
float
(
x
.
strip
())
input_dict
[
"x"
]
=
np
.
array
(
for
x
in
x_value
.
split
(
self
.
separator
)]).
reshape
(
1
,
13
)
[
float
(
x
.
strip
())
_LOGGER
.
error
(
"input_dict:{}"
.
format
(
input_dict
))
for
x
in
x_value
.
split
(
self
.
separator
)]).
reshape
(
1
,
13
)
_LOGGER
.
error
(
"input_dict:{}"
.
format
(
input_dict
))
else
:
if
isinstance
(
x_value
,
str
):
input_dict
[
"x"
]
=
np
.
array
(
[
float
(
x
.
strip
())
for
x
in
x_value
.
split
(
self
.
separator
)]).
reshape
(
1
,
13
)
_LOGGER
.
error
(
"input_dict:{}"
.
format
(
input_dict
))
return
input_dict
,
False
,
None
,
""
return
input_dict
,
False
,
None
,
""
...
...
python/pipeline/analyse.py
浏览文件 @
f7ee7b16
...
@@ -312,7 +312,7 @@ class OpAnalyst(object):
...
@@ -312,7 +312,7 @@ class OpAnalyst(object):
# reduce op times
# reduce op times
op_times
=
{
op_times
=
{
op_name
:
sum
(
step_times
.
values
(
))
op_name
:
sum
(
list
(
step_times
.
values
()
))
for
op_name
,
step_times
in
op_times
.
items
()
for
op_name
,
step_times
in
op_times
.
items
()
}
}
...
...
python/pipeline/channel.py
浏览文件 @
f7ee7b16
...
@@ -429,9 +429,12 @@ class ProcessChannel(object):
...
@@ -429,9 +429,12 @@ class ProcessChannel(object):
self
.
_cv
.
wait
()
self
.
_cv
.
wait
()
if
self
.
_stop
.
value
==
1
:
if
self
.
_stop
.
value
==
1
:
raise
ChannelStopError
()
raise
ChannelStopError
()
_LOGGER
.
debug
(
self
.
_log
(
"(data_id={} log_id={}) Op({}) Got data"
.
format
(
if
resp
is
not
None
:
resp
.
values
()[
0
].
id
,
resp
.
values
()[
0
].
log_id
,
op_name
)))
list_values
=
list
(
resp
.
values
())
_LOGGER
.
debug
(
self
.
_log
(
"(data_id={} log_id={}) Op({}) Got data"
.
format
(
list_values
[
0
].
id
,
list_values
[
0
].
log_id
,
op_name
)))
return
resp
return
resp
elif
op_name
is
None
:
elif
op_name
is
None
:
_LOGGER
.
critical
(
_LOGGER
.
critical
(
...
@@ -458,11 +461,12 @@ class ProcessChannel(object):
...
@@ -458,11 +461,12 @@ class ProcessChannel(object):
try
:
try
:
channeldata
=
self
.
_que
.
get
(
timeout
=
0
)
channeldata
=
self
.
_que
.
get
(
timeout
=
0
)
self
.
_output_buf
.
append
(
channeldata
)
self
.
_output_buf
.
append
(
channeldata
)
list_values
=
list
(
channeldata
.
values
())
_LOGGER
.
debug
(
_LOGGER
.
debug
(
self
.
_log
(
self
.
_log
(
"(data_id={} log_id={}) Op({}) Pop ready item into output_buffer"
.
"(data_id={} log_id={}) Op({}) Pop ready item into output_buffer"
.
format
(
channeldata
.
values
()[
0
].
id
,
format
(
list_values
[
0
].
id
,
list_values
[
0
].
log_
id
,
channeldata
.
values
()[
0
].
log_id
,
op_name
)))
op_name
)))
break
break
except
Queue
.
Empty
:
except
Queue
.
Empty
:
if
timeout
is
not
None
:
if
timeout
is
not
None
:
...
@@ -513,10 +517,12 @@ class ProcessChannel(object):
...
@@ -513,10 +517,12 @@ class ProcessChannel(object):
self
.
_cv
.
notify_all
()
self
.
_cv
.
notify_all
()
_LOGGER
.
debug
(
if
resp
is
not
None
:
self
.
_log
(
list_values
=
list
(
resp
.
values
())
"(data_id={} log_id={}) Op({}) Got data from output_buffer"
.
_LOGGER
.
debug
(
format
(
resp
.
values
()[
0
].
id
,
resp
.
values
()[
0
].
log_id
,
op_name
)))
self
.
_log
(
"(data_id={} log_id={}) Op({}) Got data from output_buffer"
.
format
(
list_values
[
0
].
id
,
list_values
[
0
].
log_id
,
op_name
)))
return
resp
return
resp
def
stop
(
self
):
def
stop
(
self
):
...
@@ -726,9 +732,11 @@ class ThreadChannel(Queue.PriorityQueue):
...
@@ -726,9 +732,11 @@ class ThreadChannel(Queue.PriorityQueue):
self
.
_cv
.
wait
()
self
.
_cv
.
wait
()
if
self
.
_stop
:
if
self
.
_stop
:
raise
ChannelStopError
()
raise
ChannelStopError
()
_LOGGER
.
debug
(
if
resp
is
not
None
:
self
.
_log
(
"(data_id={} log_id={}) Op({}) Got data"
.
format
(
list_values
=
list
(
resp
.
values
())
resp
.
values
()[
0
].
id
,
resp
.
values
()[
0
].
log_id
,
op_name
)))
_LOGGER
.
debug
(
self
.
_log
(
"(data_id={} log_id={}) Op({}) Got data"
.
format
(
list_values
[
0
].
id
,
list_values
[
0
].
log_id
,
op_name
)))
return
resp
return
resp
elif
op_name
is
None
:
elif
op_name
is
None
:
_LOGGER
.
critical
(
_LOGGER
.
critical
(
...
@@ -755,11 +763,12 @@ class ThreadChannel(Queue.PriorityQueue):
...
@@ -755,11 +763,12 @@ class ThreadChannel(Queue.PriorityQueue):
try
:
try
:
channeldata
=
self
.
get
(
timeout
=
0
)
channeldata
=
self
.
get
(
timeout
=
0
)
self
.
_output_buf
.
append
(
channeldata
)
self
.
_output_buf
.
append
(
channeldata
)
list_values
=
list
(
channeldata
.
values
())
_LOGGER
.
debug
(
_LOGGER
.
debug
(
self
.
_log
(
self
.
_log
(
"(data_id={} log_id={}) Op({}) Pop ready item into output_buffer"
.
"(data_id={} log_id={}) Op({}) Pop ready item into output_buffer"
.
format
(
channeldata
.
values
()[
0
].
id
,
format
(
list_values
[
0
].
id
,
list_values
[
0
].
log_
id
,
channeldata
.
values
()[
0
].
log_id
,
op_name
)))
op_name
)))
break
break
except
Queue
.
Empty
:
except
Queue
.
Empty
:
if
timeout
is
not
None
:
if
timeout
is
not
None
:
...
@@ -810,10 +819,12 @@ class ThreadChannel(Queue.PriorityQueue):
...
@@ -810,10 +819,12 @@ class ThreadChannel(Queue.PriorityQueue):
self
.
_cv
.
notify_all
()
self
.
_cv
.
notify_all
()
_LOGGER
.
debug
(
if
resp
is
not
None
:
self
.
_log
(
list_values
=
list
(
resp
.
values
())
"(data_id={} log_id={}) Op({}) Got data from output_buffer"
.
_LOGGER
.
debug
(
format
(
resp
.
values
()[
0
].
id
,
resp
.
values
()[
0
].
log_id
,
op_name
)))
self
.
_log
(
"(data_id={} log_id={}) Op({}) Got data from output_buffer"
.
format
(
list_values
[
0
].
id
,
list_values
[
0
].
log_id
,
op_name
)))
return
resp
return
resp
def
stop
(
self
):
def
stop
(
self
):
...
...
python/pipeline/local_service_handler.py
浏览文件 @
f7ee7b16
...
@@ -105,18 +105,35 @@ class LocalServiceHandler(object):
...
@@ -105,18 +105,35 @@ class LocalServiceHandler(object):
def
get_port_list
(
self
):
def
get_port_list
(
self
):
return
self
.
_port_list
return
self
.
_port_list
def
get_client
(
self
):
def
get_client
(
self
,
concurrency_idx
):
"""
"""
Function get_client is only used for local predictor case, creates one
Function get_client is only used for local predictor case, creates one
LocalPredictor object, and initializes the paddle predictor by function
LocalPredictor object, and initializes the paddle predictor by function
load_model_config.
load_model_config.
The concurrency_idx is used to select running devices.
Args:
Args:
None
concurrency_idx: process/thread index
Returns:
Returns:
_local_predictor_client
_local_predictor_client
"""
"""
#checking the legality of concurrency_idx.
device_num
=
len
(
self
.
_devices
)
if
device_num
<=
0
:
_LOGGER
.
error
(
"device_num must be not greater than 0. devices({})"
.
format
(
self
.
_devices
))
raise
ValueError
(
"The number of self._devices error"
)
if
concurrency_idx
<
0
:
_LOGGER
.
error
(
"concurrency_idx({}) must be one positive number"
.
format
(
concurrency_idx
))
concurrency_idx
=
0
elif
concurrency_idx
>=
device_num
:
concurrency_idx
=
concurrency_idx
%
device_num
_LOGGER
.
info
(
"GET_CLIENT : concurrency_idx={}, device_num={}"
.
format
(
concurrency_idx
,
device_num
))
from
paddle_serving_app.local_predict
import
LocalPredictor
from
paddle_serving_app.local_predict
import
LocalPredictor
if
self
.
_local_predictor_client
is
None
:
if
self
.
_local_predictor_client
is
None
:
self
.
_local_predictor_client
=
LocalPredictor
()
self
.
_local_predictor_client
=
LocalPredictor
()
...
@@ -126,7 +143,7 @@ class LocalServiceHandler(object):
...
@@ -126,7 +143,7 @@ class LocalServiceHandler(object):
self
.
_local_predictor_client
.
load_model_config
(
self
.
_local_predictor_client
.
load_model_config
(
model_path
=
self
.
_model_config
,
model_path
=
self
.
_model_config
,
use_gpu
=
use_gpu
,
use_gpu
=
use_gpu
,
gpu_id
=
self
.
_devices
[
0
],
gpu_id
=
self
.
_devices
[
concurrency_idx
],
use_profile
=
self
.
_use_profile
,
use_profile
=
self
.
_use_profile
,
thread_num
=
self
.
_thread_num
,
thread_num
=
self
.
_thread_num
,
mem_optim
=
self
.
_mem_optim
,
mem_optim
=
self
.
_mem_optim
,
...
...
python/pipeline/operator.py
浏览文件 @
f7ee7b16
...
@@ -55,7 +55,7 @@ class Op(object):
...
@@ -55,7 +55,7 @@ class Op(object):
client_type
=
None
,
client_type
=
None
,
concurrency
=
None
,
concurrency
=
None
,
timeout
=
None
,
timeout
=
None
,
retry
=
None
,
retry
=
0
,
batch_size
=
None
,
batch_size
=
None
,
auto_batching_timeout
=
None
,
auto_batching_timeout
=
None
,
local_service_handler
=
None
):
local_service_handler
=
None
):
...
@@ -574,7 +574,7 @@ class Op(object):
...
@@ -574,7 +574,7 @@ class Op(object):
#Init cuda env in main thread
#Init cuda env in main thread
if
self
.
client_type
==
"local_predictor"
:
if
self
.
client_type
==
"local_predictor"
:
_LOGGER
.
info
(
"Init cuda env in main thread"
)
_LOGGER
.
info
(
"Init cuda env in main thread"
)
self
.
local_predictor
=
self
.
_local_service_handler
.
get_client
()
self
.
local_predictor
=
self
.
_local_service_handler
.
get_client
(
0
)
threads
=
[]
threads
=
[]
for
concurrency_idx
in
range
(
self
.
concurrency
):
for
concurrency_idx
in
range
(
self
.
concurrency
):
...
@@ -679,7 +679,7 @@ class Op(object):
...
@@ -679,7 +679,7 @@ class Op(object):
err_channeldata_dict
=
collections
.
OrderedDict
()
err_channeldata_dict
=
collections
.
OrderedDict
()
### if (batch_num == 1 && skip == True) ,then skip the process stage.
### if (batch_num == 1 && skip == True) ,then skip the process stage.
is_skip_process
=
False
is_skip_process
=
False
data_ids
=
preped_data_dict
.
keys
(
)
data_ids
=
list
(
preped_data_dict
.
keys
()
)
if
len
(
data_ids
)
==
1
and
skip_process_dict
.
get
(
data_ids
[
0
])
==
True
:
if
len
(
data_ids
)
==
1
and
skip_process_dict
.
get
(
data_ids
[
0
])
==
True
:
is_skip_process
=
True
is_skip_process
=
True
_LOGGER
.
info
(
"(data_id={} log_id={}) skip process stage"
.
format
(
_LOGGER
.
info
(
"(data_id={} log_id={}) skip process stage"
.
format
(
...
@@ -1034,7 +1034,8 @@ class Op(object):
...
@@ -1034,7 +1034,8 @@ class Op(object):
_LOGGER
.
info
(
"Init cuda env in process {}"
.
format
(
_LOGGER
.
info
(
"Init cuda env in process {}"
.
format
(
concurrency_idx
))
concurrency_idx
))
self
.
local_predictor
=
self
.
service_handler
.
get_client
()
self
.
local_predictor
=
self
.
service_handler
.
get_client
(
concurrency_idx
)
# check all ops initialized successfully.
# check all ops initialized successfully.
profiler
=
self
.
_initialize
(
is_thread_op
,
concurrency_idx
)
profiler
=
self
.
_initialize
(
is_thread_op
,
concurrency_idx
)
...
...
python/pipeline/pipeline_client.py
浏览文件 @
f7ee7b16
...
@@ -53,10 +53,10 @@ class PipelineClient(object):
...
@@ -53,10 +53,10 @@ class PipelineClient(object):
if
logid
is
None
:
if
logid
is
None
:
req
.
logid
=
0
req
.
logid
=
0
else
:
else
:
if
s
ix
.
PY
2
:
if
s
ys
.
version_info
.
major
==
2
:
req
.
logid
=
long
(
logid
)
req
.
logid
=
long
(
logid
)
elif
s
ix
.
PY
3
:
elif
s
ys
.
version_info
.
major
==
3
:
req
.
logid
=
int
(
log
_
id
)
req
.
logid
=
int
(
logid
)
feed_dict
.
pop
(
"logid"
)
feed_dict
.
pop
(
"logid"
)
clientip
=
feed_dict
.
get
(
"clientip"
)
clientip
=
feed_dict
.
get
(
"clientip"
)
...
@@ -71,10 +71,15 @@ class PipelineClient(object):
...
@@ -71,10 +71,15 @@ class PipelineClient(object):
np
.
set_printoptions
(
threshold
=
sys
.
maxsize
)
np
.
set_printoptions
(
threshold
=
sys
.
maxsize
)
for
key
,
value
in
feed_dict
.
items
():
for
key
,
value
in
feed_dict
.
items
():
req
.
key
.
append
(
key
)
req
.
key
.
append
(
key
)
if
(
sys
.
version_info
.
major
==
2
and
isinstance
(
value
,
(
str
,
unicode
))
or
((
sys
.
version_info
.
major
==
3
)
and
isinstance
(
value
,
str
))):
req
.
value
.
append
(
value
)
continue
if
isinstance
(
value
,
np
.
ndarray
):
if
isinstance
(
value
,
np
.
ndarray
):
req
.
value
.
append
(
value
.
__repr__
())
req
.
value
.
append
(
value
.
__repr__
())
elif
isinstance
(
value
,
(
str
,
unicode
)):
req
.
value
.
append
(
value
)
elif
isinstance
(
value
,
list
):
elif
isinstance
(
value
,
list
):
req
.
value
.
append
(
np
.
array
(
value
).
__repr__
())
req
.
value
.
append
(
np
.
array
(
value
).
__repr__
())
else
:
else
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录