每天一个linux小技巧

1.nohup

no hang up,用nohup运行命令可以使命令永久的执行下去,和用户终端没有关系,例如我们断开SSH连接都不会影响他的运行,注意了nohup没有后台运行的意思。

加&的作用是将,命令放到后台运行,使得终端可以继续输入其他命令。

nohup python xx.py >> xx.log(脚本输出的内容重定向输入到xx.log)

2. conda虚拟环境

linux 安装conda ➡️ 🏠

安装成功后的命令:

conda create -n 环境名 python=3.7(自选版本)

激活环境

conda activate 环境名

退出环境

deactivate

3.编写测试脚本

1. 创建.sh文件

sudo vim test.sh

2.往.sh文件中填写内容,下面这个例子是语音识别某一目录下所有的.mp3文件

#!/bin/bash
for file in folder/*.mp3
do
  whisper "$file" --model small
done

3.为脚本授予执行权限

chmod +x test.sh

4.执行脚本

./test.sh

 4.GPU

运行报错

torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 14.76 GiB total capacity; 6.38 GiB already allocated; 4.88 MiB free; 6.70 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation.  See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF

这个错误消息表明在使用 PyTorch 运行程序时,CUDA 显存不足以分配所需的内存。

可以运行:

nvidia-smi

查看当前查看现存占用情况