nohup

  • 执行脚本:nohup ./train.sh > ./res/.out 2>&1 &

  • 脚本配置:编辑train.sh

    1
    2
    #!/bin/bash
    python main.py --config ./exps/simplecil.json

标准错误和标准输出分开在两个文件中

1
nohup your_command > stdout.log 2> stderr.log &
  • your_command:要运行的命令。
  • > stdout.log:将标准输出重定向到 stdout.log 文件。
  • 2> stderr.log:将标准错误重定向到 stderr.log 文件。
  • &:将任务放到后台运行。

示例

假设您要运行一个 Python 脚本 script.py,并希望将标准输出保存到 output.log 文件,将标准错误保存到 error.log 文件,可以这样做:

1
nohup python script.py > output.log 2> error.log &

这样,script.py 的标准输出会写入 output.log,而标准错误会写入 error.log,并且程序会在后台运行。

如果您还希望在任务执行完之后可以关闭终端但保持任务运行,可以结合 nohup& 一起使用,如上所示。

sbatch

  • 执行脚本:sbatch train.slurm

  • 脚本配置:编辑train.slurm

1
2
3
4
5
6
7
8
9
10
11
12
#SBATCH -p gpu-quota # 提交到指定分区
#SBATCH -N 1 # 使用一个节点
#SBATCH -n 8 # 使用进程(cpu 核)
#SBATCH --gres=gpu:1
#SBATCH -o ./res/l2p-cifar.out
#SBATCH -e ./res/l2p-cifa.err

module load anaconda3
source activate cil

# l2p-cifar
python main.py --config=./exps/l2p_cifar_B0_Inc5.json