Debian Codegraph @

docker/accelerate-gpu-deepspeed/Dockerfile

raw
1 # Builds GPU docker image of PyTorch specifically
2 # Uses multi-staged approach to reduce size
3 # Stage 1
4 # Use base conda image to reduce time
5 FROM continuumio/miniconda3:latest AS compile-image
6 # Specify py version
7 ENV PYTHON_VERSION=3.10
8 # Install apt libs
9 RUN apt-get update && \
10 apt-get install -y curl git wget && \
11 apt-get clean && \
12 rm -rf /var/lib/apt/lists*
13
14 # Create our conda env
15 RUN conda create --name accelerate python=${PYTHON_VERSION} ipython jupyter pip
16 # We don't install pytorch here yet since CUDA isn't available
17 # instead we use the direct torch wheel
18 ENV PATH /opt/conda/envs/accelerate/bin:$PATH
19 # Activate our bash shell
20 RUN chsh -s /bin/bash
21 SHELL ["/bin/bash", "-c"]
22 # Activate the conda env, install mpy4pi, and install torch + accelerate
23 RUN source activate accelerate && conda install -c conda-forge mpi4py
24 RUN source activate accelerate && \
25 python3 -m pip install --no-cache-dir \
26 "accelerate[testing,test_trackers,deepspeed] @ git+https://github.com/huggingface/accelerate" \
27 --extra-index-url https://download.pytorch.org/whl/cu126
28
29 RUN python3 -m pip install --no-cache-dir bitsandbytes
30
31 # Stage 2
32 FROM nvidia/cuda:12.6.3-cudnn-devel-ubuntu22.04 AS build-image
33 COPY --from=compile-image /opt/conda /opt/conda
34 ENV PATH /opt/conda/bin:$PATH
35
36 # Install apt libs
37 RUN apt-get update && \
38 apt-get install -y curl git wget && \
39 apt-get clean && \
40 rm -rf /var/lib/apt/lists*
41
42 RUN echo "source activate accelerate" >> ~/.profile
43
44 # Activate the virtualenv
45 CMD ["/bin/bash"]