Dockerfile.rocm 6.39 KB
Newer Older
1
2
3
4
5
6
# Default ROCm 6.1 base image
ARG BASE_IMAGE="rocm/pytorch:rocm6.1.2_ubuntu20.04_py3.9_pytorch_staging"

# Default ROCm ARCHes to build vLLM for.
ARG PYTORCH_ROCM_ARCH="gfx908;gfx90a;gfx942;gfx1100"

7
8
# Whether to install CK-based flash-attention
# If 0, will not install flash-attention
9
ARG BUILD_FA="1"
10
11
12
13
14
15
# If `TRY_FA_WHEEL=1`, we will try installing flash-attention from `FA_WHEEL_URL`
# If this succeeds, we use the downloaded wheel and skip building flash-attention.
# Otherwise, ROCm flash-attention from `FA_BRANCH` will be built for the
# architectures specified in `FA_GFX_ARCHS`
ARG TRY_FA_WHEEL="1"
ARG FA_WHEEL_URL="https://github.com/ROCm/flash-attention/releases/download/v2.5.9post1-cktile-vllm/flash_attn-2.5.9.post1-cp39-cp39-linux_x86_64.whl"
16
ARG FA_GFX_ARCHS="gfx90a;gfx942"
17
ARG FA_BRANCH="23a2b1c2"
18

19
# Whether to build triton on rocm
20
ARG BUILD_TRITON="1"
21
ARG TRITON_BRANCH="e0fc12c"
22

23
24
25
26
27
### Base image build stage
FROM $BASE_IMAGE AS base

# Import arg(s) defined before this build stage
ARG PYTORCH_ROCM_ARCH
28
29

# Install some basic utilities
30
RUN apt-get update && apt-get install python3 python3-pip -y
31
32
33
34
35
36
37
38
39
40
41
RUN apt-get update && apt-get install -y \
    curl \
    ca-certificates \
    sudo \
    git \
    bzip2 \
    libx11-6 \
    build-essential \
    wget \
    unzip \
    tmux \
Simon Mo's avatar
Simon Mo committed
42
    ccache \
