1 Star 1 Fork 0

binghai / FastDeploy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
model_configuration.md 6.92 KB
一键复制 编辑 原始数据 按行查看 历史

中文 | English

模型配置

模型存储库中的每个模型都必须包含一个模型配置,该配置提供了关于模型的必要和可选信息。这些配置信息一般写在 config.pbtxt 文件中,ModelConfig protobuf格式。

模型通用最小配置

详细的模型通用配置请看官网文档: model_configuration.Triton的最小模型配置必须包括: platformbackend 属性、max_batch_size 属性和模型的输入输出.

例如一个Paddle模型,有两个输入input0input1,一个输出output0,输入输出都是float32类型的tensor,最大batch为8.则最小的配置如下:

  backend: "fastdeploy"
  max_batch_size: 8
  input [
    {
      name: "input0"
      data_type: TYPE_FP32
      dims: [ 16 ]
    },
    {
      name: "input1"
      data_type: TYPE_FP32
      dims: [ 16 ]
    }
  ]
  output [
    {
      name: "output0"
      data_type: TYPE_FP32
      dims: [ 16 ]
    }
  ]

CPU、GPU和实例个数配置

通过instance_group属性可以配置服务使用哪种硬件资源,分别部署多少个模型推理实例。

CPU部署例子:

  instance_group [
    {
      # 创建两个CPU实例
      count: 2
      # 使用CPU部署  
      kind: KIND_CPU
    }
  ]

GPU 0上部署2个实例,在GPU1GPU上分别部署1个实例

  instance_group [
    {
      # 创建两个GPU实例
      count: 2
      # 使用GPU推理
      kind: KIND_GPU
      # 部署在GPU卡0上
      gpus: [ 0 ]
    },
    {
      count: 1
      kind: KIND_GPU
      # 在GPU卡1、2都部署
      gpus: [ 1, 2 ]
    }
  ]

Name, Platform and Backend

模型配置中 name 属性是可选的。如果模型没有在配置中指定,则使用模型的目录名;如果指定了该属性,它必须要跟模型的目录名一致。

使用 fastdeploy backend,没有platform属性可以配置,必须配置backend属性为fastdeploy

backend: "fastdeploy"

FastDeploy Backend配置

FastDeploy后端目前支持cpugpu推理,cpu上支持paddleonnxruntimeopenvino三个推理引擎,gpu上支持paddleonnxruntimetensorrt三个引擎。

配置使用Paddle引擎

除去配置 Instance Groups,决定模型运行在CPU还是GPU上。Paddle引擎中,还可以进行如下配置,具体例子可参照PP-OCRv3例子中Runtime配置:

optimization {
  execution_accelerators {
    # CPU推理配置, 配合KIND_CPU使用
    cpu_execution_accelerator : [
      {
        name : "paddle"
        # 设置推理并行计算线程数为4
        parameters { key: "cpu_threads" value: "4" }
        # 开启mkldnn加速,设置为0关闭mkldnn
        parameters { key: "use_mkldnn" value: "1" }
      }
    ],
    # GPU推理配置, 配合KIND_GPU使用
    gpu_execution_accelerator : [
      {
        name : "paddle"
        # 设置推理并行计算线程数为4
        parameters { key: "cpu_threads" value: "4" }
        # 开启mkldnn加速,设置为0关闭mkldnn
        parameters { key: "use_mkldnn" value: "1" }
      }
    ]
  }
}

配置使用Paddle+XPU引擎

optimization {
  execution_accelerators {
    # XPU推理配置通过CPU Execution启动, 配合KIND_CPU使用
    cpu_execution_accelerator: [
      {
        name: "paddle_xpu",
        # CPU相关配置
        # cpu_threads: CPU计算线程数
        # use_paddle_log: 开启paddle log信息
        parameters { key: "cpu_threads" value: "4" }
        parameters { key: "use_paddle_log" value: "0" }
        # XPU相关配置
        # kunlunxin_id: 使用的XPU卡号
        # l3_workspace_size: L3缓存size
        parameters { key: "kunlunxin_id" value: "0" }
        parameters { key: "l3_workspace_size" value: "0xfffc00" }
        parameters { key: "locked" value: "0" }
        parameters { key: "autotune" value: "1" }
        parameters { key: "precision" value: "int16" }
        parameters { key: "adaptive_seqlen" value: "0" }
        parameters { key: "enable_multi_stream" value: "0" }
        parameters { key: "gm_default_size" value: "0" }
      }
    ]
  }
}

配置使用ONNXRuntime引擎

除去配置 Instance Groups,决定模型运行在CPU还是GPU上。ONNXRuntime引擎中,还可以进行如下配置,具体例子可参照YOLOv5的Runtime配置:

optimization {
  execution_accelerators {
    cpu_execution_accelerator : [
      {
        name : "onnxruntime"
        # 设置推理并行计算线程数为4
        parameters { key: "cpu_threads" value: "4" }
      }
    ],
    gpu_execution_accelerator : [
      {
        name : "onnxruntime"
      }
    ]
  }
}

配置使用OpenVINO引擎

OpenVINO引擎只支持CPU推理,配置如下:

optimization {
  execution_accelerators {
    cpu_execution_accelerator : [
      {
        name : "openvino"
        # 设置推理并行计算线程数为4(所有实例总共线程数)
        parameters { key: "cpu_threads" value: "4" }
        # 设置OpenVINO的num_streams(一般设置为跟实例数一致)
        parameters { key: "num_streams" value: "1" }
      }
    ]
  }
}

配置使用TensorRT引擎

TensorRT引擎只支持GPU推理,配置如下:

optimization {
  execution_accelerators {
    gpu_execution_accelerator : [
      {
        name : "tensorrt"
        # 使用TensorRT的FP16推理,其他可选项为: trt_fp32
        # 如果加载的是量化模型,此精度设置无效,会默认使用int8进行推理
        parameters { key: "precision" value: "trt_fp16" }
      }
    ]
  }
}

配置TensorRT动态shape的格式如下,可参照PaddleCls例子中Runtime配置:

optimization {
  execution_accelerators {
  gpu_execution_accelerator : [ {
    # use TRT engine
    name: "tensorrt",
    # use fp16 on TRT engine
    parameters { key: "precision" value: "trt_fp16" }
  },
  {
    # Configure the minimum shape of dynamic shape
    name: "min_shape"
    # All input name and minimum shape
    parameters { key: "input1" value: "1 3 224 224" }
    parameters { key: "input2" value: "1 10" }
  },
  {
    # Configure the optimal shape of dynamic shape
    name: "opt_shape"
    # All input name and optimal shape
    parameters { key: "input1" value: "2 3 224 224" }
    parameters { key: "input2" value: "2 20" }
  },
  {
    # Configure the maximum shape of dynamic shape
    name: "max_shape"
    # All input name and maximum shape
    parameters { key: "input1" value: "8 3 224 224" }
    parameters { key: "input2" value: "8 30" }
  }
  ]
}}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/binghai228/FastDeploy.git
git@gitee.com:binghai228/FastDeploy.git
binghai228
FastDeploy
FastDeploy
develop

搜索帮助

344bd9b3 5694891 D2dac590 5694891