Skip to content

Commit

Permalink
add docker for llamafactory
Browse files Browse the repository at this point in the history
  • Loading branch information
MengqingCao authored and FFFrog committed Jun 24, 2024
1 parent 828c0fa commit 1c972bf
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 4 deletions.
37 changes: 37 additions & 0 deletions sources/llamafactory/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions sources/llamafactory/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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
52 changes: 48 additions & 4 deletions sources/llamafactory/install.rst
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,7 +21,7 @@
安装 CANN 时,请同时安装 Kernel 算子包。

Python 环境创建
----------------------
~~~~~~~~~~~~~~~

.. note::
如果你已经选择使用上述 docker 镜像,可忽略此步骤,直接开始使用 LLaMA-Factory。
Expand All @@ -31,7 +36,7 @@ Python 环境创建
LLaMA-Factory 安装
----------------------
~~~~~~~~~~~~~~~~~~~~~~~~

使用以下指令安装带有 torch-npu 的 LLaMA-Factory:

Expand All @@ -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 <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>`_.

使用以下指令构建及启动 docker 容器:

.. code-block:: shell
docker build -f ./Dockerfile \
--build-arg INSTALL_DEEPSPEED=false \
--build-arg PIP_INDEX=https://pypi.org/simple \
-t llamafactory:latest
安装校验
----------------------

Expand Down

0 comments on commit 1c972bf

Please sign in to comment.