-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathDockerfile.310p
More file actions
181 lines (164 loc) · 8.65 KB
/
Copy pathDockerfile.310p
File metadata and controls
181 lines (164 loc) · 8.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#
# Copyright (c) 2025 Huawei Technologies Co., Ltd. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This file is a part of the vllm-ascend project.
#
ARG CANN_QUAY_URL="quay.io/ascend/cann"
ARG CANN_VERSION="9.1.0"
FROM ${CANN_QUAY_URL}:${CANN_VERSION}-310p-ubuntu22.04-py3.12
ARG PIP_INDEX_URL="https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"
ARG MOONCAKE_INDEX_URL="https://mirrors.aliyun.com/pypi/web/simple"
ARG PYTORCH_INDEX_URL="https://download.pytorch.org/whl/cpu/"
ARG ASCEND_INDEX_URL="https://mirrors.huaweicloud.com/ascend/repos/pypi"
ARG APTMIRROR=""
ARG GIT_PROXY=""
ARG PIP_TRUSTED_HOST=""
WORKDIR /workspace
RUN if [ -n "$APTMIRROR" ]; then \
sed -Ei "s@(ports|archive).ubuntu.com@${APTMIRROR#http://}@g" /etc/apt/sources.list; \
fi && \
apt-get update -y && \
apt-get install -y python3-pip git vim wget curl protobuf-compiler libprotobuf-dev net-tools gcc g++ cmake numactl libnuma-dev libjemalloc2 pciutils && \
rm -rf /var/cache/apt/* && \
rm -rf /var/lib/apt/lists/*
# Install modelscope (for fast download) and ray (for multinode)
RUN pip config set global.index-url ${PIP_INDEX_URL} && \
if [ -n "$PIP_TRUSTED_HOST" ]; then pip config set global.trusted-host "$PIP_TRUSTED_HOST"; fi && \
python3 -m pip install 'modelscope<1.38' 'ray>=2.47.1,<=2.48.0' 'protobuf>3.20.0' && \
python3 -m pip cache purge
# Install vLLM
ARG VLLM_REPO=https://github.com/vllm-project/vllm.git
ARG VLLM_TAG=v0.28.0
ARG VLLM_COMMIT=""
RUN if [ -n "$VLLM_COMMIT" ]; then \
git init /vllm-workspace/vllm && \
git -C /vllm-workspace/vllm fetch --depth 1 $VLLM_REPO "$VLLM_COMMIT" && \
git -C /vllm-workspace/vllm checkout FETCH_HEAD; \
else \
if [ -n "$GIT_PROXY" ]; then git config --global url."${GIT_PROXY}https://github.com/".insteadOf https://github.com/; fi && \
git clone --depth 1 -b $VLLM_TAG $VLLM_REPO /vllm-workspace/vllm; \
fi
# In x86, triton will be installed by vllm. But in Ascend, triton doesn't work correctly. we need to uninstall it.
RUN VLLM_TARGET_DEVICE="empty" python3 -m pip install -e /vllm-workspace/vllm/[audio] --extra-index-url ${PYTORCH_INDEX_URL} && \
python3 -m pip uninstall -y triton && \
python3 -m pip cache purge
# Install vllm-ascend
ARG SOC_VERSION="ascend310p1"
ARG COMPILE_CUSTOM_KERNELS=1
ENV DEBIAN_FRONTEND=noninteractive
ENV SOC_VERSION=$SOC_VERSION \
TASK_QUEUE_ENABLE=1 \
OMP_NUM_THREADS=1
COPY . /vllm-workspace/vllm-ascend/
RUN export PIP_EXTRA_INDEX_URL="${ASCEND_INDEX_URL}" && \
source /usr/local/Ascend/ascend-toolkit/set_env.sh && \
source /usr/local/Ascend/nnal/atb/set_env.sh && \
python3 -m pip install -e /vllm-workspace/vllm-ascend/ --extra-index-url ${PYTORCH_INDEX_URL} && \
python3 -m pip uninstall -y triton-ascend triton && \
python3 -m pip cache purge
# Install _rust_tool_parser for the Rust frontend.
ARG RUSTUP_DIST_SERVER
ARG RUSTUP_UPDATE_ROOT
ENV RUSTUP_DIST_SERVER=$RUSTUP_DIST_SERVER \
RUSTUP_UPDATE_ROOT=$RUSTUP_UPDATE_ROOT
# When an internal RUSTUP_DIST_SERVER mirror is provided (CI builds), pre-install
# rustup via the rustup-init.sh bootstrap from the mirror so build_rust.sh
# doesn't reach the public https://sh.rustup.rs (unreachable from build
# containers). The bootstrap downloader hardcodes --proto '=https' (curl) and
# --https-only (wget), so strip them via sed to allow the internal http mirror.
# External builds without the mirror keep the original public install path. The
# default toolchain is read from vllm's rust-toolchain.toml (falling back to
# stable).
RUN if [ -n "$RUSTUP_DIST_SERVER" ]; then \
TOOLCHAIN=$(sed -n 's/^channel *= *"\([^"]*\)".*/\1/p' /vllm-workspace/vllm/rust-toolchain.toml) && \
curl -fsSL "${RUSTUP_UPDATE_ROOT}/rustup-init.sh" -o /tmp/rustup-init.sh && \
sed -i "s/--proto '=https'//g; s/--https-only//g" /tmp/rustup-init.sh && \
sh /tmp/rustup-init.sh -y --default-toolchain "${TOOLCHAIN:-stable}" && \
rm /tmp/rustup-init.sh; \
fi
ENV PATH="/root/.cargo/bin:$PATH"
# Configure cargo only for internal (CI) builds: route git dependencies through
# GIT_PROXY and the crates.io sparse index through an internal mirror. External
# builds leave these build-args empty and keep the default public endpoints.
ARG CRATES_IO_INDEX=""
RUN if [ -n "$GIT_PROXY" ] || [ -n "$CRATES_IO_INDEX" ]; then \
mkdir -p $HOME/.cargo; \
if [ -n "$GIT_PROXY" ]; then \
printf '[net]\ngit-fetch-with-cli = true\n' > $HOME/.cargo/config.toml; \
else \
: > $HOME/.cargo/config.toml; \
fi; \
if [ -n "$CRATES_IO_INDEX" ]; then \
printf '[source.crates-io]\nreplace-with = "mirror"\n\n[source.mirror]\nregistry = "sparse+%s"\n' "$CRATES_IO_INDEX" >> $HOME/.cargo/config.toml; \
fi; \
fi
RUN cd /vllm-workspace/vllm && \
export PROTOC_INCLUDE=/usr/include && \
python3 -m pip install setuptools-rust && \
./build_rust.sh
# Append `libascend_hal.so` path (devlib) to LD_LIBRARY_PATH
RUN echo "export LD_PRELOAD=/usr/lib/$(uname -m)-linux-gnu/libjemalloc.so.2:$LD_PRELOAD" >> ~/.bashrc
RUN echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib" >> ~/.bashrc
RUN echo 'export LD_LIBRARY_PATH=/usr/local/Ascend/driver/lib64:/usr/lib64:/root/aicpu_kernels/0/aicpu_kernels_device/sand_box:$LD_LIBRARY_PATH' >> /root/.bashrc
# Initialize driver directories, users and file groups
RUN mkdir -m 750 /var/driver -m 750 /var/dmp -m 750 /usr/slog && \
mkdir -m 755 /home/drv && \
mkdir -m 750 /home/drv/hdc_ppc -m 750 -p /var/log/npu/slog && \
ldconfig && \
ln -sf /lib /lib64 && \
userdel -r ubuntu || true && \
groupadd -g 1000 HwHiAiUser && useradd -u 1000 -g HwHiAiUser -d /home/HwHiAiUser -m HwHiAiUser && \
groupadd -g 1101 HwDmUser && useradd -u 1101 -g HwDmUser -d /home/HwDmUser -m HwDmUser && \
groupadd -g 1102 HwBaseUser && useradd -u 1102 -g HwBaseUser -d /home/HwBaseUser -m HwBaseUser && \
groupadd -g 1100 HwSysUser && useradd -u 1100 -g HwSysUser -d /home/HwSysUser -m HwSysUser && \
usermod -a -G HwBaseUser HwHiAiUser && \
usermod -a -G HwDmUser HwHiAiUser && \
usermod -a -G HwBaseUser HwDmUser && \
usermod -a -G HwHiAiUser HwDmUser && \
usermod -a -G HwSysUser HwSysUser && \
chown HwDmUser:HwDmUser /var/dmp && \
chown HwHiAiUser:HwHiAiUser /var/driver && \
chown HwHiAiUser:HwHiAiUser /usr/slog && \
chown HwHiAiUser:HwHiAiUser /home/drv/hdc_ppc && \
chown HwHiAiUser:HwHiAiUser /var/log/npu/slog
# Dynamically generate entrypoint.sh for dual mode compatibility
RUN echo '#!/bin/bash' > /usr/local/bin/entrypoint.sh && \
echo 'if lspci 2>/dev/null | grep -qi "accelerators"; then' >> /usr/local/bin/entrypoint.sh && \
echo ' :' >> /usr/local/bin/entrypoint.sh && \
echo 'else' >> /usr/local/bin/entrypoint.sh && \
echo ' su - HwHiAiUser -c "export LD_LIBRARY_PATH=/usr/local/Ascend/driver/lib64/:/usr/lib64 && /lib/ld-linux-aarch64.so.1 /var/slogd -d >/dev/null &"' >> /usr/local/bin/entrypoint.sh && \
echo ' su - HwDmUser -c "export LD_LIBRARY_PATH=/usr/local/Ascend/driver/lib64/:/usr/lib64 && /var/dmp_daemon -I -M -U 8087 &"' >> /usr/local/bin/entrypoint.sh && \
echo ' ' >> /usr/local/bin/entrypoint.sh && \
echo ' rm -rf /lib64/ld-linux-aarch64.so.1' >> /usr/local/bin/entrypoint.sh && \
echo ' ln -sf /lib/ld-linux-aarch64.so.1 /lib64/ld-linux-aarch64.so.1' >> /usr/local/bin/entrypoint.sh && \
echo 'fi' >> /usr/local/bin/entrypoint.sh && \
echo '' >> /usr/local/bin/entrypoint.sh && \
echo 'exec "$@"' >> /usr/local/bin/entrypoint.sh && \
chmod +x /usr/local/bin/entrypoint.sh
# ===== Conditional installation based on BUILD_TYPE =====
# All ARG definitions are in the same stage for better maintainability
ARG BUILD_TYPE="release"
ARG TORCH_NPU_VERSION
ARG TORCH_NPU_DATE
ARG DAILY_DEPS_MODE="torch_npu_only"
# Install daily packages via shared script
COPY .github/workflows/scripts/install_daily_deps.sh /tmp/
RUN if [ "$BUILD_TYPE" = "daily" ]; then \
bash /tmp/install_daily_deps.sh; \
else \
echo "Building release version without daily packages"; \
fi && rm -f /tmp/install_daily_deps.sh
# Set entrypoint and default command
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["/bin/bash"]