fix(docker): remove unrelated added docker files

This commit is contained in:
Yunnglin
2026-06-17 15:10:53 +08:00
parent 65e16d1d2a
commit d275e86416
9 changed files with 0 additions and 628 deletions

View File

@@ -1,145 +0,0 @@
ARG BUILD_BASE_IMAGE=registry.access.redhat.com/ubi9/ubi:9.6
ARG PYTHON_VERSION=3.12
ARG UV_EXTRA_INDEX_URL=https://repos.metax-tech.com/r/maca-pypi/simple
ARG UV_TRUSTED_HOST=repos.metax-tech.com
# may need passing a particular vllm version during build
ARG VLLM_VERSION
ARG MACA_VERSION
ARG CU_BRIDGE_VERSION=${MACA_VERSION}
#################### BASE BUILD IMAGE ####################
FROM ${BUILD_BASE_IMAGE} AS base
ARG UV_TRUSTED_HOST
# maca environment variables
ENV MACA_PATH=/opt/maca
ENV MACA_CLANG_PATH=/opt/maca/mxgpu_llvm/bin
ENV CUCC_PATH="${MACA_PATH}/tools/cu-bridge"
ENV CUDA_PATH=/root/cu-bridge/CUDA_DIR
ENV CUCC_CMAKE_ENTRY=2
ENV PATH="/opt/venv/bin:/root/.local/bin:$PATH"
ENV PATH=/opt/mxdriver/bin:${MACA_PATH}/bin:${MACA_PATH}/mxgpu_llvm/bin:${MACA_PATH}/tools/cu-bridge/tools:${MACA_PATH}/tools/cu-bridge/bin:${PATH}
ENV LD_LIBRARY_PATH=/opt/mxdriver/lib:${MACA_PATH}/lib:${MACA_PATH}/mxgpu_llvm/lib:${MACA_PATH}/ompi/lib:${MACA_PATH}/ucx/lib:${LD_LIBRARY_PATH}
# uv environment variables
ENV VIRTUAL_ENV=/opt/venv
ENV UV_INDEX_STRATEGY="unsafe-best-match"
ENV UV_HTTP_TIMEOUT=6000
ENV UV_LINK_MODE=copy
ARG UV_EXTRA_INDEX_URL
ENV UV_EXTRA_INDEX_URL=${UV_EXTRA_INDEX_URL}
ARG UV_INDEX_URL
ENV UV_INDEX_URL=https://mirrors.aliyun.com/pypi/simple
ENV UV_TRUSTED_INDEX_HOST=mirrors.aliyun.com
ENV UV_OVERRIDE=/workspace/override.txt
# vllm compile option
ENV VLLM_INSTALL_PUNICA_KERNELS=1
# AI version arguments
ARG PYTHON_VERSION
ARG VLLM_VERSION
ARG VLLM_METAX_VERSION
ARG MACA_VERSION
ARG MEGATRON_VERSION
ARG SWIFT_VERSION
ARG CU_BRIDGE_VERSION
ARG TE_VERSION
WORKDIR /workspace
COPY override.txt /workspace/override.txt
COPY requirements_extra.txt /workspace/requirements_extra.txt
RUN printf "[metax-centos]\n\
name=Maca Driver Yum Repository\n\
baseurl=https://repos.metax-tech.com/r/metax-driver-centos-$(uname -m)/\n\
enabled=1\n\
gpgcheck=0" > /etc/yum.repos.d/metax-driver-centos.repo && \
printf "[maca-sdk]\n\
name=Maca Sdk Yum Repository\n\
baseurl=https://repos.metax-tech.com/r/maca-sdk-rpm-$(uname -m)/\n\
enabled=1\n\
gpgcheck=0" > /etc/yum.repos.d/maca-sdk-rpm.repo
RUN yum install -y \
python3-pip hostname \
unzip vim git openblas-devel make cmake \
ninja-build gcc g++ procps-ng \
libibverbs librdmacm libibumad \
binutils numactl-libs \
metax-driver-${MACA_VERSION}* mxgvm \
maca_sdk-${MACA_VERSION}* \
&& yum clean all && rm -rf /var/cache/yum /tmp/*
RUN python3 -m pip install uv -i $UV_INDEX_URL --trusted-host ${UV_TRUSTED_INDEX_HOST} && \
uv venv /opt/venv --python=${PYTHON_VERSION}
RUN python3 --version && \
uv self version
RUN git clone --depth 1 --branch ${SWIFT_VERSION} https://github.com/modelscope/ms-swift.git && \
git clone --depth 1 --branch ${VLLM_METAX_VERSION} https://github.com/MetaX-MACA/vLLM-metax.git && \
git clone --depth 1 --branch ${VLLM_VERSION} https://github.com/vllm-project/vllm.git && \
git clone --depth 1 --branch ${MEGATRON_VERSION} https://github.com/NVIDIA/Megatron-LM.git
# Step 1: install MACA SDK, Metax-Driver and cu-bridge
# Metax-Driver mainly contains vbios and kmd files, which are not needed in a container.
# Here we keep the mx-smi management tool. Kernel version mismatch errors are ignored.
RUN cd /tmp/ && \
export MACA_PATH=/opt/maca && \
curl -o ${CU_BRIDGE_VERSION}.zip -LsSf https://gitee.com/metax-maca/cu-bridge/repository/archive/${CU_BRIDGE_VERSION}.zip && \
unzip ${CU_BRIDGE_VERSION}.zip && \
mv cu-bridge-${CU_BRIDGE_VERSION} cu-bridge && \
chmod -R 755 cu-bridge && \
cd cu-bridge && \
mkdir build && cd build && \
cmake -DCMAKE_INSTALL_PREFIX=/opt/maca/tools/cu-bridge ../ && \
make && make install
# Step 2: trim unused MACA packages and install build prerequisites
RUN cd vLLM-metax && \
uv pip install -r requirements/build.txt && \
uv pip install build
# Step 3: install Metax python requirements
RUN cd vLLM-metax && \
UV_HTTP_TIMEOUT=960 uv pip install -r requirements/maca.txt --trusted-host ${UV_TRUSTED_HOST}
# Step 4: build vLLM with empty device to avoid CUDA dependency
RUN cd vllm && \
python3 use_existing_torch.py && \
uv pip install -r requirements/build/cuda.txt && \
VLLM_TARGET_DEVICE=empty uv pip install -v . --no-build-isolation
# Step 5: build vLLM-metax
RUN cd vLLM-metax && \
uv pip install -r requirements/build.txt && \
python3 -m build -w -n && \
uv pip install dist/*.whl
# Step 6: install Megatron-LM
RUN cd /workspace/Megatron-LM && \
if [ -f megatron/legacy/fused_kernels/__init__.py ]; then \
sed -i 's/nvcc/cucc/g' megatron/legacy/fused_kernels/__init__.py; \
fi && \
uv pip install .
# Step 7: install transformer-engine
RUN uv pip install transformer_engine==${TE_VERSION} -i https://repos.metax-tech.com/r/maca-pypi/simple --trusted-host ${UV_TRUSTED_HOST}
# Step 8: patch and install ms-swift v4.2.0 with Megatron extra dependencies
RUN sed -i '0,/^\(from \|import \)/{s//import vllm_metax.patch\n&/}' ms-swift/swift/__init__.py && \
cd ms-swift && \
uv pip install '.[megatron]'
# Step 9: install optional runtime dependencies used by swift 4.2.0
RUN uv pip install deepspeed -i https://repos.metax-tech.com/r/maca-pypi/simple --trusted-host ${UV_TRUSTED_HOST}
RUN uv pip install pip
RUN uv pip install -r requirements_extra.txt
RUN ln -sf ${CUDA_PATH}/bin/nvcc ${CUDA_PATH}/bin/cucc
# vllm installation may bring in incompatible CUDA-only wheels. Remove them here.
RUN uv pip uninstall flashinfer-python cupy-cuda12x
#################### FINAL IMAGE ####################

View File

@@ -1,78 +0,0 @@
ARG BUILD_BASE_IMAGE=mx-devops-acr-cn-shanghai.cr.volces.com/opensource/public-ai-release/maca/sglang:0.5.10-maca.ai3.7.1.12-torch2.8-py312-ubuntu22.04-amd64
ARG PYTHON_VERSION=3.12
FROM ${BUILD_BASE_IMAGE} AS base
# NOTE:
# This fast-build path inherits Python/Torch/TE from a prebuilt Metax release image.
# We keep the verified base image tag here instead of guessing a newer one.
# As a result, this path may lag behind the Megatron-SWIFT Quick Start recommendations.
# may need passing a particular vllm version during build
ARG VLLM_VERSION
ARG VLLM_METAX_VERSION
ARG MEGATRON_VERSION
ARG SWIFT_VERSION
ENV MACA_PATH=/opt/maca
ENV CUCC_CMAKE_ENTRY=2
ENV CUDA_PATH=/root/cu-bridge/CUDA_DIR
ENV CUCC_PATH=${MACA_PATH}/tools/cu-bridge
ENV PATH=/opt/conda/bin:/opt/conda/condabin:${CUDA_PATH}/bin:${CUCC_PATH}/tools:${CUCC_PATH}/bin:${MACA_PATH}/bin:${PATH}
ENV LD_LIBRARY_PATH=${CUDA_PATH}/lib64:${MACA_PATH}/lib:${MACA_PATH}/mxgpu_llvm/lib:${LD_LIBRARY_PATH}
WORKDIR /workspace
COPY requirements_extra.txt /workspace/requirements_extra.txt
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
# Initialize cu-bridge if it is not already prepared in the base image.
RUN if [ ! -d /root/cu-bridge ]; then \
${MACA_PATH}/tools/cu-bridge/tools/pre_make; \
fi
# Clone all GitHub sources while the external proxy is enabled.
RUN rm -rf /workspace/ms-swift /workspace/vLLM-metax /workspace/vllm /workspace/Megatron-LM && \
git clone --depth 1 --branch ${SWIFT_VERSION} https://github.com/modelscope/ms-swift.git && \
git clone --depth 1 --branch ${VLLM_METAX_VERSION} https://github.com/MetaX-MACA/vLLM-metax.git && \
git clone --depth 1 --branch ${VLLM_VERSION} https://github.com/vllm-project/vllm.git && \
git clone --depth 1 --branch ${MEGATRON_VERSION} https://github.com/NVIDIA/Megatron-LM.git
# install cmake
RUN pip install cmake ninja
# Step 1: build original vLLM for torch setup
RUN cd vllm && \
python3 use_existing_torch.py && \
pip install -r requirements/build/cuda.txt && \
VLLM_TARGET_DEVICE=empty pip install -v . --no-build-isolation
# Step 3: build vLLM-metax
RUN cd vLLM-metax && \
python3 use_existing_metax.py && \
pip install -r requirements/build.txt && \
python3 -m build -w -n && \
pip install dist/*.whl
# Step 4: patch and install Megatron-LM
RUN cd /workspace/Megatron-LM && \
if [ -f megatron/legacy/fused_kernels/__init__.py ]; then \
sed -i 's/nvcc/cucc/g' megatron/legacy/fused_kernels/__init__.py; \
fi && \
pip install .
# Step 5: install transformer-engine
ARG TE_VERSION=2.8.0+4a002bf5.maca3.5.3.105.torch2.8
ARG UV_TRUSTED_HOST=repos.metax-tech.com
RUN pip install transformer_engine==${TE_VERSION} -i https://repos.metax-tech.com/r/maca-pypi/simple --trusted-host ${UV_TRUSTED_HOST}
# Step 6: patch and install ms-swift v4.2.0 with its Megatron extra
RUN sed -i '0,/^\(from \|import \)/{s//import vllm_metax.patch\n&/}' ms-swift/swift/__init__.py && \
cd ms-swift && \
pip install "transformers<5.4.0" && \
pip install '.[megatron]' && \
pip install -r /workspace/requirements_extra.txt
RUN pip uninstall torchao -y
CMD ["bash"]

View File

@@ -1,12 +0,0 @@
docker build \
--network host \
-f Dockerfile.metax \
-t swift:v4.2.3 \
--build-arg VLLM_VERSION=v0.20.0 \
--build-arg VLLM_METAX_VERSION=v0.20.0 \
--build-arg MACA_VERSION=3.7.0 \
--build-arg MEGATRON_VERSION=core_v0.16.0 \
--build-arg SWIFT_VERSION=v4.2.3 \
--build-arg TE_VERSION=2.8.0+4a002bf5.maca3.5.3.105.torch2.8 \
--build-arg CU_BRIDGE_VERSION=3.7.0 \
.

View File

@@ -1,9 +0,0 @@
docker build \
--network host \
-f Dockerfile.with_metax_image \
-t swift:v4.2.3-with-metax-base \
--build-arg VLLM_VERSION=v0.20.0 \
--build-arg VLLM_METAX_VERSION=v0.20.0 \
--build-arg MEGATRON_VERSION=core_v0.16.0 \
--build-arg SWIFT_VERSION=v4.2.3 \
.

View File

@@ -1,6 +0,0 @@
setuptools>=77.0.3,<80
datasets>=3.0,<4.0
flash-linear-attention
mcoplib
transformers<5.4.0
numpy<2

View File

@@ -1,14 +0,0 @@
decord
diffusers==0.35.2
evalscope>=1.0.0
evalscope[opencompass]
evalscope[vlmeval]
keye_vl_utils>=1.5.2
librosa
mpi4py
optimum==1.27.0
pytorchvideo
qwen_omni_utils>=0.0.9
qwen_vl_utils==0.0.14
soundfile
timm

View File

@@ -1,52 +0,0 @@
# 1. Build swift 4.2 image from a UBI9 base image
Full build from a minimal base image, using a venv virtual environment.
## 1.1. Build
``` bash
bash build.sh
```
## 1.2. Run a container
``` bash
docker run -d -it --net=host --uts=host --ipc=host --privileged=true --group-add video \
--shm-size 100gb --ulimit memlock=-1 \
--security-opt seccomp=unconfined --security-opt apparmor=unconfined \
--device=/dev/dri --device=/dev/mxcd \
--name base_image \
${IMAGE_ID} bash
```
## 1.3. Activate the venv environment
``` bash
source /opt/venv/bin/activate
```
## 1.4. Run swift examples
``` bash
cd /workspace/ms-swift
bash examples/train/full/train.sh
```
# 2. Build swift 4.2 image from a Metax release image
Faster build based on the pre-built Metax release image.
## 2.1. Build
``` bash
bash build_from_metax_image.sh
```
## 2.2. Run a container
``` bash
docker run -d -it --net=host --uts=host --ipc=host --privileged=true --group-add video \
--shm-size 100gb --ulimit memlock=-1 \
--security-opt seccomp=unconfined --security-opt apparmor=unconfined \
--device=/dev/dri --device=/dev/mxcd \
--name base_image \
${IMAGE_ID} bash
```
## 2.3. Run swift examples
``` bash
cd /workspace/ms-swift
bash examples/train/full/train.sh
```

View File

@@ -1,156 +0,0 @@
# ms-swift Ascend
> English | [中文](./OVERVIEW.ascend.zh.md)
ms-swift Ascend images provide a ready-to-use ms-swift environment for Huawei Ascend Atlas NPUs. The images are built on top of the Ascend CANN container images and include the Python, CANN, PyTorch NPU, vLLM Ascend, Megatron, MindSpeed, mcore-bridge, ms-swift, and ModelScope runtime components needed for Ascend inference and training workflows.
## Quick Reference
- Base image: `quay.io/ascend/cann:<cann-version>-<hardware>-<os>-py<python-version>`
- Build template: `docker/Dockerfile.ascend`
- Build entrypoint: `docker/build_image.py --image_type ascend`
- Default base image: `quay.io/ascend/cann:8.5.1-a3-ubuntu22.04-py3.11`
- Default output tag: `${DOCKER_REGISTRY}:main-A3-py311-CANN8.5.1-ubuntu22.04-<arch>`
- Ascend runtime environment is sourced from `/usr/local/Ascend/ascend-toolkit/set_env.sh`
- If available, NNAL/ATB runtime is sourced from `/usr/local/Ascend/nnal/atb/set_env.sh`
## Image Contents
The Ascend Dockerfile installs and configures:
| Component | Version / Source |
| --- | --- |
| CANN | inherited from the selected `quay.io/ascend/cann` base image |
| Python | inherited from the base image tag, for example `py3.11` |
| PyTorch | `torch==2.9.0` |
| torch-npu | `torch_npu==2.9.0.post2` |
| torchvision / torchaudio | `torchvision==0.24.0`, `torchaudio==2.9.0` |
| vLLM | source install from `vllm-project/vllm`, default branch `v0.18.0` |
| vLLM Ascend | source install from `vllm-project/vllm-ascend`, default branch `v0.18.0` |
| Megatron-LM | source checkout, default branch `v0.15.3` |
| MindSpeed | source checkout, default branch `core_r0.15.3` |
| mcore-bridge | source checkout from `modelscope/mcore-bridge` |
| ms-swift | source checkout from `modelscope/ms-swift`, default branch `main` |
| ModelScope | source checkout from `modelscope/modelscope`, default branch `master` |
| triton-ascend | `3.2.0` for CANN `8.5.*`; local wheel install of `3.2.1` for CANN `9.0.0` |
## Supported Tag Format
Images built by `docker/build_image.py --image_type ascend` use this tag format:
```text
${DOCKER_REGISTRY}:<swift-branch>-<atlas-hardware>-<python-tag>-<cann-version-tag>-<os-tag>-<arch>
```
| Field | Example | Description |
| --- | --- | --- |
| `swift-branch` | `main` | ms-swift branch used during image build |
| `atlas-hardware` | `A2`, `A3`, `300I`, `A5` | Derived from `--soc_version` |
| `python-tag` | `py311` | Derived from `--python_version` |
| `cann-version-tag` | `CANN8.5.1`, `CANN9.0.0` | Parsed from the CANN base image tag |
| `os-tag` | `ubuntu22.04` | Parsed from the CANN base image tag |
| `arch` | `arm`, `x86` | Derived from host architecture or `--arch` |
Default example on an ARM64 host:
```text
${DOCKER_REGISTRY}:main-A3-py311-CANN8.5.1-ubuntu22.04-arm
```
A2 / CANN 9.0.0 example:
```text
${DOCKER_REGISTRY}:main-A2-py311-CANN9.0.0-ubuntu22.04-arm
```
## Build Locally
Set the target registry first. The build script renders `docker/Dockerfile.ascend` into the root `Dockerfile`, builds it, and skips push for Ascend images.
```bash
export DOCKER_REGISTRY=registry.example.com/ms-swift/ms-swift
python docker/build_image.py \
--image_type ascend
```
Build an A2 / CANN 9.0.0 image:
```bash
export DOCKER_REGISTRY=registry.example.com/ms-swift/ms-swift
python docker/build_image.py \
--image_type ascend \
--base_image quay.io/ascend/cann:9.0.0-910b-ubuntu22.04-py3.11 \
--soc_version ascend910b1
```
Override Megatron or MindSpeed source branches when needed:
```bash
python docker/build_image.py \
--image_type ascend \
--megatron_branch v0.15.3 \
--mindspeed_branch core_r0.15.3
```
For slow networks, Linux hosts can use Docker host networking after the root `Dockerfile` is generated:
```bash
docker build --network host \
-t ${DOCKER_REGISTRY}:main-A2-py311-CANN9.0.0-ubuntu22.04-arm \
-f Dockerfile .
```
## Run An Ascend Container
The host must have a compatible Ascend driver and firmware installed. The container uses the host NPU devices and driver libraries.
```bash
docker run --rm -it \
--name ms_swift_ascend \
--device /dev/davinci0 \
--device /dev/davinci_manager \
--device /dev/devmm_svm \
--device /dev/hisi_hdc \
-v /usr/local/dcmi:/usr/local/dcmi \
-v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi \
-v /usr/local/Ascend/driver/lib64:/usr/local/Ascend/driver/lib64 \
-v /usr/local/Ascend/driver/version.info:/usr/local/Ascend/driver/version.info \
-v /etc/ascend_install.info:/etc/ascend_install.info \
-v /mnt/workspace:/mnt/workspace \
${DOCKER_REGISTRY}:main-A2-py311-CANN9.0.0-ubuntu22.04-arm \
bash
```
Inside the container, verify the NPU and Python packages:
```bash
npu-smi info
python -c "import torch, torch_npu; print(torch.__version__, torch_npu.__version__)"
python -c "import vllm, vllm_ascend; print('vllm ascend ok')"
pip show ms-swift modelscope torch-npu triton-ascend
```
## Environment Variables
| Variable | Value |
| --- | --- |
| `SOC_VERSION` | Selected Ascend SoC version, for example `ascend910b1` or `ascend910_9391` |
| `CANN_VERSION` | Parsed from the base image tag |
| `MEGATRON_LM_PATH` | `/Megatron-LM` |
| `PYTHONPATH` | includes `/Megatron-LM` |
| `VLLM_USE_MODELSCOPE` | `True` |
| `LMDEPLOY_USE_MODELSCOPE` | `True` |
| `MODELSCOPE_CACHE` | `/mnt/workspace/.cache/modelscope/hub` |
## Notes
- CANN, firmware, and driver versions must be compatible with each other.
- CANN `8.5.*` and CANN `9.0.0` use different `triton-ascend` install paths in this Dockerfile.
- The image is intended for Ascend NPU ms-swift workflows. CUDA-only packages pulled in by dependencies are removed when they conflict with NPU runtime libraries.
- Use a fixed image tag for production jobs instead of relying on a moving branch name.
## License
ms-swift and ModelScope components follow their upstream repository licenses. CANN, MindSpeed, torch-npu, vLLM Ascend, and other pre-installed third-party components are subject to their own upstream licenses.

View File

@@ -1,156 +0,0 @@
# ms-swift Ascend
> [English](./OVERVIEW.ascend.md) | 中文
ms-swift Ascend 镜像面向华为昇腾 Atlas NPU提供可直接使用的 ms-swift 运行环境。镜像基于 Ascend CANN 容器镜像构建,包含 Ascend 推理和训练工作流所需的 Python、CANN、PyTorch NPU、vLLM Ascend、Megatron、MindSpeed、mcore-bridge、ms-swift 以及 ModelScope 运行组件。
## 快速参考
- 基础镜像:`quay.io/ascend/cann:<cann-version>-<hardware>-<os>-py<python-version>`
- 构建模板:`docker/Dockerfile.ascend`
- 构建入口:`docker/build_image.py --image_type ascend`
- 默认基础镜像:`quay.io/ascend/cann:8.5.1-a3-ubuntu22.04-py3.11`
- 默认输出 tag`${DOCKER_REGISTRY}:main-A3-py311-CANN8.5.1-ubuntu22.04-<arch>`
- Ascend runtime 环境来自 `/usr/local/Ascend/ascend-toolkit/set_env.sh`
- 如果镜像内存在 NNAL/ATB则会加载 `/usr/local/Ascend/nnal/atb/set_env.sh`
## 镜像内容
Ascend Dockerfile 会安装和配置:
| 组件 | 版本 / 来源 |
| --- | --- |
| CANN | 继承自选定的 `quay.io/ascend/cann` 基础镜像 |
| Python | 继承自基础镜像 tag例如 `py3.11` |
| PyTorch | `torch==2.9.0` |
| torch-npu | `torch_npu==2.9.0.post2` |
| torchvision / torchaudio | `torchvision==0.24.0``torchaudio==2.9.0` |
| vLLM | 从 `vllm-project/vllm` 源码安装,默认分支 `v0.18.0` |
| vLLM Ascend | 从 `vllm-project/vllm-ascend` 源码安装,默认分支 `v0.18.0` |
| Megatron-LM | 源码 checkout默认分支 `v0.15.3` |
| MindSpeed | 源码 checkout默认分支 `core_r0.15.3` |
| mcore-bridge | 来自 `modelscope/mcore-bridge` 的源码 checkout |
| ms-swift | 来自 `modelscope/ms-swift` 的源码 checkout默认分支 `main` |
| ModelScope | 来自 `modelscope/modelscope` 的源码 checkout默认分支 `master` |
| triton-ascend | CANN `8.5.*` 安装 `3.2.0`CANN `9.0.0` 下载并本地安装 `3.2.1` wheel |
## 支持的 Tag 格式
通过 `docker/build_image.py --image_type ascend` 构建的镜像使用以下 tag 格式:
```text
${DOCKER_REGISTRY}:<swift-branch>-<atlas-hardware>-<python-tag>-<cann-version-tag>-<os-tag>-<arch>
```
| 字段 | 示例 | 说明 |
| --- | --- | --- |
| `swift-branch` | `main` | 构建镜像时使用的 ms-swift 分支 |
| `atlas-hardware` | `A2``A3``300I``A5` | 从 `--soc_version` 推导 |
| `python-tag` | `py311` | 从 `--python_version` 推导 |
| `cann-version-tag` | `CANN8.5.1``CANN9.0.0` | 从 CANN 基础镜像 tag 解析 |
| `os-tag` | `ubuntu22.04` | 从 CANN 基础镜像 tag 解析 |
| `arch` | `arm``x86` | 从宿主机架构或 `--arch` 推导 |
ARM64 宿主机上的默认示例:
```text
${DOCKER_REGISTRY}:main-A3-py311-CANN8.5.1-ubuntu22.04-arm
```
A2 / CANN 9.0.0 示例:
```text
${DOCKER_REGISTRY}:main-A2-py311-CANN9.0.0-ubuntu22.04-arm
```
## 本地构建
先设置目标镜像仓库。构建脚本会把 `docker/Dockerfile.ascend` 渲染成根目录 `Dockerfile`然后执行构建Ascend 镜像分支当前不执行 push。
```bash
export DOCKER_REGISTRY=registry.example.com/ms-swift/ms-swift
python docker/build_image.py \
--image_type ascend
```
构建 A2 / CANN 9.0.0 镜像:
```bash
export DOCKER_REGISTRY=registry.example.com/ms-swift/ms-swift
python docker/build_image.py \
--image_type ascend \
--base_image quay.io/ascend/cann:9.0.0-910b-ubuntu22.04-py3.11 \
--soc_version ascend910b1
```
需要时可以覆盖 Megatron 或 MindSpeed 源码分支:
```bash
python docker/build_image.py \
--image_type ascend \
--megatron_branch v0.15.3 \
--mindspeed_branch core_r0.15.3
```
如果构建时网络较慢Linux 宿主机可以在根目录 `Dockerfile` 生成后使用 host network 构建:
```bash
docker build --network host \
-t ${DOCKER_REGISTRY}:main-A2-py311-CANN9.0.0-ubuntu22.04-arm \
-f Dockerfile .
```
## 运行 Ascend 容器
宿主机需要提前安装兼容的 Ascend driver 和 firmware。容器通过挂载宿主机 NPU 设备和 driver 库使用昇腾硬件。
```bash
docker run --rm -it \
--name ms_swift_ascend \
--device /dev/davinci0 \
--device /dev/davinci_manager \
--device /dev/devmm_svm \
--device /dev/hisi_hdc \
-v /usr/local/dcmi:/usr/local/dcmi \
-v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi \
-v /usr/local/Ascend/driver/lib64:/usr/local/Ascend/driver/lib64 \
-v /usr/local/Ascend/driver/version.info:/usr/local/Ascend/driver/version.info \
-v /etc/ascend_install.info:/etc/ascend_install.info \
-v /mnt/workspace:/mnt/workspace \
${DOCKER_REGISTRY}:main-A2-py311-CANN9.0.0-ubuntu22.04-arm \
bash
```
进入容器后可以验证 NPU 和 Python 包:
```bash
npu-smi info
python -c "import torch, torch_npu; print(torch.__version__, torch_npu.__version__)"
python -c "import vllm, vllm_ascend; print('vllm ascend ok')"
pip show ms-swift modelscope torch-npu triton-ascend
```
## 环境变量
| 变量 | 值 |
| --- | --- |
| `SOC_VERSION` | 选定的 Ascend SoC例如 `ascend910b1``ascend910_9391` |
| `CANN_VERSION` | 从基础镜像 tag 解析得到 |
| `MEGATRON_LM_PATH` | `/Megatron-LM` |
| `PYTHONPATH` | 包含 `/Megatron-LM` |
| `VLLM_USE_MODELSCOPE` | `True` |
| `LMDEPLOY_USE_MODELSCOPE` | `True` |
| `MODELSCOPE_CACHE` | `/mnt/workspace/.cache/modelscope/hub` |
## 注意事项
- CANN、firmware 和 driver 版本必须互相兼容。
- 这个 Dockerfile 对 CANN `8.5.*` 和 CANN `9.0.0` 使用不同的 `triton-ascend` 安装路径。
- 该镜像面向 Ascend NPU 上的 ms-swift 工作流。依赖安装过程中引入且与 NPU runtime 冲突的 CUDA-only 包会被移除。
- 生产任务建议使用固定镜像 tag不要依赖浮动分支名。
## License
ms-swift 和 ModelScope 组件遵循各自上游仓库的 license。CANN、MindSpeed、torch-npu、vLLM Ascend 以及其他预装第三方组件遵循各自上游 license。