Skip to main content

A web server for deploy ml/dl model

Project description

介绍

fastml-engine. 采用Gunicorn Web服务框架搭建,以简化模型推理工程部署的工作内容

功能特性

  1. 集成Gunicorn Flask 服务组件,稳定可靠,可用于生产.

  2. 统一推理服务接口,支持多种接口请求格式(text/json/octet-stream/form-data)

  3. 搭配inference-template使用,支持自定义模型推理代码

  4. 支持简便的启动命令

install

  1. pip

    https://gitee.com/easy-ams/ams-processor-template.git pip install fastml-engine

使用说明

  1. ams-processor-template使用说明

  2. 启动服务

    ams_engine安装完成,在python的bin目录下会产生ams-start.sh和ams-stop.sh两个脚本,linux环境下可直接使用.

    sh ams-start.sh <absolute path> <port> <workers> <timeout> sh ams-start.sh /home/work_path/ams-processor-template 9000 2 60 port:端口号(可选,默认8088 workers:进程wokers数(可选,默认1) timeout:请求响应超时,单位s(可选,默认60s)

  3. 验证服务

    a)通过浏览器访问健康检查接口 ip:port/health b)查看启动日志,日志目录在代码根路径/logs目录下

  4. 停止服务

    执行脚本指定进程占用端口 sh ams-stop.sh 9000

接口描述

接口说明

URI

请求协议

返回内容

健康检查

/health

GET

{ status:UP}

查询推理接口

/endpoints

GET

接口名称json报文

推理接口

/algo/

POST

返回推理预测结果报文

健康检查接口响应报文

{
  "status": "UP"
}

endpoints接口响应报文
[
  {
    "processor_class_name": "Inference",
    "processor_script_name": "customized_processor"
  }
]

推理接口响应报文
{
     "result": true,
     "data": {
         "k": "v"
     },
     "metadata": {
         "duration": 1.65576171875,
         "content_type": "json"
     }
 }

测试

使用POSTMAN调用推理接口
注意:请求头需要添加Content-Type参数,用来指定请求报文格式

Content-Type

说明

text/plain

文本格式

application/json

json格式

application/octet-stream

文件

multipart/form-data

form-data格式

请求发起后报文将作为入参传入推理算法主函数 > windows本地运行服务

ams_engine包提供app.py脚本,可本地代码导入使用,启动flask

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
# 设置环境变量
os.environ['PROCESSOR_PATH'] = 'D:/code/processor-customized/'
os.environ['default_model_path'] = 'D:/code/processor-customized/model'
import ams_engine.app as ams

if __name__ == '__main__':
    # 启动运行,使用ams_engine的app模块直接启动flask程序
    ams.app.run('0.0.0.0', 8088, debug=False, threaded=True)

日志说明

运行日志存放在推理引擎根目录logs文件夹下

  1. access.log为请求调用日志

  2. error-access.log为错误日志

  3. app.log为业务日志,使用python logging模块打印

改进计划

  1. 实践优化,结合实际使用场景,不断发现缺陷并进行优化迭代

  2. 提供更多推理引擎模版 ams-processor-xxx

  3. 集成监控模块

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

fastml_engine-1.0.1-py3-none-any.whl (21.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page