Skip to content

Commit 69985a3

Browse files
authored
Update distributed training doc. (#89)
* bugfix * remove conflict dir * Update distributed training doc.
1 parent 36ae37d commit 69985a3

File tree

3 files changed

+94
-56
lines changed

3 files changed

+94
-56
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
分布式训练
2+
==============
3+
4+
.. note::
5+
阅读本篇前,请确保已按照 :doc:`安装教程 <./install>` 准备好昇腾环境及 LLaMA-Factory !
6+
7+
本篇为 :doc:`快速开始 <./quick_start>` 的进阶,同样首先安装 DeepSpeed 和 ModelScope:
8+
9+
.. code-block::
10+
11+
pip install -e ".[deepspeed,modelscope]" -i https://pypi.tuna.tsinghua.edu.cn/simple
12+
13+
多卡 NPU 指定
14+
--------------------------
15+
16+
无论是单机还是多机环境,请先使用 ``export ASCEND_RT_VISIBLE_DEVICES=0,1,2,3`` 显式指定所需 NPU 卡号,此处为 0~3 四卡 NPU。
17+
18+
.. note::
19+
20+
昇腾 NPU 卡从 0 开始编号,docker 容器内也是如此;
21+
22+
如映射物理机上的 6,7 号 NPU 卡到容器内使用,其对应的卡号分别为 0,1
23+
24+
25+
或使用以下脚本自动检测并指定多卡 NPU:
26+
27+
.. code-block:: shell
28+
29+
# ------------------------------ detect npu --------------------------------------
30+
# detect npu via npu-smi
31+
if command -v npu-smi info &> /dev/null; then
32+
num_npus=$(npu-smi info -l | grep "Total Count" | awk -F ":" '{print $NF}')
33+
npu_list=$(seq -s, 0 $((num_npus-1)))
34+
else
35+
num_npus=-1
36+
npu_list="-1"
37+
fi
38+
echo using npu : $npu_list
39+
num_gpus=$(echo $npu_list | awk -F "," '{print NF}')
40+
# --------------------------------------------------------------------------------
41+
export ASCEND_RT_VISIBLE_DEVICES=$npu_list
42+
43+
44+
单机多卡微调
45+
--------------------------
46+
47+
通过 ``ASCEND_RT_VISIBLE_DEVICES`` 变量显式指定多卡后,使用 torchrun 启动分布式训练,需指定 ``nproc_per_node`` 参数为 NPU 卡数量,其余参数配置与 :doc:`快速开始 <./quick_start>` 中单卡微调保持一致
48+
49+
.. code-block:: shell
50+
51+
torchrun --nproc_per_node $num_npus \
52+
--nnodes 1 \
53+
--node_rank 0 \
54+
--master_addr 127.0.0.1 \
55+
--master_port 7007 \
56+
src/train.py <your_path>/qwen1_5_lora_sft_ds.yaml
57+
58+
59+
多机多卡微调
60+
--------------------------
61+
62+
在每个节点上通过 ``ASCEND_RT_VISIBLE_DEVICES`` 变量显式指定需要用到的多个 NPU 卡,如果不指定,则默认使用所有 NPU 卡(此时需要确保显存是否够用)。
63+
64+
其次,必须在每个节点上使用 ``export HCCL_SOCKET_IFNAME=eth0`` 来指定当前节点的 HCCL 通信网卡(请使用目标网卡名替换 ``eth0``)。
65+
66+
以两机环境为例,分别在主、从节点(机器)上执行如下两条命令即可启动多机训练:
67+
68+
.. code-block:: shell
69+
70+
# 在主节点执行如下命令,设置 rank_id = 0
71+
FORCE_TORCHRUN=1 NNODES=2 NODE_RANK=0 MASTER_ADDR=192.168.0.1 MASTER_PORT=29500 \
72+
llamafactory-cli train <your_path>/qwen1_5_lora_sft_ds.yaml
73+
74+
# 在从节点执行如下命令,设置 rank_id = 1
75+
FORCE_TORCHRUN=1 NNODES=2 NODE_RANK=1 MASTER_ADDR=192.168.0.1 MASTER_PORT=29500 \
76+
llamafactory-cli train <your_path>/qwen1_5_lora_sft_ds.yaml
77+
78+
.. list-table::
79+
:widths: 30 70
80+
:header-rows: 1
81+
82+
* - 变量名
83+
- 介绍
84+
* - FORCE_TORCHRUN
85+
- 是否强制使用torchrun
86+
* - NNODES
87+
- 节点数量
88+
* - NODE_RANK
89+
- 各个节点的rank。
90+
* - MASTER_ADDR
91+
- 主节点的地址。
92+
* - MASTER_PORT
93+
- 主节点的端口。

sources/llamafactory/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ LLaMA-Factory
66

77
install.rst
88
quick_start.rst
9-
multi_npu.rst
9+
distributed.rst
1010
example.rst
1111
faq.rst

sources/llamafactory/multi_npu.rst

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)