tensorflow model serving 显存按需增加方法

tensorflow_model_serving部署时默认会占满整个GPU的显存, 这会很费显存,让model serving按需使用显存的方案如下:

解决方案详见: https://github.com/tensorflow/serving/issues/836#issue-311505466

指定platform_config_file, 文件内容:

platform_configs {
  key: "tensorflow"
  value {
    source_adapter_config {
      [type.googleapis.com/tensorflow.serving.SavedModelBundleSourceAdapterConfig] {
        legacy_config {
          session_config {
            allow_soft_placement: true
            gpu_options {
              per_process_gpu_memory_fraction: 1.0
              allow_growth: true
            }
          }
        }
      }
    }
  }
}

重点是allow_growth=true

然后

tensorflow_model_serving --model_base_path=models --model_name=model1@1;model2@1 --platform_config_file=platform_config.config

附:

为何tensorflow (serving)会默认占满显存?
显存一般是由CUDA进行分配,而tensorflow为了加速计算,它自己实现了显存分配的逻辑,维护了一个自己的显存堆. 所以它一开始就吃满了整个显存,然后在框架内部进行显存分配.

https://www.reddit.com/r/MachineLearning/comments/ea083i/d_tensorflow_gpu_memory_management_tf_force_gpu/

原文地址:https://www.cnblogs.com/xyb930826/p/14633402.html