nateraw commited on
Commit
eff37e3
·
1 Parent(s): c7a96cd

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +99 -179
Dockerfile CHANGED
@@ -1,179 +1,99 @@
1
- # Rust builder
2
- FROM lukemathwalker/cargo-chef:latest-rust-1.69 AS chef
3
- WORKDIR /usr/src
4
-
5
- FROM chef as planner
6
- COPY Cargo.toml Cargo.toml
7
- COPY rust-toolchain.toml rust-toolchain.toml
8
- COPY proto proto
9
- COPY router router
10
- COPY launcher launcher
11
- RUN cargo chef prepare --recipe-path recipe.json
12
-
13
- FROM chef AS builder
14
-
15
- ARG GIT_SHA
16
- ARG DOCKER_LABEL
17
-
18
- RUN PROTOC_ZIP=protoc-21.12-linux-x86_64.zip && \
19
- curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v21.12/$PROTOC_ZIP && \
20
- unzip -o $PROTOC_ZIP -d /usr/local bin/protoc && \
21
- unzip -o $PROTOC_ZIP -d /usr/local 'include/*' && \
22
- rm -f $PROTOC_ZIP
23
-
24
- COPY --from=planner /usr/src/recipe.json recipe.json
25
- RUN cargo chef cook --release --recipe-path recipe.json
26
-
27
- COPY Cargo.toml Cargo.toml
28
- COPY rust-toolchain.toml rust-toolchain.toml
29
- COPY proto proto
30
- COPY router router
31
- COPY launcher launcher
32
- RUN cargo build --release
33
-
34
- # Python builder
35
- # Adapted from: https://github.com/pytorch/pytorch/blob/master/Dockerfile
36
- FROM debian:bullseye-slim as pytorch-install
37
-
38
- ARG PYTORCH_VERSION=2.0.0
39
- ARG PYTHON_VERSION=3.9
40
- ARG CUDA_VERSION=11.8
41
- ARG MAMBA_VERSION=23.1.0-1
42
- ARG CUDA_CHANNEL=nvidia
43
- ARG INSTALL_CHANNEL=pytorch
44
- # Automatically set by buildx
45
- ARG TARGETPLATFORM
46
-
47
- ENV PATH /opt/conda/bin:$PATH
48
-
49
- RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
50
- build-essential \
51
- ca-certificates \
52
- ccache \
53
- curl \
54
- git && \
55
- rm -rf /var/lib/apt/lists/*
56
-
57
- # Install conda
58
- # translating Docker's TARGETPLATFORM into mamba arches
59
- RUN case ${TARGETPLATFORM} in \
60
- "linux/arm64") MAMBA_ARCH=aarch64 ;; \
61
- *) MAMBA_ARCH=x86_64 ;; \
62
- esac && \
63
- curl -fsSL -v -o ~/mambaforge.sh -O "https://github.com/conda-forge/miniforge/releases/download/${MAMBA_VERSION}/Mambaforge-${MAMBA_VERSION}-Linux-${MAMBA_ARCH}.sh"
64
- RUN chmod +x ~/mambaforge.sh && \
65
- bash ~/mambaforge.sh -b -p /opt/conda && \
66
- rm ~/mambaforge.sh
67
-
68
- # Install pytorch
69
- # On arm64 we exit with an error code
70
- RUN case ${TARGETPLATFORM} in \
71
- "linux/arm64") exit 1 ;; \
72
- *) /opt/conda/bin/conda update -y conda && \
73
- /opt/conda/bin/conda install -c "${INSTALL_CHANNEL}" -c "${CUDA_CHANNEL}" -y "python=${PYTHON_VERSION}" pytorch==$PYTORCH_VERSION "pytorch-cuda=$(echo $CUDA_VERSION | cut -d'.' -f 1-2)" ;; \
74
- esac && \
75
- /opt/conda/bin/conda clean -ya
76
-
77
- # CUDA kernels builder image
78
- FROM pytorch-install as kernel-builder
79
-
80
- RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
81
- ninja-build \
82
- && rm -rf /var/lib/apt/lists/*
83
-
84
- RUN /opt/conda/bin/conda install -c "nvidia/label/cuda-11.8.0" cuda==11.8 && \
85
- /opt/conda/bin/conda clean -ya
86
-
87
-
88
- # Build Flash Attention CUDA kernels
89
- FROM kernel-builder as flash-att-builder
90
-
91
- WORKDIR /usr/src
92
-
93
- COPY server/Makefile-flash-att Makefile
94
-
95
- # Build specific version of flash attention
96
- RUN make build-flash-attention
97
-
98
- # Build Transformers CUDA kernels
99
- FROM kernel-builder as transformers-builder
100
-
101
- WORKDIR /usr/src
102
-
103
- COPY server/Makefile-transformers Makefile
104
-
105
- # Build specific version of transformers
106
- RUN BUILD_EXTENSIONS="True" make build-transformers
107
-
108
- # Text Generation Inference base image
109
- FROM debian:bullseye-slim as base
110
-
111
- # Conda env
112
- ENV PATH=/opt/conda/bin:$PATH \
113
- CONDA_PREFIX=/opt/conda
114
-
115
- # Text Generation Inference base env
116
- ENV HUGGINGFACE_HUB_CACHE=/data \
117
- HF_HUB_ENABLE_HF_TRANSFER=1 \
118
- MODEL_ID=bigscience/bloom-560m \
119
- QUANTIZE=false \
120
- NUM_SHARD=1 \
121
- PORT=80
122
-
123
- LABEL com.nvidia.volumes.needed="nvidia_driver"
124
-
125
- WORKDIR /usr/src
126
-
127
- RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
128
- libssl-dev \
129
- ca-certificates \
130
- make \
131
- && rm -rf /var/lib/apt/lists/*
132
-
133
- # Copy conda with PyTorch installed
134
- COPY --from=pytorch-install /opt/conda /opt/conda
135
-
136
- # Copy build artifacts from flash attention builder
137
- COPY --from=flash-att-builder /usr/src/flash-attention/build/lib.linux-x86_64-cpython-39 /opt/conda/lib/python3.9/site-packages
138
- COPY --from=flash-att-builder /usr/src/flash-attention/csrc/layer_norm/build/lib.linux-x86_64-cpython-39 /opt/conda/lib/python3.9/site-packages
139
- COPY --from=flash-att-builder /usr/src/flash-attention/csrc/rotary/build/lib.linux-x86_64-cpython-39 /opt/conda/lib/python3.9/site-packages
140
-
141
- # Copy build artifacts from transformers builder
142
- COPY --from=transformers-builder /usr/src/transformers /usr/src/transformers
143
- COPY --from=transformers-builder /usr/src/transformers/build/lib.linux-x86_64-cpython-39/transformers /usr/src/transformers/src/transformers
144
-
145
- # Install transformers dependencies
146
- RUN cd /usr/src/transformers && pip install -e . --no-cache-dir && pip install einops --no-cache-dir
147
-
148
- # Install server
149
- COPY proto proto
150
- COPY server server
151
- COPY server/Makefile server/Makefile
152
- RUN cd server && \
153
- make gen-server && \
154
- pip install -r requirements.txt && \
155
- pip install ".[bnb, accelerate]" --no-cache-dir
156
-
157
- # Install router
158
- COPY --from=builder /usr/src/target/release/text-generation-router /usr/local/bin/text-generation-router
159
- # Install launcher
160
- COPY --from=builder /usr/src/target/release/text-generation-launcher /usr/local/bin/text-generation-launcher
161
-
162
- # AWS Sagemaker compatbile image
163
- FROM base as sagemaker
164
-
165
- COPY sagemaker-entrypoint.sh entrypoint.sh
166
- RUN chmod +x entrypoint.sh
167
-
168
- # NVIDIA env vars
169
- ENV NVIDIA_VISIBLE_DEVICES all
170
- ENV NVIDIA_DRIVER_CAPABILITIES compute,utility
171
- ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64
172
-
173
- ENTRYPOINT ["./entrypoint.sh"]
174
-
175
- # Final image
176
- FROM base
177
-
178
- ENTRYPOINT ["text-generation-launcher"]
179
- CMD ["--json-output"]
 
1
+ FROM nvidia/cuda:11.3.1-base-ubuntu20.04
2
+
3
+ ENV DEBIAN_FRONTEND=noninteractive \
4
+ TZ=Europe/Paris
5
+
6
+ # Remove any third-party apt sources to avoid issues with expiring keys.
7
+ # Install some basic utilities
8
+ RUN rm -f /etc/apt/sources.list.d/*.list && \
9
+ apt-get update && apt-get install -y --no-install-recommends \
10
+ curl \
11
+ ca-certificates \
12
+ sudo \
13
+ git \
14
+ git-lfs \
15
+ zip \
16
+ unzip \
17
+ htop \
18
+ bzip2 \
19
+ libx11-6 \
20
+ build-essential \
21
+ libsndfile-dev \
22
+ software-properties-common \
23
+ && rm -rf /var/lib/apt/lists/*
24
+
25
+ RUN add-apt-repository ppa:flexiondotorg/nvtop && \
26
+ apt-get upgrade -y && \
27
+ apt-get install -y --no-install-recommends nvtop
28
+
29
+ RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
30
+ apt-get install -y nodejs && \
31
+ npm install -g configurable-http-proxy
32
+
33
+ # Create a working directory
34
+ WORKDIR /app
35
+
36
+ # Create a non-root user and switch to it
37
+ RUN adduser --disabled-password --gecos '' --shell /bin/bash user \
38
+ && chown -R user:user /app
39
+ RUN echo "user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-user
40
+ USER user
41
+
42
+ # All users can use /home/user as their home directory
43
+ ENV HOME=/home/user
44
+ RUN mkdir $HOME/.cache $HOME/.config \
45
+ && chmod -R 777 $HOME
46
+
47
+ # Set up the Conda environment
48
+ ENV CONDA_AUTO_UPDATE_CONDA=false \
49
+ PATH=$HOME/miniconda/bin:$PATH
50
+ RUN curl -sLo ~/miniconda.sh https://repo.continuum.io/miniconda/Miniconda3-py39_4.10.3-Linux-x86_64.sh \
51
+ && chmod +x ~/miniconda.sh \
52
+ && ~/miniconda.sh -b -p ~/miniconda \
53
+ && rm ~/miniconda.sh \
54
+ && conda clean -ya
55
+
56
+ WORKDIR $HOME/app
57
+
58
+ #######################################
59
+ # Start root user section
60
+ #######################################
61
+
62
+ USER root
63
+
64
+ # User Debian packages
65
+ ## Security warning : Potential user code executed as root (build time)
66
+ RUN --mount=target=/root/packages.txt,source=packages.txt \
67
+ apt-get update && \
68
+ xargs -r -a /root/packages.txt apt-get install -y --no-install-recommends \
69
+ && rm -rf /var/lib/apt/lists/*
70
+
71
+ RUN --mount=target=/root/on_startup.sh,source=on_startup.sh,readwrite \
72
+ bash /root/on_startup.sh
73
+
74
+ #######################################
75
+ # End root user section
76
+ #######################################
77
+
78
+ USER user
79
+
80
+ # Python packages
81
+ RUN --mount=target=requirements.txt,source=requirements.txt \
82
+ pip install --no-cache-dir --upgrade -r requirements.txt
83
+
84
+ # Copy the current directory contents into the container at $HOME/app setting the owner to the user
85
+ COPY --chown=user . $HOME/app
86
+
87
+ RUN chmod +x start_server.sh
88
+
89
+ COPY --chown=user login.html /home/user/miniconda/lib/python3.9/site-packages/jupyter_server/templates/login.html
90
+
91
+ ENV PYTHONUNBUFFERED=1 \
92
+ GRADIO_ALLOW_FLAGGING=never \
93
+ GRADIO_NUM_PORTS=1 \
94
+ GRADIO_SERVER_NAME=0.0.0.0 \
95
+ GRADIO_THEME=huggingface \
96
+ SYSTEM=spaces \
97
+ SHELL=/bin/bash
98
+
99
+ CMD ["./start_server.sh"]