From 470929bee1c794d5b4c166d9885d610a2607ab62 Mon Sep 17 00:00:00 2001 From: yaofengchen Date: Mon, 3 Nov 2025 10:47:46 +0000 Subject: [PATCH 1/9] add ascend_a3 Dockerfile --- docker/Dockerfile.ascend_a3 | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 docker/Dockerfile.ascend_a3 diff --git a/docker/Dockerfile.ascend_a3 b/docker/Dockerfile.ascend_a3 new file mode 100644 index 0000000000..ccfa85fbd1 --- /dev/null +++ b/docker/Dockerfile.ascend_a3 @@ -0,0 +1,40 @@ +# DOCKER_BUILDKIT=1 docker build --network=host -t lmdeploy_dlinfer:a3 -f Dockerfile.ascend_a3 . +ARG ASCEND_DEVICE=ascend_a3 +ARG ASCEND_HUB=swr.cn-south-1.myhuaweicloud.com/ascendhub + +FROM ${ASCEND_HUB}/cann:8.3.rc1.alpha002-a3-openeuler24.03-py3.11 AS ascend_a3_base + +FROM ${ASCEND_DEVICE}_base AS builder +ENV LMDEPLOY_TARGET_DEVICE=ascend +WORKDIR /opt/lmdeploy +COPY lmdeploy /opt/lmdeploy +RUN --mount=type=cache,target=/root/.cache \ + pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \ + pip config set global.trusted-host pypi.tuna.tsinghua.edu.cn && \ + pip install --no-cache-dir -U pip build && \ + python -m build -w -o /wheels -v . + +ENV DEVICE=ascend +ENV TORCH_DEVICE_BACKEND_AUTOLOAD=0 +WORKDIR /opt/dlinfer +COPY dlinfer /opt/dlinfer +RUN python -m build -w -o /wheels -v . + +FROM ${ASCEND_DEVICE}_base AS final +ENV DEBIAN_FRONTEND=noninteractive +RUN dnf update -y && \ + dnf install -y jemalloc jemalloc-devel && \ + dnf clean all + +ENV HCCL_CONNECT_TIMEOUT=7200 +ENV PYTORCH_NPU_ALLOC_CONF="expandable_segments:True" +ENV HCCL_OP_EXPANSION_MODE="AIV" +ENV LD_PRELOAD=/usr/lib64/libjemalloc.so.2:$LD_PRELOAD + +RUN --mount=type=cache,target=/root/.cache \ + pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \ + pip config set global.trusted-host pypi.tuna.tsinghua.edu.cn && \ + pip install --no-cache-dir torch==2.8.0 torch-npu==2.8.0rc1 torchvision==0.23.0 + +RUN --mount=type=cache,target=/wheels,from=builder,source=/wheels \ + pip install --no-cache-dir /wheels/*.whl From d53c8df1ae78939211ed02c9abaddca5de2f1c9c Mon Sep 17 00:00:00 2001 From: yaofengchen Date: Mon, 3 Nov 2025 11:08:38 +0000 Subject: [PATCH 2/9] fix lint --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8929ca93d0..16ee563385 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -41,7 +41,7 @@ repos: rev: v2.1.0 hooks: - id: codespell - args: ["--skip=third_party/*,*.ipynb,*.proto,src/turbomind/*,docker/Dockerfile.ascend,docs/en/get_started/ascend/get_started.md,docs/zh_cn/get_started/ascend/get_started.md"] + args: ["--skip=third_party/*,*.ipynb,*.proto,src/turbomind/*,docker/Dockerfile.ascend*,docs/en/get_started/ascend/get_started.md,docs/zh_cn/get_started/ascend/get_started.md"] - repo: https://github.com/myint/docformatter From 522b6ee81793283eaa001540d191a26a9cbeb1ae Mon Sep 17 00:00:00 2001 From: yaofengchen Date: Wed, 5 Nov 2025 08:25:22 +0000 Subject: [PATCH 3/9] refactor ascend Dockerfile --- docker/Dockerfile.ascend | 40 +++++++++++++++++----------------- docker/Dockerfile.ascend_a3 | 43 +++++++++++++------------------------ 2 files changed, 35 insertions(+), 48 deletions(-) diff --git a/docker/Dockerfile.ascend b/docker/Dockerfile.ascend index c069ac48d9..d40cab91ef 100644 --- a/docker/Dockerfile.ascend +++ b/docker/Dockerfile.ascend @@ -1,28 +1,28 @@ -# Run the following command in the root directory of lmdeploy to build the image: -# DOCKER_BUILDKIT=1 docker build --network=host -t lmdeploy_dlinfer:a2 -f docker/Dockerfile.ascend . -ARG ASCEND_DEVICE=ascend_a2 +# DOCKER_BUILDKIT=1 docker build --build-arg ASCEND_DEVICE_TYPE=ascend_a2 \ +# --build-arg DLINFER_TAG=main --build-arg LMDEPLOY_TAG=main --network=host \ +# -t lmdeploy_dlinfer:a2 -f docker/Dockerfile.ascend . +ARG ASCEND_DEVICE_TYPE=ascend_a2 ARG ASCEND_HUB=swr.cn-south-1.myhuaweicloud.com/ascendhub FROM ${ASCEND_HUB}/cann:8.1.rc1-910b-ubuntu22.04-py3.10 AS ascend_a2_base - FROM ${ASCEND_HUB}/cann:8.1.rc1-310p-ubuntu22.04-py3.10 AS ascend_300i_base -FROM ${ASCEND_DEVICE}_base AS builder -ENV LMDEPLOY_TARGET_DEVICE=ascend -WORKDIR /opt/lmdeploy -COPY . . -RUN --mount=type=cache,target=/root/.cache \ - pip config set global.index-url https://mirrors.aliyun.com/pypi/simple && \ - pip config set global.trusted-host mirrors.aliyun.com && \ - pip install --no-cache-dir -U pip build && \ - python -m build -w -o /wheels -v . +FROM ${ASCEND_DEVICE_TYPE}_base AS builder +ENV DEBIAN_FRONTEND=noninteractive +RUN apt update -y && \ + apt install -y libjemalloc-dev && \ + apt clean && rm -rf /var/lib/apt/lists/* -FROM ${ASCEND_DEVICE}_base AS final +ENV HCCL_CONNECT_TIMEOUT=7200 \ + PYTORCH_NPU_ALLOC_CONF="expandable_segments:True" \ + HCCL_OP_EXPANSION_MODE="AIV" \ + LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libjemalloc.so:$LD_PRELOAD +ARG DLINFER_TAG=main +ARG LMDEPLOY_TAG=main RUN --mount=type=cache,target=/root/.cache \ - pip config set global.index-url https://mirrors.aliyun.com/pypi/simple && \ - pip config set global.trusted-host mirrors.aliyun.com && \ - pip install --no-cache-dir torch==2.3.1 torch-npu==2.3.1 torchvision==0.18.1 - -RUN --mount=type=cache,target=/wheels,from=builder,source=/wheels \ - pip install --no-cache-dir /wheels/*.whl + pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \ + pip config set global.trusted-host pypi.tuna.tsinghua.edu.cn && \ + pip install --no-cache-dir torch==2.8.0 torch-npu==2.8.0rc1 torchvision==0.23.0 && \ + TORCH_DEVICE_BACKEND_AUTOLOAD=0 DEVICE=ascend pip install git+https://github.com/DeepLink-org/dlinfer.git@${DLINFER_TAG} && \ + LMDEPLOY_TARGET_DEVICE=ascend pip install git+https://github.com/InternLM/lmdeploy.git@${LMDEPLOY_TAG} diff --git a/docker/Dockerfile.ascend_a3 b/docker/Dockerfile.ascend_a3 index ccfa85fbd1..485b30b769 100644 --- a/docker/Dockerfile.ascend_a3 +++ b/docker/Dockerfile.ascend_a3 @@ -1,40 +1,27 @@ -# DOCKER_BUILDKIT=1 docker build --network=host -t lmdeploy_dlinfer:a3 -f Dockerfile.ascend_a3 . -ARG ASCEND_DEVICE=ascend_a3 +# DOCKER_BUILDKIT=1 docker build --build-arg ASCEND_DEVICE=ascend_a3 \ +# --build-arg DLINFER_TAG=main --build-arg LMDEPLOY_TAG=main --network=host \ +# -t lmdeploy_dlinfer:a3 -f Dockerfile.ascend_a3 . +ARG ASCEND_DEVICE_TYPE=ascend_a3 ARG ASCEND_HUB=swr.cn-south-1.myhuaweicloud.com/ascendhub FROM ${ASCEND_HUB}/cann:8.3.rc1.alpha002-a3-openeuler24.03-py3.11 AS ascend_a3_base -FROM ${ASCEND_DEVICE}_base AS builder -ENV LMDEPLOY_TARGET_DEVICE=ascend -WORKDIR /opt/lmdeploy -COPY lmdeploy /opt/lmdeploy -RUN --mount=type=cache,target=/root/.cache \ - pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \ - pip config set global.trusted-host pypi.tuna.tsinghua.edu.cn && \ - pip install --no-cache-dir -U pip build && \ - python -m build -w -o /wheels -v . - -ENV DEVICE=ascend -ENV TORCH_DEVICE_BACKEND_AUTOLOAD=0 -WORKDIR /opt/dlinfer -COPY dlinfer /opt/dlinfer -RUN python -m build -w -o /wheels -v . - -FROM ${ASCEND_DEVICE}_base AS final +FROM ${ASCEND_DEVICE_TYPE}_base AS builder ENV DEBIAN_FRONTEND=noninteractive RUN dnf update -y && \ dnf install -y jemalloc jemalloc-devel && \ - dnf clean all + dnf clean all && rm -rf /var/cache/dnf -ENV HCCL_CONNECT_TIMEOUT=7200 -ENV PYTORCH_NPU_ALLOC_CONF="expandable_segments:True" -ENV HCCL_OP_EXPANSION_MODE="AIV" -ENV LD_PRELOAD=/usr/lib64/libjemalloc.so.2:$LD_PRELOAD +ENV HCCL_CONNECT_TIMEOUT=7200 \ + PYTORCH_NPU_ALLOC_CONF="expandable_segments:True" \ + HCCL_OP_EXPANSION_MODE="AIV" \ + LD_PRELOAD=/usr/lib64/libjemalloc.so.2:$LD_PRELOAD +ARG DLINFER_TAG=main +ARG LMDEPLOY_TAG=main RUN --mount=type=cache,target=/root/.cache \ pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \ pip config set global.trusted-host pypi.tuna.tsinghua.edu.cn && \ - pip install --no-cache-dir torch==2.8.0 torch-npu==2.8.0rc1 torchvision==0.23.0 - -RUN --mount=type=cache,target=/wheels,from=builder,source=/wheels \ - pip install --no-cache-dir /wheels/*.whl + pip install --no-cache-dir torch==2.8.0 torch-npu==2.8.0rc1 torchvision==0.23.0 && \ + TORCH_DEVICE_BACKEND_AUTOLOAD=0 DEVICE=ascend pip install git+https://github.com/DeepLink-org/dlinfer.git@${DLINFER_TAG} && \ + LMDEPLOY_TARGET_DEVICE=ascend pip install git+https://github.com/InternLM/lmdeploy.git@${LMDEPLOY_TAG} From 9ceb454d06b3e5e2d341d45671785dd35c639e9a Mon Sep 17 00:00:00 2001 From: yaofengchen Date: Wed, 5 Nov 2025 08:38:30 +0000 Subject: [PATCH 4/9] rename ascend Dockerfile --- docker/{Dockerfile.ascend => Dockerfile_ascend_a2_300i} | 0 docker/{Dockerfile.ascend_a3 => Dockerfile_ascend_a3} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename docker/{Dockerfile.ascend => Dockerfile_ascend_a2_300i} (100%) rename docker/{Dockerfile.ascend_a3 => Dockerfile_ascend_a3} (100%) diff --git a/docker/Dockerfile.ascend b/docker/Dockerfile_ascend_a2_300i similarity index 100% rename from docker/Dockerfile.ascend rename to docker/Dockerfile_ascend_a2_300i diff --git a/docker/Dockerfile.ascend_a3 b/docker/Dockerfile_ascend_a3 similarity index 100% rename from docker/Dockerfile.ascend_a3 rename to docker/Dockerfile_ascend_a3 From d6d6b295d2b8d41e652bdfbc08f8a70f02790fb9 Mon Sep 17 00:00:00 2001 From: yaofengchen Date: Wed, 5 Nov 2025 08:41:24 +0000 Subject: [PATCH 5/9] fix lint --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 16ee563385..1caf8f7dbd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -41,7 +41,7 @@ repos: rev: v2.1.0 hooks: - id: codespell - args: ["--skip=third_party/*,*.ipynb,*.proto,src/turbomind/*,docker/Dockerfile.ascend*,docs/en/get_started/ascend/get_started.md,docs/zh_cn/get_started/ascend/get_started.md"] + args: ["--skip=third_party/*,*.ipynb,*.proto,src/turbomind/*,docker/Dockerfile_ascend*,docs/en/get_started/ascend/get_started.md,docs/zh_cn/get_started/ascend/get_started.md"] - repo: https://github.com/myint/docformatter From c08de14ddba8ab91961d781cb4805bfa99626647 Mon Sep 17 00:00:00 2001 From: yaofengchen Date: Wed, 5 Nov 2025 08:49:57 +0000 Subject: [PATCH 6/9] fix a2_300i build err --- docker/Dockerfile_ascend_a2_300i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile_ascend_a2_300i b/docker/Dockerfile_ascend_a2_300i index d40cab91ef..704073ea00 100644 --- a/docker/Dockerfile_ascend_a2_300i +++ b/docker/Dockerfile_ascend_a2_300i @@ -10,7 +10,7 @@ FROM ${ASCEND_HUB}/cann:8.1.rc1-310p-ubuntu22.04-py3.10 AS ascend_300i_base FROM ${ASCEND_DEVICE_TYPE}_base AS builder ENV DEBIAN_FRONTEND=noninteractive RUN apt update -y && \ - apt install -y libjemalloc-dev && \ + apt install -y libjemalloc-dev git && \ apt clean && rm -rf /var/lib/apt/lists/* ENV HCCL_CONNECT_TIMEOUT=7200 \ From d98215f5789a02a305bfc832958ac6cc98898856 Mon Sep 17 00:00:00 2001 From: yaofengchen Date: Wed, 5 Nov 2025 09:40:36 +0000 Subject: [PATCH 7/9] update base_image of a2 and 300i --- docker/Dockerfile_ascend_a2_300i | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/Dockerfile_ascend_a2_300i b/docker/Dockerfile_ascend_a2_300i index 704073ea00..51d97ad6b2 100644 --- a/docker/Dockerfile_ascend_a2_300i +++ b/docker/Dockerfile_ascend_a2_300i @@ -4,8 +4,8 @@ ARG ASCEND_DEVICE_TYPE=ascend_a2 ARG ASCEND_HUB=swr.cn-south-1.myhuaweicloud.com/ascendhub -FROM ${ASCEND_HUB}/cann:8.1.rc1-910b-ubuntu22.04-py3.10 AS ascend_a2_base -FROM ${ASCEND_HUB}/cann:8.1.rc1-310p-ubuntu22.04-py3.10 AS ascend_300i_base +FROM ${ASCEND_HUB}/cann:8.3.rc1.alpha002-910b-ubuntu22.04-py3.11 AS ascend_a2_base +FROM ${ASCEND_HUB}/cann:8.3.rc1.alpha002-310p-ubuntu22.04-py3.11 AS ascend_300i_base FROM ${ASCEND_DEVICE_TYPE}_base AS builder ENV DEBIAN_FRONTEND=noninteractive From 741b8a335d556678f337e7dd65de1bca890e9c47 Mon Sep 17 00:00:00 2001 From: yaofengchen Date: Wed, 5 Nov 2025 09:44:40 +0000 Subject: [PATCH 8/9] update --- docker/Dockerfile_ascend_a2_300i | 2 +- docker/Dockerfile_ascend_a3 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/Dockerfile_ascend_a2_300i b/docker/Dockerfile_ascend_a2_300i index 51d97ad6b2..c840e6f016 100644 --- a/docker/Dockerfile_ascend_a2_300i +++ b/docker/Dockerfile_ascend_a2_300i @@ -1,6 +1,6 @@ # DOCKER_BUILDKIT=1 docker build --build-arg ASCEND_DEVICE_TYPE=ascend_a2 \ # --build-arg DLINFER_TAG=main --build-arg LMDEPLOY_TAG=main --network=host \ -# -t lmdeploy_dlinfer:a2 -f docker/Dockerfile.ascend . +# -t lmdeploy_dlinfer:a2 -f docker/Dockerfile_ascend . ARG ASCEND_DEVICE_TYPE=ascend_a2 ARG ASCEND_HUB=swr.cn-south-1.myhuaweicloud.com/ascendhub diff --git a/docker/Dockerfile_ascend_a3 b/docker/Dockerfile_ascend_a3 index 485b30b769..9764c3e548 100644 --- a/docker/Dockerfile_ascend_a3 +++ b/docker/Dockerfile_ascend_a3 @@ -1,6 +1,6 @@ # DOCKER_BUILDKIT=1 docker build --build-arg ASCEND_DEVICE=ascend_a3 \ # --build-arg DLINFER_TAG=main --build-arg LMDEPLOY_TAG=main --network=host \ -# -t lmdeploy_dlinfer:a3 -f Dockerfile.ascend_a3 . +# -t lmdeploy_dlinfer:a3 -f Dockerfile_ascend_a3 . ARG ASCEND_DEVICE_TYPE=ascend_a3 ARG ASCEND_HUB=swr.cn-south-1.myhuaweicloud.com/ascendhub From 3a7a0b73fa0fc646ee0f968c95c6094f5bbe2cb6 Mon Sep 17 00:00:00 2001 From: yaofengchen Date: Thu, 6 Nov 2025 05:03:23 +0000 Subject: [PATCH 9/9] fix ci --- .github/workflows/docker.yml | 3 +-- .github/workflows/test_docker.yml | 4 +--- docker/Dockerfile_ascend_a2_300i | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 229f3345b8..8c3225d51f 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -147,7 +147,6 @@ jobs: env: TAG_PREFIX: "openmmlab/lmdeploy" TAG: "openmmlab/lmdeploy:ascend" - PYTHON_VERSION: '3.10' steps: - name: Checkout repository uses: actions/checkout@v3 @@ -188,5 +187,5 @@ jobs: - name: Build and push Docker image run: | echo $TAG - docker build . -t ${TAG} -f docker/Dockerfile.ascend --platform linux/arm64 --build-arg PYTHON_VERSION=${PYTHON_VERSION} + docker build . -t ${TAG} -f docker/Dockerfile_ascend_a3 --platform linux/arm64 docker push $TAG diff --git a/.github/workflows/test_docker.yml b/.github/workflows/test_docker.yml index bc8b4c4d01..6acb924033 100644 --- a/.github/workflows/test_docker.yml +++ b/.github/workflows/test_docker.yml @@ -65,8 +65,6 @@ jobs: permissions: pull-requests: write runs-on: ubuntu-22.04-arm - env: - PYTHON_VERSION: '3.10' steps: - name: Checkout repository uses: actions/checkout@v3 @@ -93,7 +91,7 @@ jobs: git config --local --unset "http.https://github.com/.extraheader" - name: Build Docker image run: | - docker build . -t lmdeploy:ascend -f docker/Dockerfile.ascend --build-arg PYTHON_VERSION=${PYTHON_VERSION} + docker build . -t lmdeploy:ascend -f docker/Dockerfile_ascend_a3 # - name: Test image with lmdeploy check_env # run: | # docker images diff --git a/docker/Dockerfile_ascend_a2_300i b/docker/Dockerfile_ascend_a2_300i index c840e6f016..47fc5fd8bc 100644 --- a/docker/Dockerfile_ascend_a2_300i +++ b/docker/Dockerfile_ascend_a2_300i @@ -1,6 +1,6 @@ # DOCKER_BUILDKIT=1 docker build --build-arg ASCEND_DEVICE_TYPE=ascend_a2 \ # --build-arg DLINFER_TAG=main --build-arg LMDEPLOY_TAG=main --network=host \ -# -t lmdeploy_dlinfer:a2 -f docker/Dockerfile_ascend . +# -t lmdeploy_dlinfer:a2 -f Dockerfile_ascend_a2_300i . ARG ASCEND_DEVICE_TYPE=ascend_a2 ARG ASCEND_HUB=swr.cn-south-1.myhuaweicloud.com/ascendhub