From 1c972bff8da2ba1e39d4bc488d0c5bfa81e2fb47 Mon Sep 17 00:00:00 2001 From: MengqingCao Date: Mon, 24 Jun 2024 03:40:44 +0000 Subject: [PATCH] add docker for llamafactory --- sources/llamafactory/Dockerfile | 37 +++++++++++++++++ sources/llamafactory/docker-compose.yaml | 31 ++++++++++++++ sources/llamafactory/install.rst | 52 ++++++++++++++++++++++-- 3 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 sources/llamafactory/Dockerfile create mode 100644 sources/llamafactory/docker-compose.yaml diff --git a/sources/llamafactory/Dockerfile b/sources/llamafactory/Dockerfile new file mode 100644 index 0000000..955256c --- /dev/null +++ b/sources/llamafactory/Dockerfile @@ -0,0 +1,37 @@ +# 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 diff --git a/sources/llamafactory/docker-compose.yaml b/sources/llamafactory/docker-compose.yaml new file mode 100644 index 0000000..93eb671 --- /dev/null +++ b/sources/llamafactory/docker-compose.yaml @@ -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 diff --git a/sources/llamafactory/install.rst b/sources/llamafactory/install.rst index 3c63e33..75a270a 100644 --- a/sources/llamafactory/install.rst +++ b/sources/llamafactory/install.rst @@ -1,11 +1,16 @@ 安装指南 ============== -本教程面向使用 LLAMA-Factory & 昇腾的开发者,帮助完成昇腾环境下 LLaMA-Factory 的安装。 +本教程面向使用 LLAMA-Factory & 昇腾的开发者,帮助完成昇腾环境下 LLaMA-Factory 的安装。此处提供 :ref:`install` 和 :ref:`docker` 两种安装方式。 -昇腾环境安装 +.. _install: + +直接安装 ------------ +昇腾环境安装 +~~~~~~~~~~~~~~~ + 请根据已有昇腾产品型号及CPU架构等按照 :doc:`快速安装昇腾环境指引 <../ascend/quick_install>` 进行昇腾环境安装,或使用已安装好昇腾环境及 LLaMA-Factory 的 docker 镜像: - TODO @@ -16,7 +21,7 @@ 安装 CANN 时,请同时安装 Kernel 算子包。 Python 环境创建 ----------------------- +~~~~~~~~~~~~~~~ .. note:: 如果你已经选择使用上述 docker 镜像,可忽略此步骤,直接开始使用 LLaMA-Factory。 @@ -31,7 +36,7 @@ Python 环境创建 LLaMA-Factory 安装 ----------------------- +~~~~~~~~~~~~~~~~~~~~~~~~ 使用以下指令安装带有 torch-npu 的 LLaMA-Factory: @@ -40,6 +45,45 @@ LLaMA-Factory 安装 pip install -e .[torch_npu,metrics] +.. _docker: + +使用 Docker +------------ + +进入 docker-npu 目录: + +.. code-block:: shell + + cd docker/docker-npu + +该目录下为 Dockerfile 及 docker compose 配置文件: + +Dockerfile: + +.. literalinclude:: ./Dockerfile + :language: docker + :linenos: + +docker-compose.yaml: + +.. literalinclude:: ./docker-compose.yaml + :language: yaml + :linenos: + +.. note:: + + 默认镜像为 `cosdt/cann:8.0.rc1-910b-ubuntu22.04 `_。 + 更多选择见 `cosdt/cann `_. + +使用以下指令构建及启动 docker 容器: + +.. code-block:: shell + + docker build -f ./Dockerfile \ + --build-arg INSTALL_DEEPSPEED=false \ + --build-arg PIP_INDEX=https://pypi.org/simple \ + -t llamafactory:latest + 安装校验 ----------------------