Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
VisualDL
提交
9583bf7c
V
VisualDL
项目概览
PaddlePaddle
/
VisualDL
大约 1 年 前同步成功
通知
88
Star
4655
Fork
642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
10
列表
看板
标记
里程碑
合并请求
2
Wiki
5
Wiki
分析
仓库
DevOps
项目成员
Pages
V
VisualDL
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
10
Issue
10
列表
看板
标记
里程碑
合并请求
2
合并请求
2
Pages
分析
分析
仓库分析
DevOps
Wiki
5
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
9583bf7c
编写于
1月 13, 2023
作者:
C
chenjian
提交者:
GitHub
1月 13, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add English version for fastdeploy client (#1197)
* add english page for fastdeploy client * fix a bug
上级
a418dd44
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
598 addition
and
80 deletion
+598
-80
visualdl/component/inference/fastdeploy_client/client_app.py
visualdl/component/inference/fastdeploy_client/client_app.py
+401
-11
visualdl/component/inference/fastdeploy_client/http_client_manager.py
...ponent/inference/fastdeploy_client/http_client_manager.py
+59
-3
visualdl/component/inference/fastdeploy_server.py
visualdl/component/inference/fastdeploy_server.py
+41
-30
visualdl/server/app.py
visualdl/server/app.py
+97
-36
未找到文件。
visualdl/component/inference/fastdeploy_client/client_app.py
浏览文件 @
9583bf7c
此差异已折叠。
点击以展开。
visualdl/component/inference/fastdeploy_client/http_client_manager.py
浏览文件 @
9583bf7c
...
@@ -19,7 +19,6 @@ import numpy as np
...
@@ -19,7 +19,6 @@ import numpy as np
import
requests
import
requests
import
tritonclient.http
as
httpclient
import
tritonclient.http
as
httpclient
from
attrdict
import
AttrDict
from
attrdict
import
AttrDict
from
tritonclient.utils
import
InferenceServerException
def
convert_http_metadata_config
(
metadata
):
def
convert_http_metadata_config
(
metadata
):
...
@@ -118,8 +117,63 @@ table, th {{
...
@@ -118,8 +117,63 @@ table, th {{
</div>
</div>
"""
"""
metrics_table_head_en
=
"""
<style>
table, th {{
border:0.1px solid black;
}}
</style>
<div>
<table style="width:100%">
<tr>
<th rowspan="2">Model name</th>
<th colspan="4">Execution metric</th>
<th colspan="5">Delay metric</th>
</tr>
<tr>
<th>inference request success</th>
<th>inference request failure</th>
<th>inference count</th>
<th>inference exec count</th>
<th>inference request duration(ms)</th>
<th>inference queue duration(ms)</th>
<th>inference comput input duration(ms)</th>
<th>inference compute infer duration
(ms)</th>
<th>inference compute output duration(ms)</th>
</tr>
{}
</table>
</div>
<br>
<br>
<br>
<br>
<br>
<div>
<table style="width:100%">
<tr>
<th rowspan="2">GPU</th>
<th colspan="4">Performance metric</th>
<th colspan="2">Memory</th>
</tr>
<tr>
<th>utilization(%)</th>
<th>power usage(W)</th>
<th>power limit(W)</th>
<th>energy consumption(W)</th>
<th>total(GB)</th>
<th>used(GB)</th>
</tr>
{}
</table>
</div>
"""
def
get_metric_data
(
server_addr
,
metric_port
):
# noqa:C901
def
get_metric_data
(
server_addr
,
metric_port
,
lang
=
'zh'
):
# noqa:C901
'''
'''
Get metrics data from fastdeploy server, and transform it into html table.
Get metrics data from fastdeploy server, and transform it into html table.
Args:
Args:
...
@@ -235,6 +289,8 @@ def get_metric_data(server_addr, metric_port): # noqa:C901
...
@@ -235,6 +289,8 @@ def get_metric_data(server_addr, metric_port): # noqa:C901
for
item
in
data
])
+
"</tr>"
for
item
in
data
])
+
"</tr>"
for
data
in
gpu_data_list
for
data
in
gpu_data_list
])
])
if
lang
==
'en'
:
return
metrics_table_head_en
.
format
(
model_data
,
gpu_data
)
return
metrics_table_head
.
format
(
model_data
,
gpu_data
)
return
metrics_table_head
.
format
(
model_data
,
gpu_data
)
...
@@ -294,7 +350,7 @@ class HttpClientManager:
...
@@ -294,7 +350,7 @@ class HttpClientManager:
try
:
try
:
model_metadata
=
fastdeploy_client
.
get_model_metadata
(
model_metadata
=
fastdeploy_client
.
get_model_metadata
(
model_name
=
model_name
,
model_version
=
model_version
)
model_name
=
model_name
,
model_version
=
model_version
)
except
InferenceServer
Exception
as
e
:
except
Exception
as
e
:
raise
RuntimeError
(
"Failed to retrieve the metadata: "
+
str
(
e
))
raise
RuntimeError
(
"Failed to retrieve the metadata: "
+
str
(
e
))
model_metadata
=
convert_http_metadata_config
(
model_metadata
)
model_metadata
=
convert_http_metadata_config
(
model_metadata
)
...
...
visualdl/component/inference/fastdeploy_server.py
浏览文件 @
9583bf7c
...
@@ -25,6 +25,7 @@ from pathlib import Path
...
@@ -25,6 +25,7 @@ from pathlib import Path
import
requests
import
requests
from
.fastdeploy_client.client_app
import
create_gradio_client_app
from
.fastdeploy_client.client_app
import
create_gradio_client_app
from
.fastdeploy_client.client_app
import
create_gradio_client_app_en
from
.fastdeploy_lib
import
analyse_config
from
.fastdeploy_lib
import
analyse_config
from
.fastdeploy_lib
import
check_process_zombie
from
.fastdeploy_lib
import
check_process_zombie
from
.fastdeploy_lib
import
copy_config_file_to_default_config
from
.fastdeploy_lib
import
copy_config_file_to_default_config
...
@@ -53,7 +54,8 @@ class FastDeployServerApi(object):
...
@@ -53,7 +54,8 @@ class FastDeployServerApi(object):
self
.
root_dir
=
Path
(
os
.
getcwd
())
self
.
root_dir
=
Path
(
os
.
getcwd
())
self
.
opened_servers
=
{
self
.
opened_servers
=
{
}
# Use to store the opened server process pid and process itself
}
# Use to store the opened server process pid and process itself
self
.
client_port
=
None
self
.
client_port
=
None
# Chinese version
self
.
client_en_port
=
None
# English version
@
result
()
@
result
()
def
get_directory
(
self
,
cur_dir
):
def
get_directory
(
self
,
cur_dir
):
...
@@ -351,34 +353,43 @@ class FastDeployServerApi(object):
...
@@ -351,34 +353,43 @@ class FastDeployServerApi(object):
version_filenames_dict_for_frontend
)
version_filenames_dict_for_frontend
)
return
version_info_for_frontend
return
version_info_for_frontend
def
create_fastdeploy_client
(
self
):
def
create_fastdeploy_client
(
self
,
lang
=
'zh'
):
if
self
.
client_port
is
None
:
def
get_free_tcp_port
():
tcp
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
def
get_free_tcp_port
():
# tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
tcp
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
tcp
.
bind
((
'localhost'
,
0
))
# tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
addr
,
port
=
tcp
.
getsockname
()
tcp
.
bind
((
'localhost'
,
0
))
tcp
.
close
()
addr
,
port
=
tcp
.
getsockname
()
return
port
tcp
.
close
()
return
port
def
check_alive
(
client_port
):
while
True
:
self
.
client_port
=
get_free_tcp_port
()
try
:
app
=
create_gradio_client_app
()
requests
.
get
(
'http://localhost:{}/'
.
format
(
client_port
))
thread
=
Process
(
break
target
=
app
.
launch
,
kwargs
=
{
'server_port'
:
self
.
client_port
})
except
Exception
:
thread
.
start
()
time
.
sleep
(
1
)
def
check_alive
():
if
lang
==
'en'
:
while
True
:
if
self
.
client_en_port
is
None
:
try
:
self
.
client_en_port
=
get_free_tcp_port
()
requests
.
get
(
'http://localhost:{}/'
.
format
(
app
=
create_gradio_client_app_en
()
self
.
client_port
))
thread
=
Process
(
break
target
=
app
.
launch
,
except
Exception
:
kwargs
=
{
'server_port'
:
self
.
client_en_port
})
time
.
sleep
(
1
)
thread
.
start
()
check_alive
(
self
.
client_en_port
)
check_alive
()
return
self
.
client_en_port
return
self
.
client_port
else
:
if
self
.
client_port
is
None
:
self
.
client_port
=
get_free_tcp_port
()
app
=
create_gradio_client_app
()
thread
=
Process
(
target
=
app
.
launch
,
kwargs
=
{
'server_port'
:
self
.
client_port
})
thread
.
start
()
check_alive
(
self
.
client_port
)
return
self
.
client_port
def
_poll_zombie_process
(
self
):
def
_poll_zombie_process
(
self
):
# check if there are servers killed by other vdl app instance and become zoombie
# check if there are servers killed by other vdl app instance and become zoombie
...
@@ -410,7 +421,7 @@ def create_fastdeploy_api_call():
...
@@ -410,7 +421,7 @@ def create_fastdeploy_api_call():
'start_server'
:
(
api
.
start_server
,
[
'config'
]),
'start_server'
:
(
api
.
start_server
,
[
'config'
]),
'stop_server'
:
(
api
.
stop_server
,
[
'server_id'
]),
'stop_server'
:
(
api
.
stop_server
,
[
'server_id'
]),
'get_server_output'
:
(
api
.
get_server_output
,
[
'server_id'
,
'length'
]),
'get_server_output'
:
(
api
.
get_server_output
,
[
'server_id'
,
'length'
]),
'create_fastdeploy_client'
:
(
api
.
create_fastdeploy_client
,
[]),
'create_fastdeploy_client'
:
(
api
.
create_fastdeploy_client
,
[
'lang'
]),
'get_server_list'
:
(
api
.
get_server_list
,
[]),
'get_server_list'
:
(
api
.
get_server_list
,
[]),
'get_server_metric'
:
(
api
.
get_server_metric
,
[
'server_id'
]),
'get_server_metric'
:
(
api
.
get_server_metric
,
[
'server_id'
]),
'get_server_config'
:
(
api
.
get_server_config
,
[
'server_id'
]),
'get_server_config'
:
(
api
.
get_server_config
,
[
'server_id'
]),
...
...
visualdl/server/app.py
浏览文件 @
9583bf7c
...
@@ -181,6 +181,7 @@ def create_app(args): # noqa: C901
...
@@ -181,6 +181,7 @@ def create_app(args): # noqa: C901
error_msg
=
'{}'
.
format
(
e
)
error_msg
=
'{}'
.
format
(
e
)
return
make_response
(
error_msg
)
return
make_response
(
error_msg
)
args
=
urllib
.
parse
.
urlencode
(
request_args
)
args
=
urllib
.
parse
.
urlencode
(
request_args
)
if
args
:
if
args
:
return
redirect
(
return
redirect
(
api_path
+
"/fastdeploy/fastdeploy_client/app?{}"
.
format
(
args
),
api_path
+
"/fastdeploy/fastdeploy_client/app?{}"
.
format
(
args
),
...
@@ -201,14 +202,30 @@ def create_app(args): # noqa: C901
...
@@ -201,14 +202,30 @@ def create_app(args): # noqa: C901
Returns:
Returns:
Any thing from gradio server.
Any thing from gradio server.
'''
'''
lang
=
'zh'
if
request
.
method
==
'POST'
:
if
request
.
method
==
'POST'
:
if
request
.
mimetype
==
'application/json'
:
request_args
=
request
.
json
else
:
request_args
=
request
.
form
.
to_dict
()
if
'data'
in
request_args
:
lang
=
request_args
[
'data'
][
-
1
]
request_args
[
'lang'
]
=
lang
elif
'lang'
in
request_args
:
lang
=
request_args
[
'lang'
]
port
=
fastdeploy_api_call
(
'create_fastdeploy_client'
,
port
=
fastdeploy_api_call
(
'create_fastdeploy_client'
,
request
.
form
)
request_args
)
request_args
=
request
.
form
else
:
else
:
request_args
=
request
.
args
.
to_dict
()
if
'data'
in
request_args
:
lang
=
request_args
[
'data'
][
-
1
]
request_args
[
'lang'
]
=
lang
elif
'lang'
in
request_args
:
lang
=
request_args
[
'lang'
]
port
=
fastdeploy_api_call
(
'create_fastdeploy_client'
,
port
=
fastdeploy_api_call
(
'create_fastdeploy_client'
,
request
.
args
)
request
_
args
)
request_args
=
request
.
args
if
path
==
'app'
:
if
path
==
'app'
:
proxy_url
=
request
.
url
.
replace
(
proxy_url
=
request
.
url
.
replace
(
request
.
host_url
.
rstrip
(
'/'
)
+
api_path
+
request
.
host_url
.
rstrip
(
'/'
)
+
api_path
+
...
@@ -239,38 +256,82 @@ def create_app(args): # noqa: C901
...
@@ -239,38 +256,82 @@ def create_app(args): # noqa: C901
model_name
=
start_args
.
get
(
'default_model_name'
,
''
)
model_name
=
start_args
.
get
(
'default_model_name'
,
''
)
content
=
content
.
decode
()
content
=
content
.
decode
()
try
:
try
:
default_server_addr
=
re
.
search
(
if
request_args
.
get
(
'lang'
,
'zh'
)
==
'en'
:
'"label": {}.*?"value": "".*?}}'
.
format
(
default_server_addr
=
re
.
search
(
json
.
dumps
(
"服务ip"
,
ensure_ascii
=
True
).
replace
(
'"label": {}.*?"value": "".*?}}'
.
format
(
'
\\
'
,
'
\\\\
'
)),
content
).
group
(
0
)
json
.
dumps
(
cur_server_addr
=
default_server_addr
.
replace
(
"server ip"
,
ensure_ascii
=
True
).
replace
(
'"value": ""'
,
'"value": "localhost"'
)
'
\\
'
,
'
\\\\
'
)),
content
).
group
(
0
)
default_http_port
=
re
.
search
(
cur_server_addr
=
default_server_addr
.
replace
(
'"label": {}.*?"value": "".*?}}'
.
format
(
'"value": ""'
,
'"value": "localhost"'
)
json
.
dumps
(
"推理服务端口"
,
ensure_ascii
=
True
).
replace
(
default_http_port
=
re
.
search
(
'
\\
'
,
'
\\\\
'
)),
content
).
group
(
0
)
'"label": {}.*?"value": "".*?}}'
.
format
(
cur_http_port
=
default_http_port
.
replace
(
json
.
dumps
(
'"value": ""'
,
'"value": "{}"'
.
format
(
http_port
))
"server port"
,
ensure_ascii
=
True
).
replace
(
default_metrics_port
=
re
.
search
(
'
\\
'
,
'
\\\\
'
)),
content
).
group
(
0
)
'"label": {}.*?"value": "".*?}}'
.
format
(
cur_http_port
=
default_http_port
.
replace
(
json
.
dumps
(
"性能服务端口"
,
ensure_ascii
=
True
).
replace
(
'"value": ""'
,
'"value": "{}"'
.
format
(
http_port
))
'
\\
'
,
'
\\\\
'
)),
content
).
group
(
0
)
default_metrics_port
=
re
.
search
(
cur_metrics_port
=
default_metrics_port
.
replace
(
'"label": {}.*?"value": "".*?}}'
.
format
(
'"value": ""'
,
'"value": "{}"'
.
format
(
metrics_port
))
json
.
dumps
(
default_model_name
=
re
.
search
(
"metrics port"
,
ensure_ascii
=
True
).
replace
(
'"label": {}.*?"value": "".*?}}'
.
format
(
'
\\
'
,
'
\\\\
'
)),
content
).
group
(
0
)
json
.
dumps
(
"模型名称"
,
ensure_ascii
=
True
).
replace
(
cur_metrics_port
=
default_metrics_port
.
replace
(
'
\\
'
,
'
\\\\
'
)),
content
).
group
(
0
)
'"value": ""'
,
cur_model_name
=
default_model_name
.
replace
(
'"value": "{}"'
.
format
(
metrics_port
))
'"value": ""'
,
'"value": "{}"'
.
format
(
model_name
))
default_model_name
=
re
.
search
(
default_model_version
=
re
.
search
(
'"label": {}.*?"value": "".*?}}'
.
format
(
'"label": {}.*?"value": "".*?}}'
.
format
(
json
.
dumps
(
json
.
dumps
(
"模型版本"
,
ensure_ascii
=
True
).
replace
(
"model name"
,
ensure_ascii
=
True
).
replace
(
'
\\
'
,
'
\\\\
'
)),
content
).
group
(
0
)
'
\\
'
,
'
\\\\
'
)),
content
).
group
(
0
)
cur_model_version
=
default_model_version
.
replace
(
cur_model_name
=
default_model_name
.
replace
(
'"value": ""'
,
'"value": "{}"'
.
format
(
'1'
))
'"value": ""'
,
'"value": "{}"'
.
format
(
model_name
))
content
=
content
.
replace
(
default_server_addr
,
default_model_version
=
re
.
search
(
cur_server_addr
)
'"label": {}.*?"value": "".*?}}'
.
format
(
json
.
dumps
(
"model version"
,
ensure_ascii
=
True
).
replace
(
'
\\
'
,
'
\\\\
'
)),
content
).
group
(
0
)
cur_model_version
=
default_model_version
.
replace
(
'"value": ""'
,
'"value": "{}"'
.
format
(
'1'
))
content
=
content
.
replace
(
default_server_addr
,
cur_server_addr
)
else
:
default_server_addr
=
re
.
search
(
'"label": {}.*?"value": "".*?}}'
.
format
(
json
.
dumps
(
"服务ip"
,
ensure_ascii
=
True
).
replace
(
'
\\
'
,
'
\\\\
'
)),
content
).
group
(
0
)
cur_server_addr
=
default_server_addr
.
replace
(
'"value": ""'
,
'"value": "localhost"'
)
default_http_port
=
re
.
search
(
'"label": {}.*?"value": "".*?}}'
.
format
(
json
.
dumps
(
"推理服务端口"
,
ensure_ascii
=
True
).
replace
(
'
\\
'
,
'
\\\\
'
)),
content
).
group
(
0
)
cur_http_port
=
default_http_port
.
replace
(
'"value": ""'
,
'"value": "{}"'
.
format
(
http_port
))
default_metrics_port
=
re
.
search
(
'"label": {}.*?"value": "".*?}}'
.
format
(
json
.
dumps
(
"性能服务端口"
,
ensure_ascii
=
True
).
replace
(
'
\\
'
,
'
\\\\
'
)),
content
).
group
(
0
)
cur_metrics_port
=
default_metrics_port
.
replace
(
'"value": ""'
,
'"value": "{}"'
.
format
(
metrics_port
))
default_model_name
=
re
.
search
(
'"label": {}.*?"value": "".*?}}'
.
format
(
json
.
dumps
(
"模型名称"
,
ensure_ascii
=
True
).
replace
(
'
\\
'
,
'
\\\\
'
)),
content
).
group
(
0
)
cur_model_name
=
default_model_name
.
replace
(
'"value": ""'
,
'"value": "{}"'
.
format
(
model_name
))
default_model_version
=
re
.
search
(
'"label": {}.*?"value": "".*?}}'
.
format
(
json
.
dumps
(
"模型版本"
,
ensure_ascii
=
True
).
replace
(
'
\\
'
,
'
\\\\
'
)),
content
).
group
(
0
)
cur_model_version
=
default_model_version
.
replace
(
'"value": ""'
,
'"value": "{}"'
.
format
(
'1'
))
content
=
content
.
replace
(
default_server_addr
,
cur_server_addr
)
if
http_port
:
if
http_port
:
content
=
content
.
replace
(
default_http_port
,
content
=
content
.
replace
(
default_http_port
,
cur_http_port
)
cur_http_port
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录