This document is relevant for: Inf1

torch-neuron Dockerfile#

 1# Example pytorch neuron container
 2# Note: a dockerd_entrypoint.sh script is required to succesfully build this image. Place the script on the same folder as the Dockerfile
 3# To build:
 4#    docker build . -f Dockerfile.pt -t neuron-container:pytorch
 5# To run on EC2 Inf1 instances with AWS DLAMI:
 6#    sudo service neuron-rtd stop
 7#    docker run -it --device=/dev/neuron0 --cap-add IPC_LOCK neuron-container:pytorch
 8
 9FROM ubuntu:18.04
10
11LABEL maintainer=" "
12
13RUN apt-get update -y \
14 && apt-get install -y --no-install-recommends \
15    gnupg2 \
16    wget \
17    python3-pip \
18    python3-setuptools \
19    libcap-dev \
20    && cd /usr/local/bin \
21    && pip3 --no-cache-dir install --upgrade pip \
22    && rm -rf /var/lib/apt/lists/* \
23    && apt-get clean
24
25RUN echo "deb https://apt.repos.neuron.amazonaws.com bionic main" > /etc/apt/sources.list.d/neuron.list
26RUN wget -qO - https://apt.repos.neuron.amazonaws.com/GPG-PUB-KEY-AMAZON-AWS-NEURON.PUB | apt-key add -
27
28# Installing Neuron Runtime and Tools
29RUN apt-get update -y && apt-get install -y \
30    aws-neuron-runtime \
31    aws-neuron-tools
32
33# Sets up Path for Neuron tools
34ENV PATH="/opt/bin/:/opt/aws/neuron/bin:${PATH}"
35
36# Include framework tensorflow-neuron or torch-neuron and compiler (compiler not needed for inference)
37RUN pip3 install \
38    torch-neuron \
39    --extra-index-url=https://pip.repos.neuron.amazonaws.com
40
41# Include your APP dependencies here.
42# RUN ...
43
44# Define the entrypoint script that starts the runtime and executes the docker run command
45COPY dockerd-entrypoint.sh /opt/bin/dockerd-entrypoint.sh
46RUN chmod +x /opt/bin/dockerd-entrypoint.sh
47ENTRYPOINT ["/opt/bin/dockerd-entrypoint.sh"]
48
49CMD ["neuron-top"]

This document is relevant for: Inf1