NVIDIA GPU
We offer an accelerated inference solution that you can deploy to your GPU devices.
The following task types are supported by the hosted API:
To deploy theGPU inference server, you must first install NVIDIA drivers and nvidia-container-runtime, allowing docker to passthrough your GPU to the inference server. You can test to see if your system already has
nvidia-container-runtime
and if your installation was successful with the following command:docker run --gpus all -it ubuntu nvidia-smi
If your installation was successful, you will see your GPU device from within the container:
Tue Nov 9 16:04:47 2021
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.91.03 Driver Version: 460.91.03 CUDA Version: N/A |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 Tesla K80 Off | 00000000:00:1E.0 Off | 0 |
| N/A 41C P0 56W / 149W | 504MiB / 11441MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
+-----------------------------------------------------------------------------+
The last thing you need before building your GPU TRT container is your project information. This includes your Roboflow API Key, Model ID and Model Version. If you don't have this information you can follow this link to Locate Your Project Information. Once located, save those three variables for later.
The GPU TRT deployment compiles your model on device, optimizing for the hardware that you have available. There are currently three deployment options for the GPU TRT container. Deploying to an EC2 instance via AWS, deploying to WSL2 via Windows, and deploying to Anaconda via Windows.
To run the TRT GPU container on an EC2 instance, you first need to select the proper AMI. The AMI can be configured when you are launching your instance and should be selected before you launch the instance. We are going to be using the NVIDIA GPU-Optimized AMI which comes with Ubuntu 20.04, Docker and other requirements pre-installed.

Configure EC2 Instance with NVIDIA GPU-Optimized AMI
With your EC2 instance successfully running, we can log into it using SSH and our Amazon Keypair. Amazon provides the documentation for connecting to their instances here. If you have your Keypair ready and know your EC2 instance's Public DNS, we can use the command below to log into the instance. The default
instance-user-name
for this instance should be ubuntu.ssh -i /path/key-pair-name.pem instance-user-name@instance-public-dns-name
Once you are logged into the EC2 instance via SSH. We can start the Docker container with the following command:
sudo docker run --gpus all -p 9001:9001 --network="host" roboflow/roboflow-inference-server-trt
Run inference on your model by posting a base64 encoded image to the server - if this is the first time you have compiled your model without cache, it will compile before inferring:
base64 your_img.jpg | curl -d @- "http://0.0.0.0:9001/[YOUR MODEL]/[YOUR VERSION]?api_key=[YOUR API KEY]"
conda create -n TRT python=3.8
conda activate TRT
pip install pybase64
You can download and run docker via Docker Desktop or you can install Docker via
conda-forge
. The code below will install Docker using Anaconda's recipe manager.conda install -c conda-forge docker
If you have installed Docker Desktop, make sure to have it running in order to access the container. Those of you that did not download Docker Desktop should be able to access the daemon version of Docker via our previous
conda-forge
install process. Once your Anaconda environment can successfully access Docker. We can start the Docker container with the following command:
docker run --gpus all -p 9001:9001 roboflow/roboflow-inference-server-trt
Open up another Anaconda terminal and navigate to a directory that contains data you want to run inference on. Run inference on your model by posting a base64 encoded image to the server - if this is the first time you have compiled your model without cache, it will compile before inferring:
pybase64 encode your_img.jpg | curl -d @- "http://localhost:9001/[YOUR MODEL]/[YOUR VERSION]?api_key=[YOUR API KEY]"
We have developed a repository for quickly accessing examples on how to use the Roboflow TRT Docker container. To get started, run the git clone command below to download our docker compose template.
git clone https://github.com/roboflow/trt-demos.git
For this example, we have configured the docker to run 8 GPUs with a load balancer. If you need to run less than 8 GPUs. We will cover that here.
To build the load balancer docker container use the command below. If you want more information on the load balancer we are using you can find that information here.
docker build . -t lb
Make sure that the names of the services in the docker-compose.yaml file are correctly reflected in the .conf/roboflow-nginx.conf file then run docker compose.
docker-compose up
Your Docker should now be spinning up multiple GPU containers that all share a volume and a port with the load balancer. This way the load balancer can manage the throughput of each container for optimal speed. If you are running in Docker Desktop, a successful boot up should look something like this.

