From 8096f94a7db3e357c52906c83cad9f3c360bad7e Mon Sep 17 00:00:00 2001 From: fanjunliang Date: Wed, 26 Jun 2024 18:21:42 +0800 Subject: [PATCH 1/8] fix torch-npu dependency --- docker/docker-npu/Dockerfile | 9 +++++---- setup.py | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docker/docker-npu/Dockerfile b/docker/docker-npu/Dockerfile index 08de626b..0ec16107 100644 --- a/docker/docker-npu/Dockerfile +++ b/docker/docker-npu/Dockerfile @@ -7,16 +7,17 @@ ENV DEBIAN_FRONTEND=noninteractive # Define installation arguments ARG INSTALL_DEEPSPEED=false ARG PIP_INDEX=https://pypi.org/simple +ARG EXTRA_INDEX=https://download.pytorch.org/whl/cpu # Set the working directory WORKDIR /app # Install the requirements COPY requirements.txt /app -RUN pip config set global.index-url $PIP_INDEX -RUN pip config set global.extra-index-url $PIP_INDEX -RUN python -m pip install --upgrade pip -RUN python -m pip install -r requirements.txt +RUN pip config set global.index-url $PIP_INDEX && \ + pip config set global.extra-index-url $EXTRA_INDEX && \ + pip install --upgrade pip && \ + pip install -r requirements.txt # Copy the rest of the application into the image COPY . /app diff --git a/setup.py b/setup.py index 64f50a87..89301d1b 100644 --- a/setup.py +++ b/setup.py @@ -35,7 +35,7 @@ def get_requires(): extra_require = { "torch": ["torch>=1.13.1"], - "torch-npu": ["torch==2.1.0", "torch-npu==2.1.0.post3", "decorator"], + "torch-npu": ["torch==2.1.0+cpu", "torch-npu==2.1.0.post3", "decorator"], "metrics": ["nltk", "jieba", "rouge-chinese"], "deepspeed": ["deepspeed>=0.10.0"], "bitsandbytes": ["bitsandbytes>=0.39.0"], From bdda0827b35cbb6005f10aa661fe6f3940b598d8 Mon Sep 17 00:00:00 2001 From: fanjunliang Date: Thu, 27 Jun 2024 15:21:55 +0800 Subject: [PATCH 2/8] support docker-npu-[amd64|arm64] build --- README.md | 2 +- README_zh.md | 2 +- docker/docker-npu/Dockerfile | 12 +++++++++--- setup.py | 3 ++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4b42edd7..9c509ff0 100644 --- a/README.md +++ b/README.md @@ -465,7 +465,7 @@ For Ascend NPU users: ```bash # Choose docker image upon your environment -docker build -f ./docker/docker-npu/Dockerfile \ +docker build --platform linux/arm64 -f ./docker/docker-npu/Dockerfile \ --build-arg INSTALL_DEEPSPEED=false \ --build-arg PIP_INDEX=https://pypi.org/simple \ -t llamafactory:latest . diff --git a/README_zh.md b/README_zh.md index 3926c09d..c3fb6ecf 100644 --- a/README_zh.md +++ b/README_zh.md @@ -465,7 +465,7 @@ docker exec -it llamafactory bash ```bash # 根据您的环境选择镜像 -docker build -f ./docker/docker-npu/Dockerfile \ +docker build --platform linux/arm64 -f ./docker/docker-npu/Dockerfile \ --build-arg INSTALL_DEEPSPEED=false \ --build-arg PIP_INDEX=https://pypi.org/simple \ -t llamafactory:latest . diff --git a/docker/docker-npu/Dockerfile b/docker/docker-npu/Dockerfile index 0ec16107..8d80397e 100644 --- a/docker/docker-npu/Dockerfile +++ b/docker/docker-npu/Dockerfile @@ -1,10 +1,11 @@ # Use the Ubuntu 22.04 image with CANN 8.0.rc1 # More versions can be found at https://hub.docker.com/r/cosdt/cann/tags -FROM cosdt/cann:8.0.rc1-910b-ubuntu22.04 +FROM --platform=$TARGETPLATFORM cosdt/cann:8.0.rc1-910b-ubuntu22.04 ENV DEBIAN_FRONTEND=noninteractive # Define installation arguments +ARG TARGETPLATFORM ARG INSTALL_DEEPSPEED=false ARG PIP_INDEX=https://pypi.org/simple ARG EXTRA_INDEX=https://download.pytorch.org/whl/cpu @@ -15,7 +16,6 @@ WORKDIR /app # Install the requirements COPY requirements.txt /app RUN pip config set global.index-url $PIP_INDEX && \ - pip config set global.extra-index-url $EXTRA_INDEX && \ pip install --upgrade pip && \ pip install -r requirements.txt @@ -23,7 +23,13 @@ RUN pip config set global.index-url $PIP_INDEX && \ COPY . /app # Install the LLaMA Factory -RUN EXTRA_PACKAGES="torch-npu,metrics"; \ +RUN EXTRA_PACKAGES="metrics"; \ + if [ "$TARGETPLATFORM" == "linux/arm64" ]; then \ + EXTRA_PACKAGES="${EXTRA_PACKAGES},torch-npu-arm64"; \ + else \ + pip config set global.extra-index-url $EXTRA_INDEX; \ + EXTRA_PACKAGES="${EXTRA_PACKAGES},torch-npu-amd64"; \ + fi; \ if [ "$INSTALL_DEEPSPEED" = "true" ]; then \ EXTRA_PACKAGES="${EXTRA_PACKAGES},deepspeed"; \ fi; \ diff --git a/setup.py b/setup.py index 89301d1b..594070cd 100644 --- a/setup.py +++ b/setup.py @@ -35,7 +35,8 @@ def get_requires(): extra_require = { "torch": ["torch>=1.13.1"], - "torch-npu": ["torch==2.1.0+cpu", "torch-npu==2.1.0.post3", "decorator"], + "torch-npu-arm64": ["torch==2.1.0", "torch-npu==2.1.0.post3", "decorator"], + "torch-npu-amd64": ["torch==2.1.0+cpu", "torch-npu==2.1.0.post3", "decorator"], "metrics": ["nltk", "jieba", "rouge-chinese"], "deepspeed": ["deepspeed>=0.10.0"], "bitsandbytes": ["bitsandbytes>=0.39.0"], From 03389207f473d43360bd938972da02c92e80322f Mon Sep 17 00:00:00 2001 From: hoshi-hiyouga Date: Thu, 27 Jun 2024 19:16:46 +0800 Subject: [PATCH 3/8] Update setup.py --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 594070cd..dd333c48 100644 --- a/setup.py +++ b/setup.py @@ -35,8 +35,8 @@ def get_requires(): extra_require = { "torch": ["torch>=1.13.1"], - "torch-npu-arm64": ["torch==2.1.0", "torch-npu==2.1.0.post3", "decorator"], - "torch-npu-amd64": ["torch==2.1.0+cpu", "torch-npu==2.1.0.post3", "decorator"], + "torch-npu": ["torch==2.1.0", "torch-npu==2.1.0.post3", "decorator"], + "torch-npu-amd": ["torch==2.1.0+cpu", "torch-npu==2.1.0.post3", "decorator"], "metrics": ["nltk", "jieba", "rouge-chinese"], "deepspeed": ["deepspeed>=0.10.0"], "bitsandbytes": ["bitsandbytes>=0.39.0"], From 06536c44d472fa2b380ebdb3f51865edb028ac5d Mon Sep 17 00:00:00 2001 From: hoshi-hiyouga Date: Thu, 27 Jun 2024 19:17:35 +0800 Subject: [PATCH 4/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9c509ff0..4b42edd7 100644 --- a/README.md +++ b/README.md @@ -465,7 +465,7 @@ For Ascend NPU users: ```bash # Choose docker image upon your environment -docker build --platform linux/arm64 -f ./docker/docker-npu/Dockerfile \ +docker build -f ./docker/docker-npu/Dockerfile \ --build-arg INSTALL_DEEPSPEED=false \ --build-arg PIP_INDEX=https://pypi.org/simple \ -t llamafactory:latest . From fc7a08e16a00db0e2f8bb2b1966b3d363434ddc6 Mon Sep 17 00:00:00 2001 From: hoshi-hiyouga Date: Thu, 27 Jun 2024 19:17:52 +0800 Subject: [PATCH 5/8] Update README_zh.md --- README_zh.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README_zh.md b/README_zh.md index c3fb6ecf..3926c09d 100644 --- a/README_zh.md +++ b/README_zh.md @@ -465,7 +465,7 @@ docker exec -it llamafactory bash ```bash # 根据您的环境选择镜像 -docker build --platform linux/arm64 -f ./docker/docker-npu/Dockerfile \ +docker build -f ./docker/docker-npu/Dockerfile \ --build-arg INSTALL_DEEPSPEED=false \ --build-arg PIP_INDEX=https://pypi.org/simple \ -t llamafactory:latest . From 569f03ca1abf844f6893745c2cbabf056f21d1cb Mon Sep 17 00:00:00 2001 From: hoshi-hiyouga Date: Thu, 27 Jun 2024 19:38:15 +0800 Subject: [PATCH 6/8] Update setup.py --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index dd333c48..64f50a87 100644 --- a/setup.py +++ b/setup.py @@ -36,7 +36,6 @@ def get_requires(): extra_require = { "torch": ["torch>=1.13.1"], "torch-npu": ["torch==2.1.0", "torch-npu==2.1.0.post3", "decorator"], - "torch-npu-amd": ["torch==2.1.0+cpu", "torch-npu==2.1.0.post3", "decorator"], "metrics": ["nltk", "jieba", "rouge-chinese"], "deepspeed": ["deepspeed>=0.10.0"], "bitsandbytes": ["bitsandbytes>=0.39.0"], From 9624af1df3e4b260b37ad10e2a9be8e69ab066df Mon Sep 17 00:00:00 2001 From: hoshi-hiyouga Date: Thu, 27 Jun 2024 19:51:25 +0800 Subject: [PATCH 7/8] Update Dockerfile --- docker/docker-npu/Dockerfile | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/docker/docker-npu/Dockerfile b/docker/docker-npu/Dockerfile index 8d80397e..d1d176e9 100644 --- a/docker/docker-npu/Dockerfile +++ b/docker/docker-npu/Dockerfile @@ -1,39 +1,38 @@ # Use the Ubuntu 22.04 image with CANN 8.0.rc1 # More versions can be found at https://hub.docker.com/r/cosdt/cann/tags -FROM --platform=$TARGETPLATFORM cosdt/cann:8.0.rc1-910b-ubuntu22.04 +FROM cosdt/cann:8.0.rc1-910b-ubuntu22.04 +# Set env ENV DEBIAN_FRONTEND=noninteractive # Define installation arguments -ARG TARGETPLATFORM ARG INSTALL_DEEPSPEED=false ARG PIP_INDEX=https://pypi.org/simple -ARG EXTRA_INDEX=https://download.pytorch.org/whl/cpu +# x86 torch cpu index +ARG TORCH_INDEX=https://download.pytorch.org/whl/cpu # Set the working directory WORKDIR /app # Install the requirements COPY requirements.txt /app -RUN pip config set global.index-url $PIP_INDEX && \ - pip install --upgrade pip && \ - pip install -r requirements.txt +RUN pip config set global.index-url "$PIP_INDEX" && \ + pip config set global.extra-index-url "$PIP_INDEX" && \ + python -m pip install --upgrade pip && \ + python -m pip install -r requirements.txt # Copy the rest of the application into the image COPY . /app # Install the LLaMA Factory -RUN EXTRA_PACKAGES="metrics"; \ - if [ "$TARGETPLATFORM" == "linux/arm64" ]; then \ - EXTRA_PACKAGES="${EXTRA_PACKAGES},torch-npu-arm64"; \ - else \ - pip config set global.extra-index-url $EXTRA_INDEX; \ - EXTRA_PACKAGES="${EXTRA_PACKAGES},torch-npu-amd64"; \ - fi; \ - if [ "$INSTALL_DEEPSPEED" = "true" ]; then \ +RUN EXTRA_PACKAGES="torch-npu,metrics"; \ + if [ "$INSTALL_DEEPSPEED" == "true" ]; then \ EXTRA_PACKAGES="${EXTRA_PACKAGES},deepspeed"; \ fi; \ - pip install -e .[$EXTRA_PACKAGES] && \ + if [ "$(uname -i)" != "aarch64" ]; then \ + pip config set global.extra-index-url "$TORCH_INDEX" \ + fi; \ + pip install -e ".[$EXTRA_PACKAGES]" && \ pip uninstall -y transformer-engine flash-attn # Set up volumes From 5fcd33fd4f08f5e46c1df541f188d13faefa7c8e Mon Sep 17 00:00:00 2001 From: hoshi-hiyouga Date: Thu, 27 Jun 2024 19:57:40 +0800 Subject: [PATCH 8/8] Update Dockerfile --- docker/docker-npu/Dockerfile | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/docker/docker-npu/Dockerfile b/docker/docker-npu/Dockerfile index d1d176e9..71ab3daf 100644 --- a/docker/docker-npu/Dockerfile +++ b/docker/docker-npu/Dockerfile @@ -2,13 +2,11 @@ # More versions can be found at https://hub.docker.com/r/cosdt/cann/tags FROM cosdt/cann:8.0.rc1-910b-ubuntu22.04 -# Set env ENV DEBIAN_FRONTEND=noninteractive # Define installation arguments ARG INSTALL_DEEPSPEED=false ARG PIP_INDEX=https://pypi.org/simple -# x86 torch cpu index ARG TORCH_INDEX=https://download.pytorch.org/whl/cpu # Set the working directory @@ -17,7 +15,7 @@ WORKDIR /app # Install the requirements COPY requirements.txt /app RUN pip config set global.index-url "$PIP_INDEX" && \ - pip config set global.extra-index-url "$PIP_INDEX" && \ + pip config set global.extra-index-url "$TORCH_INDEX" && \ python -m pip install --upgrade pip && \ python -m pip install -r requirements.txt @@ -29,9 +27,6 @@ RUN EXTRA_PACKAGES="torch-npu,metrics"; \ if [ "$INSTALL_DEEPSPEED" == "true" ]; then \ EXTRA_PACKAGES="${EXTRA_PACKAGES},deepspeed"; \ fi; \ - if [ "$(uname -i)" != "aarch64" ]; then \ - pip config set global.extra-index-url "$TORCH_INDEX" \ - fi; \ pip install -e ".[$EXTRA_PACKAGES]" && \ pip uninstall -y transformer-engine flash-attn