本教程介绍如何在Ascend AI处理器上使用MindSpore Profiler进行集群训练性能调试。
/home/user/code/data
,则summary-base-dir设为/home/user/code
。启动成功后,根据IP和端口访问可视化界面,默认访问地址为 http://127.0.0.1:8080
。分布式训练请参考分布式训练教程。
多机多卡训练的时候,一次集群训练后,性能数据分布在各个主机上(host节点)。要进行集群性能分析,需要将所有主机上的性能数据收集到一台主机上进行分析。考虑到集群运行环境的复杂以及相关的权限问题、登录问题,比较合理的方式是让用户去收集集群性能数据。 下面是一次分布式集群训练后,使用脚本收集性能数据的过程,用户可以参照此脚本进行集群性能数据收集。
脚本程序说明:脚本程序首先创建了集群作业文件夹,然后利用SSHPass技术进行非交互式的远程拷贝(避免了手动认证,手动输入密码),将集群中各个host节点的数据拷贝到集群作业文件夹中。
#!/bin/bash
echo "=============================================================================================================="
echo "Please run the script as: "
echo "bash collect_cluster_profiler_data.sh"
echo "for example: bash collect_cluster_profiler_data.sh cluster_hccl_config_path cluster_account_config_path cluster_train_id host_train_id is_absolute_path"
echo "=============================================================================================================="
SSH="ssh -o StrictHostKeyChecking=no"
SCP="scp -o StrictHostKeyChecking=no"
# Get the node list in the cluster.
get_cluster_list()
{
local cluster_config=$1
cat ${cluster_config} | python3 -c 'import sys,json;[print(node) for node in json.load(sys.stdin)["cluster"].keys()]'
}
# Get the account number of node.
get_node_user()
{
local cluster_config=$1
local node=$2
cat ${cluster_config} | python3 -c 'import sys,json;print(json.load(sys.stdin)["cluster"]['\"${node}\"']["user"])'
}
# Get the password of node.
get_node_passwd()
{
local cluster_config=$1
local node=$2
cat ${cluster_config} | python3 -c 'import sys,json;print(json.load(sys.stdin)["cluster"]['\"${node}\"']["passwd"])'
}
# Copy data from remote node to local node.
rscp_pass()
{
local node="$1"
local user="$2"
local passwd="$3"
local src="$4"
local target="$5"
sshpass -p "${passwd}" ${SCP} -r "${user}"@"${node}":"${src}" "${target}"
}
cluster_hccl_config_path=$1
cluster_account_config_path=$2
cluster_train_id=$3
host_train_id=$4
is_absolute_path=$5
node_list=$(get_cluster_list ${cluster_account_config_path})
echo "-----begin----"
target_dir=${cluster_train_id}/profiler/
if [ ! -d "${target_dir}" ]; then
mkdir -p ${target_dir}
fi
for node in ${node_list}
do
user=$(get_node_user ${cluster_account_config_path} ${node})
passwd=$(get_node_passwd ${cluster_account_config_path} ${node})
echo "------------------${user}@${node}---------------------"
# Eight devices data
if [ $is_absolute_path = '0' ];then
device_regex=$(basename $(dirname $host_train_id))
output=$(basename $host_train_id)
grandfather_host_train_id=$(dirname $(dirname $host_train_id))
for((i=0;i<8;i++));
do
src_dir=${grandfather_host_train_id}/${device_regex}${i}/${output}*/profiler/*.*
$(rscp_pass ${node} ${user} ${passwd} "${src_dir}" ${target_dir})
done
elif [ $is_absolute_path = '1' ];then
src_dir=${host_train_id}/profiler/*.*
for((i=0;i<8;i++));
do
$(rscp_pass ${node} ${user} ${passwd} "${src_dir}" ${target_dir})
done
else
echo "The value of is_absolute_path can only be 0 or 1."
exit 1
fi
done
脚本参数说明:
cluster_hccl_config_path
为多卡环境的组网信息文件路径。内容格式如下:
{
"version": "1.0",
"server_count": "1",
"server_list": [
{
"server_id": "10.xxx.xxx.1",
"device": [
{"device_id": "0","device_ip": "192.1.27.6","rank_id": "0"},
{"device_id": "1","device_ip": "192.2.27.6","rank_id": "1"},
{"device_id": "2","device_ip": "192.3.27.6","rank_id": "2"},
{"device_id": "3","device_ip": "192.4.27.6","rank_id": "3"},
{"device_id": "4","device_ip": "192.1.27.7","rank_id": "4"},
{"device_id": "5","device_ip": "192.2.27.7","rank_id": "5"},
{"device_id": "6","device_ip": "192.3.27.7","rank_id": "6"},
{"device_id": "7","device_ip": "192.4.27.7","rank_id": "7"}],
"host_nic_ip": "reserve"
}
],
"status": "completed"
}
cluster_account_config_path
为各主机账号密码配置文件路径,内容格式如下:
{
"rank_size": 16,
"cluster": {
"10.xxx.xxx.1": {
"user": "root",
"passwd": "xxx"
},
"10.xxx.xxx.2": {
"user": "root",
"passwd": "xxx"
}
}
}
cluster_train_id
集群性能数据汇总保存的路径,比如/home/summary/run1
、/home/summary/run2
其中run1
和run2
分别保存两次集群训练的所有性能数据。
host_train_id
集群训练中,用户设置的性能数据保存路径。当性能数据保存路径设置为绝对路径时,host_train_id
的值即为用户设置的值。比如值为/data/run
时,多卡性能数据均保存在/data/run/profiler
中(profliler
文件夹由程序自动创建),host_train_id
值应该设置为/data/run
。当性能数据保存路径设置为相对路径时,多卡性能数据可能保存在不同的文件夹中。比如/data/run/device0/data/profiler
、/data/run/device1/data/profiler
。它们的共性路径为/data/run/device/data/profiler
,每张卡的性能数据保存路径为/data/run/device{device_id}/data/profiler
。host_train_id
值应该设置为/data/run/device/data
。
is_absolute_path
在需要收集的集群性能数据中,单机多卡数据是否保存在同一个目录中。若是,设置为1;不是,设置为0。
通过脚本收集到的集群性能目录结构为:
|-- run
|-- profiler
|-- step_trace_raw_{rank_id}_detail_time.csv
集群性能目录和单卡性能目录格式进行了统一。
在MindInsight r1.3以及之前的版本中,集群性能目录结构如下:
|-- run
|-- hccl.json
|-- host_ips_mapping.txt
|-- cluster_profiler
|-- 1
| |-- profiler
| |-- step_trace_raw_0_detail_time.csv
通过数据转换脚本,可以将用户使用MindInsight r1.3以及之前的版本创建的集群性能目录转换为当前支持的集群性能目录。可以从官网下载集群目录转换脚本。
启动命令请参考MindInsight相关命令。
用户从训练列表中选择指定的训练,点击性能调试,点击集群
Table标签,可以以集群视角展示本次训练性能数据。集群训练性能包括集群迭代轨迹分析、集群通信性能分析。
图1:集群训练性能总览
图1为集群训练性能总揽,是对集群迭代轨迹组件、集群通信性能组件的总体呈现。各组件展示内容如下:
使用集群迭代轨迹分析组件,可以找出集群训练中的慢主机、慢卡。 集群迭代轨迹分析组件展示所有卡的迭代信息,包括迭代间隙、前反向、迭代拖尾,均支持排序操作。其中迭代间隙反映了数据处理阶段的快慢,通过卡的迭代间隙时间可以反映出对应主机处理数据的快慢。卡的前反向时间反映了卡的计算能力。迭代拖尾反映了all_reduce耗时以及并行情况。
图2:集群迭代轨迹
图2展示了集群迭代轨迹分析页面,默认展示卡的性能平均值,支持查询特定step下的卡的迭代轨迹信息。通过点击单卡中的详情连接,也可以跳转到单卡的详细性能展示页面,查询详细的单卡性能数据。
图3:单卡性能信息
图3展示集群中单卡性能信息,单卡性能信息请参考单卡性能信息。
集群通信与计算重叠时间分析组件用于流水并行和模型并行场景,可以找出集群训练中的慢主机、慢卡。
集群通信与计算重叠时间分析组件新增了五项指标:纯通信时间(仅包含Receive算子)、state时间、纯通信时间、计算时间、纯通信时间(不包含Receive算子)。
图4:流水并行模式分析
图4展示了流水并行场景下页面展示的内容,默认展示所有step的平均数值。页面中展示了迭代间隙时间、纯接收时间、阶段时间、纯通信时间、计算时间、纯集合通信时间。由于整个网络的计算图被切分为多个阶段的子图,阶段时间可用于定位慢的阶段,通过选择阶段编号可以筛选出同一阶段的卡,在阶段内部可用模型并行场景的思路定位瓶颈。
图5:模型并行模式分析
图5展示了模型并行场景(此处指层内模型并行)下页面展示的内容,默认展示所有step的平均数值。页面中展示了迭代间隙时间、纯通信时间、计算时间。计算时间可用于定位慢卡,如果没有慢卡,查看通信时间与计算时间占比,若通信时间占比较大,考虑是否有慢链路。
集群通信性能组件从两个维度来展示集群通信性能信息,以卡为粒度展示和全网链路展示。
图6:集群通信性能分析
图6展示了集群通信性能分析页面,包含逻辑卡通信性能以及全网链路信息(所有逻辑卡链路信息)。
逻辑卡通信性能TAB页主要用来展示逻辑卡的通信性能,包括通信时间、等待时间、算子详情、逻辑卡链路信息。
Reduce inline
和Memcpy
算子总时间作为通信时间;如果是RDMA链路,取连续三个算子RDMASendPayload
、RDMASendNotify
、Notify Wait
的总时间为通信时间。Notify Wait
算子总耗时并减去RDMA链路通信时间中的Notify Wait
算子耗时。图7:算子性能信息
图8:逻辑卡链路信息
全网链路信息TAB页面展示所有逻辑卡的链路信息,提供源卡、目的卡、链路类型的选择。
图9:全网链路信息
默认不收集通信性能数据,需要通过mindspore.profiler.Profiler
中的profile_communication
参数像Profiler(profile_communication=True)
一样打开通信性能数据开关。只有多卡训练才能产生通信算子性能数据,在单卡训练场景中设置该参数是无效的。
使用MindInsight可视化通信性能数据需要安装Ascend 910 AI处理器配套软件包提供的通信性能数据解析whl包,whl包随配套软件包发布,参考如下命令完成安装。
pip install /usr/local/Ascend/tools/hccl_parser-{version}-py3-none-any.whl
该页面展示了并行场景下,模型在Device侧的内存使用情况,是基于理论值的理想预估。页面内容包括:
图10:集群内存概览页面
内存使用情况分析暂不支持异构训练场景。
该页面展示了并行场景下,每个设备的FLOPs(浮点运算次)数据,热力图反映了设备之间FLOPs的相对大小。页面内容包括:
图11:集群FLOPs概览页面
为了控制性能测试时生成数据的大小,大型网络建议性能调试的step数目限制在10以内。
控制step数目可以通过控制训练数据集的大小来实现,如
mindspore.dataset.MindDataset
类中的num_samples
参数可以控制数据集大小,详情参考:https://www.mindspore.cn/docs/api/zh-CN/r1.5/api_python/dataset/mindspore.dataset.MindDataset.html
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。