Abstract
This User Guide focuses on documenting the Inference Server and its benefits. The Inference Server is included within the Inference Server container. This guide provides step-by-step instructions for pulling and running the Inference Server container, along with the details of the model store and the Inference API.
1. Overview Of The Inference Server
- Multiple model support
- The server can manage any number and mix of models (limited by system disk and memory resources). Supports TensorRT, TensorFlow GraphDef, TensorFlow SavedModel and Caffe2 NetDef model formats. Also supports TensorFlow-TensorRT integrated models.
- Multi-GPU support
- The server can distribute inferencing across all system GPUs.
- Multi-tenancy support
- Multiple models (or multiple instances of the same model) can run simultaneously on the same GPU.
- Batching support
The Inference Server itself is provided as a pre-built container. External to the server, API schemas, C++ and Python client libraries and examples, and related documentation are provided in source at: GitHub Inference Server.
Contents Of The Inference Server Container
This image contains the inference server in /opt/inference_server. The executable is /opt/inference_server/bin/inference_server.
2. Pulling The Inference Server Container
You can pull (download) an NVIDIA container that is already built, tested, tuned, and ready to run. Each NVIDIA deep learning container includes the code required to build the framework so that you can make changes to the internals. The containers do not contain sample data-sets or sample model definitions unless they are included with the source for the framework.
Currently, you can access NVIDIA GPU accelerated containers in one of two ways depending upon where you doing your training. If you own a DGX-1™ or a DGX Station™ , then you should use the NVIDIA® DGX™ container registry located at https://compute.nvidia.com. You can pull the containers from there and you can also push containers there into your own account on the nvidia-docker repository, nvcr.io.
Before you can pull a container you must have Docker and nvidia-docker installed as explained in Preparing to use NVIDIA Containers Getting Started Guide. You must also have access and logged into the NGC container registry as explained in NGC Getting Started Guide.
For step-by-step instructions, see Container User Guide.
3. Running The Inference Server Container
$ nvidia-docker run --rm --shm-size=1g --ulimit memlock=-1 --ulimit stack=67108864 -p8000:8000 -p8001:8001 -v/path/to/model/store:/tmp/models inferenceserver:18.xx-py<x> /opt/inference_server/bin/inference_server --model-store=/tmp/modelsWhere inferenceserver:18.xx-py<x> is the container that was pulled from the NVIDIA DGX or NGC container registry as described in Pulling The Inference Server Container.
The nvidia-docker -v option maps /path/to/model/store on the host into the container at /tmp/models, and the --model-store option to the Inference Server is used to point to /tmp/models as the model store.
- HTTP requests on port 8000
- gRPC requests on port 8001
The --shm-size and --ulimit flags are recommended to improve Inference Server performance. For --shm-size the minimum recommended size is 1g but larger sizes may be necessary depending on the number and size of models being served.
Starting server 'inference:0' listening on http://localhost:8000
4. Verifying The Inference Server
$ curl localhost:8000/api/status id: "inference:0" version: "1.1.0" uptime_ns: 23322988571 model_status { key: "resnet50_netdef" value { config { name: "resnet50_netdef" platform: "caffe2_netdef" } ... version_status { key: 1 value { ready_state: MODEL_READY } } } } ready_state: SERVER_READY
This status shows configuration information as well as indicating that version 1 of the resnet50_netdef model is MODEL_READY, indicating the Inference Server is ready to accept inferencing requests for version 1 of that model. A model version ready_state will show up as MODEL_UNAVAILABLE if the model failed to load for some reason or if it was unloaded due to the model version policy discussed here.
5. Model Store
<model-store path>/ model_0/ config.pbtxt output0_labels.txt 1/ model.plan 2/ model.plan model_1/ config.pbtxt output0_labels.txt output1_labels.txt 0/ model.graphdef 7/ model.graphdef model_2/ … model_n/
- Stop the Inference Server.
- Update the model store.
- Start the Inference Server.
The name of the model directory (for example, model_0, model_1) must match the name of the model specified in the required configuration file, config.pbtxt. This model name is used in the client and server APIs to identify the model. Each model directory must have at least one numeric subdirectory (for example, model_0/1). Each of these subdirectories holds a version of the model with the version number corresponding to the directory name. Version subdirectories can be added and removed from the model store while the Inference Server is running.
For more information about how the model versions are handled by the server, see Model Versions. Within each version subdirectory, there is one or more model definition files. For more information about the model definition files contained in each version subdirectory, see Model Definition Files.
The configuration file, config.pbtxt, for each model must be protobuf text adhering to the ModelConfig schema defined and explained below. The *_labels.txt files are optional and are used to provide labels for outputs that represent classifications.
5.1. Model Versions
- All
- All versions of the model that are specified in the model store are available for inferencing.
- Latest
- Only the latest n versions of the model specified in the model store are available for inferencing. The latest versions of the model are the numerically greatest version numbers.
- Specific
- The specifically listed versions of the model are available for inferencing.
If no version policy is specified, then Latest (with num_version = 1) is used as the default, indicating that only the most recent version of the model is made available by the Inference Server. In all cases, the addition or removal of version subdirectories from the model store can change which model version is used on subsequent inference requests.
5.2. Model Definition Files
- model.plan for TensorRT models
- model.graphdef for TensorFlow GraphDef models
- model.savedmodel for TensorFlow SavedModel models
- model.netdef / init_model.netdef for Caffe2 Netdef models
Optionally, a model can provide multiple model definition files, each targeted at a GPU with a different Compute Capability. Most commonly, this feature is needed for TensorRT and TensorFlow to TensorRT integrated models where the model definition is valid for only a single compute capability. See the trt_mnist configuration in Model Configuration Schema for an example.
An example model store is available at Deep Learning Inference Server Clients.
5.3. Model Configuration Schema
Each model in the model store must include a file called config.pbtxt that contains the configuration information for the model. The model configuration must be specified as protobuf text using the ModelConfig schema described at GitHub: Inference Server model_config.proto.
name: "trt_mnist" platform: "tensorrt_plan" max_batch_size: 8 input [ { name: "data" data_type: TYPE_FP32 format: FORMAT_NCHW dims: [ 1, 28, 28 ] } ] output [ { name: "prob" data_type: TYPE_FP32 dims: [ 10, 1, 1 ] label_filename: "mnist_labels.txt" } ] cc_model_filenames [ { key: "6.1" value: "model6_1.plan" }, { key: "7.0" value: "model7_0.plan" } ] instance_group [ { count: 2 gpus: [ 0 ] }]
name: "resnet50" platform: "tensorflow_graphdef" max_batch_size: 128 input [ { name: "input" data_type: TYPE_FP32 format: FORMAT_NHWC dims: [ 224, 224, 3 ] } ] output [ { name: "output" data_type: TYPE_FP32 dims: [ 1000 ] } ] instance_group [ { gpus: [ 0 ] }, { gpus: [ 1 ] } ]
5.3.1. TensorFlow GraphDef Models
The configuration platform value for TensorFlow GraphDef models must be tensorflow_graphdef and the model definition file must be named model.graphdef (unless the default_model_filename property is set in the model configuration).
TensorFlow 1.7 and later integrates TensorRT to enable TensorFlow models to benefit from the inference optimizations provided by TensorRT. Because the Inference Server supports GraphDef models that have been optimized with TensorRT, it can serve those models just like any other TensorFlow model. The Inference Server's TensorRT version (available in the Inference Server Container Release Notes must match the TensorRT version that was used when the GraphDef model was created.
name: "resnet50" platform: "tensorflow_graphdef" max_batch_size: 128 input [ { name: "input" data_type: TYPE_FP32 format: FORMAT_NHWC dims: [ 224, 224, 3 ] } ] output [ { name: "output" data_type: TYPE_FP32 dims: [ 1000 ] } ] instance_group [ { count: 1 gpus: [ 0, 1 ] } ]
5.3.2. TensorFlow SavedModel Models
The configuration platform value for TensorFlow SavedModel models must be tensorflow_savedmodel and the saved-model directory must be named model.savedmodel (unless the default_model_filename property is set in the model configuration).
TensorFlow 1.7 and later integrates TensorRT to enable TensorFlow models to benefit from the inference optimizations provided by TensorRT. Because the Inference Server supports SavedModel models that have been optimized with TensorRT, it can serve those models just like any other TensorFlow model. The Inference Server’s TensorRT version (available in the Inference Server Container Release Notes (https://docs.nvidia.com/deeplearning/sdk/inference-release-notes/index.html ) must match the TensorRT version that was used when the SavedModel model was created.
5.3.3. TensorRT PLAN Models
The configuration platform value for TensorRT PLAN models must be tensorrt_plan and the model definition file must be named model.plan (unless the default_model_filename property is set in the model configuration).
name: "trt_mnist" platform: "tensorrt_plan" max_batch_size: 8 input [ { name: "data" data_type: TYPE_FP32 format: FORMAT_NCHW dims: [ 1, 28, 28 ] } ] output [ { name: "prob" data_type: TYPE_FP32 dims: [ 10, 1, 1 ] label_filename: "mnist_labels.txt" } ] cc_model_filenames [ { key: "6.1" value: "model6_1.plan" }, { key: "7.0" value: "model7_0.plan" } ] instance_group [ { count: 2 gpus: [ 0 ] }]
model_store/ trt_mnist/ config.pbtxt mnist_labels.txt 1/ model6_1.plan model7_0.plan
5.3.4. Caffe2 NetDef Models
The configuration platform value for Caffe2 NetDef models must be caffe2_netdef. NetDef model definition is split across two files: the initialization network and the predict network. These files must be named init_model.netdef and model.netdef (unless the default_model_filename property is set in the model configuration).
5.3.5. ONNX Models
The Inference Server cannot directly perform inferencing using ONNX models. An ONNX model must be converted to either TensorRT PLAN or Caffe2 NetDef to be served by the Inference Server. To convert your ONNX model to a TensorRT PLAN use either the ONNX Parser included in TensorRT or the open-source TensorRT backend for ONNX. Another option is to convert your ONNX model to Caffe2 NetDef as described here.
6. Inference Server HTTP API
- /api/status
- The server status API for getting information about the server and about the models being served.
- /api/infer
- The inference API that accepts model inputs, runs inference and returns the requested outputs.
The HTTP endpoints can be used directly as described in this section, but for most use-cases, the preferred way to access the Inference Server is via the C++ and Python client API libraries. The libraries are available at GitHub: Inference Server.
6.1. Server Status API
Performing an HTTP GET to /api/status returns status information about the server and all the models being served. Performing an HTTP GET to /api/status/<model name> returns information about the server and the single model specified by <model name>. An example is shown in Verifying The Inference Server.
The server status is returned in the HTTP response body in either text format (the default) or in binary format if query parameter format=binary is specified (for example, /api/status?format=binary). The status schema is defined by the protobuf schema given in server_status.proto defined at GitHub: Inference Server server_status.proto.
NV-Status: code: SUCCESS
NV-Status: code: NOT_FOUND msg: "no status available for unknown model \'x\'"
6.2. Infer
Performing an HTTP POST to /api/infer/<model name> performs inference using the latest available version of <model name> model. The latest available version is the numerically greatest version number. Performing an HTTP POST to /api/infer/<model name>/<model version> performs inference using a specific version of the model.
NV-InferRequest: batch_size: 1 input { name: "input" byte_size: 602112 } output { name: "output" byte_size: 4000 cls { count: 3 } }
The input tensor values are communicated in the body of the HTTP POST request as raw binary in the order as the inputs are listed in the request header.
The inference results are returned in the body of the HTTP response to the POST request. For outputs where full result tensors were requested, the result values are communicated in the body of the response in the order as the outputs are listed in the request header. After those, an InferResponseHeader message is appended to the response body. The InferResponseHeader message is returned in either text format (the default) or in binary format if query parameter format=binary is specified (for example, /api/infer/foo?format=binary).
<raw binary tensor values for output0, if raw output was requested for output0> <raw binary tensor values for output1, if raw output was requested for output1> ... <raw binary tensor values for outputn, if raw output was requested for outputn> <text or binary encoded InferResponseHeader proto>
NV-Status: code: SUCCESS
NV-Status: code: NOT_FOUND msg: "no status available for unknown model \'x\'"
7. Inference Server gRPC API
- GRPCServer.Status: The server status API for getting information about the server and about the models being served.
- GRPCServer.Infer: The inference API that accepts model inputs, runs inference and returns the requested outputs.
The gRPC endpoints can be used via the gRPC generated client (demonstrated in the image classification example at (grpc_image_client.py or via the C++ and Python client API libraries. Build instructions for the gRPC client libraries are available at Deep Learning Inference Server clients.
Notices
Notice
THE INFORMATION IN THIS GUIDE AND ALL OTHER INFORMATION CONTAINED IN NVIDIA DOCUMENTATION REFERENCED IN THIS GUIDE IS PROVIDED “AS IS.” NVIDIA MAKES NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO THE INFORMATION FOR THE PRODUCT, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. Notwithstanding any damages that customer might incur for any reason whatsoever, NVIDIA’s aggregate and cumulative liability towards customer for the product described in this guide shall be limited in accordance with the NVIDIA terms and conditions of sale for the product.
THE NVIDIA PRODUCT DESCRIBED IN THIS GUIDE IS NOT FAULT TOLERANT AND IS NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE IN CONNECTION WITH THE DESIGN, CONSTRUCTION, MAINTENANCE, AND/OR OPERATION OF ANY SYSTEM WHERE THE USE OR A FAILURE OF SUCH SYSTEM COULD RESULT IN A SITUATION THAT THREATENS THE SAFETY OF HUMAN LIFE OR SEVERE PHYSICAL HARM OR PROPERTY DAMAGE (INCLUDING, FOR EXAMPLE, USE IN CONNECTION WITH ANY NUCLEAR, AVIONICS, LIFE SUPPORT OR OTHER LIFE CRITICAL APPLICATION). NVIDIA EXPRESSLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR SUCH HIGH RISK USES. NVIDIA SHALL NOT BE LIABLE TO CUSTOMER OR ANY THIRD PARTY, IN WHOLE OR IN PART, FOR ANY CLAIMS OR DAMAGES ARISING FROM SUCH HIGH RISK USES.
NVIDIA makes no representation or warranty that the product described in this guide will be suitable for any specified use without further testing or modification. Testing of all parameters of each product is not necessarily performed by NVIDIA. It is customer’s sole responsibility to ensure the product is suitable and fit for the application planned by customer and to do the necessary testing for the application in order to avoid a default of the application or the product. Weaknesses in customer’s product designs may affect the quality and reliability of the NVIDIA product and may result in additional or different conditions and/or requirements beyond those contained in this guide. NVIDIA does not accept any liability related to any default, damage, costs or problem which may be based on or attributable to: (i) the use of the NVIDIA product in any manner that is contrary to this guide, or (ii) customer product designs.
Other than the right for customer to use the information in this guide with the product, no other license, either expressed or implied, is hereby granted by NVIDIA under this guide. Reproduction of information in this guide is permissible only if reproduction is approved by NVIDIA in writing, is reproduced without alteration, and is accompanied by all associated conditions, limitations, and notices.
Trademarks
NVIDIA, the NVIDIA logo, and cuBLAS, CUDA, cuDNN, cuFFT, cuSPARSE, DALI, DIGITS, DGX, DGX-1, Jetson, Kepler, NVIDIA Maxwell, NCCL, NVLink, Pascal, Tegra, TensorRT, and Tesla are trademarks and/or registered trademarks of NVIDIA Corporation in the Unites States and other countries. Other company and product names may be trademarks of the respective companies with which they are associated.