一、Tritonserver 介绍
Tritonserver是Nvidia推出的基于GPU和CPU的在线推理服务解决方案,因其具有高性能的并发处理和支持几乎所有主流机器学习框架模型的特点,是目前云端的GPU服务高效部署的主流方案。
Tritonserver的部署是以模型仓库(Model Repository)的形式体现的,即需要模型文件和配置文件,且按一定的格式放置如下,根目录下每个模型有各自的文件夹。
./
└── my_model_repo
├── 1
│ └── model.plan
└── config.pbtxt
Tritonserver 有auto-generate-config功能,关于模型的输入(inputs)、输出(outputs)和最大batch(max_batch_size)等可以根据对模型的分析自动生成,对onnx, tensorrt, tf saved model等带模型结构的模型极为方便,最简便的config.pbtxt可以只定义模型的name和backend,例如针对上述模型:
# config.pbtxt
name: "my_model_repo"
backend: "tensorrt"
二、部署Features
Ensemble Pipeline
Pipeline 模式是实际生产中机器学习模型应用常见的场景,比如一个含有带Python代码前处理和后处理的模型,或者含有前后处理的多个模型串联成一个生产处理流程;比如下图左边的OCR流程,若单独部署了文字检测和文字识别模型,图像经过检测模型返回boxes块后,再经过cropping后,接着请求识别模型,最后返回识别的文字,这样在客户端和服务端之间需要交互多次;而像右图,将中间的cropping处理过程也视作一个model形式,部署在服务测,则单次请求中,服务端完成Text Detection -> Image Cropping -> Text Recognition处理后返回,减少了交互次数,极大降低了耗时。

【出处:https://github.com/triton-inference-server/tutorials/blob/main/Conceptual_Guide/Part_5-Model_Ensembles/README.md】
Ensemble Pipeline 需要额外定义一个Model Repository, 里边的版本文件夹为空,config.pbtxt中定义数据流的处理流程,指明服务端接收到数据后在各个模型之间处理的逻辑顺序,格式如下:
ensemble_model/
├── 1
└── config.pbtxt
以上图的OCR Pipeline 为例,除了本身的两个模型:text_detection和text_recognition, 我们额外定义三个Model Repository:detection_preprocessing, detection_postprocessing, recognition_postprocessing, 分别表示检测模型的前处理,检测模型的后处理和识别模型的后处理, 按实际处理中的逻辑顺序将上述的所有模型串联如下:

上图模型及各自输入输出之间的逻辑关系写到ensemble_model的配置文件里边如下。文件的信息由两部分组成,第一部分定义整个Pipeline的基础信息,第二部分中的step定义了推理时上图的逻辑关系。
name: "ensemble_model"
platform: "ensemble"
max_batch_size: 256
input [
{
name: "input_image"
data_type: TYPE_UINT8
dims: [ -1 ]
}
]
output [
{
name: "recognized_text"
data_type: TYPE_STRING
dims: [ -1 ]
}
]
ensemble_scheduling {
step [
{
model_name: "detection_preprocessing"
model_version: -1
input_map {
key: "detection_preprocessing_input"
value: "input_image"
}
output_map {
key: "detection_preprocessing_output"
value: "preprocessed_image"
}
},
{
model_name: "text_detection"
model_version: -1
input_map {
key: "input_images:0"
value: "preprocessed_image"
}
output_map {
key: "feature_fusion/Conv_7/Sigmoid:0"
value: "Sigmoid:0"
},
output_map {
key: "feature_fusion/concat_3:0"
value: "concat_3:0"
}
},
{

最低0.47元/天 解锁文章
385

被折叠的 条评论
为什么被折叠?



