mirror of
https://github.com/tencentmusic/cube-studio.git
synced 2024-11-21 01:16:33 +08:00
add model register
This commit is contained in:
parent
0c1968fe45
commit
77ea05e234
31
job-template/job/model_register/Dockerfile
Normal file
31
job-template/job/model_register/Dockerfile
Normal file
@ -0,0 +1,31 @@
|
||||
FROM ubuntu:18.04
|
||||
|
||||
# 安装运维工具
|
||||
RUN apt-get update && apt install -y --force-yes --no-install-recommends vim apt-transport-https gnupg2 ca-certificates-java rsync jq wget git dnsutils iputils-ping net-tools curl locales zip
|
||||
# 安装python
|
||||
RUN apt install -y python3.6-dev python3-pip libsasl2-dev libpq-dev \
|
||||
&& ln -s /usr/bin/python3 /usr/bin/python \
|
||||
&& ln -s /usr/bin/pip3 /usr/bin/pip
|
||||
|
||||
# 安装中文
|
||||
RUN apt install -y --force-yes --no-install-recommends locales ttf-wqy-microhei ttf-wqy-zenhei xfonts-wqy && locale-gen zh_CN && locale-gen zh_CN.utf8
|
||||
ENV LANG zh_CN.UTF-8
|
||||
ENV LC_ALL zh_CN.UTF-8
|
||||
ENV LANGUAGE zh_CN.UTF-8
|
||||
|
||||
# 便捷操作
|
||||
RUN echo "alias ll='ls -alF'" >> /root/.bashrc && \
|
||||
echo "alias la='ls -A'" >> /root/.bashrc && \
|
||||
echo "alias vi='vim'" >> /root/.bashrc && \
|
||||
/bin/bash -c "source /root/.bashrc"
|
||||
|
||||
|
||||
RUN pip install kubernetes==18.20.0 pysnooper psutil
|
||||
COPY job/register_model/* /app/
|
||||
|
||||
WORKDIR /app
|
||||
ENV PYTHONPATH=/app:$PYTHONPATH
|
||||
|
||||
ENTRYPOINT ["python3", "launcher.py"]
|
||||
|
||||
|
118
job-template/job/model_register/README.md
Normal file
118
job-template/job/model_register/README.md
Normal file
@ -0,0 +1,118 @@
|
||||
# register_model 模板
|
||||
镜像:ccr.ccs.tencentyun.com/cube-studio/model:20221001
|
||||
启动参数:
|
||||
```bash
|
||||
{
|
||||
"参数": {
|
||||
"--project_name": {
|
||||
"type": "str",
|
||||
"item_type": "str",
|
||||
"label": "部署项目名",
|
||||
"require": 1,
|
||||
"choice": [],
|
||||
"range": "",
|
||||
"default": "public",
|
||||
"placeholder": "",
|
||||
"describe": "部署项目名",
|
||||
"editable": 1,
|
||||
"condition": "",
|
||||
"sub_args": {}
|
||||
},
|
||||
"--model_name": {
|
||||
"type": "str",
|
||||
"item_type": "str",
|
||||
"label": "模型名",
|
||||
"require": 1,
|
||||
"choice": [],
|
||||
"range": "",
|
||||
"default": "",
|
||||
"placeholder": "",
|
||||
"describe": "模型名",
|
||||
"editable": 1,
|
||||
"condition": "",
|
||||
"sub_args": {}
|
||||
},
|
||||
"--model_version": {
|
||||
"type": "str",
|
||||
"item_type": "str",
|
||||
"label": "模型版本号",
|
||||
"require": 1,
|
||||
"choice": [],
|
||||
"range": "",
|
||||
"default": "v2022.10.01.1",
|
||||
"placeholder": "",
|
||||
"describe": "模型版本号",
|
||||
"editable": 1,
|
||||
"condition": "",
|
||||
"sub_args": {}
|
||||
},
|
||||
"--model_path": {
|
||||
"type": "str",
|
||||
"item_type": "str",
|
||||
"label": "模型地址",
|
||||
"require": 1,
|
||||
"choice": [],
|
||||
"range": "",
|
||||
"default": "",
|
||||
"placeholder": "",
|
||||
"describe": "模型地址",
|
||||
"editable": 1,
|
||||
"condition": "",
|
||||
"sub_args": {}
|
||||
},
|
||||
"--describe": {
|
||||
"type": "str",
|
||||
"item_type": "str",
|
||||
"label": "模型描述",
|
||||
"require": 1,
|
||||
"choice": [],
|
||||
"range": "",
|
||||
"default": "",
|
||||
"placeholder": "",
|
||||
"describe": "模型描述",
|
||||
"editable": 1,
|
||||
"condition": "",
|
||||
"sub_args": {}
|
||||
},
|
||||
"--framework": {
|
||||
"type": "str",
|
||||
"item_type": "str",
|
||||
"label": "模型框架",
|
||||
"require": 1,
|
||||
"choice": [
|
||||
"xgb",
|
||||
"tf",
|
||||
"pytorch",
|
||||
"onnx",
|
||||
"tensorrt"
|
||||
],
|
||||
"range": "",
|
||||
"default": "tf",
|
||||
"placeholder": "",
|
||||
"describe": "模型框架",
|
||||
"editable": 1,
|
||||
"condition": "",
|
||||
"sub_args": {}
|
||||
},
|
||||
"--inference_framework": {
|
||||
"type": "str",
|
||||
"item_type": "str",
|
||||
"label": "推理框架",
|
||||
"require": 1,
|
||||
"choice": [
|
||||
"tfserving",
|
||||
"torch-server",
|
||||
"onnxruntime",
|
||||
"triton-server"
|
||||
],
|
||||
"range": "",
|
||||
"default": "tfserving",
|
||||
"placeholder": "",
|
||||
"describe": "推理框架",
|
||||
"editable": 1,
|
||||
"condition": "",
|
||||
"sub_args": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
9
job-template/job/model_register/build.sh
Normal file
9
job-template/job/model_register/build.sh
Normal file
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -ex
|
||||
|
||||
docker build -t ccr.ccs.tencentyun.com/cube-studio/model:20221001 -f job/register_model/Dockerfile .
|
||||
docker push ccr.ccs.tencentyun.com/cube-studio/model:20221001
|
||||
|
||||
|
||||
|
132
job-template/job/model_register/launcher.py
Normal file
132
job-template/job/model_register/launcher.py
Normal file
@ -0,0 +1,132 @@
|
||||
|
||||
import os,sys
|
||||
import argparse
|
||||
import datetime
|
||||
import json
|
||||
import time
|
||||
import uuid
|
||||
import pysnooper
|
||||
import re
|
||||
import requests
|
||||
import copy
|
||||
import os
|
||||
KFJ_CREATOR = os.getenv('KFJ_CREATOR', 'admin')
|
||||
KFJ_TASK_PROJECT_NAME = os.getenv('KFJ_TASK_PROJECT_NAME','public')
|
||||
KFJ_RUN_ID = os.getenv('KFJ_RUN_ID', '')
|
||||
KFJ_PIPELINE_ID = os.getenv('KFJ_PIPELINE_ID', '0')
|
||||
host = os.getenv('HOST',os.getenv('KFJ_MODEL_REPO_API_URL','http://kubeflow-dashboard.infra')).strip('/')
|
||||
|
||||
@pysnooper.snoop()
|
||||
def deploy(**kwargs):
|
||||
# print(kwargs)
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': KFJ_CREATOR
|
||||
}
|
||||
|
||||
# 获取项目组
|
||||
url = host + "/project_modelview/api/?form_data=" + json.dumps({
|
||||
"filters": [
|
||||
{
|
||||
"col": "name",
|
||||
"opr": "eq",
|
||||
"value": kwargs['project_name']
|
||||
}
|
||||
]
|
||||
})
|
||||
res = requests.get(url, headers=headers)
|
||||
exist_project = res.json().get('result', {}).get('data', [])
|
||||
if not exist_project:
|
||||
print('不存在项目组')
|
||||
return
|
||||
exist_project = exist_project[0]
|
||||
|
||||
# 查询同名,同run-id是否存在
|
||||
url = host+"/training_model_modelview/api/?form_data="+json.dumps({
|
||||
"filters":[
|
||||
{
|
||||
"col": "name",
|
||||
"opr": "eq",
|
||||
"value": kwargs['model_name']
|
||||
},
|
||||
{
|
||||
"col": "run_id",
|
||||
"opr": "eq",
|
||||
"value": KFJ_RUN_ID
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
# print(url)
|
||||
res = requests.get(url,headers=headers, allow_redirects=False)
|
||||
# print(res.content)
|
||||
if res.status_code==200:
|
||||
|
||||
payload = {
|
||||
'name': kwargs['model_name'],
|
||||
'version': kwargs['model_version'],
|
||||
'path':kwargs['model_path'],
|
||||
'describe': kwargs['describe'],
|
||||
'project': exist_project['id'],
|
||||
'framework': kwargs['framework'],
|
||||
'run_id': KFJ_RUN_ID,
|
||||
'run_time': datetime.datetime.now().strftime('%Y.%m.%d %H:%M:%S'),
|
||||
'metrics': '',
|
||||
'md5': '',
|
||||
'api_type': kwargs['inference_framework'],
|
||||
'pipeline_id': KFJ_PIPELINE_ID
|
||||
}
|
||||
|
||||
exist_models = res.json().get('result',{}).get('data',[])
|
||||
|
||||
# 不存在就创建新的模型
|
||||
if not exist_models:
|
||||
url = host + "/training_model_modelview/api/"
|
||||
res = requests.post(url, headers=headers,json=payload, allow_redirects=False)
|
||||
if res.status_code==200:
|
||||
new_model = res.json().get('result', {})
|
||||
print('注册成功')
|
||||
else:
|
||||
print(res.content)
|
||||
print('注册失败')
|
||||
exit(1)
|
||||
|
||||
# print(res)
|
||||
|
||||
else:
|
||||
exist_model=exist_models[0]
|
||||
# 更新模型
|
||||
url = host + "/training_model_modelview/api/%s"%exist_model['id']
|
||||
res = requests.put(url, headers=headers, json=payload, allow_redirects=False)
|
||||
if res.status_code==200:
|
||||
new_model = res.json().get('result',{})
|
||||
print('更新成功')
|
||||
else:
|
||||
print(res.content)
|
||||
print('更新失败')
|
||||
exit(1)
|
||||
|
||||
|
||||
else:
|
||||
print(res.content)
|
||||
exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
arg_parser = argparse.ArgumentParser("deploy service launcher")
|
||||
arg_parser.add_argument('--project_name', type=str, help="所属项目组", default='public')
|
||||
arg_parser.add_argument('--model_name', type=str, help="模型名", default='demo')
|
||||
arg_parser.add_argument('--model_version', type=str, help="模型版本号",
|
||||
default=datetime.datetime.now().strftime('v%Y.%m.%d.1'))
|
||||
arg_parser.add_argument('--model_path', type=str, help="模型地址", default='')
|
||||
arg_parser.add_argument('--describe', type=str, help="模型描述", default='xx模型')
|
||||
|
||||
arg_parser.add_argument('--framework', type=str, help="算法框架", default='tf')
|
||||
arg_parser.add_argument('--inference_framework', type=str, help="推理框架", default='tfserving')
|
||||
|
||||
args = arg_parser.parse_args()
|
||||
# print("{} args: {}".format(__file__, args))
|
||||
|
||||
deploy(**args.__dict__)
|
||||
|
||||
|
@ -6,6 +6,6 @@ COPY . /SVC
|
||||
RUN python3 -m pip install pickle-mixin -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
RUN python3 -m pip install FastAPI -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
RUN python3 -m pip install uvicorn -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
WORKDIR /SVC
|
||||
|
||||
|
||||
ENTRYPOINT ["python3", "/SVC/launcher.py"]
|
||||
ENTRYPOINT ["python3", "launcher.py"]
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
set -ex
|
||||
|
||||
docker build -t ccr.ccs.tencentyun.com/cube-studio/ner-service:20220812 -f job/ner_service/Dockerfile .
|
||||
docker push ccr.ccs.tencentyun.com/cube-studio/ner-service:20220812
|
||||
docker build -t ccr.ccs.tencentyun.com/cube-studio/ner:service-20220812 .
|
||||
docker push ccr.ccs.tencentyun.com/cube-studio/ner:service-20220812
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user