From 6b32c77804579d3eb671029fd26400a537466f9b Mon Sep 17 00:00:00 2001 From: Vinitra Swamy Date: Tue, 9 Jul 2019 02:03:55 -0700 Subject: [PATCH] Dockerfiles for TensorRT, CUDA, build from source (#922) * dockerfile updates for BYOC scenario * updates for 3 different build versions * updating to remove libopenblas, python3, python3-pip * Including LICENSE-IMAGE.txt for CUDA/TensorRT dockerfiles * remove unnecessary cmake files * fixing comment typo * optimizing dockerfile.source as per review suggestions (not working currently) * Optimizing dockerfiles with install_dependencies script * update dockerfile with --cmake_extra_defines version number * add &&\ for license copy lines * updates, adding miniconda to path, reincluded clearing the pycache * adding maintainer note * update readme instructions * update tensorrt versioning in dockerfile --- dockerfiles/Dockerfile.cuda | 28 ++++++++++ dockerfiles/Dockerfile.source | 27 +++++++++ dockerfiles/Dockerfile.tensorrt | 28 ++++++++++ dockerfiles/LICENSE-IMAGE.txt | 15 +++++ dockerfiles/README.md | 89 +++++++++++++++++++++++++----- dockerfiles/install_common_deps.sh | 25 +++++++++ 6 files changed, 198 insertions(+), 14 deletions(-) create mode 100644 dockerfiles/Dockerfile.cuda create mode 100644 dockerfiles/Dockerfile.source create mode 100644 dockerfiles/Dockerfile.tensorrt create mode 100644 dockerfiles/LICENSE-IMAGE.txt create mode 100644 dockerfiles/install_common_deps.sh diff --git a/dockerfiles/Dockerfile.cuda b/dockerfiles/Dockerfile.cuda new file mode 100644 index 0000000000..0a537b7748 --- /dev/null +++ b/dockerfiles/Dockerfile.cuda @@ -0,0 +1,28 @@ +# -------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +# -------------------------------------------------------------- +# Dockerfile to run ONNXRuntime with CUDA, CUDNN integration + +# nVidia cuda 10.0 Base Image +FROM nvidia/cuda:10.0-cudnn7-devel +MAINTAINER Vinitra Swamy "viswamy@microsoft.com" + +ARG ONNXRUNTIME_REPO=https://github.com/Microsoft/onnxruntime +ARG ONNXRUNTIME_SERVER_BRANCH=master + +RUN apt-get update &&\ + apt-get install -y sudo git bash + +WORKDIR /code +ENV PATH /usr/local/nvidia/bin:/usr/local/cuda/bin:/code/cmake-3.14.3-Linux-x86_64/bin:/opt/miniconda/bin:${PATH} + +# Prepare onnxruntime repository & build onnxruntime with TensorRT +RUN git clone --single-branch --branch ${ONNXRUNTIME_SERVER_BRANCH} --recursive ${ONNXRUNTIME_REPO} onnxruntime &&\ + /bin/sh onnxruntime/dockerfiles/install_common_deps.sh &&\ + cp onnxruntime/dockerfiles/LICENSE-IMAGE.txt /code/LICENSE-IMAGE.txt &&\ + cd onnxruntime &&\ + /bin/sh ./build.sh --cuda_home /usr/local/cuda --cudnn_home /usr/lib/x86_64-linux-gnu/ --use_cuda --config Release --build_wheel --update --build --cmake_extra_defines ONNXRUNTIME_VERSION=$(cat ./VERSION_NUMBER) &&\ + pip install /code/onnxruntime/build/Linux/Release/dist/*.whl &&\ + cd .. &&\ + rm -rf onnxruntime cmake-3.14.3-Linux-x86_64.tar.gz cmake-3.14.3-Linux-x86_64 diff --git a/dockerfiles/Dockerfile.source b/dockerfiles/Dockerfile.source new file mode 100644 index 0000000000..1a0f092113 --- /dev/null +++ b/dockerfiles/Dockerfile.source @@ -0,0 +1,27 @@ +# -------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +# -------------------------------------------------------------- +# Dockerfile to run ONNXRuntime with source build for CPU + +# Ubuntu 16.04 Base Image +FROM ubuntu:16.04 +MAINTAINER Vinitra Swamy "viswamy@microsoft.com" + +ARG ONNXRUNTIME_REPO=https://github.com/Microsoft/onnxruntime +ARG ONNXRUNTIME_SERVER_BRANCH=master + +RUN apt-get update &&\ + apt-get install -y sudo git bash + +WORKDIR /code +ENV PATH /opt/miniconda/bin:/code/cmake-3.14.3-Linux-x86_64/bin:${PATH} + +# Prepare onnxruntime repository & build onnxruntime +RUN git clone --single-branch --branch ${ONNXRUNTIME_SERVER_BRANCH} --recursive ${ONNXRUNTIME_REPO} onnxruntime &&\ + /bin/sh onnxruntime/dockerfiles/install_common_deps.sh &&\ + cd onnxruntime &&\ + /bin/sh ./build.sh --config Release --build_wheel --update --build --cmake_extra_defines ONNXRUNTIME_VERSION=$(cat ./VERSION_NUMBER) &&\ + pip install /code/onnxruntime/build/Linux/Release/dist/*.whl &&\ + cd .. &&\ + rm -rf onnxruntime cmake-3.14.3-Linux-x86_64.tar.gz cmake-3.14.3-Linux-x86_64 diff --git a/dockerfiles/Dockerfile.tensorrt b/dockerfiles/Dockerfile.tensorrt new file mode 100644 index 0000000000..6f3df1fbbb --- /dev/null +++ b/dockerfiles/Dockerfile.tensorrt @@ -0,0 +1,28 @@ +# -------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +# -------------------------------------------------------------- +# Dockerfile to run ONNXRuntime with TensorRT integration + +# nVidia TensorRT Base Image +FROM nvcr.io/nvidia/tensorrt:19.02-py3 +MAINTAINER Vinitra Swamy "viswamy@microsoft.com" + +ARG ONNXRUNTIME_REPO=https://github.com/Microsoft/onnxruntime +ARG ONNXRUNTIME_SERVER_BRANCH=master + +RUN apt-get update &&\ + apt-get install -y sudo git bash + +WORKDIR /code +ENV PATH /usr/local/nvidia/bin:/usr/local/cuda/bin:/code/cmake-3.14.3-Linux-x86_64/bin:/opt/miniconda/bin:${PATH} + +# Prepare onnxruntime repository & build onnxruntime with TensorRT +RUN git clone --single-branch --branch ${ONNXRUNTIME_SERVER_BRANCH} --recursive ${ONNXRUNTIME_REPO} onnxruntime &&\ + /bin/sh onnxruntime/dockerfiles/install_common_deps.sh &&\ + cp onnxruntime/dockerfiles/LICENSE-IMAGE.txt /code/LICENSE-IMAGE.txt &&\ + cd onnxruntime &&\ + /bin/sh ./build.sh --cuda_home /usr/local/cuda --cudnn_home /usr/lib/x86_64-linux-gnu/ --use_tensorrt --tensorrt_home /workspace/tensorrt --config Release --build_wheel --update --build --cmake_extra_defines ONNXRUNTIME_VERSION=$(cat ./VERSION_NUMBER) &&\ + pip install /code/onnxruntime/build/Linux/Release/dist/*.whl &&\ + cd .. &&\ + rm -rf onnxruntime cmake-3.14.3-Linux-x86_64.tar.gz cmake-3.14.3-Linux-x86_64 diff --git a/dockerfiles/LICENSE-IMAGE.txt b/dockerfiles/LICENSE-IMAGE.txt new file mode 100644 index 0000000000..b26cc03986 --- /dev/null +++ b/dockerfiles/LICENSE-IMAGE.txt @@ -0,0 +1,15 @@ +This image is made available to you on the condition that you agree to +[your agreement][1] governing your use of Azure. +If you do not have an existing agreement governing your use of Azure, you agree that +your agreement governing use of Azure is the [Microsoft Online Subscription Agreement][2] +(which incorporates the [Online Services Terms][3]). +By using the software you agree to these terms. This software may collect data +that is transmitted to Microsoft. Please see the [Microsoft Privacy Statement][4] +to learn more about how Microsoft processes personal data. + +This image must be used on Microsoft Azure Services only. + +[1]: https://azure.microsoft.com/en-us/support/legal/ +[2]: https://azure.microsoft.com/en-us/support/legal/subscription-agreement/ +[3]: http://www.microsoftvolumelicensing.com/DocumentSearch.aspx?Mode=3&DocumentTypeId=46 +[4]: http://go.microsoft.com/fwlink/?LinkId=248681 diff --git a/dockerfiles/README.md b/dockerfiles/README.md index 96aeb0f0c2..b7eff9e08a 100644 --- a/dockerfiles/README.md +++ b/dockerfiles/README.md @@ -1,4 +1,48 @@ -# Quick-start Docker containers for ONNX Runtime +# Docker containers for ONNX Runtime + +- [Arm 32v7](Dockerfile.arm32v7) +- [Build from source (CPU)](Dockerfile.source) +- [CUDA + CUDNN](Dockerfile.cuda) +- [nGraph](Dockerfile.ngraph) +- [TensorRT](Dockerfile.tensorrt) +- [OpenVINO](Dockerfile.openvino) +- [ONNX Runtime Server](Dockerfile.server) + +## Build from Source Version (Preview) +#### Linux 16.04, CPU, Python Bindings + +1. Build the docker image from the Dockerfile in this repository. + ``` + # If you have a Linux machine, preface this command with "sudo" + + docker build -t onnxruntime-source -f Dockerfile.source . + ``` + +2. Run the Docker image + + ``` + # If you have a Linux machine, preface this command with "sudo" + + docker run -it onnxruntime-source + ``` + +## CUDA Version (Preview) +#### Linux 16.04, CUDA 10.0, CuDNN 7 + +1. Build the docker image from the Dockerfile in this repository. + ``` + # If you have a Linux machine, preface this command with "sudo" + + docker build -t onnxruntime-cuda -f Dockerfile.cuda . + ``` + +2. Run the Docker image + + ``` + # If you have a Linux machine, preface this command with "sudo" + + docker run -it onnxruntime-cuda + ``` ## nGraph Version (Preview) #### Linux 16.04, Python Bindings @@ -18,24 +62,22 @@ docker run -it onnxruntime-ngraph ``` -## ONNX Runtime Server (Preview) -#### Linux 16.04 +## TensorRT Version (Preview) +#### Linux 16.04, TensorRT 5.0.2 -1. Build the docker image from the Dockerfile in this repository +1. Build the docker image from the Dockerfile in this repository. ``` - docker build -t {docker_image_name} -f Dockerfile.server . + # If you have a Linux machine, preface this command with "sudo" + + docker build -t onnxruntime-trt -f Dockerfile.tensorrt . ``` - -2. Run the ONNXRuntime server with the image created in step 1 + +2. Run the Docker image ``` - docker run -v {localModelAbsoluteFolder}:{dockerModelAbsoluteFolder} -e MODEL_ABSOLUTE_PATH={dockerModelAbsolutePath} -p {your_local_port}:8001 {imageName} - ``` -3. Send HTTP requests to the container running ONNX Runtime Server + # If you have a Linux machine, preface this command with "sudo" - Send HTTP requests to the docker container through the binding local port. Here is the full [usage document](https://github.com/Microsoft/onnxruntime/blob/master/docs/ONNX_Runtime_Server_Usage.md). - ``` - curl -X POST -d "@request.json" -H "Content-Type: application/json" http://0.0.0.0:{your_local_port}/v1/models/mymodel/versions/3:predict + docker run -it onnxruntime-trt ``` ## OpenVINO Version (Preview) @@ -58,4 +100,23 @@ # If you have a Linux machine, preface this command with "sudo" docker run -it onnxruntime-openvino - ``` \ No newline at end of file + ``` +## ONNX Runtime Server (Preview) +#### Linux 16.04 + +1. Build the docker image from the Dockerfile in this repository + ``` + docker build -t {docker_image_name} -f Dockerfile.server . + ``` + +2. Run the ONNXRuntime server with the image created in step 1 + + ``` + docker run -v {localModelAbsoluteFolder}:{dockerModelAbsoluteFolder} -e MODEL_ABSOLUTE_PATH={dockerModelAbsolutePath} -p {your_local_port}:8001 {imageName} + ``` +3. Send HTTP requests to the container running ONNX Runtime Server + + Send HTTP requests to the docker container through the binding local port. Here is the full [usage document](https://github.com/Microsoft/onnxruntime/blob/master/docs/ONNX_Runtime_Server_Usage.md). + ``` + curl -X POST -d "@request.json" -H "Content-Type: application/json" http://0.0.0.0:{your_local_port}/v1/models/mymodel/versions/3:predict + ``` diff --git a/dockerfiles/install_common_deps.sh b/dockerfiles/install_common_deps.sh new file mode 100644 index 0000000000..dab394cb33 --- /dev/null +++ b/dockerfiles/install_common_deps.sh @@ -0,0 +1,25 @@ +#!/bin/bash +DEBIAN_FRONTEND=noninteractive +apt-get install -y --no-install-recommends \ + wget \ + zip \ + ca-certificates \ + build-essential \ + curl \ + libcurl4-openssl-dev \ + libssl-dev \ + python3-dev + +# Dependencies: conda +wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-4.5.11-Linux-x86_64.sh -O ~/miniconda.sh --no-check-certificate && /bin/bash ~/miniconda.sh -b -p /opt/miniconda +rm ~/miniconda.sh +/opt/miniconda/bin/conda clean -tipsy +find / -type d -name __pycache__ -prune -exec rm -rf {}; + +conda install -y python=3.6 numpy +conda clean -aqy +rm -rf /opt/miniconda/pkgs + +# Dependencies: cmake +sudo wget --quiet https://github.com/Kitware/CMake/releases/download/v3.14.3/cmake-3.14.3-Linux-x86_64.tar.gz +tar zxf cmake-3.14.3-Linux-x86_64.tar.gz