如何在TensorFlow Servings batching_parameters.txt文件中将max_batch_size设置为无穷大

问题描述

TensorFlow Serving的批处理guide建议

如果您的系统是仅cpu(无GPU)的,则考虑从以下值开始:num_batch_threads等于cpu内核数; max_batch_size到无穷大;

但是,不清楚max_batch_size的无穷大是什么。

将值设置为零或-1似乎会导致错误,因此我正在考虑将其设置为10000,以使其远远大于我可能尝试的任何值。

不过,文档中存在一些“无限”值的建议使我难以入睡。我怎么在这里表示无穷大?

解决方法

查看code source,尤其是定义protobuf消息session_bundle_config.proto的文件BatchingParameters,似乎不可能提供无穷大的值。

message BatchingParameters {
  // SharedBatchScheduler options (see shared_batch_scheduler.h for more details
  // about what each field means):
  //

  // The maximum size of each input batch.
  //
  // IMPORTANT: As discussed above,use 'max_batch_size * 2' client threads to
  // achieve high throughput with batching.
  google.protobuf.Int64Value max_batch_size = 1;
}

BatchingParameters原始消息描述了传递batching_parameters.txt的可能选项。 model_servers/server.cc中的以下行对其进行了解析:

if (server_options.batching_parameters_file.empty()) {
  batching_parameters->mutable_thread_pool_name()->set_value(
     "model_server_batch_threads");
} else {
  TF_RETURN_IF_ERROR(ParseProtoTextFile<BatchingParameters>(
      server_options.batching_parameters_file,batching_parameters));
}

我猜想,无穷大值的替换将是int64的最大值,所以2^63 - 19 223 372 036 854 775 807