执行摘要
- 一句话:为 Ascend NPU 添加 nightly Docker 镜像 v0.7.1
- 推荐动作:该 PR 可读性中等,主要涉及基础设施配置。建议关注审查意见所提问题,在后续版本的 Dockerfile 中修复,特别是补丁机制和环境变量持久化。
功能与动机
PR body 说明 add nightly npu docker for v0.7.1,目标是为 Ascend NPU 用户提供预构建的 Docker 镜像,免去手动编译环境的繁琐过程。
实现拆解
- 创建两个 Dockerfile:
docker/ascend/Dockerfile.ascend_8.5.0_a2_v0.7.1 和 docker/ascend/Dockerfile.ascend_8.5.0_a3_v0.7.1,分别基于华为 CANN 8.5.0 的 a2 和 a3 基础镜像。
- 在 Dockerfile 中安装系统编译工具、Python 包管理器;编译并安装 vLLM 0.13.0、vLLM Ascend 插件、MindSpeed 2.3.0、Megatron-LM core 0.12.1。
- 安装 mbridge 和 torch_npu,并对 mbridge 中 DeepSeek 模型加载文件执行 sed 补丁,将 CUDA 调用映射为 NPU 兼容代码。
- 从 release/v0.7.1 分支克隆 verl,安装其 NPU 依赖(requirements-npu.txt),并以 editable 模式安装 verl。
- 更新 CI 工作流:在
docker-build-ascend-a2.yml 和 docker-build-ascend-a3.yml 中各追加一个 job step,当文件变更或定时触发时,使用新 Dockerfile 构建多架构镜像并推送到 quay.io。
关键文件:
docker/ascend/Dockerfile.ascend_8.5.0_a2_v0.7.1(模块 镜像构建;类别 infra;类型 infrastructure): 定义 Ascend a2 平台的完整 Docker 构建步骤,包括所有依赖安装、编译和补丁。
docker/ascend/Dockerfile.ascend_8.5.0_a3_v0.7.1(模块 镜像构建;类别 infra;类型 infrastructure): 为 Ascend a3 平台构建 Docker 镜像,与 a2 版本类似但基础镜像不同,且 mbridge 版本未固定。
.github/workflows/docker-build-ascend-a2.yml(模块 CI 工作流;类别 infra;类型 infrastructure): 更新 CI 工作流,新增构建和推送 v0.7.1 镜像的 step,确保 nightly 构建自动执行。
.github/workflows/docker-build-ascend-a3.yml(模块 CI 工作流;类别 infra;类型 infrastructure): 与 a2 工作流类似,为 a3 镜像添加构建步骤,触发路径包含新 Dockerfile。
关键符号:未识别
关键源码片段
docker/ascend/Dockerfile.ascend_8.5.0_a2_v0.7.1
定义 Ascend a2 平台的完整 Docker 构建步骤,包括所有依赖安装、编译和补丁。
FROM swr.cn-south-1.myhuaweicloud.com/ascendhub/cann:8.5.0-910b-ubuntu22.04-py3.11
ARG SOC_VERSION="ascend910b1"
# 安装系统基础编译工具和 Python 包管理
RUN apt-get update -y && \
apt-get install -y --no-install-recommends gcc g++ cmake libnuma-dev wget git curl jq vim build-essential && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
pip install --upgrade pip packaging setuptools==80.10.2 && \
pip cache purge
# 克隆并编译 vLLM、vLLM Ascend、MindSpeed、Megatron-LM
RUN git clone --depth 1 --branch v0.13.0 https://github.com/vllm-project/vllm.git && \
git clone -b releases/v0.13.0 https://github.com/vllm-project/vllm-ascend.git && \
git clone https://gitcode.com/Ascend/MindSpeed.git && \
cd MindSpeed && git checkout 2.3.0_core_r0.12.1 && cd .. && \
git clone --depth 1 --branch core_v0.12.1 https://github.com/NVIDIA/Megatron-LM.git
# 安装各组件
RUN source /usr/local/Ascend/ascend-toolkit/set_env.sh && \
source /usr/local/Ascend/nnal/atb/set_env.sh && \
pip install transformers==4.57.6 && \
cd vllm && VLLM_TARGET_DEVICE=empty pip install -v -e . && cd .. && \
cd vllm-ascend && export COMPILE_CUSTOM_KERNELS=1 && pip install -v -e . && cd .. && \
pip install -e MindSpeed && pip install -e Megatron-LM && \
pip uninstall -y triton && \
pip install mbridge==0.15.1 torch_npu==2.8.0 && \
rm -rf /tmp/* /var/tmp/* && pip cache purge
# 安装 verl v0.7.1
RUN git clone -b release/v0.7.1 https://github.com/verl-project/verl.git && \
cd verl && git submodule update --init --recursive --remote && \
pip install -r requirements-npu.txt && pip install -v -e . && \
cd .. && rm -rf /tmp/* /var/tmp/* && pip cache purge
# 对 mbridge 的 DeepSeek 模型加载文件打补丁,适配 NPU
RUN MBRIDGE_PATH=$(pip show mbridge | grep Location | awk '{print $2}') && \
TARGET_FILE="${MBRIDGE_PATH}/mbridge/models/ext/deepseek_v3/dequant_fp8_safetensor_io.py" && \
sed -i '...' "$TARGET_FILE"
docker/ascend/Dockerfile.ascend_8.5.0_a3_v0.7.1
为 Ascend a3 平台构建 Docker 镜像,与 a2 版本类似但基础镜像不同,且 mbridge 版本未固定。
FROM swr.cn-south-1.myhuaweicloud.com/ascendhub/cann:8.5.0-a3-ubuntu22.04-py3.11
ARG SOC_VERSION="ascend910_9392"
# 安装系统基础编译工具和 Python 包管理(与 a2 相同)
RUN apt-get update -y && \
apt-get install -y --no-install-recommends gcc g++ cmake libnuma-dev wget git curl jq vim build-essential && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
pip install --upgrade pip packaging setuptools==80.10.2 && \
pip cache purge
# 克隆并编译 vLLM、vLLM Ascend、MindSpeed、Megatron-LM
RUN git clone --depth 1 --branch v0.13.0 https://github.com/vllm-project/vllm.git && \
git clone -b releases/v0.13.0 https://github.com/vllm-project/vllm-ascend.git && \
git clone https://gitcode.com/Ascend/MindSpeed.git && \
cd MindSpeed && git checkout 2.3.0_core_r0.12.1 && cd .. && \
git clone --depth 1 --branch core_v0.12.1 https://github.com/NVIDIA/Megatron-LM.git
# 安装各组件
RUN source /usr/local/Ascend/ascend-toolkit/set_env.sh && \
source /usr/local/Ascend/nnal/atb/set_env.sh && \
pip install transformers==4.57.6 && \
cd vllm && VLLM_TARGET_DEVICE=empty pip install -v -e . && cd .. && \
cd vllm-ascend && export COMPILE_CUSTOM_KERNELS=1 && pip install -v -e . && cd .. && \
pip install -e MindSpeed && pip install -e Megatron-LM && \
pip uninstall -y triton && \
# 注意:此处 mbridge 未固定版本,与 a2 不同(a2 使用 mbridge==0.15.1)
pip install mbridge torch_npu==2.8.0 && \
rm -rf /tmp/* /var/tmp/* && pip cache purge
# 安装 verl v0.7.1
RUN git clone -b release/v0.7.1 https://github.com/verl-project/verl.git && \
cd verl && git submodule update --init --recursive --remote && \
pip install -r requirements-npu.txt && pip install -v -e . && \
cd .. && rm -rf /tmp/* /var/tmp/* && pip cache purge
# 对 mbridge 的 DeepSeek 模型加载文件打补丁,适配 NPU
RUN MBRIDGE_PATH=$(pip show mbridge | grep Location | awk '{print $2}') && \
TARGET_FILE="${MBRIDGE_PATH}/mbridge/models/ext/deepseek_v3/dequant_fp8_safetensor_io.py" && \
sed -i '...' "$TARGET_FILE"
评论区精华
代码审查由 Gemini Code Assist 自动执行,指出三个主要问题:环境变量持久化缺失(critical)、使用硬编码行号的 sed 补丁(high)、A3 Dockerfile 未固定 mbridge 版本(high)。这些意见在 PR 合并前未被解决。
- 环境变量不会持久化到运行时 (correctness): 未在 PR 中解决,但 PR 已合并。
- sed 补丁使用硬编码行号很脆弱 (design): 未在 PR 中解决。
- A3 Dockerfile 缺少 mbridge 版本固定 (design): 未在 PR 中解决。
风险与影响
- 风险:环境变量不持久导致容器运行时依赖可能丢失;sed 补丁随 mbridge 更新可能失效,破坏 DeepSeek 模型支持;缺少版本固定可引入构建不一致。对现有系统无直接影响。
- 影响:对 Ascend NPU 用户提供便利,降低部署复杂度;对非 NPU 用户无影响。影响范围限于构建基础设施。
- 风险标记:环境变量不持久, sed 补丁脆弱, 缺少版本固定
关联脉络
参与讨论