Now that you have your GPU containers and the load balancer running. You are able to interact with the load balancer which will route all of your request to the respective GPU in order to maintain optimal throughput.
You can test the load balancer by opening up a new terminal and using one of the curl commands below.
# Amazon EC2 Deployments
base64 your_img.jpg | curl -d @- "http://0.0.0.0:9001/[YOUR MODEL]/[YOUR VERSION]?api_key=[YOUR API KEY]"
# Anaconda Deployments
pip install pybase64
pybase64 encode your_img.jpg | curl -d @- "http://localhost:9001/[YOUR MODEL]/[YOUR VERSION]?api_key=[YOUR API KEY]"
# Windows Subsystem Linux
base64 your_img.jpg | curl -d @- "http://0.0.0.0:9001/[YOUR MODEL]/[YOUR VERSION]?api_key=[YOUR API KEY]"
To run less than the default 8 GPUs you will need to make some changes to a couple of the files in this repo. The first we will look at is the docker-compose.yaml which has a bunch of services such as Roboflow-GPU-1, Roboflow-GPU-2, etc. These services are what run the docker containers and attach to each GPU.
If we want to run only 3 GPUs, then we can delete all of the other services except for Roboflow-GPU-1, Roboflow-GPU-2 and Roboflow-GPU-3. To delete a service remove the line containing the service name and all the lines below it until the next service name. For the 3 GPU example, we can delete lines 39-99.
docker-compose.yaml
1
version: "3"
2
services:
3
Roboflow-GPU-1:
4
image: roboflow/roboflow-inference-server-trt
5
restart: always
6
volumes:
7
- shared-volume:/cache
8
deploy:
9
resources:
10
reservations:
11
devices:
12
- driver: nvidia
13
device_ids: ['0']
14
capabilities: [gpu]
15
Roboflow-GPU-2:
16
image: roboflow/roboflow-inference-server-trt
17
restart: always
18
volumes:
19
- shared-volume:/cache
20
deploy:
21
resources:
22
reservations:
23
devices:
24
- driver: nvidia
25
device_ids: ['1']
26
capabilities: [gpu]
27
Roboflow-GPU-3:
28
image: roboflow/roboflow-inference-server-trt
29
restart: always
30
volumes:
31
- shared-volume:/cache
32
deploy:
33
resources:
34
reservations:
35
devices:
36
- driver: nvidia
37
device_ids: ['2']
38
capabilities: [gpu]
39
Roboflow-GPU-4:
40
image: roboflow/roboflow-inference-server-trt
41
restart: always
42
volumes:
43
- shared-volume:/cache
44
deploy:
45
resources:
46
reservations:
47
devices:
48
- driver: nvidia
49
device_ids: ['3']
50
capabilities: [gpu]
51
Roboflow-GPU-5:
52
image: roboflow/roboflow-inference-server-trt
53
restart: always
54
volumes:
55
- shared-volume:/cache
56
deploy:
57
resources:
58
reservations:
59
devices:
60
- driver: nvidia
61
device_ids: ['4']
62
capabilities: [gpu]
63
Roboflow-GPU-6:
64
image: roboflow/roboflow-inference-server-trt
65
restart: always
66
volumes:
67
- shared-volume:/cache
68
deploy:
69
resources:
70
reservations:
71
devices:
72
- driver: nvidia
73
device_ids: ['5']
74
capabilities: [gpu]
75
Roboflow-GPU-7:
76
image: roboflow/roboflow-inference-server-trt
77
restart: always
78
volumes:
79
- shared-volume:/cache
80
deploy:
81
resources:
82
reservations:
83
devices:
84
- driver: nvidia
85
device_ids: ['6']
86
capabilities: [gpu]
87
Roboflow-GPU-8:
88
image: roboflow/roboflow-inference-server-trt
89
restart: always
90
volumes:
91
- shared-volume:/cache
92
deploy:
93
resources:
94
reservations:
95
devices:
96
- driver: nvidia
97
device_ids: ['7']
98
capabilities: [gpu]
99
<Continued>
The next file we need to edit would be the roboflow-nginx.conf which is found inside of the conf folder.
Continuing our example of going from 8 to 3 GPUs. We will need to remove some of the server lines of code in the upstream myapp1. Specifically line 17 through line 21 aren't necessary anymore because that would exceed our target number.
roboflow-nginx.conf
1
user nginx;
2
worker_processes auto;
3
4
error_log /var/log/nginx/error.log notice;
5
pid /var/run/nginx.pid;
6
7
8
events {
9
worker_connections 1024;
10
}
11
12
http {
13
upstream myapp1 {
14
server Roboflow-GPU-1:9001;
15
server Roboflow-GPU-2:9001;
16
server Roboflow-GPU-3:9001;
17
server Roboflow-GPU-4:9001;
18
server Roboflow-GPU-5:9001;
19
server Roboflow-GPU-6:9001;
20
server Roboflow-GPU-7:9001;
21
server Roboflow-GPU-8:9001;
22
}
23
24
server {
25
listen 80;
26
27
location / {
28
proxy_pass http://myapp1;
29
}
30
}
31
}
After you have changed these two files, you should be able to continue with the docker-compose tutorial by building the load balancer.
In some cases, you may have multiple camera streams that you want to process in parallel on the same TRT Container on the same GPU. To spin up multiple model services on in your TRT container specify the
--env NUM_WORKERS=[desired num_workers]
On NVIDIA V100, we found that 2-4 workers provided optimal latency..png?alt=media&token=70d306b5-122f-4f7e-843d-373a1c542131)
Benchmark statistics for TRT multi-stream on Roboflow Accurate model on NVIDIA V100
In certain cases, you may want your TRT container to run on a specific GPU or vGPU. You can do so by specifying
CUDA_VISIBLE_DEVICES=[DESIRED GPU OR MIG ID]
Last modified 2mo ago