[docker] improve NPU image build and distribution (#10664)

This commit is contained in:
xvxuopop
2026-07-24 15:22:01 +08:00
committed by GitHub
parent d0eaa10b0c
commit 19e9fe3ced
7 changed files with 701 additions and 96 deletions

View File

@@ -29,8 +29,6 @@ jobs:
matrix:
include:
- device: "cuda"
- device: "npu-a2"
- device: "npu-a3"
runs-on: ubuntu-latest
@@ -71,14 +69,6 @@ jobs:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to Quay
if: ${{ github.event_name != 'pull_request' && startsWith(matrix.device, 'npu') }}
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ vars.QUAY_ASCEND_USERNAME }}
password: ${{ secrets.QUAY_ASCEND_TOKEN }}
- name: Build and push Docker image (CUDA)
if: ${{ matrix.device == 'cuda' }}
uses: docker/build-push-action@v6
@@ -88,29 +78,3 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
tags: |
docker.io/hiyouga/llamafactory:${{ steps.version.outputs.tag }}
- name: Build and push Docker image (NPU-A2)
if: ${{ matrix.device == 'npu-a2' }}
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
file: ./docker/docker-npu/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: |
docker.io/hiyouga/llamafactory:${{ steps.version.outputs.tag }}-npu-a2
quay.io/ascend/llamafactory:${{ steps.version.outputs.tag }}-npu-a2
- name: Build and push Docker image (NPU-A3)
if: ${{ matrix.device == 'npu-a3' }}
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
file: ./docker/docker-npu/Dockerfile
build-args: |
BASE_IMAGE=quay.io/ascend/cann:9.0.0-a3-ubuntu22.04-py3.11
push: ${{ github.event_name != 'pull_request' }}
tags: |
docker.io/hiyouga/llamafactory:${{ steps.version.outputs.tag }}-npu-a3
quay.io/ascend/llamafactory:${{ steps.version.outputs.tag }}-npu-a3

115
.github/workflows/docker_npu.yml vendored Normal file
View File

@@ -0,0 +1,115 @@
name: docker-npu
on:
workflow_dispatch:
schedule:
- cron: "17 2 * * *"
timezone: "Asia/Shanghai"
release:
types:
- published
jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- device: "npu-a2"
os: "ubuntu"
base_image: "quay.io/ascend/cann:9.0.0-910b-ubuntu22.04-py3.11"
- device: "npu-a3"
os: "ubuntu"
base_image: "quay.io/ascend/cann:9.0.0-a3-ubuntu22.04-py3.11"
- device: "npu-a2"
os: "openeuler"
base_image: "quay.io/ascend/cann:9.0.0-910b-openeuler24.03-py3.11"
- device: "npu-a3"
os: "openeuler"
base_image: "quay.io/ascend/cann:9.0.0-a3-openeuler24.03-py3.11"
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.device }}-${{ matrix.os }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
environment:
name: docker
url: https://hub.docker.com/r/hiyouga/llamafactory
steps:
- name: Free up disk space
uses: jlumbroso/free-disk-space@v1.3.1
with:
tool-cache: true
docker-images: false
- name: Checkout
uses: actions/checkout@v6
- name: Get llamafactory version
id: version
run: |
if [ "${{ github.event_name }}" = "release" ]; then
echo "tag=$(grep -oP 'VERSION = "\K[^"]+' src/llamafactory/extras/env.py)" >> "$GITHUB_OUTPUT"
else
echo "tag=latest" >> "$GITHUB_OUTPUT"
fi
- name: Get NPU image tag
id: npu_tag
env:
BASE_IMAGE: ${{ matrix.base_image }}
DEVICE: ${{ matrix.device }}
MATRIX_OS: ${{ matrix.os }}
LLAMAFACTORY_VERSION: ${{ steps.version.outputs.tag }}
run: |
base_image_tag="${BASE_IMAGE##*:}"
cann_version="${base_image_tag%%-*}"
torch_npu_version="$(sed -nE 's/^torch[-_]npu==([0-9]+(\.[0-9]+)*).*/\1/p' requirements/npu.txt)"
accelerator="${DEVICE#npu-}"
accelerator="${accelerator^^}"
operating_system="$(grep -oE '(ubuntu|openeuler)' <<< "${base_image_tag}" | head -n 1)"
python_version="$(grep -oE 'py[0-9]+\.[0-9]+' <<< "${base_image_tag}" | head -n 1)"
if [[ -z "${cann_version}" || -z "${torch_npu_version}" || -z "${operating_system}" || -z "${python_version}" ]]; then
echo "Failed to derive the NPU image tag from ${BASE_IMAGE} and requirements/npu.txt" >&2
exit 1
fi
if [[ "${operating_system}" != "${MATRIX_OS}" ]]; then
echo "Operating system ${operating_system} derived from ${BASE_IMAGE} does not match matrix OS ${MATRIX_OS}" >&2
exit 1
fi
echo "tag=${LLAMAFACTORY_VERSION}-cann${cann_version}-torch_npu${torch_npu_version}-${accelerator}-${operating_system}-${python_version}" >> "$GITHUB_OUTPUT"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to Quay
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ vars.QUAY_ASCEND_USERNAME }}
password: ${{ secrets.QUAY_ASCEND_TOKEN }}
- name: Build and push Docker image (${{ matrix.device }}-${{ matrix.os }})
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
file: ./docker/docker-npu/Dockerfile
build-args: |
BASE_IMAGE=${{ matrix.base_image }}
push: true
tags: |
docker.io/hiyouga/llamafactory:${{ steps.npu_tag.outputs.tag }}
quay.io/ascend/llamafactory:${{ steps.npu_tag.outputs.tag }}