Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
6223770c
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看板
提交
6223770c
编写于
6月 02, 2021
作者:
H
HexToString
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update pybind
上级
470a7db9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
16 addition
and
294 deletion
+16
-294
core/general-client/src/general_model.cpp
core/general-client/src/general_model.cpp
+8
-287
python/paddle_serving_client/client.py
python/paddle_serving_client/client.py
+7
-6
python/paddle_serving_server/rpc_service.py
python/paddle_serving_server/rpc_service.py
+1
-1
未找到文件。
core/general-client/src/general_model.cpp
100755 → 100644
浏览文件 @
6223770c
...
...
@@ -145,59 +145,6 @@ int PredictorClient::create_predictor() {
return
0
;
}
/*Determine whether the memory structure can be copied directly
if the memory offset stored in rows == the actual memory offset
if means the structure of memory is not changed by numpy(newaxis,numpy) or
numpy(1:numpy)
so you can directly copy the memory.
*/
template
<
typename
T
>
bool
isCopyLegal
(
py
::
array_t
<
T
>
*
feed_array
)
{
const
ssize_t
*
shape
=
feed_array
->
shape
();
ssize_t
dims
=
feed_array
->
ndim
();
ssize_t
item_size
=
feed_array
->
itemsize
();
ssize_t
*
middle
=
new
ssize_t
[
dims
];
// Calculates the memory offset stored in rows
int64_t
memory_offset
=
0
;
for
(
int16_t
i
=
dims
-
1
;
i
>=
0
;
--
i
)
{
middle
[
i
]
=
i
==
0
?
(
ssize_t
)(
shape
[
i
]
/
3
)
:
(
ssize_t
)(
shape
[
i
]
/
2
);
int64_t
one_dim_offset
=
middle
[
i
];
for
(
int16_t
j
=
i
+
1
;
j
<
dims
;
++
j
)
{
one_dim_offset
=
one_dim_offset
*
shape
[
j
];
}
memory_offset
+=
item_size
*
one_dim_offset
;
}
// Calculate the actual memory offset
int64_t
feed_offset
=
0
;
switch
(
dims
)
{
case
6
:
{
feed_offset
=
feed_array
->
offset_at
(
middle
[
0
],
middle
[
1
],
middle
[
2
],
middle
[
3
],
middle
[
4
],
middle
[
5
]);
break
;
}
case
5
:
{
feed_offset
=
feed_array
->
offset_at
(
middle
[
0
],
middle
[
1
],
middle
[
2
],
middle
[
3
],
middle
[
4
]);
break
;
}
case
4
:
{
feed_offset
=
feed_array
->
offset_at
(
middle
[
0
],
middle
[
1
],
middle
[
2
],
middle
[
3
]);
break
;
}
case
3
:
{
feed_offset
=
feed_array
->
offset_at
(
middle
[
0
],
middle
[
1
],
middle
[
2
]);
break
;
}
case
2
:
{
feed_offset
=
feed_array
->
offset_at
(
middle
[
0
],
middle
[
1
]);
break
;
}
}
delete
[]
middle
;
return
memory_offset
==
feed_offset
;
}
int
PredictorClient
::
numpy_predict
(
const
std
::
vector
<
std
::
vector
<
py
::
array_t
<
float
>>>
&
float_feed_batch
,
const
std
::
vector
<
std
::
string
>
&
float_feed_name
,
...
...
@@ -271,7 +218,7 @@ int PredictorClient::numpy_predict(
return
-
1
;
}
int
nbytes
=
float_feed
[
vec_idx
].
nbytes
();
void
*
rawdata_ptr
=
(
void
*
)(
float_feed
[
vec_idx
].
data
(
0
));
void
*
rawdata_ptr
=
(
void
*
)(
float_feed
[
vec_idx
].
data
(
0
));
int
total_number
=
float_feed
[
vec_idx
].
size
();
Tensor
*
tensor
=
tensor_vec
[
idx
];
...
...
@@ -284,120 +231,9 @@ int PredictorClient::numpy_predict(
tensor
->
add_lod
(
float_lod_slot_batch
[
vec_idx
][
j
]);
}
tensor
->
set_elem_type
(
P_FLOAT32
);
if
(
isCopyLegal
(
&
float_feed
[
vec_idx
]))
{
tensor
->
mutable_float_data
()
->
Resize
(
total_number
,
0
);
memcpy
(
tensor
->
mutable_float_data
()
->
mutable_data
(),
rawdata_ptr
,
nbytes
);
vec_idx
++
;
continue
;
}
tensor
->
mutable_float_data
()
->
Reserve
(
total_number
);
const
int
float_shape_size
=
float_shape
[
vec_idx
].
size
();
switch
(
float_shape_size
)
{
case
6
:
{
auto
float_array
=
float_feed
[
vec_idx
].
unchecked
<
6
>
();
for
(
ssize_t
i
=
0
;
i
<
float_array
.
shape
(
0
);
++
i
)
{
for
(
ssize_t
j
=
0
;
j
<
float_array
.
shape
(
1
);
++
j
)
{
for
(
ssize_t
k
=
0
;
k
<
float_array
.
shape
(
2
);
++
k
)
{
for
(
ssize_t
l
=
0
;
l
<
float_array
.
shape
(
3
);
++
l
)
{
for
(
ssize_t
m
=
0
;
m
<
float_array
.
shape
(
4
);
++
m
)
{
for
(
ssize_t
n
=
0
;
n
<
float_array
.
shape
(
5
);
++
n
)
{
tensor
->
add_float_data
(
float_array
(
i
,
j
,
k
,
l
,
m
,
n
));
}
}
}
}
}
}
break
;
}
case
5
:
{
auto
float_array
=
float_feed
[
vec_idx
].
unchecked
<
5
>
();
for
(
ssize_t
i
=
0
;
i
<
float_array
.
shape
(
0
);
++
i
)
{
for
(
ssize_t
j
=
0
;
j
<
float_array
.
shape
(
1
);
++
j
)
{
for
(
ssize_t
k
=
0
;
k
<
float_array
.
shape
(
2
);
++
k
)
{
for
(
ssize_t
l
=
0
;
l
<
float_array
.
shape
(
3
);
++
l
)
{
for
(
ssize_t
m
=
0
;
m
<
float_array
.
shape
(
4
);
++
m
)
{
tensor
->
add_float_data
(
float_array
(
i
,
j
,
k
,
l
,
m
));
}
}
}
}
}
break
;
}
case
4
:
{
auto
float_array
=
float_feed
[
vec_idx
].
unchecked
<
4
>
();
for
(
ssize_t
i
=
0
;
i
<
float_array
.
shape
(
0
);
++
i
)
{
for
(
ssize_t
j
=
0
;
j
<
float_array
.
shape
(
1
);
++
j
)
{
for
(
ssize_t
k
=
0
;
k
<
float_array
.
shape
(
2
);
++
k
)
{
for
(
ssize_t
l
=
0
;
l
<
float_array
.
shape
(
3
);
++
l
)
{
tensor
->
add_float_data
(
float_array
(
i
,
j
,
k
,
l
));
}
}
}
}
break
;
}
case
3
:
{
auto
float_array
=
float_feed
[
vec_idx
].
unchecked
<
3
>
();
for
(
ssize_t
i
=
0
;
i
<
float_array
.
shape
(
0
);
++
i
)
{
for
(
ssize_t
j
=
0
;
j
<
float_array
.
shape
(
1
);
++
j
)
{
for
(
ssize_t
k
=
0
;
k
<
float_array
.
shape
(
2
);
++
k
)
{
tensor
->
add_float_data
(
float_array
(
i
,
j
,
k
));
}
}
}
break
;
}
case
2
:
{
auto
float_array
=
float_feed
[
vec_idx
].
unchecked
<
2
>
();
for
(
ssize_t
i
=
0
;
i
<
float_array
.
shape
(
0
);
++
i
)
{
for
(
ssize_t
j
=
0
;
j
<
float_array
.
shape
(
1
);
++
j
)
{
tensor
->
add_float_data
(
float_array
(
i
,
j
));
}
}
break
;
}
case
1
:
{
auto
float_array
=
float_feed
[
vec_idx
].
unchecked
<
1
>
();
for
(
ssize_t
i
=
0
;
i
<
float_array
.
shape
(
0
);
i
++
)
{
tensor
->
add_float_data
(
float_array
(
i
));
}
break
;
}
}
/*
// this is for debug.
std::cout << std::endl;
std::cout << "origin " <<std::endl;
std::cout << "tensor->float_data_size() = " << tensor->float_data_size()
<< std::endl;
std::cout << "&tensor->first = " <<
tensor->mutable_float_data()->mutable_data() << std::endl;
std::cout << "tensor->first = " <<
*tensor->mutable_float_data()->mutable_data() << std::endl;
std::cout << "&tensor->last = " <<
(tensor->mutable_float_data()->mutable_data()+total_number-1) <<
std::endl;
std::cout << "tensor->last = " <<
*(tensor->mutable_float_data()->mutable_data()+total_number-1) <<
std::endl;
std::cout << "&tensor->middle = " <<
(tensor->mutable_float_data()->mutable_data()+int(total_number/7)) <<
std::endl;
std::cout << "tensor->middle = " <<
*(tensor->mutable_float_data()->mutable_data()+int(total_number/7)) <<
std::endl;
for(int my =0; my <total_number/1000; my++){
std::cout << my << " : " <<
*(tensor->mutable_float_data()->mutable_data()+my) << " ";
}
std::cout << std::endl;
std::cout << std::endl;
*/
tensor
->
mutable_float_data
()
->
Resize
(
total_number
,
0
);
memcpy
(
tensor
->
mutable_float_data
()
->
mutable_data
(),
rawdata_ptr
,
nbytes
);
vec_idx
++
;
}
...
...
@@ -423,129 +259,14 @@ int PredictorClient::numpy_predict(
tensor
->
add_lod
(
int_lod_slot_batch
[
vec_idx
][
j
]);
}
tensor
->
set_elem_type
(
_type
[
idx
]);
if
(
isCopyLegal
(
&
int_feed
[
vec_idx
]))
{
if
(
_type
[
idx
]
==
P_INT64
)
{
tensor
->
mutable_int64_data
()
->
Resize
(
total_number
,
0
);
memcpy
(
tensor
->
mutable_int64_data
()
->
mutable_data
(),
rawdata_ptr
,
nbytes
);
vec_idx
++
;
}
else
{
tensor
->
mutable_int_data
()
->
Resize
(
total_number
,
0
);
memcpy
(
tensor
->
mutable_int_data
()
->
mutable_data
(),
rawdata_ptr
,
nbytes
);
vec_idx
++
;
}
continue
;
}
if
(
_type
[
idx
]
==
P_INT64
)
{
VLOG
(
2
)
<<
"prepare int feed "
<<
name
<<
" shape size "
<<
int_shape
[
vec_idx
].
size
();
tensor
->
mutable_int64_data
()
->
Reserve
(
total_number
);
tensor
->
mutable_int64_data
()
->
Resize
(
total_number
,
0
);
memcpy
(
tensor
->
mutable_int64_data
()
->
mutable_data
(),
rawdata_ptr
,
nbytes
);
}
else
{
VLOG
(
2
)
<<
"prepare int32 feed "
<<
name
<<
" shape size "
<<
int_shape
[
vec_idx
].
size
();
tensor
->
mutable_int_data
()
->
Reserve
(
total_number
);
}
const
int
int_shape_size
=
int_shape
[
vec_idx
].
size
();
switch
(
int_shape_size
)
{
case
6
:
{
auto
int_array
=
int_feed
[
vec_idx
].
unchecked
<
6
>
();
for
(
ssize_t
i
=
0
;
i
<
int_array
.
shape
(
0
);
++
i
)
{
for
(
ssize_t
j
=
0
;
j
<
int_array
.
shape
(
1
);
++
j
)
{
for
(
ssize_t
k
=
0
;
k
<
int_array
.
shape
(
2
);
++
k
)
{
for
(
ssize_t
l
=
0
;
k
<
int_array
.
shape
(
3
);
++
l
)
{
for
(
ssize_t
m
=
0
;
k
<
int_array
.
shape
(
4
);
++
m
)
{
for
(
ssize_t
n
=
0
;
k
<
int_array
.
shape
(
5
);
++
n
)
{
if
(
_type
[
idx
]
==
P_INT64
)
{
tensor
->
add_int64_data
(
int_array
(
i
,
j
,
k
,
l
,
m
,
n
));
}
else
{
tensor
->
add_int_data
(
int_array
(
i
,
j
,
k
,
l
,
m
,
n
));
}
}
}
}
}
}
}
break
;
}
case
5
:
{
auto
int_array
=
int_feed
[
vec_idx
].
unchecked
<
5
>
();
for
(
ssize_t
i
=
0
;
i
<
int_array
.
shape
(
0
);
++
i
)
{
for
(
ssize_t
j
=
0
;
j
<
int_array
.
shape
(
1
);
++
j
)
{
for
(
ssize_t
k
=
0
;
k
<
int_array
.
shape
(
2
);
++
k
)
{
for
(
ssize_t
l
=
0
;
k
<
int_array
.
shape
(
3
);
++
l
)
{
for
(
ssize_t
m
=
0
;
k
<
int_array
.
shape
(
4
);
++
m
)
{
if
(
_type
[
idx
]
==
P_INT64
)
{
tensor
->
add_int64_data
(
int_array
(
i
,
j
,
k
,
l
,
m
));
}
else
{
tensor
->
add_int_data
(
int_array
(
i
,
j
,
k
,
l
,
m
));
}
}
}
}
}
}
break
;
}
case
4
:
{
auto
int_array
=
int_feed
[
vec_idx
].
unchecked
<
4
>
();
for
(
ssize_t
i
=
0
;
i
<
int_array
.
shape
(
0
);
++
i
)
{
for
(
ssize_t
j
=
0
;
j
<
int_array
.
shape
(
1
);
++
j
)
{
for
(
ssize_t
k
=
0
;
k
<
int_array
.
shape
(
2
);
++
k
)
{
for
(
ssize_t
l
=
0
;
k
<
int_array
.
shape
(
3
);
++
l
)
{
if
(
_type
[
idx
]
==
P_INT64
)
{
tensor
->
add_int64_data
(
int_array
(
i
,
j
,
k
,
l
));
}
else
{
tensor
->
add_int_data
(
int_array
(
i
,
j
,
k
,
l
));
}
}
}
}
}
break
;
}
case
3
:
{
auto
int_array
=
int_feed
[
vec_idx
].
unchecked
<
3
>
();
for
(
ssize_t
i
=
0
;
i
<
int_array
.
shape
(
0
);
++
i
)
{
for
(
ssize_t
j
=
0
;
j
<
int_array
.
shape
(
1
);
++
j
)
{
for
(
ssize_t
k
=
0
;
k
<
int_array
.
shape
(
2
);
++
k
)
{
if
(
_type
[
idx
]
==
P_INT64
)
{
tensor
->
add_int64_data
(
int_array
(
i
,
j
,
k
));
}
else
{
tensor
->
add_int_data
(
int_array
(
i
,
j
,
k
));
}
}
}
}
break
;
}
case
2
:
{
auto
int_array
=
int_feed
[
vec_idx
].
unchecked
<
2
>
();
for
(
ssize_t
i
=
0
;
i
<
int_array
.
shape
(
0
);
++
i
)
{
for
(
ssize_t
j
=
0
;
j
<
int_array
.
shape
(
1
);
++
j
)
{
if
(
_type
[
idx
]
==
P_INT64
)
{
tensor
->
add_int64_data
(
int_array
(
i
,
j
));
}
else
{
tensor
->
add_int_data
(
int_array
(
i
,
j
));
}
}
}
break
;
}
case
1
:
{
auto
int_array
=
int_feed
[
vec_idx
].
unchecked
<
1
>
();
for
(
ssize_t
i
=
0
;
i
<
int_array
.
shape
(
0
);
i
++
)
{
if
(
_type
[
idx
]
==
P_INT64
)
{
tensor
->
add_int64_data
(
int_array
(
i
));
}
else
{
tensor
->
add_int_data
(
int_array
(
i
));
}
}
break
;
}
tensor
->
mutable_int_data
()
->
Resize
(
total_number
,
0
);
memcpy
(
tensor
->
mutable_int_data
()
->
mutable_data
(),
rawdata_ptr
,
nbytes
);
}
vec_idx
++
;
}
...
...
python/paddle_serving_client/client.py
浏览文件 @
6223770c
...
...
@@ -370,10 +370,10 @@ class Client(object):
int_lod_slot_batch
.
append
([])
if
isinstance
(
feed_i
[
key
],
np
.
ndarray
):
int_slot
.
append
(
feed_i
[
key
]
)
int_slot
.
append
(
np
.
ascontiguousarray
(
feed_i
[
key
])
)
self
.
has_numpy_input
=
True
else
:
int_slot
.
append
(
feed_i
[
key
]
)
int_slot
.
append
(
np
.
ascontiguousarray
(
feed_i
[
key
])
)
self
.
all_numpy_input
=
False
elif
self
.
feed_types_
[
key
]
in
float_type
:
...
...
@@ -395,10 +395,10 @@ class Client(object):
float_lod_slot_batch
.
append
([])
if
isinstance
(
feed_i
[
key
],
np
.
ndarray
):
float_slot
.
append
(
feed_i
[
key
]
)
float_slot
.
append
(
np
.
ascontiguousarray
(
feed_i
[
key
])
)
self
.
has_numpy_input
=
True
else
:
float_slot
.
append
(
feed_i
[
key
]
)
float_slot
.
append
(
np
.
ascontiguousarray
(
feed_i
[
key
])
)
self
.
all_numpy_input
=
False
#if input is string, feed is not numpy.
elif
self
.
feed_types_
[
key
]
in
string_type
:
...
...
@@ -410,7 +410,7 @@ class Client(object):
key
)])
else
:
string_lod_slot_batch
.
append
([])
string_slot
.
append
(
feed_i
[
key
]
)
string_slot
.
append
(
np
.
ascontiguousarray
(
feed_i
[
key
])
)
self
.
has_numpy_input
=
True
int_slot_batch
.
append
(
int_slot
)
int_lod_slot_batch
.
append
(
int_lod_slot
)
...
...
@@ -628,6 +628,7 @@ class MultiLangClient(object):
raise
Exception
(
"error tensor value type."
)
else
:
raise
Exception
(
"var must be list or ndarray."
)
data
=
np
.
ascontiguousarray
(
data
)
tensor
.
data
=
data
.
tobytes
()
tensor
.
shape
.
extend
(
list
(
var
.
shape
))
if
"{}.lod"
.
format
(
name
)
in
feed
.
keys
():
...
...
@@ -702,7 +703,7 @@ class MultiLangClient(object):
if
batch
is
False
:
for
key
in
feed
:
if
".lod"
not
in
key
:
feed
[
key
]
=
feed
[
key
][
np
.
newaxis
,
:]
feed
[
key
]
=
np
.
expand_dims
(
feed_i
[
key
],
0
).
repeat
(
1
,
axis
=
0
)
if
not
asyn
:
try
:
self
.
profile_
.
record
(
'py_prepro_0'
)
...
...
python/paddle_serving_server/rpc_service.py
浏览文件 @
6223770c
...
...
@@ -126,7 +126,7 @@ class MultiLangServerServiceServicer(multi_lang_general_model_service_pb2_grpc.
else
:
raise
Exception
(
"error type."
)
data
.
shape
=
list
(
feed_inst
.
tensor_array
[
idx
].
shape
)
feed_dict
[
name
]
=
data
feed_dict
[
name
]
=
np
.
ascontiguousarray
(
data
)
if
len
(
var
.
lod
)
>
0
:
feed_dict
[
"{}.lod"
.
format
(
name
)]
=
var
.
lod
feed_batch
.
append
(
feed_dict
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录