Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
75e6613f
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看板
提交
75e6613f
编写于
7月 30, 2020
作者:
B
barriery
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
bug fix
上级
8603c340
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
62 addition
and
42 deletion
+62
-42
python/pipeline/channel.py
python/pipeline/channel.py
+20
-8
python/pipeline/operator.py
python/pipeline/operator.py
+36
-33
python/pipeline/pipeline_client.py
python/pipeline/pipeline_client.py
+6
-1
未找到文件。
python/pipeline/channel.py
浏览文件 @
75e6613f
...
@@ -117,6 +117,16 @@ class ChannelData(object):
...
@@ -117,6 +117,16 @@ class ChannelData(object):
"be dict, but get {}."
.
format
(
type
(
dictdata
))
"be dict, but get {}."
.
format
(
type
(
dictdata
))
return
ecode
,
error_info
return
ecode
,
error_info
@
staticmethod
def
check_batch_npdata
(
batch
):
ecode
=
ChannelDataEcode
.
OK
.
value
error_info
=
None
for
npdata
in
batch
:
ecode
,
error_info
=
ChannelData
.
check_npdata
(
npdata
)
if
ecode
!=
ChannelDataEcode
.
OK
.
value
:
break
return
ecode
,
error_info
@
staticmethod
@
staticmethod
def
check_npdata
(
npdata
):
def
check_npdata
(
npdata
):
ecode
=
ChannelDataEcode
.
OK
.
value
ecode
=
ChannelDataEcode
.
OK
.
value
...
@@ -329,10 +339,11 @@ class ProcessChannel(object):
...
@@ -329,10 +339,11 @@ class ProcessChannel(object):
def
front
(
self
,
op_name
=
None
,
timeout
=
None
):
def
front
(
self
,
op_name
=
None
,
timeout
=
None
):
endtime
=
None
endtime
=
None
if
timeout
is
not
None
and
timeout
<=
0
:
if
timeout
is
not
None
:
timeout
=
None
if
timeout
<=
0
:
else
:
timeout
=
None
endtime
=
_time
()
+
timeout
else
:
endtime
=
_time
()
+
timeout
_LOGGER
.
debug
(
self
.
_log
(
"{} try to get data..."
.
format
(
op_name
)))
_LOGGER
.
debug
(
self
.
_log
(
"{} try to get data..."
.
format
(
op_name
)))
if
len
(
self
.
_consumer_cursors
)
==
0
:
if
len
(
self
.
_consumer_cursors
)
==
0
:
...
@@ -600,10 +611,11 @@ class ThreadChannel(Queue.Queue):
...
@@ -600,10 +611,11 @@ class ThreadChannel(Queue.Queue):
def
front
(
self
,
op_name
=
None
,
timeout
=
None
):
def
front
(
self
,
op_name
=
None
,
timeout
=
None
):
endtime
=
None
endtime
=
None
if
timeout
is
not
None
and
timeout
<=
0
:
if
timeout
is
not
None
:
timeout
=
None
if
timeout
<=
0
:
else
:
timeout
=
None
endtime
=
_time
()
+
timeout
else
:
endtime
=
_time
()
+
timeout
_LOGGER
.
debug
(
self
.
_log
(
"{} try to get data"
.
format
(
op_name
)))
_LOGGER
.
debug
(
self
.
_log
(
"{} try to get data"
.
format
(
op_name
)))
if
len
(
self
.
_consumer_cursors
)
==
0
:
if
len
(
self
.
_consumer_cursors
)
==
0
:
...
...
python/pipeline/operator.py
浏览文件 @
75e6613f
...
@@ -26,7 +26,8 @@ from numpy import *
...
@@ -26,7 +26,8 @@ from numpy import *
from
.proto
import
pipeline_service_pb2
from
.proto
import
pipeline_service_pb2
from
.channel
import
(
ThreadChannel
,
ProcessChannel
,
ChannelDataEcode
,
from
.channel
import
(
ThreadChannel
,
ProcessChannel
,
ChannelDataEcode
,
ChannelData
,
ChannelDataType
,
ChannelStopError
)
ChannelData
,
ChannelDataType
,
ChannelStopError
,
ChannelTimeoutError
)
from
.util
import
NameGenerator
from
.util
import
NameGenerator
from
.profiler
import
TimeProfiler
from
.profiler
import
TimeProfiler
...
@@ -45,7 +46,7 @@ class Op(object):
...
@@ -45,7 +46,7 @@ class Op(object):
timeout
=-
1
,
timeout
=-
1
,
retry
=
1
,
retry
=
1
,
batch_size
=
1
,
batch_size
=
1
,
auto_batchin
t
_timeout
=
None
):
auto_batchin
g
_timeout
=
None
):
if
name
is
None
:
if
name
is
None
:
name
=
_op_name_gen
.
next
()
name
=
_op_name_gen
.
next
()
self
.
name
=
name
# to identify the type of OP, it must be globally unique
self
.
name
=
name
# to identify the type of OP, it must be globally unique
...
@@ -65,9 +66,9 @@ class Op(object):
...
@@ -65,9 +66,9 @@ class Op(object):
self
.
_outputs
=
[]
self
.
_outputs
=
[]
self
.
_batch_size
=
batch_size
self
.
_batch_size
=
batch_size
self
.
_auto_batchin
t_timeout
=
auto_batchint
_timeout
self
.
_auto_batchin
g_timeout
=
auto_batching
_timeout
if
self
.
_auto_batchin
t_timeout
is
not
None
and
self
.
_auto_batchint
_timeout
<=
0
:
if
self
.
_auto_batchin
g_timeout
is
not
None
and
self
.
_auto_batching
_timeout
<=
0
:
self
.
_auto_batchin
t
_timeout
=
None
self
.
_auto_batchin
g
_timeout
=
None
self
.
_server_use_profile
=
False
self
.
_server_use_profile
=
False
...
@@ -155,14 +156,13 @@ class Op(object):
...
@@ -155,14 +156,13 @@ class Op(object):
(
_
,
input_dict
),
=
input_dicts
.
items
()
(
_
,
input_dict
),
=
input_dicts
.
items
()
return
input_dict
return
input_dict
def
process
(
self
,
feed_dict
):
def
process
(
self
,
feed_batch
):
#TODO: check batch
err
,
err_info
=
ChannelData
.
check_batch_npdata
(
feed_batch
)
err
,
err_info
=
ChannelData
.
check_npdata
(
feed_dict
)
if
err
!=
0
:
if
err
!=
0
:
raise
NotImplementedError
(
raise
NotImplementedError
(
"{} Please override preprocess func."
.
format
(
err_info
))
"{} Please override preprocess func."
.
format
(
err_info
))
call_result
=
self
.
client
.
predict
(
call_result
=
self
.
client
.
predict
(
feed
=
feed_
dict
,
fetch
=
self
.
_fetch_names
)
feed
=
feed_
batch
,
fetch
=
self
.
_fetch_names
)
_LOGGER
.
debug
(
self
.
_log
(
"get call_result"
))
_LOGGER
.
debug
(
self
.
_log
(
"get call_result"
))
return
call_result
return
call_result
...
@@ -277,11 +277,12 @@ class Op(object):
...
@@ -277,11 +277,12 @@ class Op(object):
err_channeldata_dict
=
{}
err_channeldata_dict
=
{}
if
self
.
with_serving
:
if
self
.
with_serving
:
data_ids
=
preped_data_dict
.
keys
()
data_ids
=
preped_data_dict
.
keys
()
batch
=
[
preped_data_dict
[
data_id
]
for
data_id
in
data_ids
]
feed_batch
=
[
preped_data_dict
[
data_id
]
for
data_id
in
data_ids
]
midped_batch
=
None
ecode
=
ChannelDataEcode
.
OK
.
value
ecode
=
ChannelDataEcode
.
OK
.
value
if
self
.
_timeout
<=
0
:
if
self
.
_timeout
<=
0
:
try
:
try
:
midped_
data
=
self
.
process
(
batch
)
midped_
batch
=
self
.
process
(
feed_
batch
)
except
Exception
as
e
:
except
Exception
as
e
:
ecode
=
ChannelDataEcode
.
UNKNOW
.
value
ecode
=
ChannelDataEcode
.
UNKNOW
.
value
error_info
=
log_func
(
e
)
error_info
=
log_func
(
e
)
...
@@ -290,7 +291,7 @@ class Op(object):
...
@@ -290,7 +291,7 @@ class Op(object):
for
i
in
range
(
self
.
_retry
):
for
i
in
range
(
self
.
_retry
):
try
:
try
:
midped_batch
=
func_timeout
.
func_timeout
(
midped_batch
=
func_timeout
.
func_timeout
(
self
.
_timeout
,
self
.
process
,
args
=
(
batch
,
))
self
.
_timeout
,
self
.
process
,
args
=
(
feed_
batch
,
))
except
func_timeout
.
FunctionTimedOut
as
e
:
except
func_timeout
.
FunctionTimedOut
as
e
:
if
i
+
1
>=
self
.
_retry
:
if
i
+
1
>=
self
.
_retry
:
ecode
=
ChannelDataEcode
.
TIMEOUT
.
value
ecode
=
ChannelDataEcode
.
TIMEOUT
.
value
...
@@ -333,7 +334,7 @@ class Op(object):
...
@@ -333,7 +334,7 @@ class Op(object):
def
_run_postprocess
(
self
,
parsed_data_dict
,
midped_data_dict
,
log_func
):
def
_run_postprocess
(
self
,
parsed_data_dict
,
midped_data_dict
,
log_func
):
postped_data_dict
=
{}
postped_data_dict
=
{}
err_channeldata_dict
=
{}
err_channeldata_dict
=
{}
for
data_id
,
midped_data
in
mided_data_dict
.
items
():
for
data_id
,
midped_data
in
mid
p
ed_data_dict
.
items
():
postped_data
,
err_channeldata
=
None
,
None
postped_data
,
err_channeldata
=
None
,
None
try
:
try
:
postped_data
=
self
.
postprocess
(
postped_data
=
self
.
postprocess
(
...
@@ -403,7 +404,7 @@ class Op(object):
...
@@ -403,7 +404,7 @@ class Op(object):
parsed_data_dict
=
{}
parsed_data_dict
=
{}
need_profile_dict
=
{}
need_profile_dict
=
{}
profile_dict
=
{}
profile_dict
=
{}
for
channeldata_dict
in
channeldata_dict_
batch
:
for
channeldata_dict
in
batch
:
(
data_id
,
error_channeldata
,
parsed_data
,
(
data_id
,
error_channeldata
,
parsed_data
,
client_need_profile
,
profile_set
)
=
\
client_need_profile
,
profile_set
)
=
\
self
.
_parse_channeldata
(
channeldata_dict
)
self
.
_parse_channeldata
(
channeldata_dict
)
...
@@ -419,21 +420,23 @@ class Op(object):
...
@@ -419,21 +420,23 @@ class Op(object):
return
parsed_data_dict
,
need_profile_dict
,
profile_dict
return
parsed_data_dict
,
need_profile_dict
,
profile_dict
def
_run
(
self
,
concurrency_idx
,
input_channel
,
output_channels
,
def
_run
(
self
,
concurrency_idx
,
input_channel
,
output_channels
,
client_type
,
is_thread_op
):
client_type
,
is_thread_op
):
def
get_log_func
(
op_info_prefix
):
def
get_log_func
(
op_info_prefix
):
def
log_func
(
info_str
):
def
log_func
(
info_str
):
return
"{} {}"
.
format
(
op_info_prefix
,
info_str
)
return
"{} {}"
.
format
(
op_info_prefix
,
info_str
)
return
log_func
return
log_func
op_info_prefix
=
"[{}|{}]"
.
format
(
self
.
name
,
concurrency_idx
)
op_info_prefix
=
"[{}|{}]"
.
format
(
self
.
name
,
concurrency_idx
)
log
=
get_log_func
(
op_info_prefix
)
log
=
get_log_func
(
op_info_prefix
)
preplog
=
get_log_func
(
op_info_prefix
+
"(prep)"
)
midplog
=
get_log_func
(
op_info_prefix
+
"(midp)"
)
postplog
=
get_log_func
(
op_info_prefix
+
"(postp)"
)
tid
=
threading
.
current_thread
().
ident
tid
=
threading
.
current_thread
().
ident
# init op
# init op
try
:
try
:
self
.
_initialize
(
is_thread_op
)
self
.
_initialize
(
is_thread_op
,
client_type
)
except
Exception
as
e
:
except
Exception
as
e
:
_LOGGER
.
error
(
log
(
e
))
_LOGGER
.
error
(
log
(
e
))
os
.
_exit
(
-
1
)
os
.
_exit
(
-
1
)
...
@@ -468,7 +471,7 @@ class Op(object):
...
@@ -468,7 +471,7 @@ class Op(object):
# preprecess
# preprecess
self
.
_profiler_record
(
"prep#{}_0"
.
format
(
op_info_prefix
))
self
.
_profiler_record
(
"prep#{}_0"
.
format
(
op_info_prefix
))
preped_data_dict
,
err_channeldata_dict
\
preped_data_dict
,
err_channeldata_dict
\
=
self
.
_run_preprocess
(
parsed_data_dict
,
log
)
=
self
.
_run_preprocess
(
parsed_data_dict
,
prep
log
)
self
.
_profiler_record
(
"prep#{}_1"
.
format
(
op_info_prefix
))
self
.
_profiler_record
(
"prep#{}_1"
.
format
(
op_info_prefix
))
try
:
try
:
for
data_id
,
err_channeldata
in
err_channeldata_dict
.
items
():
for
data_id
,
err_channeldata
in
err_channeldata_dict
.
items
():
...
@@ -487,7 +490,7 @@ class Op(object):
...
@@ -487,7 +490,7 @@ class Op(object):
# process
# process
self
.
_profiler_record
(
"midp#{}_0"
.
format
(
op_info_prefix
))
self
.
_profiler_record
(
"midp#{}_0"
.
format
(
op_info_prefix
))
midped_data_dict
,
err_channeldata_dict
\
midped_data_dict
,
err_channeldata_dict
\
=
self
.
_run_process
(
preped_data_dict
,
log
)
=
self
.
_run_process
(
preped_data_dict
,
midp
log
)
self
.
_profiler_record
(
"midp#{}_1"
.
format
(
op_info_prefix
))
self
.
_profiler_record
(
"midp#{}_1"
.
format
(
op_info_prefix
))
try
:
try
:
for
data_id
,
err_channeldata
in
err_channeldata_dict
.
items
():
for
data_id
,
err_channeldata
in
err_channeldata_dict
.
items
():
...
@@ -507,7 +510,7 @@ class Op(object):
...
@@ -507,7 +510,7 @@ class Op(object):
self
.
_profiler_record
(
"postp#{}_0"
.
format
(
op_info_prefix
))
self
.
_profiler_record
(
"postp#{}_0"
.
format
(
op_info_prefix
))
postped_data_dict
,
err_channeldata_dict
\
postped_data_dict
,
err_channeldata_dict
\
=
self
.
_run_postprocess
(
=
self
.
_run_postprocess
(
parsed_data_dict
,
midped_data_dict
,
log
)
parsed_data_dict
,
midped_data_dict
,
postp
log
)
self
.
_profiler_record
(
"postp#{}_1"
.
format
(
op_info_prefix
))
self
.
_profiler_record
(
"postp#{}_1"
.
format
(
op_info_prefix
))
try
:
try
:
for
data_id
,
err_channeldata
in
err_channeldata_dict
.
items
():
for
data_id
,
err_channeldata
in
err_channeldata_dict
.
items
():
...
@@ -536,7 +539,7 @@ class Op(object):
...
@@ -536,7 +539,7 @@ class Op(object):
self
.
_finalize
(
is_thread_op
)
self
.
_finalize
(
is_thread_op
)
break
break
def
_initialize
(
self
,
is_thread_op
):
def
_initialize
(
self
,
is_thread_op
,
client_type
):
if
is_thread_op
:
if
is_thread_op
:
with
self
.
_for_init_op_lock
:
with
self
.
_for_init_op_lock
:
if
not
self
.
_succ_init_op
:
if
not
self
.
_succ_init_op
:
...
@@ -553,18 +556,18 @@ class Op(object):
...
@@ -553,18 +556,18 @@ class Op(object):
self
.
init_op
()
self
.
init_op
()
self
.
_succ_init_op
=
True
self
.
_succ_init_op
=
True
self
.
_succ_close_op
=
False
self
.
_succ_close_op
=
False
else
:
else
:
self
.
concurrency_idx
=
concurrency_idx
self
.
concurrency_idx
=
concurrency_idx
# init profiler
# init profiler
self
.
_profiler
=
TimeProfiler
()
self
.
_profiler
=
TimeProfiler
()
self
.
_profiler
.
enable
(
True
)
self
.
_profiler
.
enable
(
True
)
# init client
# init client
self
.
client
=
self
.
init_client
(
self
.
client
=
self
.
init_client
(
client_type
,
self
.
_client_config
,
client_type
,
self
.
_client_config
,
self
.
_server_endpoints
,
self
.
_server_endpoints
,
self
.
_fetch_names
)
self
.
_fetch_names
)
# user defined
# user defined
self
.
init_op
()
self
.
init_op
()
def
_finalize
(
self
,
is_thread_op
):
def
_finalize
(
self
,
is_thread_op
):
if
is_thread_op
:
if
is_thread_op
:
...
...
python/pipeline/pipeline_client.py
浏览文件 @
75e6613f
...
@@ -18,6 +18,7 @@ import numpy as np
...
@@ -18,6 +18,7 @@ import numpy as np
from
numpy
import
*
from
numpy
import
*
import
logging
import
logging
import
functools
import
functools
from
.channel
import
ChannelDataEcode
from
.proto
import
pipeline_service_pb2
from
.proto
import
pipeline_service_pb2
from
.proto
import
pipeline_service_pb2_grpc
from
.proto
import
pipeline_service_pb2_grpc
...
@@ -59,7 +60,11 @@ class PipelineClient(object):
...
@@ -59,7 +60,11 @@ class PipelineClient(object):
def
_unpack_response_package
(
self
,
resp
,
fetch
):
def
_unpack_response_package
(
self
,
resp
,
fetch
):
if
resp
.
ecode
!=
0
:
if
resp
.
ecode
!=
0
:
return
{
"ecode"
:
resp
.
ecode
,
"error_info"
:
resp
.
error_info
}
return
{
"ecode"
:
resp
.
ecode
,
"ecode_desc"
:
ChannelDataEcode
(
resp
.
ecode
),
"error_info"
:
resp
.
error_info
,
}
fetch_map
=
{
"ecode"
:
resp
.
ecode
}
fetch_map
=
{
"ecode"
:
resp
.
ecode
}
for
idx
,
key
in
enumerate
(
resp
.
key
):
for
idx
,
key
in
enumerate
(
resp
.
key
):
if
key
==
self
.
_profile_key
:
if
key
==
self
.
_profile_key
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录