tensorflow serving中enable_model_warmup在部署中的使用

15 篇文章 0 订阅
3 篇文章 0 订阅

enable_model_warmup参数:在tensorflow serving中通过saved_model模型中自带客户端的请求来预加载模型,减少第一次的请求的延迟

命名:在saved_model模型文件夹下的asserts.extra文件夹,放入命名为tf_serving_warmup_requests的tf record文件即可

其中assets.extra文件下:

 

# coding:utf-8

# @author: “”
# @file: tf_serving_warmup_requests_client.py
# @time:
# @desc:





import tensorflow as tf

from tensorflow_serving.apis import predict_pb2
from tensorflow_serving.apis import prediction_log_pb2

request_dict = {'inputs': {'input_ids': [[101, 2644, 1962, 8024, 6821, 7027, 3221, 1921, 1921, 2864, 6756, 8024, 1744, 1079, 3297, 1920, 4638, 757, 5468, 5381, 1297, 6756, 2398, 1378, 8024, 6435, 7309, 2644, 4385, 1762, 3221, 3300, 6775, 6756, 7444, 6206, 1139, 1545, 1408, 8043, 172, 3300, 702, 6756, 1762, 1297, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], 'input_mask': [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], 'segment_ids': [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], 'is_training': False}, 'signature_name': 'serving_default'}

input_ids = request_dict["inputs"]["input_ids"]
input_mask = request_dict["inputs"]["input_mask"]
segment_ids = request_dict["inputs"]["segment_ids"]
is_training = request_dict["inputs"]["is_training"]

print(input_ids)


with tf.io.TFRecordWriter("tf_serving_warmup_requests") as writer:
    predict_request = predict_pb2.PredictRequest()
    predict_request.model_spec.name = "sellcarintent_models"  ### 对应tf serving中的MODEL_NAME
    predict_request.model_spec.signature_name = "serving_default"   # 这个是预测签名, serving_default
    predict_request.inputs["input_ids"].CopyFrom(tf.make_tensor_proto(input_ids, tf.int32))
    predict_request.inputs["input_mask"].CopyFrom(tf.make_tensor_proto(input_mask, tf.int32))
    predict_request.inputs["segment_ids"].CopyFrom(tf.make_tensor_proto(segment_ids, tf.int32))
    predict_request.inputs["is_training"].CopyFrom(tf.make_tensor_proto(is_training, tf.bool))

    # log = prediction_log_pb2.PredictLog(request=predict_request)
    log = prediction_log_pb2.PredictionLog(predict_log=prediction_log_pb2.PredictLog(request=predict_request))
    for i in range(100):
        writer.write(log.SerializeToString())



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值