执行脚本
nohup
执行脚本:
nohup ./train.sh > ./res/.out 2>&1 &
脚本配置:编辑
train.sh
#!/bin/bash python main.py --config ./exps/simplecil.json
1
2
标准错误和标准输出分开在两个文件中
nohup your_command > stdout.log 2> stderr.log &
1
your_command
:要运行的命令。> stdout.log
:将标准输出重定向到stdout.log
文件。2> stderr.log
:将标准错误重定向到stderr.log
文件。&
:将任务放到后台运行。
示例
假设您要运行一个 Python 脚本 script.py
,并希望将标准输出保存到 output.log
文件,将标准错误保存到 error.log
文件,可以这样做:
nohup python script.py > output.log 2> error.log &
1
这样,script.py
的标准输出会写入 output.log
,而标准错误会写入 error.log
,并且程序会在后台运行。
如果您还希望在任务执行完之后可以关闭终端但保持任务运行,可以结合 nohup
和 &
一起使用,如上所示。
sbatch
执行脚本:
sbatch train.slurm
脚本配置:编辑
train.slurm
#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
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
上次更新: 2025/04/02, 12:03:38