【问题标题】:why tensorrt optimized pb can not be deployed by tf-serving?为什么 tensorrt 优化的 pb 不能被 tf-serving 部署?
【发布时间】:2020-02-25 11:02:04
【问题描述】:

我正在使用 tensorrt 来加速 Tacotron2 模型的推理速度。我用过

tensorrt 5.0.2.6 版本和 tensorflow 1.13.0.rc0 版本。

我使用下面的 tensorrt api 将 savedmodel 转换为 tftrt savedmodel:

trt.create_inference_graph(
input_graph_def=None,
outputs=None,
max_batch_size=32,
input_saved_model_dir=os.path.join(args.export_dir, args.version),
output_saved_model_dir=args.output_saved_model_dir,
precision_mode=args.precision_mode)

输出的tensorrt_savedmodel.pb不能导入到tensorboard查看,但tensorrt_savedmodel.pb可以用tf-serving部署。

但是,当客户端使用 grpc 请求 tf-serving 时,会出现错误:

<_Rendezvous of RPC that terminated with:
status = StatusCode.INVALID_ARGUMENT
details = "The TF function for the TRT segment could not be empty
 [[{{node model/inference/prenet/TRTEngineOp_33}}]]"
debug_error_string = " 
{"created":"@1572417319.714936208","description":"Error received from peer ipv4:192.168.23.17:8500","file":"src/core/lib/surface/call.cc","file_line":1052,"grpc_message":"The TF function for the TRT segment could not be empty\n\t [[{{node model/inference/prenet/TRTEngineOp_33}}]]","grpc_status":3}

关于这个问题的任何解决方案?

【问题讨论】:

  • 您可以使用 tensorRT 服务器而不是 tf-serving 来实现此目的

标签: tensorflow tensorflow-serving tensorrt


【解决方案1】:

TensorFlow 保存的模型还提供了一种正式且一致的方式来使用 tensorrt。您可以尝试使用 saved_model_cli 转换它,然后部署到 tf-serving。

usage: saved_model_cli convert [-h] --dir DIR --output_dir OUTPUT_DIR
                               --tag_set TAG_SET
                               {tensorrt} ...

Usage example:
To convert the SavedModel to one that have TensorRT ops:
$saved_model_cli convert \
   --dir /tmp/saved_model \
   --tag_set serve \
   --output_dir /tmp/saved_model_trt \
   tensorrt

optional arguments:
  -h, --help            show this help message and exit
  --dir DIR             directory containing the SavedModel to convert
  --output_dir OUTPUT_DIR
                        output directory for the converted SavedModel
  --tag_set TAG_SET     tag-set of graph in SavedModel to convert, separated by ','

conversion methods:
  valid conversion methods

  {tensorrt}            the conversion to run with the SavedModel

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-04
    • 2016-09-04
    • 1970-01-01
    • 2022-10-06
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 2021-05-28
    相关资源
    最近更新 更多