43
44
 && rm -rf /var/lib/apt/lists/*

45
# When launching the container, mount the code directory to /vllm-workspace
46
ARG APP_MOUNT=/vllm-workspace
47
48
WORKDIR ${APP_MOUNT}

49
RUN python3 -m pip install --upgrade pip
50
51
# Remove sccache so it doesn't interfere with ccache
# TODO: implement sccache support across components
52
RUN apt-get purge -y sccache; python3 -m pip uninstall -y sccache; rm -f "$(which sccache)"
53
# Install torch == 2.5.0 on ROCm
54
55
RUN case "$(ls /opt | grep -Po 'rocm-[0-9]\.[0-9]')" in \
        *"rocm-6.1"*) \
56
            python3 -m pip uninstall -y torch torchvision \
57
            && python3 -m pip install --no-cache-dir --pre \
58
59
                torch==2.5.0.dev20240726 \
                torchvision==0.20.0.dev20240726 \
60
61
               --index-url https://download.pytorch.org/whl/nightly/rocm6.1;; \
        *) ;; esac
62
63
64
65
66
67

ENV LLVM_SYMBOLIZER_PATH=/opt/rocm/llvm/bin/llvm-symbolizer
ENV PATH=$PATH:/opt/rocm/bin:/libtorch/bin:
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/rocm/lib/:/libtorch/lib:
ENV CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/libtorch/include:/libtorch/include/torch/csrc/api/include/:/opt/rocm/include/:

68
69
70
71
72
73
74
75
ENV PYTORCH_ROCM_ARCH=${PYTORCH_ROCM_ARCH}
ENV CCACHE_DIR=/root/.cache/ccache


### AMD-SMI build stage
FROM base AS build_amdsmi
# Build amdsmi wheel always
RUN cd /opt/rocm/share/amd_smi \
76
    && python3 -m pip wheel . --wheel-dir=/install
77
78
79
80
81


### Flash-Attention wheel build stage
FROM base AS build_fa
ARG BUILD_FA
82
83
ARG TRY_FA_WHEEL
ARG FA_WHEEL_URL
84
85
86
87
88
ARG FA_GFX_ARCHS
ARG FA_BRANCH
# Build ROCm flash-attention wheel if `BUILD_FA = 1`
RUN --mount=type=cache,target=${CCACHE_DIR} \
    if [ "$BUILD_FA" = "1" ]; then \
89
90
91
92
93
94
95
96
97
98
99
100
        if [ "${TRY_FA_WHEEL}" = "1" ] && python3 -m pip install "${FA_WHEEL_URL}"; then \
            # If a suitable wheel exists, we download it instead of building FA
            mkdir -p /install && wget -N "${FA_WHEEL_URL}" -P /install; \
        else \
            mkdir -p libs \
            && cd libs \
            && git clone https://github.com/ROCm/flash-attention.git \
            && cd flash-attention \
            && git checkout "${FA_BRANCH}" \
            && git submodule update --init \
            && GPU_ARCHS="${FA_GFX_ARCHS}" python3 setup.py bdist_wheel --dist-dir=/install; \
        fi; \
101
102
    # Create an empty directory otherwise as later build stages expect one
    else mkdir -p /install; \
103
    fi
104
105


106
107
108
109
110
111
112
### Triton wheel build stage
FROM base AS build_triton
ARG BUILD_TRITON
ARG TRITON_BRANCH
# Build triton wheel if `BUILD_TRITON = 1`
RUN --mount=type=cache,target=${CCACHE_DIR} \
    if [ "$BUILD_TRITON" = "1" ]; then \
113
114
    mkdir -p libs \
    && cd libs \
115
116
117
118
119
120
121
    && git clone https://github.com/OpenAI/triton.git \
    && cd triton \
    && git checkout "${TRITON_BRANCH}" \
    && cd python \
    && python3 setup.py bdist_wheel --dist-dir=/install; \
    # Create an empty directory otherwise as later build stages expect one
    else mkdir -p /install; \
122
123
    fi

124
125
126
127

### Final vLLM build stage
FROM base AS final
# Import the vLLM development directory from the build context
128
COPY . .
129

130
131
# Package upgrades for useful functionality or to avoid dependency issues
RUN --mount=type=cache,target=/root/.cache/pip \
132
    python3 -m pip install --upgrade numba scipy huggingface-hub[cli]
133

134

135
136
# Workaround for ray >= 2.10.0
ENV RAY_EXPERIMENTAL_NOSET_ROCR_VISIBLE_DEVICES=1
137
138
# Silences the HF Tokenizers warning
ENV TOKENIZERS_PARALLELISM=false
139

140
RUN --mount=type=cache,target=${CCACHE_DIR} \
Simon Mo's avatar
Simon Mo committed
141
    --mount=type=cache,target=/root/.cache/pip \
142
    python3 -m pip install -Ur requirements-rocm.txt \
143
144
145
    && case "$(ls /opt | grep -Po 'rocm-[0-9]\.[0-9]')" in \
        *"rocm-6.1"*) \
            # Bring in upgrades to HIP graph earlier than ROCm 6.2 for vLLM
146
            wget -N https://github.com/ROCm/vllm/raw/fa78403/rocm_patch/libamdhip64.so.6 -P /opt/rocm/lib \
147
148
149
150
151
152
153
154
155
156
157
            # Prevent interference if torch bundles its own HIP runtime
            && rm -f "$(python3 -c 'import torch; print(torch.__path__[0])')"/lib/libamdhip64.so* || true;; \
        *) ;; esac \
    && python3 setup.py clean --all \
    && python3 setup.py develop

# Copy amdsmi wheel into final image
RUN --mount=type=bind,from=build_amdsmi,src=/install,target=/install \
    mkdir -p libs \
    && cp /install/*.whl libs \
    # Preemptively uninstall to avoid same-version no-installs
158
    && python3 -m pip uninstall -y amdsmi;
159

160
161
162
163
164
165
# Copy triton wheel(s) into final image if they were built
RUN --mount=type=bind,from=build_triton,src=/install,target=/install \
    mkdir -p libs \
    && if ls /install/*.whl; then \
        cp /install/*.whl libs \
        # Preemptively uninstall to avoid same-version no-installs
166
        && python3 -m pip uninstall -y triton; fi
167
168
169
170
171
172
173

# Copy flash-attn wheel(s) into final image if they were built
RUN --mount=type=bind,from=build_fa,src=/install,target=/install \
    mkdir -p libs \
    && if ls /install/*.whl; then \
        cp /install/*.whl libs \
        # Preemptively uninstall to avoid same-version no-installs
174
        && python3 -m pip uninstall -y flash-attn; fi
175
176
177
178

# Install wheels that were built to the final image
RUN --mount=type=cache,target=/root/.cache/pip \
    if ls libs/*.whl; then \
179
    python3 -m pip install libs/*.whl; fi
180
181

CMD ["/bin/bash"]