目的:运算量巨大的时候,需要使用SLURM的GPU集群来运行实验。每个SLURM集群的配置方法不一样,但是流程大致相同。下面为我配置SLURM集群的方法,亲测有效
目录
一、客户端部署
1.1 下载
(根据平台下载相应的客户端)
wget -e "http_proxy**" http://**/slurm-client-install.sh
下载位置,找个相对大一点的盘, df -h -l
/dev/sdb1 3.6T 1.8G 3.6T 1% /home/ssd1
$ cd /home/ssd1/
$ pwd
/home/ssd1
$ wget -e "http_proxy=****.cp**:8888" http://**/slurm-client-v2.5/slurm-client-install.sh
下载之后看到其为:
#DO NOT USE OPTION -prefix
if [ "$1" = "-prefix" ];then
******=$2
else
******=~/.******
fi
INSTALL_ROOT=${******}/
wget -e "xxxxxxxx/slurm-client-v2.5/slurm-client-v2.5.tar.gz
mkdir -p ${INSTALL_ROOT}
tar zxvf slurm-client-v2.5.tar.gz -C ${INSTALL_ROOT}
grep '#****** use' ~/.bashrc >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo '#******use' >>~/.bashrc
echo "export PATH=${INSTALL_ROOT}/software-install/bin:\${PATH}" >>~/.bashrc
else
sed -i '/******use/,+1d' ~/.bashrc
echo '#****** use' >>~/.bashrc
echo "export PATH=${INSTALL_ROOT}/software-install/bin:\${PATH}" >>~/.bashrc
不让运用-prefix选项
1.2 安装
sh slurm-client-install.sh
会下载和安装一堆选项
输入下面命令行看token测试命令是否安装成功
tokenapply
tokenapply
bash: tokenapply: command not found
- 安装脚本会自动将安装目录写入到
~/.bashrc
中 - 如果提示找不到命令,请手动
source ~/.bashrc
- 执行2后,如果还提示找不到命令,请尝试退出机器然后重新登录机器
[ssd1]$ source ~/.bashrc
[ssd1]$ tokenapply
=======================================================
xxx Client is updating
Version: 2.6
-------------------------------------------------------
[Total Size]:2.00 MB
[██████████████████████████████████████████████████] 100%
your client is not new, we have already update it for you
Client updated done.
=======================================================
======================================================================
Apply token successfully, the information about your token
has been sent to mailbox(*****@*****.com)
======================================================================
1.3 help
[~]$ tokenapply -h
usage: client.py [-h] [-v] [-s SUBMITTER]
optional arguments:
-h, --help show this help message and exit
-v, --version version info
-s SUBMITTER, --submitter SUBMITTER
the prefix of your mailbox
二、环境配置
2.1 python与torch配置
把相应的环境配置好。
python 位置:/home/xingxiangrui/env/bin/python
cuda位置:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/work/cuda-8.0/lib64
export PATH=$PATH:/home/work/cuda-8.0/bin
client位置
2.2 配置汇总
[bin]$ ls
deljob showframework showjob shownode showquota submit tokenapply tokenclean tokenconfig tokenquery
[bin]$ ./tokenapply
deljob showjob showquota tokenapply tokenconfig
showframework shownode submit tokenclean tokenquery
[bin]$ ./tokenapply
======================================================================
Apply token successfully, the information about your token
has been sent to mailbox(**@**.com)
======================================================================
[bin]$ ./tokenconfig
Please input the token:
ak: ***
sk: ***
==================================================
Config token successfully
==================================================
三、运用
3.1 进入文件夹
注意是程序运行的文件夹,可以参考:
3.2 目录结构
submit.sh | 调用qsub_f提交任务的脚本 |
bin | 任务的可执行文件及相关文件 |
data | 本机训练数据所在目标文件夹 |
job.sh | 任务执行脚本 |
log | 存放运行日志(任务运行结束后会上传到 hadoop 中) |
output | 存放输出(任务运行结束后会上传到 hadoop 中) |
common.conf | 环境变量配置,训练脚本配置可以统一在conf里 |
3.3 拷入文件
文件运行之前需要确保可以本地运行
env环境拷入,先把之前的删掉。rm -rf
cp -r /home/xingxiangrui/env/* env/
cp -rf /home/xingxiangrui/env/ .
两个文件需要拷入,submit.sh , job.sh
3.4 路径地址
submit.sh, job.sh, run.sh都要改
路径 /home/xingxiangrui/.******/software-install**
MPI地址: /home/xingxiangruisoftware-install/openmpi-1.8.5/bin/mpirun
OpenMPI是一种高性能消息传递库,OpenMPI能够从高性能社区中获得专业技术、工业技术和资源支持
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/work/cuda-8.0/lib64
export PATH=$PATH:/home/work/cuda-8.0/bin
3.5 三个sh文件
job.sh,设定服务器工作,注意下面的MPIRUN直接要用绝对路径,直接mpirun即可。
# !!! Only Runing on master node
# 1. Set the env for multi-node training
MPIRUN="mpirun --bind-to none"
IPLIST=`cat nodelist-${SLURM_JOB_ID} | xargs | sed 's/ /,/g'`
IP0=`echo $IPLIST | awk -F',' '{print $1}' | sed 's/ //g'`
echo "==== GLOBAL INFO ====" | tee -a screen.log
echo "IPLIST: $IPLIST" | tee -a screen.log
echo "IP0: $IP0" | tee -a screen.log
echo "====================" | tee -a screen.log
# 2. Trigger on master node
$MPIRUN -x IP0=$IP0 sh run.sh
submit.sh 将任务提交服务器
******_CLIENT_BIN=/**/bin/
${******_CLIENT_BIN}/submit \
--hdfs hdfs://** \
--hdfs-user ** \
--hdfs-passwd *** \
--hdfs-path /app**/**** \
--file-dir ./ \
--job-name *** \
--queue-name *** \
--num-nodes 1 \
--num-task-pernode 1 \
--gpu-pnode 8 \
--submitter ***\
--time-limit 0 \
--job-script ./job.sh
run.sh
# 2. Get node env
NODE_IP=`hostname -i`
NODE_RANK=${OMPI_COMM_WORLD_RANK}
echo "==== NODE INFO ====" | tee -a screen.log
echo "NODE_RNAK: $NODE_RANK" | tee -a screen.log
echo "IP0: $IP0" | tee -a screen.log
echo "NODE_IP: $NODE_IP" | tee -a screen.log
echo "===================" | tee -a screen.log
# 3. Run training
PYTHON=./torch/bin/python
export LD_LIBRARY_PATH=/home/work/cuda-8.0/lib64:$LD_LIBRARY_PATH
#sh train_**_nls.sh
#../env/bin/python ../tools/train.py ../configs/cascade_rcnn_seresnet_50**.py --gpus 1 --resume_from ./work_dirs/cascade_rcnn_senet50_**_nls/epoch_288_93.4.pth
#../env/bin/python ../tools/train.py ../configs/retinanet_seresnet101_fpn_1x_**nls.py --gpus 4
#../env/bin/python ../tools/train.py ../configs/cascade_rcnn_mobilenetv2_clstest_nls.py --gpus 4
#../env/bin/python ../tools/train.py ../configs/cascade_rcnn_seresnet_50_slim_clstest_nls.py --gpus 4 --validate
#../tools/dist_train.sh ../configs/dcn/cascade_rcnn_seresnet_50_mdpool_**s.py 4
./torch/bin/python train_se_clsgat.py
四、hadoop数据服务器文件操作
ls,cp,mkdir等等
Hadoop实现了一个分布式文件系统(Hadoop Distributed File System),简称HDFS。HDFS有高容错性的特点,并且设计用来部署在低廉的(low-cost)硬件上;而且它提供高吞吐量(high throughput)来访问应用程序的数据,适合那些有着超大数据集(large data set)的应用程序。HDFS放宽了(relax)POSIX的要求,可以以流的形式访问(streaming access)文件系统中的数据。
Hadoop的框架最核心的设计就是:HDFS和MapReduce。HDFS为海量的数据提供了存储,而MapReduce则为海量的数据提供了计算。
4.1 submit.sh
目的是在此程序中更改相应的hdfs path
--******-path /app***tmp/$TIME \
******-path要通过hadoop客户端建立,使用手册如下
4.2 下载与安装
2018-05-07 | client 1.6.4 | 最新版本,支持afs和hdfs | wget -O output.tar.gz --header "***-************" |
解压
路径/home******/bin
运行 ./hadoop
4.3 afs agent
下载并使用。
#启动afs_agent
cd output && sh start_agent.sh
#停止afs_agent
cd output && sh stop_agent.sh
#检查afs_agent是否运行,看进程存在即可
ps -ef|grep bin/afs_agent|grep -v grep
路径:/home/xingxiangrui/hadoop-client/afs_agent/bin
4.4 配套hadoop
运行 ./hadoop
过于复杂,直接在submit.sh中更改相应的命令行即可。(直接运行不可,会报错)
[]$ source submit.sh
Notes: 'submitter' parameter has been removed, the submission will ignore this parameter.
cat: ./torch/lib/python3.5/site-packages/zmq/ssh: Is a directory
Error: /app/mmt-vis/xingxiangrui/se_cls_gat_on_coco is not a directory!
4.5 参考
~/.******/software-install/******/tools/hadoop-v2/hadoop/bin/hadoop fs -D fs.default.name=afs://****** -D hadoop.job.ugi=******,******-D dfs.replication=1 -D fs.afs.impl=org.apache.hadoop.fs.DFileSystem -ls /user/******/******/
五、运行集群
5.1 提交任务
直接提交
******_CLIENT_BIN=/******/bin/
${******_CLIENT_BIN}/submit \
--hdfs afs:****** \
--hdfs-user ******\
--hdfs-passwd ******\
--hdfs-path ****** \
--file-dir ./ \
--job-name ******\
--queue-name ******-p40-2-8 \
--num-nodes 1 \
--num-task-pernode 1 \
--gpu-pnode 8 \
--submitter ******\
--time-limit 0 \
--job-script ./job.sh
source submit.sh
可以将gpu-pnode设为1,表示节点的个数。
注意地址要在三级目录之后再建
同时注意,相应的用户名与密码要改为上面的这些模式
5.2 查看队列情况
showjob -p ******
查看相应的集群上的队列
查看相应的工作 show -j <job ID>
[]$ showjob -p ******
QueueName: ******
========================================================================================================================
JobId JobName Submitter RunningTime TotalGpus Status GpuUtil
========================================================================================================================
...
...
]$ showjob -j ******
==============================================================================================================
Job Information
==============================================================================================================
...
...
5.3 删除操作
# 1. 命令
deljob -j JOBID
# 2. 举例
# deljob -j
******
删除之后相应status变为 CANCELLED
六、结果查看及文件传输
相关命令行。
服务器上cp,mv 等等,用到后续来更新。与文件系统有关。
相关Linux及环境配置
客户端配置Hadoop并运用SLURM GPU集群与HDFS文件系统
SSH相关
windows PC用SSH连接Ubuntu14.04的配置与方法
macOS与CentOS之间互传文件(iTerm2与lrzsz)
环境配置相关
CentOS 6.3安装anaconda并配置pytorch与cuda
Ubuntu14.04安装Anaconda3-2018.12-x86_64
运用Anaconda对python 3.6与tensorflow-gpu与pip环境配置