From d7207e8ad10c7df6dcb1f5e59ff8eb06f9d77e67 Mon Sep 17 00:00:00 2001 From: MengqingCao Date: Mon, 24 Jun 2024 10:57:36 +0000 Subject: [PATCH 1/8] update docker files 1. add docker-npu (Dockerfile and docker-compose.yml) 2. move cuda docker to docker-cuda and tiny changes to adapt to the new path --- README.md | 61 +++++++++++++++++-- README_zh.md | 58 ++++++++++++++++-- Dockerfile => docker/docker-cuda/Dockerfile | 10 +-- .../docker-cuda/docker-compose.yml | 6 +- docker/docker-npu/Dockerfile | 40 ++++++++++++ docker/docker-npu/docker-compose.yml | 31 ++++++++++ 6 files changed, 187 insertions(+), 19 deletions(-) rename Dockerfile => docker/docker-cuda/Dockerfile (87%) rename docker-compose.yml => docker/docker-cuda/docker-compose.yml (80%) create mode 100644 docker/docker-npu/Dockerfile create mode 100644 docker/docker-npu/docker-compose.yml diff --git a/README.md b/README.md index 9462964c..1107ae0b 100644 --- a/README.md +++ b/README.md @@ -383,10 +383,11 @@ source /usr/local/Ascend/ascend-toolkit/set_env.sh | torch-npu | 2.1.0 | 2.1.0.post3 | | deepspeed | 0.13.2 | 0.13.2 | -Docker image: +Docker users please refer to [Build Docker](#Build-Docker). -- 32GB: [Download page](http://mirrors.cn-central-221.ovaijisuan.com/detail/130.html) -- 64GB: [Download page](http://mirrors.cn-central-221.ovaijisuan.com/detail/131.html) +**NOTE** + +The default docker image is [cosdt/cann:8.0.rc1-910b-ubuntu22.04](https://hub.docker.com/layers/cosdt/cann/8.0.rc1-910b-ubuntu22.04/images/sha256-29ef8aacf6b2babd292f06f00b9190c212e7c79a947411e213135e4d41a178a9?context=explore). More options can be found at [cosdt/cann](https://hub.docker.com/r/cosdt/cann/tags). Remember to use `ASCEND_RT_VISIBLE_DEVICES` instead of `CUDA_VISIBLE_DEVICES` to specify the device to use. @@ -426,7 +427,10 @@ llamafactory-cli webui #### Use Docker +
For NVIDIA GPU users: + ```bash +cd ./docker/docker-cuda docker build -f ./Dockerfile \ --build-arg INSTALL_BNB=false \ --build-arg INSTALL_VLLM=false \ @@ -435,18 +439,63 @@ docker build -f ./Dockerfile \ -t llamafactory:latest . docker run -it --gpus=all \ - -v ./hf_cache:/root/.cache/huggingface/ \ - -v ./data:/app/data \ - -v ./output:/app/output \ + -v /$(dirname $(dirname "$PWD"))/hf_cache:/root/.cache/huggingface/ \ + -v /$(dirname $(dirname "$PWD"))/data:/app/data \ + -v /$(dirname $(dirname "$PWD"))/output:/app/output \ -p 7860:7860 \ -p 8000:8000 \ --shm-size 16G \ --name llamafactory \ llamafactory:latest ``` +
+ +
For Ascend NPU users: + +```bash +cd ./docker/docker-npu +docker build -f ./Dockerfile \ + --build-arg INSTALL_DEEPSPEED=false \ + --build-arg PIP_INDEX=https://pypi.org/simple \ + -t llamafactory:latest . + +# add --device for multi-npu usage +# or modify --device to change npu card +docker run -it \ + -v /$(dirname $(dirname "$PWD"))/hf_cache:/root/.cache/huggingface/ \ + -v /$(dirname $(dirname "$PWD"))/data:/app/data \ + -v /$(dirname $(dirname "$PWD"))/output:/app/output \ + -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 \ + -p 7860:7860 \ + -p 8000:8000 \ + --device /dev/davinci0 \ + --device /dev/davinci_manager \ + --device /dev/devmm_svm \ + --device /dev/hisi_hdc \ + --shm-size 16G \ + --name llamafactory \ + llamafactory:latest +``` +
#### Use Docker Compose +Firstly enter your docker path: + +```bash +# for NVIDIA GPU users +cd ./docker/docker-cuda + +# for Ascend NPU users +cd ./docker/docker-npu +``` + +Then run the following command to build docker image and start the container: + ```bash docker-compose up -d docker-compose exec llamafactory bash diff --git a/README_zh.md b/README_zh.md index 8b77e91e..6326c0b5 100644 --- a/README_zh.md +++ b/README_zh.md @@ -383,10 +383,11 @@ source /usr/local/Ascend/ascend-toolkit/set_env.sh | torch-npu | 2.1.0 | 2.1.0.post3 | | deepspeed | 0.13.2 | 0.13.2 | -Docker 镜像: +Docker用户请参考 [构建 Docker](#构建-Docker). -- 32GB:[下载地址](http://mirrors.cn-central-221.ovaijisuan.com/detail/130.html) -- 64GB:[下载地址](http://mirrors.cn-central-221.ovaijisuan.com/detail/131.html) +**NOTE** + +默认镜像为 [cosdt/cann:8.0.rc1-910b-ubuntu22.04](https://hub.docker.com/layers/cosdt/cann/8.0.rc1-910b-ubuntu22.04/images/sha256-29ef8aacf6b2babd292f06f00b9190c212e7c79a947411e213135e4d41a178a9?context=explore). 更多选择见 [cosdt/cann](https://hub.docker.com/r/cosdt/cann/tags). 请使用 `ASCEND_RT_VISIBLE_DEVICES` 而非 `CUDA_VISIBLE_DEVICES` 来指定运算设备。 @@ -426,7 +427,10 @@ llamafactory-cli webui #### 使用 Docker +
NVIDIA GPU 用户: + ```bash +cd ./docker/docker-cuda docker build -f ./Dockerfile \ --build-arg INSTALL_BNB=false \ --build-arg INSTALL_VLLM=false \ @@ -435,18 +439,60 @@ docker build -f ./Dockerfile \ -t llamafactory:latest . docker run -it --gpus=all \ - -v ./hf_cache:/root/.cache/huggingface/ \ - -v ./data:/app/data \ - -v ./output:/app/output \ + -v /$(dirname $(dirname "$PWD"))/hf_cache:/root/.cache/huggingface/ \ + -v /$(dirname $(dirname "$PWD"))/data:/app/data \ + -v /$(dirname $(dirname "$PWD"))/output:/app/output \ -p 7860:7860 \ -p 8000:8000 \ --shm-size 16G \ --name llamafactory \ llamafactory:latest ``` +
+ +
Ascend NPU 用户: + +```bash +cd ./docker/docker-npu +docker build -f ./Dockerfile \ + --build-arg INSTALL_DEEPSPEED=false \ + --build-arg PIP_INDEX=https://pypi.org/simple \ + -t llamafactory:latest . + +# 增加 --device 来使用多卡 NPU 或修改第一个 --device 来更改 NPU 卡 +docker run -it \ + -v /$(dirname $(dirname "$PWD"))/hf_cache:/root/.cache/huggingface/ \ + -v /$(dirname $(dirname "$PWD"))/data:/app/data \ + -v /$(dirname $(dirname "$PWD"))/output:/app/output \ + -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 \ + -p 7860:7860 \ + -p 8000:8000 \ + --device /dev/davinci0 \ + --device /dev/davinci_manager \ + --device /dev/devmm_svm \ + --device /dev/hisi_hdc \ + --shm-size 16G \ + --name llamafactory \ + llamafactory:latest +``` +
#### 使用 Docker Compose +首先进入 docker 目录: +```bash +# NVIDIA GPU 用户 +cd ./docker/docker-cuda + +# Ascend NPU 用户 +cd ./docker/docker-npu +``` +然后运行以下命令创建 docker 镜像并启动容器: + ```bash docker-compose up -d docker-compose exec llamafactory bash diff --git a/Dockerfile b/docker/docker-cuda/Dockerfile similarity index 87% rename from Dockerfile rename to docker/docker-cuda/Dockerfile index 61d58005..72797a26 100644 --- a/Dockerfile +++ b/docker/docker-cuda/Dockerfile @@ -9,16 +9,18 @@ ARG INSTALL_DEEPSPEED=false ARG PIP_INDEX=https://pypi.org/simple # Set the working directory -WORKDIR /app +WORKDIR /app/LLaMA-Factory + +RUN cd /app && \ + git config --global http.version HTTP/1.1 && \ + git clone https://github.com/hiyouga/LLaMA-Factory.git && \ + cd /app/LLaMA-Factory # Install the requirements -COPY requirements.txt /app/ RUN pip config set global.index-url $PIP_INDEX RUN python -m pip install --upgrade pip RUN 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"; \ diff --git a/docker-compose.yml b/docker/docker-cuda/docker-compose.yml similarity index 80% rename from docker-compose.yml rename to docker/docker-cuda/docker-compose.yml index c5dc34e9..a470aa60 100644 --- a/docker-compose.yml +++ b/docker/docker-cuda/docker-compose.yml @@ -10,9 +10,9 @@ services: PIP_INDEX: https://pypi.org/simple container_name: llamafactory volumes: - - ./hf_cache:/root/.cache/huggingface/ - - ./data:/app/data - - ./output:/app/output + - ../../hf_cache:/root/.cache/huggingface/ + - ../../data:/app/LLaMA-Factory/data + - ../../output:/app/LLaMA-Factory/output ports: - "7860:7860" - "8000:8000" diff --git a/docker/docker-npu/Dockerfile b/docker/docker-npu/Dockerfile new file mode 100644 index 00000000..9456bcbf --- /dev/null +++ b/docker/docker-npu/Dockerfile @@ -0,0 +1,40 @@ +# Using ubuntu 22.04 images with cann 8.0.rc1 +# More options can be found at https://hub.docker.com/r/cosdt/cann/tags +FROM cosdt/cann:8.0.rc1-910b-ubuntu22.04 + +ENV DEBIAN_FRONTEND=noninteractive + +# Define installation arguments +ARG INSTALL_DEEPSPEED=false +ARG PIP_INDEX=https://pypi.org/simple + +# Set the working directory +WORKDIR /app/LLaMA-Factory + +RUN cd /app && \ + git config --global http.version HTTP/1.1 && \ + git clone https://github.com/hiyouga/LLaMA-Factory.git && \ + cd /app/LLaMA-Factory + +RUN pip config set global.index-url $PIP_INDEX +RUN python3 -m pip install --upgrade pip + +# Install the LLaMA Factory +RUN EXTRA_PACKAGES="torch-npu,metrics"; \ + if [ "$INSTALL_DEEPSPEED" = "true" ]; then \ + EXTRA_PACKAGES="${EXTRA_PACKAGES},deepspeed"; \ + fi; \ + pip install -e .[$EXTRA_PACKAGES] && \ + pip uninstall -y transformer-engine flash-attn + +# Set up volumes +VOLUME [ "/root/.cache/huggingface/", "/app/data", "/app/output" ] + +# Expose port 7860 for the LLaMA Board +EXPOSE 7860 + +# Expose port 8000 for the API service +EXPOSE 8000 + +# Launch LLaMA Board +CMD [ "llamafactory-cli", "webui" ] diff --git a/docker/docker-npu/docker-compose.yml b/docker/docker-npu/docker-compose.yml new file mode 100644 index 00000000..93eb6718 --- /dev/null +++ b/docker/docker-npu/docker-compose.yml @@ -0,0 +1,31 @@ +services: + llamafactory: + build: + dockerfile: Dockerfile + context: . + args: + INSTALL_DEEPSPEED: false + PIP_INDEX: https://pypi.org/simple + container_name: llamafactory + volumes: + - ../../hf_cache:/root/.cache/huggingface/ + - ../../data:/app/LLaMA-Factory/data + - ../../output:/app/LLaMA-Factory/output + - /usr/local/dcmi:/usr/local/dcmi + - /usr/local/bin/npu-smi:/usr/local/bin/npu-smi + - /usr/local/Ascend/driver/lib64:/usr/local/Ascend/driver/lib64 + - /usr/local/Ascend/driver/version.info:/usr/local/Ascend/driver/version.info + - /etc/ascend_install.info:/etc/ascend_install.info + ports: + - "7860:7860" + - "8000:8000" + ipc: host + tty: true + stdin_open: true + command: bash + devices: + - /dev/davinci0 + - /dev/davinci_manager + - /dev/devmm_svm + - /dev/hisi_hdc + restart: unless-stopped From dcc2e24f5cd441a242829f2fb090506db507babd Mon Sep 17 00:00:00 2001 From: hoshi-hiyouga Date: Mon, 24 Jun 2024 23:41:35 +0800 Subject: [PATCH 2/8] Update Dockerfile --- docker/docker-cuda/Dockerfile | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/docker/docker-cuda/Dockerfile b/docker/docker-cuda/Dockerfile index 72797a26..61d58005 100644 --- a/docker/docker-cuda/Dockerfile +++ b/docker/docker-cuda/Dockerfile @@ -9,18 +9,16 @@ ARG INSTALL_DEEPSPEED=false ARG PIP_INDEX=https://pypi.org/simple # Set the working directory -WORKDIR /app/LLaMA-Factory - -RUN cd /app && \ - git config --global http.version HTTP/1.1 && \ - git clone https://github.com/hiyouga/LLaMA-Factory.git && \ - cd /app/LLaMA-Factory +WORKDIR /app # Install the requirements +COPY requirements.txt /app/ RUN pip config set global.index-url $PIP_INDEX RUN python -m pip install --upgrade pip RUN 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"; \ From fce146ab681a5682d3f96254e3863f70aca8a4af Mon Sep 17 00:00:00 2001 From: hoshi-hiyouga Date: Tue, 25 Jun 2024 00:46:08 +0800 Subject: [PATCH 3/8] Update Dockerfile --- docker/docker-cuda/Dockerfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docker/docker-cuda/Dockerfile b/docker/docker-cuda/Dockerfile index 61d58005..2d20bfe4 100644 --- a/docker/docker-cuda/Dockerfile +++ b/docker/docker-cuda/Dockerfile @@ -12,13 +12,14 @@ ARG PIP_INDEX=https://pypi.org/simple WORKDIR /app # Install the requirements -COPY requirements.txt /app/ +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 # Copy the rest of the application into the image -COPY . /app/ +COPY . /app # Install the LLaMA Factory RUN EXTRA_PACKAGES="metrics"; \ @@ -38,10 +39,9 @@ RUN EXTRA_PACKAGES="metrics"; \ VOLUME [ "/root/.cache/huggingface/", "/app/data", "/app/output" ] # Expose port 7860 for the LLaMA Board +ENV GRADIO_SERVER_PORT 7860 EXPOSE 7860 # Expose port 8000 for the API service +ENV API_PORT 8000 EXPOSE 8000 - -# Launch LLaMA Board -CMD [ "llamafactory-cli", "webui" ] From 15608d055827e41b44fb8a381b1fe5a1230afcb0 Mon Sep 17 00:00:00 2001 From: hoshi-hiyouga Date: Tue, 25 Jun 2024 00:46:47 +0800 Subject: [PATCH 4/8] Update docker-compose.yml --- docker/docker-cuda/docker-compose.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docker/docker-cuda/docker-compose.yml b/docker/docker-cuda/docker-compose.yml index a470aa60..04d6531a 100644 --- a/docker/docker-cuda/docker-compose.yml +++ b/docker/docker-cuda/docker-compose.yml @@ -1,8 +1,8 @@ services: llamafactory: build: - dockerfile: Dockerfile - context: . + dockerfile: ./docker/docker-cuda/Dockerfile + context: ../.. args: INSTALL_BNB: false INSTALL_VLLM: false @@ -10,9 +10,9 @@ services: PIP_INDEX: https://pypi.org/simple container_name: llamafactory volumes: - - ../../hf_cache:/root/.cache/huggingface/ - - ../../data:/app/LLaMA-Factory/data - - ../../output:/app/LLaMA-Factory/output + - ./hf_cache:/root/.cache/huggingface/ + - ./data:/app/data + - ./output:/app/output ports: - "7860:7860" - "8000:8000" From 3af936a76d726c73d14ff6cf8c3088bda5b904c3 Mon Sep 17 00:00:00 2001 From: hoshi-hiyouga Date: Tue, 25 Jun 2024 00:50:34 +0800 Subject: [PATCH 5/8] Update Dockerfile --- docker/docker-npu/Dockerfile | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/docker/docker-npu/Dockerfile b/docker/docker-npu/Dockerfile index 9456bcbf..0fdd4472 100644 --- a/docker/docker-npu/Dockerfile +++ b/docker/docker-npu/Dockerfile @@ -1,5 +1,5 @@ -# Using ubuntu 22.04 images with cann 8.0.rc1 -# More options can be found at https://hub.docker.com/r/cosdt/cann/tags +# 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 ENV DEBIAN_FRONTEND=noninteractive @@ -9,15 +9,17 @@ ARG INSTALL_DEEPSPEED=false ARG PIP_INDEX=https://pypi.org/simple # Set the working directory -WORKDIR /app/LLaMA-Factory - -RUN cd /app && \ - git config --global http.version HTTP/1.1 && \ - git clone https://github.com/hiyouga/LLaMA-Factory.git && \ - cd /app/LLaMA-Factory +WORKDIR /app +# Install the requirements +COPY requirements.txt /app RUN pip config set global.index-url $PIP_INDEX -RUN python3 -m pip install --upgrade pip +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 + +# Copy the rest of the application into the image +COPY . /app # Install the LLaMA Factory RUN EXTRA_PACKAGES="torch-npu,metrics"; \ @@ -31,10 +33,9 @@ RUN EXTRA_PACKAGES="torch-npu,metrics"; \ VOLUME [ "/root/.cache/huggingface/", "/app/data", "/app/output" ] # Expose port 7860 for the LLaMA Board +ENV GRADIO_SERVER_PORT 7860 EXPOSE 7860 # Expose port 8000 for the API service +ENV API_PORT 8000 EXPOSE 8000 - -# Launch LLaMA Board -CMD [ "llamafactory-cli", "webui" ] From 721acd87688b3edd41d2e1890971eb387afc1b6e Mon Sep 17 00:00:00 2001 From: hoshi-hiyouga Date: Tue, 25 Jun 2024 00:54:28 +0800 Subject: [PATCH 6/8] Update docker-compose.yml --- docker/docker-npu/docker-compose.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/docker/docker-npu/docker-compose.yml b/docker/docker-npu/docker-compose.yml index 93eb6718..7fff6e73 100644 --- a/docker/docker-npu/docker-compose.yml +++ b/docker/docker-npu/docker-compose.yml @@ -1,20 +1,19 @@ services: llamafactory: build: - dockerfile: Dockerfile - context: . + dockerfile: ./docker/docker-npu/Dockerfile + context: ../.. args: INSTALL_DEEPSPEED: false PIP_INDEX: https://pypi.org/simple container_name: llamafactory volumes: - - ../../hf_cache:/root/.cache/huggingface/ - - ../../data:/app/LLaMA-Factory/data - - ../../output:/app/LLaMA-Factory/output + - ./hf_cache:/root/.cache/huggingface/ + - ./data:/app/data + - ./output:/app/output - /usr/local/dcmi:/usr/local/dcmi - /usr/local/bin/npu-smi:/usr/local/bin/npu-smi - - /usr/local/Ascend/driver/lib64:/usr/local/Ascend/driver/lib64 - - /usr/local/Ascend/driver/version.info:/usr/local/Ascend/driver/version.info + - /usr/local/Ascend/driver:/usr/local/Ascend/driver - /etc/ascend_install.info:/etc/ascend_install.info ports: - "7860:7860" From 5dc8fa647e9af2c6d666c9559553c05d1c4860b3 Mon Sep 17 00:00:00 2001 From: hoshi-hiyouga Date: Tue, 25 Jun 2024 01:03:38 +0800 Subject: [PATCH 7/8] Update README.md --- README.md | 84 ++++++++++++++++++++++++------------------------------- 1 file changed, 37 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index 1107ae0b..a20b848b 100644 --- a/README.md +++ b/README.md @@ -383,12 +383,6 @@ source /usr/local/Ascend/ascend-toolkit/set_env.sh | torch-npu | 2.1.0 | 2.1.0.post3 | | deepspeed | 0.13.2 | 0.13.2 | -Docker users please refer to [Build Docker](#Build-Docker). - -**NOTE** - -The default docker image is [cosdt/cann:8.0.rc1-910b-ubuntu22.04](https://hub.docker.com/layers/cosdt/cann/8.0.rc1-910b-ubuntu22.04/images/sha256-29ef8aacf6b2babd292f06f00b9190c212e7c79a947411e213135e4d41a178a9?context=explore). More options can be found at [cosdt/cann](https://hub.docker.com/r/cosdt/cann/tags). - Remember to use `ASCEND_RT_VISIBLE_DEVICES` instead of `CUDA_VISIBLE_DEVICES` to specify the device to use. If you cannot infer model on NPU devices, try setting `do_sample: false` in the configurations. @@ -425,50 +419,62 @@ llamafactory-cli webui ### Build Docker -#### Use Docker - -
For NVIDIA GPU users: +For CUDA users: ```bash -cd ./docker/docker-cuda -docker build -f ./Dockerfile \ +docker-compose -f ./docker/docker-cuda/docker-compose.yml up -d +docker-compose exec llamafactory bash +``` + +For Ascend NPU users: + +```bash +docker-compose -f ./docker/docker-npu/docker-compose.yml up -d +docker-compose exec llamafactory bash +``` + +
Build without Docker Compose + +For CUDA users: + +```bash +docker build -f ./docker/docker-cuda/Dockerfile \ --build-arg INSTALL_BNB=false \ --build-arg INSTALL_VLLM=false \ --build-arg INSTALL_DEEPSPEED=false \ --build-arg PIP_INDEX=https://pypi.org/simple \ -t llamafactory:latest . -docker run -it --gpus=all \ - -v /$(dirname $(dirname "$PWD"))/hf_cache:/root/.cache/huggingface/ \ - -v /$(dirname $(dirname "$PWD"))/data:/app/data \ - -v /$(dirname $(dirname "$PWD"))/output:/app/output \ +docker run -dit --gpus=all \ + -v ./hf_cache:/root/.cache/huggingface/ \ + -v ./data:/app/data \ + -v ./output:/app/output \ -p 7860:7860 \ -p 8000:8000 \ --shm-size 16G \ --name llamafactory \ llamafactory:latest -``` -
-
For Ascend NPU users: +docker exec -it llamafactory bash +``` + +For Ascend NPU users: ```bash -cd ./docker/docker-npu -docker build -f ./Dockerfile \ +# Change docker image upon your environment +docker build -f ./docker/docker-npu/Dockerfile \ --build-arg INSTALL_DEEPSPEED=false \ --build-arg PIP_INDEX=https://pypi.org/simple \ -t llamafactory:latest . -# add --device for multi-npu usage -# or modify --device to change npu card -docker run -it \ - -v /$(dirname $(dirname "$PWD"))/hf_cache:/root/.cache/huggingface/ \ - -v /$(dirname $(dirname "$PWD"))/data:/app/data \ - -v /$(dirname $(dirname "$PWD"))/output:/app/output \ +# Change `device` upon your resources +docker run -dit \ + -v ./hf_cache:/root/.cache/huggingface/ \ + -v ./data:/app/data \ + -v ./output:/app/output \ -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 /usr/local/Ascend/driver:/usr/local/Ascend/driver \ -v /etc/ascend_install.info:/etc/ascend_install.info \ -p 7860:7860 \ -p 8000:8000 \ @@ -479,28 +485,12 @@ docker run -it \ --shm-size 16G \ --name llamafactory \ llamafactory:latest + +docker exec -it llamafactory bash ``` +
-#### Use Docker Compose - -Firstly enter your docker path: - -```bash -# for NVIDIA GPU users -cd ./docker/docker-cuda - -# for Ascend NPU users -cd ./docker/docker-npu -``` - -Then run the following command to build docker image and start the container: - -```bash -docker-compose up -d -docker-compose exec llamafactory bash -``` -
Details about volume - hf_cache: Utilize Hugging Face cache on the host machine. Reassignable if a cache already exists in a different directory. From ec95f942d1f36dee9facb687ae4168e7c3c4d3f5 Mon Sep 17 00:00:00 2001 From: hoshi-hiyouga Date: Tue, 25 Jun 2024 01:06:59 +0800 Subject: [PATCH 8/8] Update README_zh.md --- README_zh.md | 83 ++++++++++++++++++++++++---------------------------- 1 file changed, 38 insertions(+), 45 deletions(-) diff --git a/README_zh.md b/README_zh.md index 6326c0b5..3bed0846 100644 --- a/README_zh.md +++ b/README_zh.md @@ -360,7 +360,7 @@ pip install https://github.com/jllllll/bitsandbytes-windows-webui/releases/downl
昇腾 NPU 用户指南 -在昇腾 NPU 设备上安装 LLaMA Factory 时,需要指定额外依赖项,使用 `pip install -e '.[torch-npu,metrics]'` 命令安装。此外,还需要安装 **[Ascend CANN Toolkit and Kernels](https://www.hiascend.com/developer/download/community/result?module=cann)**,安装方法请参考[安装教程](https://www.hiascend.com/document/detail/zh/CANNCommunityEdition/80RC2alpha002/quickstart/quickstart/quickstart_18_0004.html)或使用以下命令: +在昇腾 NPU 设备上安装 LLaMA Factory 时,需要指定额外依赖项,使用 `pip install -e ".[torch-npu,metrics]"` 命令安装。此外,还需要安装 **[Ascend CANN Toolkit and Kernels](https://www.hiascend.com/developer/download/community/result?module=cann)**,安装方法请参考[安装教程](https://www.hiascend.com/document/detail/zh/CANNCommunityEdition/80RC2alpha002/quickstart/quickstart/quickstart_18_0004.html)或使用以下命令: ```bash # 请替换 URL 为 CANN 版本和设备型号对应的 URL @@ -383,12 +383,6 @@ source /usr/local/Ascend/ascend-toolkit/set_env.sh | torch-npu | 2.1.0 | 2.1.0.post3 | | deepspeed | 0.13.2 | 0.13.2 | -Docker用户请参考 [构建 Docker](#构建-Docker). - -**NOTE** - -默认镜像为 [cosdt/cann:8.0.rc1-910b-ubuntu22.04](https://hub.docker.com/layers/cosdt/cann/8.0.rc1-910b-ubuntu22.04/images/sha256-29ef8aacf6b2babd292f06f00b9190c212e7c79a947411e213135e4d41a178a9?context=explore). 更多选择见 [cosdt/cann](https://hub.docker.com/r/cosdt/cann/tags). - 请使用 `ASCEND_RT_VISIBLE_DEVICES` 而非 `CUDA_VISIBLE_DEVICES` 来指定运算设备。 如果遇到无法正常推理的情况,请尝试设置 `do_sample: false`。 @@ -425,49 +419,62 @@ llamafactory-cli webui ### 构建 Docker -#### 使用 Docker - -
NVIDIA GPU 用户: +CUDA 用户: ```bash -cd ./docker/docker-cuda -docker build -f ./Dockerfile \ +docker-compose -f ./docker/docker-cuda/docker-compose.yml up -d +docker-compose exec llamafactory bash +``` + +昇腾 NPU 用户: + +```bash +docker-compose -f ./docker/docker-npu/docker-compose.yml up -d +docker-compose exec llamafactory bash +``` + +
不使用 Docker Compose 构建 + +CUDA 用户: + +```bash +docker build -f ./docker/docker-cuda/Dockerfile \ --build-arg INSTALL_BNB=false \ --build-arg INSTALL_VLLM=false \ --build-arg INSTALL_DEEPSPEED=false \ --build-arg PIP_INDEX=https://pypi.org/simple \ -t llamafactory:latest . -docker run -it --gpus=all \ - -v /$(dirname $(dirname "$PWD"))/hf_cache:/root/.cache/huggingface/ \ - -v /$(dirname $(dirname "$PWD"))/data:/app/data \ - -v /$(dirname $(dirname "$PWD"))/output:/app/output \ +docker run -dit --gpus=all \ + -v ./hf_cache:/root/.cache/huggingface/ \ + -v ./data:/app/data \ + -v ./output:/app/output \ -p 7860:7860 \ -p 8000:8000 \ --shm-size 16G \ --name llamafactory \ llamafactory:latest -``` -
-
Ascend NPU 用户: +docker exec -it llamafactory bash +``` + +昇腾 NPU 用户: ```bash -cd ./docker/docker-npu -docker build -f ./Dockerfile \ +# 根据您的环境选择镜像 +docker build -f ./docker/docker-npu/Dockerfile \ --build-arg INSTALL_DEEPSPEED=false \ --build-arg PIP_INDEX=https://pypi.org/simple \ -t llamafactory:latest . -# 增加 --device 来使用多卡 NPU 或修改第一个 --device 来更改 NPU 卡 -docker run -it \ - -v /$(dirname $(dirname "$PWD"))/hf_cache:/root/.cache/huggingface/ \ - -v /$(dirname $(dirname "$PWD"))/data:/app/data \ - -v /$(dirname $(dirname "$PWD"))/output:/app/output \ +# 根据您的资源更改 `device` +docker run -dit \ + -v ./hf_cache:/root/.cache/huggingface/ \ + -v ./data:/app/data \ + -v ./output:/app/output \ -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 /usr/local/Ascend/driver:/usr/local/Ascend/driver \ -v /etc/ascend_install.info:/etc/ascend_install.info \ -p 7860:7860 \ -p 8000:8000 \ @@ -478,26 +485,12 @@ docker run -it \ --shm-size 16G \ --name llamafactory \ llamafactory:latest + +docker exec -it llamafactory bash ``` +
-#### 使用 Docker Compose - -首先进入 docker 目录: -```bash -# NVIDIA GPU 用户 -cd ./docker/docker-cuda - -# Ascend NPU 用户 -cd ./docker/docker-npu -``` -然后运行以下命令创建 docker 镜像并启动容器: - -```bash -docker-compose up -d -docker-compose exec llamafactory bash -``` -
数据卷详情 - hf_cache:使用宿主机的 Hugging Face 缓存文件夹,允许更改为新的目录。