Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
8ea6f038
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看板
提交
8ea6f038
编写于
11月 05, 2020
作者:
T
TeslaZhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update FAQ & Pipeline
上级
94da03bd
变更
8
展开全部
隐藏空白更改
内联
并排
Showing
8 changed file
with
490 addition
and
224 deletion
+490
-224
doc/FAQ.md
doc/FAQ.md
+4
-0
python/pipeline/channel.py
python/pipeline/channel.py
+97
-68
python/pipeline/dag.py
python/pipeline/dag.py
+33
-17
python/pipeline/gateway/proto/gateway.proto
python/pipeline/gateway/proto/gateway.proto
+14
-9
python/pipeline/operator.py
python/pipeline/operator.py
+308
-90
python/pipeline/pipeline_client.py
python/pipeline/pipeline_client.py
+17
-30
python/pipeline/pipeline_server.py
python/pipeline/pipeline_server.py
+5
-3
python/pipeline/proto/pipeline_service.proto
python/pipeline/proto/pipeline_service.proto
+12
-7
未找到文件。
doc/FAQ.md
浏览文件 @
8ea6f038
...
...
@@ -46,6 +46,10 @@ InvalidArgumentError: Device id must be less than GPU count, but received id is:
**A:**
目前(0.4.0)仅支持CentOS,具体列表查阅
[
这里
](
https://github.com/PaddlePaddle/Serving/blob/develop/doc/DOCKER_IMAGES.md
)
#### Q: 使用Java客户端,mvn compile过程出现"No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?"错误
**A:**
没有安装JDK,或者JAVA_HOME路径配置错误(正确配置是JDK路径,常见错误配置成JRE路径,例如正确路径参考JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-0.el7_8.x86_64/")。Java JDK安装参考https://segmentfault.com/a/1190000015389941
## 预测问题
...
...
python/pipeline/channel.py
浏览文件 @
8ea6f038
...
...
@@ -32,7 +32,10 @@ import copy
_LOGGER
=
logging
.
getLogger
(
__name__
)
class
ChannelDataEcode
(
enum
.
Enum
):
class
ChannelDataErrcode
(
enum
.
Enum
):
"""
ChannelData error code
"""
OK
=
0
TIMEOUT
=
1
NOT_IMPLEMENTED
=
2
...
...
@@ -42,6 +45,15 @@ class ChannelDataEcode(enum.Enum):
CLOSED_ERROR
=
6
NO_SERVICE
=
7
UNKNOW
=
8
PRODUCT_ERROR
=
9
class
ProductErrCode
(
enum
.
Enum
):
"""
ProductErrCode is a base class for recording business error code.
product developers inherit this class and extend more error codes.
"""
pass
class
ChannelDataType
(
enum
.
Enum
):
...
...
@@ -56,20 +68,23 @@ class ChannelData(object):
npdata
=
None
,
dictdata
=
None
,
data_id
=
None
,
ecode
=
None
,
log_id
=
None
,
error_code
=
None
,
error_info
=
None
,
prod_error_code
=
None
,
prod_error_info
=
None
,
client_need_profile
=
False
):
'''
There are several ways to use it:
1. ChannelData(ChannelDataType.CHANNEL_NPDATA.value, npdata, data_id)
2. ChannelData(ChannelDataType.DICT.value, dictdata, data_id)
3. ChannelData(e
code, error_info, data
_id)
1. ChannelData(ChannelDataType.CHANNEL_NPDATA.value, npdata, data_id
, log_id
)
2. ChannelData(ChannelDataType.DICT.value, dictdata, data_id
, log_id
)
3. ChannelData(e
rror_code, error_info, prod_error_code, prod_error_info, data_id, log
_id)
Protobufs are not pickle-able:
https://stackoverflow.com/questions/55344376/how-to-import-protobuf-module
'''
if
ecode
is
not
None
:
if
e
rror_code
is
not
None
or
prod_error_
code
is
not
None
:
if
data_id
is
None
or
error_info
is
None
:
_LOGGER
.
critical
(
"Failed to generate ChannelData: data_id"
" and error_info cannot be None"
)
...
...
@@ -77,25 +92,30 @@ class ChannelData(object):
datatype
=
ChannelDataType
.
ERROR
.
value
else
:
if
datatype
==
ChannelDataType
.
CHANNEL_NPDATA
.
value
:
ecode
,
error_info
=
ChannelData
.
check_npdata
(
npdata
)
if
e
code
!=
ChannelDataE
code
.
OK
.
value
:
e
rror_
code
,
error_info
=
ChannelData
.
check_npdata
(
npdata
)
if
e
rror_code
!=
ChannelDataErr
code
.
OK
.
value
:
datatype
=
ChannelDataType
.
ERROR
.
value
_LOGGER
.
error
(
"(logid={}) {}"
.
format
(
data_id
,
error_info
))
_LOGGER
.
error
(
"(data_id={} log_id={}) {}"
.
format
(
data_id
,
log_id
,
error_info
))
elif
datatype
==
ChannelDataType
.
DICT
.
value
:
ecode
,
error_info
=
ChannelData
.
check_dictdata
(
dictdata
)
if
e
code
!=
ChannelDataE
code
.
OK
.
value
:
e
rror_
code
,
error_info
=
ChannelData
.
check_dictdata
(
dictdata
)
if
e
rror_code
!=
ChannelDataErr
code
.
OK
.
value
:
datatype
=
ChannelDataType
.
ERROR
.
value
_LOGGER
.
error
(
"(logid={}) {}"
.
format
(
data_id
,
error_info
))
_LOGGER
.
error
(
"(data_id={} log_id={}) {}"
.
format
(
data_id
,
log_id
,
error_info
))
else
:
_LOGGER
.
critical
(
"(
logid={}) datatype not match"
.
format
(
data
_id
))
_LOGGER
.
critical
(
"(
data_id={} log_id={}) datatype not match"
.
format
(
data_id
,
log
_id
))
os
.
_exit
(
-
1
)
self
.
datatype
=
datatype
self
.
npdata
=
npdata
self
.
dictdata
=
dictdata
self
.
id
=
data_id
self
.
ecode
=
ecode
self
.
log_id
=
log_id
self
.
error_code
=
error_code
self
.
error_info
=
error_info
self
.
prod_error_code
=
prod_error_code
self
.
prod_error_info
=
prod_error_info
self
.
client_need_profile
=
client_need_profile
self
.
profile_data_set
=
set
()
...
...
@@ -106,67 +126,67 @@ class ChannelData(object):
@
staticmethod
def
check_dictdata
(
dictdata
):
e
code
=
ChannelDataE
code
.
OK
.
value
e
rror_code
=
ChannelDataErr
code
.
OK
.
value
error_info
=
None
if
isinstance
(
dictdata
,
list
):
# batch data
for
sample
in
dictdata
:
if
not
isinstance
(
sample
,
dict
):
e
code
=
ChannelDataE
code
.
TYPE_ERROR
.
value
e
rror_code
=
ChannelDataErr
code
.
TYPE_ERROR
.
value
error_info
=
"Failed to check data: the type of "
\
"data must be dict, but get {}."
.
format
(
type
(
sample
))
break
elif
not
isinstance
(
dictdata
,
dict
):
# batch size = 1
e
code
=
ChannelDataE
code
.
TYPE_ERROR
.
value
e
rror_code
=
ChannelDataErr
code
.
TYPE_ERROR
.
value
error_info
=
"Failed to check data: the type of data must "
\
"be dict, but get {}."
.
format
(
type
(
dictdata
))
return
ecode
,
error_info
return
e
rror_
code
,
error_info
@
staticmethod
def
check_batch_npdata
(
batch
):
e
code
=
ChannelDataE
code
.
OK
.
value
e
rror_code
=
ChannelDataErr
code
.
OK
.
value
error_info
=
None
for
npdata
in
batch
:
ecode
,
error_info
=
ChannelData
.
check_npdata
(
npdata
)
if
e
code
!=
ChannelDataE
code
.
OK
.
value
:
e
rror_
code
,
error_info
=
ChannelData
.
check_npdata
(
npdata
)
if
e
rror_code
!=
ChannelDataErr
code
.
OK
.
value
:
break
return
ecode
,
error_info
return
e
rror_
code
,
error_info
@
staticmethod
def
check_npdata
(
npdata
):
e
code
=
ChannelDataE
code
.
OK
.
value
e
rror_code
=
ChannelDataErr
code
.
OK
.
value
error_info
=
None
if
isinstance
(
npdata
,
list
):
# batch data
for
sample
in
npdata
:
if
not
isinstance
(
sample
,
dict
):
e
code
=
ChannelDataE
code
.
TYPE_ERROR
.
value
e
rror_code
=
ChannelDataErr
code
.
TYPE_ERROR
.
value
error_info
=
"Failed to check data: the "
\
"value of data must be dict, but get {}."
.
format
(
type
(
sample
))
break
for
_
,
value
in
sample
.
items
():
if
not
isinstance
(
value
,
np
.
ndarray
):
e
code
=
ChannelDataE
code
.
TYPE_ERROR
.
value
e
rror_code
=
ChannelDataErr
code
.
TYPE_ERROR
.
value
error_info
=
"Failed to check data: the"
\
" value of data must be np.ndarray, but get {}."
.
format
(
type
(
value
))
return
ecode
,
error_info
return
e
rror_
code
,
error_info
elif
isinstance
(
npdata
,
dict
):
# batch_size = 1
for
_
,
value
in
npdata
.
items
():
if
not
isinstance
(
value
,
np
.
ndarray
):
e
code
=
ChannelDataE
code
.
TYPE_ERROR
.
value
e
rror_code
=
ChannelDataErr
code
.
TYPE_ERROR
.
value
error_info
=
"Failed to check data: the value "
\
"of data must be np.ndarray, but get {}."
.
format
(
type
(
value
))
break
else
:
e
code
=
ChannelDataE
code
.
TYPE_ERROR
.
value
e
rror_code
=
ChannelDataErr
code
.
TYPE_ERROR
.
value
error_info
=
"Failed to check data: the value of data "
\
"must be dict, but get {}."
.
format
(
type
(
npdata
))
return
ecode
,
error_info
return
e
rror_
code
,
error_info
def
parse
(
self
):
feed
=
None
...
...
@@ -191,8 +211,9 @@ class ChannelData(object):
return
1
def
__str__
(
self
):
return
"type[{}], ecode[{}], id[{}]"
.
format
(
ChannelDataType
(
self
.
datatype
).
name
,
self
.
ecode
,
self
.
id
)
return
"type[{}], error_code[{}], data_id[{}], log_id[{}]"
.
format
(
ChannelDataType
(
self
.
datatype
).
name
,
self
.
error_code
,
self
.
id
,
self
.
log_id
)
class
ProcessChannel
(
object
):
...
...
@@ -289,14 +310,14 @@ class ProcessChannel(object):
def
push
(
self
,
channeldata
,
op_name
=
None
):
_LOGGER
.
debug
(
self
.
_log
(
"(
logid={}) Op({}) Pushing data"
.
format
(
channeldata
.
id
,
op_name
)))
self
.
_log
(
"(
data_id={} log_id={}) Op({}) Pushing data"
.
format
(
channeldata
.
id
,
channeldata
.
log_id
,
op_name
)))
if
len
(
self
.
_producers
)
==
0
:
_LOGGER
.
critical
(
self
.
_log
(
"(
log
id={}) Op({}) Failed to push data: expected number"
"(
data_id={} log_
id={}) Op({}) Failed to push data: expected number"
" of producers to be greater than 0, but the it is 0."
.
format
(
channeldata
.
id
,
op_name
)))
format
(
channeldata
.
id
,
channeldata
.
log_id
,
op_name
)))
os
.
_exit
(
-
1
)
elif
len
(
self
.
_producers
)
==
1
:
with
self
.
_cv
:
...
...
@@ -310,19 +331,21 @@ class ProcessChannel(object):
raise
ChannelStopError
()
self
.
_cv
.
notify_all
()
_LOGGER
.
debug
(
self
.
_log
(
"(logid={}) Op({}) Pushed data into internal queue."
.
format
(
channeldata
.
id
,
op_name
)))
self
.
_log
(
"(data_id={} log_id={}) Op({}) Pushed data into internal queue."
.
format
(
channeldata
.
id
,
channeldata
.
log_id
,
op_name
)))
return
True
elif
op_name
is
None
:
_LOGGER
.
critical
(
self
.
_log
(
"(
log
id={}) Op({}) Failed to push data: there are multiple "
"(
data_id={} log_
id={}) Op({}) Failed to push data: there are multiple "
"producers, so op_name cannot be None."
.
format
(
channeldata
.
id
,
op_name
)))
channeldata
.
id
,
channeldata
.
log_id
,
op_name
)))
os
.
_exit
(
-
1
)
producer_num
=
len
(
self
.
_producers
)
data_id
=
channeldata
.
id
log_id
=
channeldata
.
log_id
put_data
=
None
with
self
.
_cv
:
if
data_id
not
in
self
.
_input_buf
:
...
...
@@ -347,8 +370,8 @@ class ProcessChannel(object):
if
put_data
is
None
:
_LOGGER
.
debug
(
self
.
_log
(
"(
log
id={}) Op({}) Pushed data into input_buffer."
.
format
(
data_id
,
op_name
)))
"(
data_id={} log_
id={}) Op({}) Pushed data into input_buffer."
.
format
(
data_id
,
log_id
,
op_name
)))
else
:
while
self
.
_stop
.
value
==
0
:
try
:
...
...
@@ -361,8 +384,8 @@ class ProcessChannel(object):
_LOGGER
.
debug
(
self
.
_log
(
"(
log
id={}) Op({}) Pushed data into internal_queue."
.
format
(
data_id
,
op_name
)))
"(
data_id={} log_
id={}) Op({}) Pushed data into internal_queue."
.
format
(
data_id
,
log_id
,
op_name
)))
self
.
_cv
.
notify_all
()
return
True
...
...
@@ -404,8 +427,8 @@ class ProcessChannel(object):
if
self
.
_stop
.
value
==
1
:
raise
ChannelStopError
()
_LOGGER
.
debug
(
self
.
_log
(
"(
logid={}) Op({}) Got data"
.
format
(
resp
.
values
()[
0
]
.
id
,
op_name
)))
self
.
_log
(
"(
data_id={} log_id={}) Op({}) Got data"
.
format
(
resp
.
values
()[
0
].
id
,
resp
.
values
()[
0
].
log_
id
,
op_name
)))
return
resp
elif
op_name
is
None
:
_LOGGER
.
critical
(
...
...
@@ -434,8 +457,9 @@ class ProcessChannel(object):
self
.
_output_buf
.
append
(
channeldata
)
_LOGGER
.
debug
(
self
.
_log
(
"(logid={}) Op({}) Pop ready item into output_buffer"
.
format
(
channeldata
.
values
()[
0
].
id
,
op_name
)))
"(data_id={} log_id={}) Op({}) Pop ready item into output_buffer"
.
format
(
channeldata
.
values
()[
0
].
id
,
channeldata
.
values
()[
0
].
log_id
,
op_name
)))
break
except
Queue
.
Empty
:
if
timeout
is
not
None
:
...
...
@@ -487,8 +511,9 @@ class ProcessChannel(object):
self
.
_cv
.
notify_all
()
_LOGGER
.
debug
(
self
.
_log
(
"(logid={}) Op({}) Got data from output_buffer"
.
format
(
resp
.
values
()[
0
].
id
,
op_name
)))
self
.
_log
(
"(data_id={} log_id={}) Op({}) Got data from output_buffer"
.
format
(
resp
.
values
()[
0
].
id
,
resp
.
values
()[
0
].
log_id
,
op_name
)))
return
resp
def
stop
(
self
):
...
...
@@ -586,14 +611,14 @@ class ThreadChannel(Queue.PriorityQueue):
def
push
(
self
,
channeldata
,
op_name
=
None
):
_LOGGER
.
debug
(
self
.
_log
(
"(
logid={}) Op({}) Pushing data"
.
format
(
channeldata
.
id
,
op_name
)))
self
.
_log
(
"(
data_id={} log_id={}) Op({}) Pushing data"
.
format
(
channeldata
.
id
,
channeldata
.
log_id
,
op_name
)))
if
len
(
self
.
_producers
)
==
0
:
_LOGGER
.
critical
(
self
.
_log
(
"(
log
id={}) Op({}) Failed to push data: expected number of "
"(
data_id={} log_
id={}) Op({}) Failed to push data: expected number of "
"producers to be greater than 0, but the it is 0."
.
format
(
channeldata
.
id
,
op_name
)))
channeldata
.
id
,
channeldata
.
log_id
,
op_name
)))
os
.
_exit
(
-
1
)
elif
len
(
self
.
_producers
)
==
1
:
with
self
.
_cv
:
...
...
@@ -607,19 +632,21 @@ class ThreadChannel(Queue.PriorityQueue):
raise
ChannelStopError
()
self
.
_cv
.
notify_all
()
_LOGGER
.
debug
(
self
.
_log
(
"(logid={}) Op({}) Pushed data into internal_queue."
.
format
(
channeldata
.
id
,
op_name
)))
self
.
_log
(
"(data_id={} log_id={}) Op({}) Pushed data into internal_queue."
.
format
(
channeldata
.
id
,
channeldata
.
log_id
,
op_name
)))
return
True
elif
op_name
is
None
:
_LOGGER
.
critical
(
self
.
_log
(
"(
log
id={}) Op({}) Failed to push data: there are multiple"
"(
data_id={} log_
id={}) Op({}) Failed to push data: there are multiple"
" producers, so op_name cannot be None."
.
format
(
channeldata
.
id
,
op_name
)))
channeldata
.
id
,
channeldata
.
log_id
,
op_name
)))
os
.
_exit
(
-
1
)
producer_num
=
len
(
self
.
_producers
)
data_id
=
channeldata
.
id
log_id
=
channeldata
.
log_id
put_data
=
None
with
self
.
_cv
:
if
data_id
not
in
self
.
_input_buf
:
...
...
@@ -639,8 +666,8 @@ class ThreadChannel(Queue.PriorityQueue):
if
put_data
is
None
:
_LOGGER
.
debug
(
self
.
_log
(
"(
log
id={}) Op({}) Pushed data into input_buffer."
.
format
(
data_id
,
op_name
)))
"(
data_id={} log_
id={}) Op({}) Pushed data into input_buffer."
.
format
(
data_id
,
log_id
,
op_name
)))
else
:
while
self
.
_stop
is
False
:
try
:
...
...
@@ -653,8 +680,8 @@ class ThreadChannel(Queue.PriorityQueue):
_LOGGER
.
debug
(
self
.
_log
(
"(
log
id={}) Op({}) Pushed data into internal_queue."
.
format
(
data_id
,
op_name
)))
"(
data_id={} log_
id={}) Op({}) Pushed data into internal_queue."
.
format
(
data_id
,
log_id
,
op_name
)))
self
.
_cv
.
notify_all
()
return
True
...
...
@@ -697,8 +724,8 @@ class ThreadChannel(Queue.PriorityQueue):
if
self
.
_stop
:
raise
ChannelStopError
()
_LOGGER
.
debug
(
self
.
_log
(
"(
logid={}) Op({}) Got data"
.
format
(
resp
.
values
()[
0
]
.
id
,
op_name
)))
self
.
_log
(
"(
data_id={} log_id={}) Op({}) Got data"
.
format
(
resp
.
values
()[
0
].
id
,
resp
.
values
()[
0
].
log_
id
,
op_name
)))
return
resp
elif
op_name
is
None
:
_LOGGER
.
critical
(
...
...
@@ -727,8 +754,9 @@ class ThreadChannel(Queue.PriorityQueue):
self
.
_output_buf
.
append
(
channeldata
)
_LOGGER
.
debug
(
self
.
_log
(
"(logid={}) Op({}) Pop ready item into output_buffer"
.
format
(
channeldata
.
values
()[
0
].
id
,
op_name
)))
"(data_id={} log_id={}) Op({}) Pop ready item into output_buffer"
.
format
(
channeldata
.
values
()[
0
].
id
,
channeldata
.
values
()[
0
].
log_id
,
op_name
)))
break
except
Queue
.
Empty
:
if
timeout
is
not
None
:
...
...
@@ -780,8 +808,9 @@ class ThreadChannel(Queue.PriorityQueue):
self
.
_cv
.
notify_all
()
_LOGGER
.
debug
(
self
.
_log
(
"(logid={}) Op({}) Got data from output_buffer"
.
format
(
resp
.
values
()[
0
].
id
,
op_name
)))
self
.
_log
(
"(data_id={} log_id={}) Op({}) Got data from output_buffer"
.
format
(
resp
.
values
()[
0
].
id
,
resp
.
values
()[
0
].
log_id
,
op_name
)))
return
resp
def
stop
(
self
):
...
...
python/pipeline/dag.py
浏览文件 @
8ea6f038
...
...
@@ -25,10 +25,12 @@ else:
import
os
import
logging
import
collections
import
json
from
.operator
import
Op
,
RequestOp
,
ResponseOp
,
VirtualOp
from
.channel
import
(
ThreadChannel
,
ProcessChannel
,
ChannelData
,
ChannelDataEcode
,
ChannelDataType
,
ChannelStopError
)
ChannelDataErrcode
,
ChannelDataType
,
ChannelStopError
,
ProductErrCode
)
from
.profiler
import
TimeProfiler
,
PerformanceTracer
from
.util
import
NameGenerator
,
ThreadIdGenerator
,
PipelineProcSyncManager
from
.proto
import
pipeline_service_pb2
...
...
@@ -142,7 +144,7 @@ class DAGExecutor(object):
with
self
.
_cv_for_cv_pool
:
for
data_id
,
cv
in
self
.
_cv_pool
.
items
():
closed_errror_data
=
ChannelData
(
e
code
=
ChannelDataE
code
.
CLOSED_ERROR
.
value
,
e
rror_code
=
ChannelDataErr
code
.
CLOSED_ERROR
.
value
,
error_info
=
"dag closed."
,
data_id
=
data_id
)
with
cv
:
...
...
@@ -194,25 +196,36 @@ class DAGExecutor(object):
def
_pack_channeldata
(
self
,
rpc_request
,
data_id
):
dictdata
=
None
log_id
=
None
try
:
dictdata
=
self
.
_unpack_rpc_func
(
rpc_request
)
dictdata
,
log_id
,
prod_errcode
,
prod_errinfo
=
self
.
_unpack_rpc_func
(
rpc_request
)
except
Exception
as
e
:
_LOGGER
.
error
(
"(logid={}) Failed to parse RPC request package: {}"
.
format
(
data_id
,
e
),
exc_info
=
True
)
return
ChannelData
(
e
code
=
ChannelDataE
code
.
RPC_PACKAGE_ERROR
.
value
,
e
rror_code
=
ChannelDataErr
code
.
RPC_PACKAGE_ERROR
.
value
,
error_info
=
"rpc package error: {}"
.
format
(
e
),
data_id
=
data_id
)
data_id
=
data_id
,
log_id
=
log_id
)
else
:
# because unpack_rpc_func is rewritten by user, we need
# to look for client_profile_key field in rpc_request
# because unpack_rpc_func is rewritten by user, we need to look
# for product_errcode in returns, and client_profile_key field
# in rpc_request
if
prod_errcode
is
not
None
:
# product errors occured
return
ChannelData
(
error_code
=
ChannelDataErrcode
.
PRODUCT_ERROR
.
value
,
error_info
=
""
,
prod_error_code
=
prod_errcode
,
prod_error_info
=
prod_errinfo
,
data_id
=
data_id
,
log_id
=
log_id
)
profile_value
=
None
for
idx
,
key
in
enumerate
(
rpc_request
.
key
):
if
key
==
self
.
_client_profile_key
:
profile_value
=
rpc_request
.
value
[
idx
]
break
profile_value
=
dictdata
.
get
(
self
.
_client_profile_key
)
client_need_profile
=
(
profile_value
==
self
.
_client_profile_value
)
_LOGGER
.
debug
(
"(logid={}) Need profile in client: {}"
.
format
(
data_id
,
client_need_profile
))
...
...
@@ -220,6 +233,7 @@ class DAGExecutor(object):
datatype
=
ChannelDataType
.
DICT
.
value
,
dictdata
=
dictdata
,
data_id
=
data_id
,
log_id
=
log_id
,
client_need_profile
=
client_need_profile
)
def
call
(
self
,
rpc_request
):
...
...
@@ -253,7 +267,7 @@ class DAGExecutor(object):
self
.
_cv_pool
.
pop
(
data_id
)
return
self
.
_pack_for_rpc_resp
(
ChannelData
(
e
code
=
ChannelDataE
code
.
CLOSED_ERROR
.
value
,
e
rror_code
=
ChannelDataErr
code
.
CLOSED_ERROR
.
value
,
error_info
=
"dag closed."
,
data_id
=
data_id
))
...
...
@@ -261,13 +275,13 @@ class DAGExecutor(object):
resp_channeldata
=
self
.
_get_channeldata_from_fetch_buffer
(
data_id
,
cond_v
)
if
resp_channeldata
.
e
code
==
ChannelDataE
code
.
OK
.
value
:
if
resp_channeldata
.
e
rror_code
==
ChannelDataErr
code
.
OK
.
value
:
_LOGGER
.
info
(
"(logid={}) Succ predict"
.
format
(
data_id
))
break
else
:
_LOGGER
.
error
(
"(logid={}) Failed to predict: {}"
.
format
(
data_id
,
resp_channeldata
.
error_info
))
if
resp_channeldata
.
e
code
!=
ChannelDataE
code
.
TIMEOUT
.
value
:
if
resp_channeldata
.
e
rror_code
!=
ChannelDataErr
code
.
TIMEOUT
.
value
:
break
if
i
+
1
<
self
.
_retry
:
...
...
@@ -288,7 +302,8 @@ class DAGExecutor(object):
trace_buffer
.
put
({
"name"
:
"DAG"
,
"id"
:
data_id
,
"succ"
:
resp_channeldata
.
ecode
==
ChannelDataEcode
.
OK
.
value
,
"succ"
:
resp_channeldata
.
error_code
==
ChannelDataErrcode
.
OK
.
value
,
"actions"
:
{
"call_{}"
.
format
(
data_id
):
end_call
-
start_call
,
},
...
...
@@ -317,8 +332,9 @@ class DAGExecutor(object):
.
format
(
channeldata
.
id
,
e
),
exc_info
=
True
)
resp
=
pipeline_service_pb2
.
Response
()
resp
.
ecode
=
ChannelDataEcode
.
RPC_PACKAGE_ERROR
.
value
resp
.
error_info
=
"rpc package error: {}"
.
format
(
e
)
resp
.
err_no
=
ChannelDataErrcode
.
RPC_PACKAGE_ERROR
.
value
resp
.
err_msg
=
"rpc package error: {}"
.
format
(
e
)
resp
.
result
=
""
return
resp
...
...
python/pipeline/gateway/proto/gateway.proto
浏览文件 @
8ea6f038
...
...
@@ -19,22 +19,27 @@ option go_package = ".;pipeline_serving";
import
"google/api/annotations.proto"
;
message
Response
{
repeated
string
key
=
1
;
repeated
string
value
=
2
;
int32
ecode
=
3
;
string
error_info
=
4
;
int32
err_no
=
1
;
string
err_msg
=
2
;
string
result
=
3
;
};
message
Request
{
repeated
string
key
=
1
;
repeated
string
value
=
2
;
string
name
=
3
;
}
string
name
=
1
;
string
method
=
2
;
string
appid
=
3
;
int64
logid
=
4
;
string
format
=
5
;
string
from
=
6
;
string
cmdid
=
7
;
string
clientip
=
8
;
string
data
=
9
;
};
service
PipelineService
{
rpc
inference
(
Request
)
returns
(
Response
)
{
option
(
google.api.http
)
=
{
post
:
"/{name=*}/
prediction
"
post
:
"/{name=*}/
{method=*}
"
body
:
"*"
};
}
...
...
python/pipeline/operator.py
浏览文件 @
8ea6f038
此差异已折叠。
点击以展开。
python/pipeline/pipeline_client.py
浏览文件 @
8ea6f038
...
...
@@ -18,7 +18,8 @@ import numpy as np
from
numpy
import
*
import
logging
import
functools
from
.channel
import
ChannelDataEcode
import
json
from
.channel
import
ChannelDataErrcode
from
.proto
import
pipeline_service_pb2
from
.proto
import
pipeline_service_pb2_grpc
...
...
@@ -42,47 +43,33 @@ class PipelineClient(object):
def
_pack_request_package
(
self
,
feed_dict
,
profile
):
req
=
pipeline_service_pb2
.
Request
()
"""
np.set_printoptions(threshold=sys.maxsize)
new_dict = {}
for key, value in feed_dict.items():
req
.
key
.
append
(
key
)
if isinstance(value, np.ndarray):
req
.
value
.
append
(
value
.
__repr__
()
)
new_dict[key] = value.__repr__(
)
elif isinstance(value, (str, unicode)):
req
.
value
.
append
(
value
)
new_dict[key] = value
elif isinstance(value, list):
req
.
value
.
append
(
np
.
array
(
value
).
__repr__
()
)
new_dict[key] = np.array(value).__repr__(
)
else:
raise TypeError("only str and np.ndarray type is supported: {}".
format(type(value)))
if profile:
req
.
key
.
append
(
self
.
_profile_key
)
req
.
value
.
append
(
self
.
_profile_value
)
new_dict[self._profile_key] = self._profile_value
"""
req
.
appid
=
feed_dict
.
get
(
"appid"
)
req
.
logid
=
feed_dict
.
get
(
"logid"
)
req
.
format
=
feed_dict
.
get
(
"format"
)
setattr
(
req
,
"from"
,
feed_dict
.
get
(
"from"
))
req
.
cmdid
=
feed_dict
.
get
(
"cmdid"
)
req
.
clientip
=
feed_dict
.
get
(
"clientip"
)
req
.
data
=
feed_dict
.
get
(
"data"
)
return
req
def
_unpack_response_package
(
self
,
resp
,
fetch
):
if
resp
.
ecode
!=
0
:
return
{
"ecode"
:
resp
.
ecode
,
"ecode_desc"
:
ChannelDataEcode
(
resp
.
ecode
),
"error_info"
:
resp
.
error_info
,
}
fetch_map
=
{
"ecode"
:
resp
.
ecode
}
for
idx
,
key
in
enumerate
(
resp
.
key
):
if
key
==
self
.
_profile_key
:
if
resp
.
value
[
idx
]
!=
""
:
sys
.
stderr
.
write
(
resp
.
value
[
idx
])
continue
if
fetch
is
not
None
and
key
not
in
fetch
:
continue
data
=
resp
.
value
[
idx
]
try
:
evaled_data
=
eval
(
data
)
if
isinstance
(
evaled_data
,
np
.
ndarray
):
data
=
evaled_data
except
Exception
as
e
:
pass
fetch_map
[
key
]
=
data
return
fetch_map
return
resp
def
predict
(
self
,
feed_dict
,
fetch
=
None
,
asyn
=
False
,
profile
=
False
):
if
not
isinstance
(
feed_dict
,
dict
):
...
...
python/pipeline/pipeline_server.py
浏览文件 @
8ea6f038
...
...
@@ -42,10 +42,13 @@ class PipelineServicer(pipeline_service_pb2_grpc.PipelineServiceServicer):
_LOGGER
.
info
(
"[PipelineServicer] succ init"
)
def
inference
(
self
,
request
,
context
):
_LOGGER
.
info
(
"inference request name:{} self.name:{}"
.
format
(
request
.
name
,
self
.
_name
))
if
request
.
name
!=
""
and
request
.
name
!=
self
.
_name
:
resp
=
pipeline_service_pb2
.
Response
()
resp
.
ecode
=
channel
.
ChannelDataEcode
.
NO_SERVICE
.
value
resp
.
error_info
=
"Failed to inference: Service name error."
resp
.
err_no
=
channel
.
ChannelDataErrcode
.
NO_SERVICE
.
value
resp
.
err_msg
=
"Failed to inference: Service name error."
resp
.
result
=
""
return
resp
resp
=
self
.
_dag_executor
.
call
(
request
)
return
resp
...
...
@@ -192,7 +195,6 @@ class PipelineServer(object):
bind_address
=
'localhost:{}'
.
format
(
port
)
workers
=
[]
for
i
in
range
(
self
.
_worker_num
):
show_info
=
(
i
==
0
)
worker
=
multiprocessing
.
Process
(
target
=
self
.
_run_server_func
,
args
=
(
bind_address
,
self
.
_response_op
,
self
.
_conf
,
i
))
...
...
python/pipeline/proto/pipeline_service.proto
浏览文件 @
8ea6f038
...
...
@@ -16,16 +16,21 @@ syntax = "proto2";
package
baidu
.
paddle_serving.pipeline_serving
;
message
Request
{
repeated
string
key
=
1
;
repeated
string
value
=
2
;
optional
string
name
=
3
;
optional
string
name
=
1
;
optional
string
methond
=
2
;
optional
string
appid
=
3
;
optional
int64
logid
=
4
;
optional
string
format
=
5
;
optional
string
from
=
6
;
optional
string
cmdid
=
7
;
optional
string
clientip
=
8
;
optional
string
data
=
9
;
};
message
Response
{
repeated
string
key
=
1
;
repeated
string
value
=
2
;
required
int32
ecode
=
3
;
optional
string
error_info
=
4
;
optional
int32
err_no
=
1
;
optional
string
err_msg
=
2
;
optional
string
result
=
3
;
};
service
PipelineService
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录