我们遇到的问题如下。Serving 配置为加载和服务 7 个模型,并且随着模型数量的增加,Serving 请求超时更频繁。相反,随着模型数量的减少,请求超时是微不足道的。在客户端,超时被配置为 5 秒。
有趣的是,最大批处理持续时间约为 700 毫秒,配置的最大批处理大小为 10。平均批处理持续时间约为 60 毫秒。
我们检查了 TensorFlow Serving 日志,但未发现任何警告或错误。此外,我们还监控了正在运行的 GPU 机器和主机执行对 Serving 的推理请求的网络,但也没有发现任何网络问题。
减少加载和服务的模型数量,但这不是预期的解决方案,因为这需要设置多个不同的 GPU 实例,每次加载和仅服务模型的一个子集。
操作系统平台和发行版(例如 Linux Ubuntu 16.04):Ubuntu 16.04 TensorFlow Serving 安装自(源或二进制):源 TensorFlow Serving 版本:1.9 TensorFlow Serving 在多个 AWS g2.2xlarge 实例上运行。我们使用 Docker 运行 TensorFlow Serving,并带有一个基础镜像nvidia/cuda:9.0-cudnn7-devel-ubuntu16.04
这种行为的路线原因可能是什么?在内存中加载多个模型时,Serving 如何处理请求?它如何改变模型上下文?
我正在使用 keras 和 tensorflow 进行笔迹检测。我已经准备好模型并使用 hdf5 文件。当我尝试使用tensorflow 提供服务时,出现以下错误:
grpc.framework.interfaces.face.face.LocalError: LocalError(code=StatusCode.UNIMPLEMENTED, details="Generic conv implementation does not support grouped convolutions for now.
[[{{node conv2d_1/convolution}} = Conv2D[T=DT_FLOAT, _output_shapes=[[?,40,40,20]], data_format="NHWC", dilations=[1, 1, 1, 1], padding="SAME", strides=[1, 1, 1, 1], use_cudnn_on_gpu=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_conv2d_1_input_0_0, conv2d_1/kernel/read)]]")
Run Code Online (Sandbox Code Playgroud)
我以前所提到的两个文件这个文章来从我的HDF5文件中的模型(这是工作)。请提供任何可以帮助我解决此问题的输入?
我部署了一个为多个模型提供服务的张量流服务器。客户端代码是这样的client.py,我调用预测函数。
channel = implementations.insecure_channel(host, port)
stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
request = predict_pb2.PredictRequest()
def predict(data, shape, model_name, signature_name="predict"):
request.model_spec.name = model_name
request.model_spec.signature_name = signature_name
request.inputs['image'].CopyFrom(tf.contrib.util.make_tensor_proto(data, shape=shape))
result = stub.Predict(request, 10.0)
return result.outputs['prediction'].float_val[0]
Run Code Online (Sandbox Code Playgroud)
我有大约 100 个具有相同配置的客户端。这是调用该predict函数的示例代码:
from client import predict
while True:
print(predict(data, shape, model_name))
# time.sleep some while
Run Code Online (Sandbox Code Playgroud)
首先,当我运行客户端代码时,我可以正确收到响应。但几个小时后,客户端因错误而崩溃
_Rendezvous of RPC that terminated with (StatusCode.UNAVAILABLE, Socket closed)
Run Code Online (Sandbox Code Playgroud)
我尝试将我的客户端代码修改为
def predict(data, shape, model_name, signature_name="predict"):
channel = implementations.insecure_channel(host, port)
stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
request …Run Code Online (Sandbox Code Playgroud) 我有一个带有非常简单演示的colab,Estimator目的是学习/理解EstimatorAPI,目的是为即插即用模型制定一个约定,其中包含有用的交易技巧(例如,如果验证通过,则提前停止)设置停止改进,导出模型等)。
这三个的Estimator模式(TRAIN,EVAL,和PREDICT)返回EstimatorSpec。
根据文档:
__new__(
cls,
mode,
predictions=None, # required by PREDICT
loss=None, # required by TRAIN and EVAL
train_op=None, # required by TRAIN
eval_metric_ops=None,
export_outputs=None,
training_chief_hooks=None,
training_hooks=None,
scaffold=None,
evaluation_hooks=None,
prediction_hooks=None.
)
Run Code Online (Sandbox Code Playgroud)
在这些命名参数中,我想提请注意predictions和export_outputs,它们在文档中被描述为:
predictions:预测张量或张量的字典。export_outputs:描述要导出到SavedModel并在服务期间使用的输出签名。一个字典{name: output},其中:
name:此输出的任意名称。output: 一个ExportOutput对象,例如ClassificationOutput,RegressionOutput, 或PredictOutput。单头模型只需要在这个字典中指定一个条目。多头模型应该为每个头指定一个条目,其中之一必须使用 …
我有一个模型的版本 1 和 2,我正在尝试按照https://www.tensorflow.org/serving/serving_config#assigning_string_labels_to_model_versions_to_simplify_canary_and_rollback 上的说明为它们分配标签
我分别在/path/to/model/1和 中导出了两个版本,并/path/to/model/2使用以下命令启动服务器:
tensorflow_model_server --rest_api_port=8501 --model_config_file=models.config
以下models.config文件有效,并导致仅提供版本1(如果specific省略消息,则版本2按预期提供,因为它对应于最高数字):
model_config_list {
config {
name: 'm1'
base_path: '/path/to/model/'
model_platform: 'tensorflow'
model_version_policy {
specific {
versions: 1
}
}
}
Run Code Online (Sandbox Code Playgroud)
我已经验证我可以使用服务器向模型发送请求并按预期执行推理。但是,如果我尝试version_labels使用此配置文件添加:
model_config_list {
config {
name: 'm1'
base_path: '/path/to/model/'
model_platform: 'tensorflow'
model_version_policy {
specific {
versions: 1
}
version_labels {
key: 'current'
value: 1
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后启动服务器失败并出现以下错误:
Failed to start server. Error: Failed …
我有 tf.example 形式的数据,并试图以预测形式(使用 gRPC)向保存的模型发出请求。我无法确定实现此目的的方法调用。
我从众所周知的汽车定价 DNN 回归模型(https://github.com/tensorflow/models/blob/master/samples/cookbook/regression/dnn_regression.py)开始,我已经通过 TF Serving 导出并安装了该模型码头集装箱
import grpc
import numpy as np
import tensorflow as tf
from tensorflow_serving.apis import predict_pb2, prediction_service_pb2_grpc
stub = prediction_service_pb2_grpc.PredictionServiceStub(grpc.insecure_channel("localhost:8500"))
tf_ex = tf.train.Example(
features=tf.train.Features(
feature={
'curb-weight': tf.train.Feature(float_list=tf.train.FloatList(value=[5.1])),
'highway-mpg': tf.train.Feature(float_list=tf.train.FloatList(value=[3.3])),
'body-style': tf.train.Feature(bytes_list=tf.train.BytesList(value=[b"wagon"])),
'make': tf.train.Feature(bytes_list=tf.train.BytesList(value=[b"Honda"])),
}
)
)
request = predict_pb2.PredictRequest()
request.model_spec.name = "regressor_test"
# Tried this:
request.inputs['inputs'].CopyFrom(tf_ex)
# Also tried this:
request.inputs['inputs'].CopyFrom(tf.contrib.util.make_tensor_proto(tf_ex))
# This doesn't work either:
request.input.example_list.examples.extend(tf_ex)
# If it did work, I would like to inference on it like …Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用tensorflow服务来服务模型并利用tensorflow-serving-api,如下所述:https: //github.com/tensorflow/serving/tree/master/tensorflow_serving/apis 我正在使用python并尽力尝试,我找不到该包的文档。pypi页面重定向至此处(tensorflow 服务),其中不包含 python 客户端包装器的文档。这个地方也不https://www.tensorflow.org/serving/api_docs/cc/
有人能指出我正确的方向吗?
我尽最大努力发现,如果不使用 docker,就无法安装 TensorFlow 服务。是否使用与 TensorFlow Serving 牢固嵌入的 docker,或者是否有解决方法?
我正在开发一个 Tensorflow 序列模型,该模型通过 OpenFST 解码图(从二进制文件加载)对 Tensorflow 序列模型的 logits 输出使用波束搜索。
我编写了一个自定义操作,允许我对 logits 执行解码,但每次,在执行解码之前,我都会调用 fst::Read(BINARY_FILE) 操作。只要它保持很小,这可能没问题,但我想避免 I/O 开销。
我已经阅读了 Tensorflow custom op 并试图找到类似的例子,但我仍然迷路了。基本上,我想在图中做的是:
FstDecodingOp.Initialize('BINARY_FILE.bin') #loads the BINARY_FILE.bin into memory
...
for o in output:
FstDecodingOp.decode(o) # uses BINARY_FILE.bin to decode
Run Code Online (Sandbox Code Playgroud)
这当然在 tensorflow 图之外的 Python 中很简单,但我最终需要将其移动到 vanilla TF-Serving 环境中,因此需要将其冻结到导出图中。有没有人遇到过类似的问题?
解决方案:
没有意识到您可以使用“OpKernel(context)”设置私有属性。刚刚使用该函数对其进行了初始化。
编辑:关于我是如何做到的更多细节。还没有尝试服务。
REGISTER_OP("FstDecoder")
.Input("log_likelihoods: float")
.Attr("fst_decoder_path: string")
....
...
template <typename Device, typename T>
class FstDecoderOp : public OpKernel {
private:
fst::Fst<fst::StdArc>* fst_;
float beam_;
public:
explicit FstDecoderOp(OpKernelConstruction* context) : OpKernel(context) {
OP_REQUIRES_OK(context, …Run Code Online (Sandbox Code Playgroud) 我无法在文档中找到有关如何在 TensorFlow Serving 中保存和加载模型以及在 CPU 与 GPU 上运行时可能存在的差异的特定信息。
为了提供多个模型(以及每个模型的一个或多个版本),一个通用的工作流程是:
我目前正在 CPU 上运行推理并同时加载许多模型,这比预期的更快地消耗 RAM。保存的模型在磁盘上相对较小,但是当 TF Serving 将模型加载到内存中时,它几乎大了一个数量级。磁盘上单个200MB 的saved_model 变成RAM 中的1.5GB,极大地限制了可以加载的模型数量。