Slurm 作业系统¶
Slurm 用于管理 CPU、GPU 和多节点任务。长时间任务、训练任务和多节点任务都应通过 Slurm 提交。
查看资源¶
sinfo
sinfo -Nel
squeue
squeue -u "$USER"
交互式运行¶
srun --input=none -N1 -n1 hostname
申请一个 GPU:
srun --input=none -N1 -n1 --gres=gpu:1 bash -lc 'hostname; nvidia-smi'
批处理作业¶
job.sbatch:
#!/bin/bash
#SBATCH -J my-job
#SBATCH -p debug
#SBATCH -N 1
#SBATCH -n 1
#SBATCH --gres=gpu:1
#SBATCH -t 01:00:00
#SBATCH -o logs/%x-%j.out
set -euo pipefail
mkdir -p logs
hostname
nvidia-smi
python train.py
提交:
sbatch job.sbatch
取消:
scancel <job_id>
查看历史:
sacct -S today -o JobID,JobName,User,Partition,State,Elapsed,AllocTRES
多节点示例¶
srun --input=none -N3 -n3 --chdir=/cluster/home/$USER hostname
跨节点任务必须使用共享路径作为工作目录,例如 /cluster/home/$USER 或 /cluster/shared。
常见状态¶
状态 |
含义 |
|---|---|
|
Pending,等待资源或调度。 |
|
Running,正在运行。 |
|
Completing,正在结束。 |
|
Completed,已完成。 |
|
Failed,失败。 |