[docker] upgrade NPU images to CANN 9.1 and PyTorch 2.10 (#10729)

This commit is contained in:
xvxuopop
2026-08-10 11:20:41 +08:00
committed by GitHub
parent 63a89710c7
commit 0bbe481e6e
10 changed files with 297 additions and 384 deletions

View File

@@ -1,6 +1,6 @@
# https://hub.docker.com/r/ascendai/cann/tags
ARG BASE_IMAGE=quay.io/ascend/cann:9.0.0-910b-ubuntu22.04-py3.11
ARG BASE_IMAGE=quay.io/ascend/cann:9.1.0-910b-ubuntu22.04-py3.12
FROM ${BASE_IMAGE}
# Installation arguments

View File

@@ -1,6 +1,6 @@
# LLaMA Factory for Ascend NPU
# LlamaFactory Image for Ascend NPU
LLaMA Factory Ascend NPU images provide a ready-to-use environment for fine-tuning, evaluating, and serving large language and multimodal models on Huawei Ascend Atlas NPUs. The images are based on Ascend CANN container images and include LLaMA Factory, Python, PyTorch, torch-npu, Triton Ascend, DeepSpeed, and the metric dependencies used by LLaMA Factory.
LlamaFactory Ascend NPU images are designed for Huawei Ascend Atlas NPUs and provide a ready-to-use LlamaFactory environment. Built on Ascend CANN container images, they include Python, PyTorch, TorchNPU, DeepSpeed, LlamaFactory, and other components.
For installation and troubleshooting details, see the [English NPU installation guide](https://llamafactory.readthedocs.io/en/latest/multibackend/npu/npu_installation.html).
@@ -11,77 +11,68 @@ For installation and troubleshooting details, see the [English NPU installation
- `quay.io/ascend/llamafactory`
- Dockerfile: `docker/docker-npu/Dockerfile`
- Docker Compose file: `docker/docker-npu/docker-compose.yml`
- Default base image: `quay.io/ascend/cann:9.0.0-910b-ubuntu22.04-py3.11`
- Supported accelerators: Ascend A2 and A3
- Supported container operating systems: Ubuntu 22.04 and openEuler 24.03
- Target CPU architectures: `linux/amd64` and `linux/arm64`
- Exposed ports:
- `7860`: LLaMA Board Web UI
- `8000`: API service
- Ascend environment script: `/usr/local/Ascend/ascend-toolkit/set_env.sh`
The current image variants are:
The following `latest` NPU image tags are available:
| Accelerator | Container OS | CANN base image |
| Hardware series | Operating system | Tag |
| --- | --- | --- |
| A2 | Ubuntu 22.04 | `quay.io/ascend/cann:9.0.0-910b-ubuntu22.04-py3.11` |
| A3 | Ubuntu 22.04 | `quay.io/ascend/cann:9.0.0-a3-ubuntu22.04-py3.11` |
| A2 | openEuler 24.03 | `quay.io/ascend/cann:9.0.0-910b-openeuler24.03-py3.11` |
| A3 | openEuler 24.03 | `quay.io/ascend/cann:9.0.0-a3-openeuler24.03-py3.11` |
| A2 | Ubuntu 22.04 | `latest-910b-ubuntu` |
| A3 | Ubuntu 22.04 | `latest-a3-ubuntu` |
| A2 | openEuler 24.03 | `latest-910b-openeuler` |
| A3 | openEuler 24.03 | `latest-a3-openeuler` |
## Image Contents and Intended Use
## Image Overview
The image is intended for Ascend NPU training, fine-tuning, evaluation, Web UI, and API workflows supported by LLaMA Factory. It installs the following core components:
The image includes the following core components:
| Component | Version or source |
| Component | Version |
| --- | --- |
| CANN | Inherited from the selected CANN 9.0.0 base image |
| Python | Python 3.11, inherited from the base image |
| PyTorch | `2.7.1` |
| torch-npu | `2.7.1.post4` |
| torchvision | `0.22.1` |
| torchaudio | `2.7.1` |
| CANN | `9.1.0` |
| Python | `3.12` |
| PyTorch | `2.10.0` |
| TorchNPU | `2.10.0.post2` |
| torchvision / torchaudio | `0.25.0` / `2.10.0` |
| Transformers | Latest compatible version at build time |
| Triton Ascend | `3.2.1` |
| DeepSpeed | `>=0.10.0,<=0.18.4` |
| LLaMA Factory | Installed from the repository build context |
| DeepSpeed | Latest compatible version at build time |
| LlamaFactory | Installed from the repository build context |
The image does not include model weights or datasets. Mount or download them separately and comply with their respective licenses and acceptable-use requirements.
## Image Tags and Dockerfile Archive
## Image Tags
Images use the following tag format:
NPU `latest` and release tags use different formats; the following rules do not apply to CUDA images.
Non-release builds reuse the following short tags. Each scheduled build updates the image referenced by the corresponding tag:
```text
<llamafactory-version>-cann<cann-version>-torch_npu<torch-npu-version>-<accelerator>-<os>-<python-version>
latest-<chip>-<os>
```
| Field | Values | Description |
| --- | --- | --- |
| `chip` | `910b` or `a3` | Ascend chip model supported by the image |
| `os` | `ubuntu` or `openeuler` | Container operating system family |
Release builds use full tags:
```text
<LlamaFactory-version>-cann<CANN-version>-torch_npu<TorchNPU-version>-<chip>-<os>-<Python-version>
```
| Field | Example | Description |
| --- | --- | --- |
| `llamafactory-version` | `latest` or `0.9.6` | Non-release builds use `latest`; release builds use the LLaMA Factory version |
| `cann-version` | `9.0.0` | Parsed from the CANN base image tag |
| `torch-npu-version` | `2.7.1` | Parsed from `requirements/npu.txt`; a suffix such as `.post4` is not included in the image tag |
| `accelerator` | `A2` or `A3` | Ascend hardware generation selected for the image |
| `os` | `ubuntu` or `openeuler` | Container operating system family |
| `python-version` | `py3.11` | Parsed from the CANN base image tag |
| `LlamaFactory-version` | `0.9.5` | LlamaFactory release version |
| `CANN-version` | `9.1.0` | Parsed from the CANN base image tag |
| `TorchNPU-version` | `2.10.0.post2` | Full TorchNPU version used by the image, including suffixes such as `.postN` |
| `chip` | `910b` or `a3` | Ascend chip model supported by the image |
| `os` | `ubuntu22.04` or `openeuler24.03` | Container operating system family and version |
| `Python-version` | `py3.12` | Parsed from the CANN base image tag |
Examples:
For example:
```text
latest-cann9.0.0-torch_npu2.7.1-A2-ubuntu-py3.11
latest-cann9.0.0-torch_npu2.7.1-A3-openeuler-py3.11
0.9.6-cann9.0.0-torch_npu2.7.1-A3-ubuntu-py3.11
```
The CPU architecture is not part of the tag. Published images are configured as multi-platform images, and Docker selects the `linux/amd64` or `linux/arm64` manifest for the host automatically.
The Dockerfile and its distribution overview are archived together at:
```text
docker/docker-npu/
├── Dockerfile
├── OVERVIEW.md
├── OVERVIEW.zh.md
└── docker-compose.yml
0.9.5-cann9.1.0-torch_npu2.10.0.post2-a3-ubuntu22.04-py3.12
```
## Quick Start
@@ -94,33 +85,30 @@ Before starting a container:
2. Verify that `npu-smi info` works on the host.
3. Install Docker with permission to access the required Ascend device nodes and driver files.
Driver, firmware, CANN, torch-npu, and the target Ascend hardware must be mutually compatible.
Driver, firmware, CANN, TorchNPU, and the target Ascend hardware must be mutually compatible.
### Pull and Run
The following example starts the latest A2 Ubuntu image with one NPU. Change the image tag and `/dev/davinci0` as needed.
The following example starts the latest A2 Ubuntu image with one NPU. Adjust `DOCKER_IMAGE` and the `--device` options for your environment.
```bash
export IMAGE=quay.io/ascend/llamafactory:latest-cann9.0.0-torch_npu2.7.1-A2-ubuntu-py3.11
docker pull "$IMAGE"
CONTAINER_NAME=llamafactory-npu
DOCKER_IMAGE=hiyouga/llamafactory:latest-910b-ubuntu
docker run --rm -it \
--name llamafactory-npu \
--ipc=host \
--net=host \
--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:/usr/local/Ascend/driver \
-v /usr/local/dcmi:/usr/local/dcmi \
-v /etc/ascend_install.info:/etc/ascend_install.info \
-v "$HOME/.cache/huggingface:/root/.cache/huggingface" \
-p 7860:7860 \
-p 8000:8000 \
"$IMAGE" \
bash
-v /usr/local/Ascend/driver:/usr/local/Ascend/driver \
-v /data:/data \
--name "$CONTAINER_NAME" \
"$DOCKER_IMAGE" \
/bin/bash
```
The host path for `npu-smi` may be `/usr/local/sbin/npu-smi` on some driver installations. Adjust the mount source when necessary. Add more `--device=/dev/davinci<N>` options to expose additional NPUs.
@@ -134,22 +122,16 @@ python -c "import torch, torch_npu; print(torch.__version__, torch_npu.__version
llamafactory-cli help
```
Start LLaMA Board when needed:
```bash
llamafactory-cli webui
```
### Build Locally
Run the build from the repository root. The following example builds the A3 openEuler variant:
Run the build from the repository root. The following example builds the A2 Ubuntu variant:
```bash
docker build \
-f ./docker/docker-npu/Dockerfile \
--build-arg BASE_IMAGE=quay.io/ascend/cann:9.0.0-a3-openeuler24.03-py3.11 \
--build-arg BASE_IMAGE=quay.io/ascend/cann:9.1.0-910b-ubuntu22.04-py3.12 \
--build-arg PIP_INDEX=https://pypi.org/simple \
-t llamafactory:npu-a3-openeuler \
-t llamafactory:npu-910b-ubuntu \
.
```
@@ -157,76 +139,45 @@ Available build arguments:
| Argument | Default | Purpose |
| --- | --- | --- |
| `BASE_IMAGE` | A2 Ubuntu CANN 9.0.0 image | Selects the accelerator and container OS variant |
| `BASE_IMAGE` | `quay.io/ascend/cann:9.1.0-910b-ubuntu22.04-py3.12` | Selects the base image that matches the device model and container operating system |
| `PIP_INDEX` | `https://pypi.org/simple` | Selects the Python package index |
| `PYTORCH_INDEX` | `https://download.pytorch.org/whl/cpu` | Selects the PyTorch wheel index used with torch-npu |
| `PYTORCH_INDEX` | `https://download.pytorch.org/whl/cpu` | Selects the PyTorch wheel index used with TorchNPU |
| `HTTP_PROXY` | Empty | Provides an optional HTTP/HTTPS proxy during the build |
Docker Compose can build and start each supported variant:
### Start with Docker Compose
The preceding `docker build` command invokes the Dockerfile directly. It builds an image but does not start a container. Docker Compose does not use a separate build implementation: it reads the presets in `docker-compose.yml`, reuses the same Dockerfile, and selects a hardware-series and operating-system combination through a profile. Each `up -d` command below starts the selected container in the background. If the image is not available locally, Docker Compose builds it first:
```bash
cd docker/docker-npu
# A2 with Ubuntu
docker compose up -d llamafactory-a2-ubuntu
docker compose --profile a2-ubuntu up -d
# A3 with Ubuntu
docker compose --profile a3 up -d llamafactory-a3-ubuntu
docker compose --profile a3-ubuntu up -d
# A2 with openEuler
docker compose --profile openeuler up -d llamafactory-a2-openeuler
docker compose --profile a2-openeuler up -d
# A3 with openEuler
docker compose --profile a3-openeuler up -d llamafactory-a3-openeuler
docker compose --profile a3-openeuler up -d
```
### Extend or Develop from the Image
For interactive development, mount a local checkout and reinstall it in editable mode inside the container:
```bash
git clone https://github.com/hiyouga/LLaMA-Factory.git
cd LLaMA-Factory
# Add the same Ascend --device and driver mount options shown above.
docker run --rm -it \
--ipc=host \
-v "$PWD:/workspace/LLaMA-Factory" \
-w /workspace/LLaMA-Factory \
"$IMAGE" \
bash
pip install -e . --no-build-isolation
```
For a reproducible derived image, create a separate Dockerfile:
```dockerfile
FROM quay.io/ascend/llamafactory:latest-cann9.0.0-torch_npu2.7.1-A2-ubuntu-py3.11
COPY requirements-extension.txt /tmp/requirements-extension.txt
RUN pip install --no-cache-dir -r /tmp/requirements-extension.txt
COPY . /workspace/application
WORKDIR /workspace/application
```
Pass Ascend devices and driver mounts when running the derived image; device access should not be embedded in the image itself.
To build an image with Docker Compose without starting a container, use `docker compose --profile <profile> build`.
## Hardware Support and Compatibility Notes
- A2 images use the `910b` CANN base image; A3 images use the `a3` CANN base image.
- The image build targets both x86-64 (`linux/amd64`) and AArch64 (`linux/arm64`) hosts. This CPU architecture is independent of whether the accelerator is A2 or A3.
- The image build targets both x86-64 (`linux/amd64`) and AArch64 (`linux/arm64`) hosts. The CPU architecture is independent of whether the hardware series is A2 or A3.
- Ubuntu 22.04 and openEuler 24.03 refer to the operating system inside the container.
- The current dependency baseline aligns PyTorch `2.7.1` with torch-npu `2.7.1.post4`. Upgrading either package independently may break compatibility.
- Use a fixed release tag for reproducible production deployments. The `latest` tag can change after scheduled builds.
- Legacy short tags such as `latest-npu-a2` do not encode the CANN, torch-npu, operating system, or Python versions. Prefer the full tag format documented above.
- Legacy NPU tags are replaced by the `latest-<910b|a3>-<ubuntu|openeuler>` format.
- Validate the exact driver, firmware, CANN, and SoC combination before production deployment.
## License and Disclaimer
LLaMA Factory is distributed under the [Apache License 2.0](../../LICENSE).
LlamaFactory is distributed under the [Apache License 2.0](../../LICENSE).
Ascend CANN, torch-npu, Triton Ascend, DeepSpeed, base operating-system packages, model weights, datasets, and other third-party components are governed by their respective licenses and terms. The LLaMA Factory license does not replace or override those terms.
Ascend CANN, TorchNPU, Triton Ascend, DeepSpeed, base operating-system packages, model weights, datasets, and other third-party components are governed by their respective licenses and terms. The LlamaFactory license does not replace or override those terms.
The image is provided on an "AS IS" basis, without warranties or conditions of any kind. Users are responsible for validating hardware and software compatibility, securing the container and its runtime configuration, complying with applicable licenses and laws, and reviewing model and dataset terms before training, evaluation, or deployment.

View File

@@ -1,8 +1,8 @@
# 面向昇腾 NPU 的 LLaMA Factory 镜像
# 面向昇腾 NPU 的 LlamaFactory 镜像
LLaMA Factory 昇腾 NPU 镜像面向华为昇腾 Atlas NPU提供可直接用于大语言模型和多模态模型微调、评测与服务部署的运行环境。镜像基于昇腾 CANN 容器镜像构建,预装 LLaMA Factory、Python、PyTorch、torch-npu、Triton Ascend、DeepSpeed 和 LLaMA Factory 评测依赖
LlamaFactory 昇腾 NPU 镜像面向华为昇腾 Atlas NPU提供可直接使用的 LlamaFactory 环境。镜像基于昇腾 CANN 容器镜像构建,预装 Python、PyTorch、TorchNPU、DeepSpeed、LlamaFactory 等组件
安装方法和问题排查请参考 [LLaMA Factory NPU 安装及配置文档](https://llamafactory.readthedocs.io/zh-cn/latest/multibackend/npu/npu_installation.html)。
安装方法和问题排查请参考 [LlamaFactory NPU 安装及配置文档](https://llamafactory.readthedocs.io/zh-cn/latest/multibackend/npu/npu_installation.html)。
## 快速参考
@@ -11,77 +11,68 @@ LLaMA Factory 昇腾 NPU 镜像面向华为昇腾 Atlas NPU提供可直接用
- `quay.io/ascend/llamafactory`
- Dockerfile`docker/docker-npu/Dockerfile`
- Docker Compose 文件:`docker/docker-npu/docker-compose.yml`
- 默认基础镜像:`quay.io/ascend/cann:9.0.0-910b-ubuntu22.04-py3.11`
- 支持的加速器:昇腾 A2、A3
- 支持的容器操作系统Ubuntu 22.04、openEuler 24.03
- 目标 CPU 架构:`linux/amd64``linux/arm64`
- 对外端口:
- `7860`LLaMA Board Web UI
- `8000`API 服务
- 昇腾环境脚本:`/usr/local/Ascend/ascend-toolkit/set_env.sh`
当前提供以下镜像组合
当前提供以下 `latest` NPU 镜像 tag
| 加速器 | 容器操作系统 | CANN 基础镜像 |
| 硬件系列 | 操作系统 | Tag |
| --- | --- | --- |
| A2 | Ubuntu 22.04 | `quay.io/ascend/cann:9.0.0-910b-ubuntu22.04-py3.11` |
| A3 | Ubuntu 22.04 | `quay.io/ascend/cann:9.0.0-a3-ubuntu22.04-py3.11` |
| A2 | openEuler 24.03 | `quay.io/ascend/cann:9.0.0-910b-openeuler24.03-py3.11` |
| A3 | openEuler 24.03 | `quay.io/ascend/cann:9.0.0-a3-openeuler24.03-py3.11` |
| A2 | Ubuntu 22.04 | `latest-910b-ubuntu` |
| A3 | Ubuntu 22.04 | `latest-a3-ubuntu` |
| A2 | openEuler 24.03 | `latest-910b-openeuler` |
| A3 | openEuler 24.03 | `latest-a3-openeuler` |
## 镜像介绍
镜像用于运行 LLaMA Factory 支持的昇腾 NPU 训练、微调、评测、Web UI 和 API 服务,主要包含以下组件:
镜像内预装以下主要组件:
| 组件 | 版本或来源 |
| 组件 | 版本 |
| --- | --- |
| CANN | 继承自所选 CANN 9.0.0 基础镜像 |
| Python | Python 3.11,继承自基础镜像 |
| PyTorch | `2.7.1` |
| torch-npu | `2.7.1.post4` |
| torchvision | `0.22.1` |
| torchaudio | `2.7.1` |
| CANN | `9.1.0` |
| Python | `3.12` |
| PyTorch | `2.10.0` |
| TorchNPU | `2.10.0.post2` |
| torchvision / torchaudio | `0.25.0` / `2.10.0` |
| Transformers | 构建时的最新兼容版本 |
| Triton Ascend | `3.2.1` |
| DeepSpeed | `>=0.10.0,<=0.18.4` |
| LLaMA Factory | 从构建上下文中的仓库源码安装 |
| DeepSpeed | 构建时的最新兼容版本 |
| LlamaFactory | 从构建上下文中的仓库源码安装 |
镜像不包含模型权重和数据集。请通过目录挂载或运行时下载的方式单独提供,并遵守对应的许可证和使用要求。
## 镜像 Tag 说明与 Dockerfile 归档路径
## 镜像 Tag 说明
镜像使用以下 tag 格式:
NPU 镜像的 `latest` 和 release tag 使用不同格式;以下规则不适用于 CUDA 镜像。
非 release 构建复用以下简短 tag每次定时构建会更新对应 tag 所指向的镜像:
```text
<llamafactory版本>-cann<CANN版本>-torch_npu<torch-npu版本>-<加速器>-<操作系统>-<Python版本>
latest-<芯片信息>-<操作系统>
```
| 字段 | 可选值 | 说明 |
| --- | --- | --- |
| `芯片信息` | `910b``a3` | 镜像所适配的昇腾芯片型号 |
| `操作系统` | `ubuntu``openeuler` | 容器操作系统类型 |
Release 构建使用完整 tag
```text
<LlamaFactory版本>-cann<CANN版本>-torch_npu<TorchNPU版本>-<芯片信息>-<操作系统>-<Python版本>
```
| 字段 | 示例 | 说明 |
| --- | --- | --- |
| `llamafactory版本` | `latest``0.9.6` | 非 release 构建使用 `latest`release 构建使用 LLaMA Factory 版本号 |
| `CANN版本` | `9.0.0` | 从 CANN 基础镜像 tag 中提取 |
| `torch-npu版本` | `2.7.1` | 从 `requirements/npu.txt` 中提取,镜像 tag 不包含 `.post4` 等后缀 |
| `加速器` | `A2``A3` | 当前镜像所适配的昇腾硬件代际 |
| `操作系统` | `ubuntu``openeuler` | 容器操作系统类型 |
| `Python版本` | `py3.11` | 从 CANN 基础镜像 tag 中提取 |
| `LlamaFactory版本` | `0.9.5` | LlamaFactory release 版本号 |
| `CANN版本` | `9.1.0` | 从 CANN 基础镜像 tag 中提取 |
| `TorchNPU版本` | `2.10.0.post2` | 镜像使用的 TorchNPU 完整版本,包含 `.postN` 等后缀 |
| `芯片信息` | `910b``a3` | 镜像所适配的昇腾芯片型号 |
| `操作系统` | `ubuntu22.04``openeuler24.03` | 容器操作系统类型和版本 |
| `Python版本` | `py3.12` | 从 CANN 基础镜像 tag 中提取 |
例:
```text
latest-cann9.0.0-torch_npu2.7.1-A2-ubuntu-py3.11
latest-cann9.0.0-torch_npu2.7.1-A3-openeuler-py3.11
0.9.6-cann9.0.0-torch_npu2.7.1-A3-ubuntu-py3.11
```
CPU 架构不写入 tag。发布镜像配置为多架构镜像Docker 拉取时会根据宿主机自动选择 `linux/amd64``linux/arm64` 版本。
Dockerfile 和用于镜像分发的概述文件在同一目录归档:
```text
docker/docker-npu/
├── Dockerfile
├── OVERVIEW.md
├── OVERVIEW.zh.md
└── docker-compose.yml
0.9.5-cann9.1.0-torch_npu2.10.0.post2-a3-ubuntu22.04-py3.12
```
## 快速开始
@@ -94,33 +85,30 @@ docker/docker-npu/
2. 确认宿主机执行 `npu-smi info` 可以正常识别 NPU。
3. 安装 Docker并确保当前用户有权访问所需的昇腾设备节点和驱动文件。
驱动、固件、CANN、torch-npu 与目标昇腾硬件需要保持兼容。
驱动、固件、CANN、TorchNPU 与目标昇腾硬件需要保持兼容。
### 拉取并运行镜像
以下示例使用一张 NPU 启动最新的 A2 Ubuntu 镜像。请根据实际环境修改镜像 tag 和 `/dev/davinci0`
以下示例使用一张 NPU 启动最新的 A2 Ubuntu 镜像。请根据实际情况修改 ``DOCKER_IMAGE`` 和 ``device``
```bash
export IMAGE=quay.io/ascend/llamafactory:latest-cann9.0.0-torch_npu2.7.1-A2-ubuntu-py3.11
docker pull "$IMAGE"
CONTAINER_NAME=llamafactory-npu
DOCKER_IMAGE=hiyouga/llamafactory:latest-910b-ubuntu
docker run --rm -it \
--name llamafactory-npu \
--ipc=host \
--net=host \
--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:/usr/local/Ascend/driver \
-v /usr/local/dcmi:/usr/local/dcmi \
-v /etc/ascend_install.info:/etc/ascend_install.info \
-v "$HOME/.cache/huggingface:/root/.cache/huggingface" \
-p 7860:7860 \
-p 8000:8000 \
"$IMAGE" \
bash
-v /usr/local/Ascend/driver:/usr/local/Ascend/driver \
-v /data:/data \
--name "$CONTAINER_NAME" \
"$DOCKER_IMAGE" \
/bin/bash
```
部分驱动环境中的 `npu-smi` 位于 `/usr/local/sbin/npu-smi`,此时需要调整挂载源路径。使用多张 NPU 时,继续追加 `--device=/dev/davinci<N>` 参数。
@@ -134,22 +122,16 @@ python -c "import torch, torch_npu; print(torch.__version__, torch_npu.__version
llamafactory-cli help
```
需要使用 LLaMA Board 时执行:
### 本地构建镜像
```bash
llamafactory-cli webui
```
### 本地构建
在仓库根目录执行构建。以下示例构建 A3 openEuler 镜像:
在仓库根目录执行构建。以下示例构建 A2 Ubuntu 镜像:
```bash
docker build \
-f ./docker/docker-npu/Dockerfile \
--build-arg BASE_IMAGE=quay.io/ascend/cann:9.0.0-a3-openeuler24.03-py3.11 \
--build-arg BASE_IMAGE=quay.io/ascend/cann:9.1.0-910b-ubuntu22.04-py3.12 \
--build-arg PIP_INDEX=https://pypi.org/simple \
-t llamafactory:npu-a3-openeuler \
-t llamafactory:npu-910b-ubuntu \
.
```
@@ -157,76 +139,45 @@ docker build \
| 参数 | 默认值 | 用途 |
| --- | --- | --- |
| `BASE_IMAGE` | A2 Ubuntu CANN 9.0.0 镜像 | 选择加速器和容器操作系统组合 |
| `BASE_IMAGE` | `quay.io/ascend/cann:9.1.0-910b-ubuntu22.04-py3.12` | 根据设备型号和容器操作系统选择对应的基础镜像 |
| `PIP_INDEX` | `https://pypi.org/simple` | 指定 Python 软件包索引 |
| `PYTORCH_INDEX` | `https://download.pytorch.org/whl/cpu` | 指定配合 torch-npu 使用的 PyTorch wheel 索引 |
| `PYTORCH_INDEX` | `https://download.pytorch.org/whl/cpu` | 指定配合 TorchNPU 使用的 PyTorch wheel 索引 |
| `HTTP_PROXY` | 空 | 构建期间可选的 HTTP/HTTPS 代理 |
也可以通过 Docker Compose 构建并启动各个组合:
### 通过 Docker Compose 启动
前面的 `docker build` 命令直接调用 Dockerfile只构建镜像不启动容器。Docker Compose 不使用另一套构建逻辑:它读取 `docker-compose.yml` 中的预设配置,复用同一个 Dockerfile并通过 profile 选择硬件系列和操作系统组合。下面的 `up -d` 会在后台启动容器若本地镜像不存在Docker Compose 会先构建镜像:
```bash
cd docker/docker-npu
# A2 + Ubuntu
docker compose up -d llamafactory-a2-ubuntu
docker compose --profile a2-ubuntu up -d
# A3 + Ubuntu
docker compose --profile a3 up -d llamafactory-a3-ubuntu
docker compose --profile a3-ubuntu up -d
# A2 + openEuler
docker compose --profile openeuler up -d llamafactory-a2-openeuler
docker compose --profile a2-openeuler up -d
# A3 + openEuler
docker compose --profile a3-openeuler up -d llamafactory-a3-openeuler
docker compose --profile a3-openeuler up -d
```
### 二次开发
交互式开发时,可以将本地源码挂载到容器中,并在容器内以 editable 模式重新安装:
```bash
git clone https://github.com/hiyouga/LLaMA-Factory.git
cd LLaMA-Factory
# 同时添加前述昇腾 --device 和驱动目录挂载参数。
docker run --rm -it \
--ipc=host \
-v "$PWD:/workspace/LLaMA-Factory" \
-w /workspace/LLaMA-Factory \
"$IMAGE" \
bash
pip install -e . --no-build-isolation
```
需要可复现的派生镜像时,可以新建独立 Dockerfile
```dockerfile
FROM quay.io/ascend/llamafactory:latest-cann9.0.0-torch_npu2.7.1-A2-ubuntu-py3.11
COPY requirements-extension.txt /tmp/requirements-extension.txt
RUN pip install --no-cache-dir -r /tmp/requirements-extension.txt
COPY . /workspace/application
WORKDIR /workspace/application
```
运行派生镜像时仍需传入昇腾设备和驱动挂载参数,不应将设备访问配置固化到镜像中。
如果只想通过 Docker Compose 构建镜像而不启动容器,请使用 `docker compose --profile <profile> build`。
## 硬件支持与兼容性说明
- A2 镜像使用标记为 `910b` 的 CANN 基础镜像A3 镜像使用标记为 `a3` 的 CANN 基础镜像。
- 镜像构建目标同时包含 x86-64`linux/amd64`)和 AArch64`linux/arm64`宿主机。CPU 架构与加速器属于 A2 还是 A3 无关。
- 镜像构建目标同时包含 x86-64`linux/amd64`)和 AArch64`linux/arm64`宿主机。CPU 架构与硬件系列是 A2 还是 A3 无关。
- Ubuntu 22.04 和 openEuler 24.03 指容器内部的操作系统。
- 当前依赖基线将 PyTorch `2.7.1` 与 torch-npu `2.7.1.post4` 配套使用。单独升级其中一个软件包可能破坏兼容性
- 生产环境建议使用固定 release tag以确保部署可复现定时构建可能更新 `latest` tag。
- `latest-npu-a2` 等旧式短 tag 没有体现 CANN、torch-npu、操作系统和 Python 版本,建议迁移到本文所述的完整 tag。
- 旧式 NPU tag 已由 `latest-<910b|a3>-<ubuntu|openeuler>` 格式取代。
- 正式部署前请验证具体驱动、固件、CANN 和 SoC 组合的兼容性。
## 许可证与免责声明
LLaMA Factory 基于 [Apache License 2.0](../../LICENSE) 发布。
LlamaFactory 基于 [Apache License 2.0](../../LICENSE) 发布。
昇腾 CANN、torch-npu、Triton Ascend、DeepSpeed、基础操作系统软件包、模型权重、数据集和其他第三方组件分别受其自身许可证与条款约束。LLaMA Factory 的许可证不会替代或覆盖这些条款。
昇腾 CANN、TorchNPU、Triton Ascend、DeepSpeed、基础操作系统软件包、模型权重、数据集和其他第三方组件分别受其自身许可证与条款约束。LlamaFactory 的许可证不会替代或覆盖这些条款。
本镜像按“原样”提供,不附带任何明示或暗示的保证。用户需要自行验证软硬件兼容性、保障容器及运行配置的安全、遵守适用的许可证和法律,并在训练、评测或部署前审查模型与数据集的使用条款。

View File

@@ -26,25 +26,26 @@ x-npu-common: &npu-common
services:
llamafactory-a2-ubuntu:
<<: *npu-common
profiles: ["a2-ubuntu"]
build:
<<: *build
args:
<<: *build-args
BASE_IMAGE: quay.io/ascend/cann:9.0.0-910b-ubuntu22.04-py3.11
container_name: llamafactory-a2-ubuntu
image: llamafactory:npu-a2-ubuntu
BASE_IMAGE: quay.io/ascend/cann:9.1.0-910b-ubuntu22.04-py3.12
container_name: llamafactory-910b-ubuntu
image: llamafactory:npu-910b-ubuntu
ports:
- "7860:7860"
- "8000:8000"
llamafactory-a3-ubuntu:
<<: *npu-common
profiles: ["a3"]
profiles: ["a3-ubuntu"]
build:
<<: *build
args:
<<: *build-args
BASE_IMAGE: quay.io/ascend/cann:9.0.0-a3-ubuntu22.04-py3.11
BASE_IMAGE: quay.io/ascend/cann:9.1.0-a3-ubuntu22.04-py3.12
container_name: llamafactory-a3-ubuntu
image: llamafactory:npu-a3-ubuntu
ports:
@@ -53,14 +54,14 @@ services:
llamafactory-a2-openeuler:
<<: *npu-common
profiles: ["openeuler"]
profiles: ["a2-openeuler"]
build:
<<: *build
args:
<<: *build-args
BASE_IMAGE: quay.io/ascend/cann:9.0.0-910b-openeuler24.03-py3.11
container_name: llamafactory-a2-openeuler
image: llamafactory:npu-a2-openeuler
BASE_IMAGE: quay.io/ascend/cann:9.1.0-910b-openeuler24.03-py3.12
container_name: llamafactory-910b-openeuler
image: llamafactory:npu-910b-openeuler
ports:
- "7862:7860"
- "8002:8000"
@@ -72,7 +73,7 @@ services:
<<: *build
args:
<<: *build-args
BASE_IMAGE: quay.io/ascend/cann:9.0.0-a3-openeuler24.03-py3.11
BASE_IMAGE: quay.io/ascend/cann:9.1.0-a3-openeuler24.03-py3.12
container_name: llamafactory-a3-openeuler
image: llamafactory:npu-a3-openeuler
ports: