Skip to content

Commit 99d42db

Browse files
committed
Build neuron image
Signed-off-by: Raphael Glon <[email protected]>
1 parent 0879391 commit 99d42db

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

dockerfiles/pytorch/Dockerfile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
ARG BASE_IMAGE=nvidia/cuda:12.1.0-devel-ubuntu22.04
22

33
FROM $BASE_IMAGE
4+
5+
ARG NEURONX=0
6+
47
SHELL ["/bin/bash", "-c"]
58

69
LABEL maintainer="Hugging Face"
@@ -31,12 +34,12 @@ RUN apt-get update && \
3134
libsndfile1-dev \
3235
ffmpeg \
3336
&& apt-get clean autoremove --yes \
34-
&& rm -rf /var/lib/{apt,dpkg,cache,log}
37+
&& rm -rf /var/lib/{apt,cache,log}
38+
3539
# Copying only necessary files as filtered by .dockerignore
3640
COPY . .
3741

38-
# install wheel and setuptools
39-
RUN pip install --no-cache-dir -U pip ".[torch, st, diffusers]"
42+
RUN if [[ "$NEURONX" == "1" ]];then /bin/bash -c "./dockerfiles/pytorch/neuronx.sh";else pip install --no-cache-dir -U pip ".[torch, st, diffusers]";fi
4043

4144
# copy application
4245
COPY src/huggingface_inference_toolkit huggingface_inference_toolkit
@@ -45,4 +48,6 @@ COPY src/huggingface_inference_toolkit/webservice_starlette.py webservice_starle
4548
# copy entrypoint and change permissions
4649
COPY --chmod=0755 scripts/entrypoint.sh entrypoint.sh
4750

48-
ENTRYPOINT ["bash", "-c", "./entrypoint.sh"]
51+
ENTRYPOINT ["bash", "-c", "./entrypoint.sh"]
52+
53+
RUN apt-get update && apt-get install -y vim

dockerfiles/pytorch/neuronx.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Install system prerequisites
6+
apt-get update -y \
7+
&& apt-get install -y --no-install-recommends \
8+
gnupg2 \
9+
wget
10+
11+
echo "deb https://apt.repos.neuron.amazonaws.com jammy main" > /etc/apt/sources.list.d/neuron.list
12+
wget -qO - https://apt.repos.neuron.amazonaws.com/GPG-PUB-KEY-AMAZON-AWS-NEURON.PUB | apt-key add -
13+
14+
apt-get update -y \
15+
&& apt-get install -y --no-install-recommends \
16+
aws-neuronx-dkms=2.* \
17+
aws-neuronx-collectives=2.* \
18+
aws-neuronx-runtime-lib=2.* \
19+
aws-neuronx-tools=2.*
20+
21+
pip install -U pip
22+
23+
pip3 install neuronx-cc==2.12.68.0 \
24+
torch-neuronx==1.13.1.1.13.1 \
25+
transformers-neuronx==0.9.474 \
26+
--extra-index-url=https://pip.repos.neuron.amazonaws.com
27+
28+
pip3 install optimum[neuronx,diffusers]
29+
30+
pip install ".[st,torch1]"

makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,8 @@ inference-pytorch-gpu:
2626
inference-pytorch-cpu:
2727
docker build --build-arg="BASE_IMAGE=ubuntu:22.04" -f dockerfiles/pytorch/Dockerfile -t integration-test-pytorch:cpu .
2828

29+
inference-pytorch-neuron:
30+
docker build --build-arg=BASE_IMAGE=ubuntu:22.04 --build-arg=NEURONX=1 -f dockerfiles/pytorch/Dockerfile -t integration-test-pytorch:neuron .
31+
2932
stop-all:
30-
docker stop $$(docker ps -a -q) && docker container prune --force
33+
docker stop $$(docker ps -a -q) && docker container prune --force

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
extras["st"] = ["sentence_transformers==2.4.0"]
3939
extras["diffusers"] = ["diffusers==0.26.3", "accelerate==0.27.2"]
4040
extras["torch"] = ["torch==2.2.0", "torchvision", "torchaudio"]
41+
# For neuronx
42+
extras["torch1"] = ["torch==1.13.1", "torchvision", "torchaudio"]
4143
extras["tensorflow"] = ["tensorflow"]
4244
extras["test"] = [
4345
"pytest==7.2.1",

0 commit comments

Comments
 (0)