常用命令
Note
在日常使用中,总是用到一些命令,在这些统一做归类整理
Conda
创建环境
1 | conda create --name py36 python=3.6 |
激活环境
1 | source activate py36 |
取消激活
1 | conda deactivate py36 |
安装 pytorch(CUDA=11.7)
1 | conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia |
导出环境
1 | conda env export > filename |
导入环境
1 | conda env create -n wbw_tgan -f tgan.env |
PIP
Note
有些包 Conda 无法安装,pip 却可以。个人实践发现在迁移环境的时候,使用 pip 的成功率要高过 conda。可以用 conda 创建环境,在进入环境后用 pip 来安装。
导出依赖
1 | pip freeze > requirements.txt |
导入依赖
1 | pip install -r requirements.txt |
如果依赖中包含 Pytorch,还需要加上额外的索引。如 Pytorch 1.10.1:
1 | pip install -r requirements.txt -f https://download.pytorch.org/whl/cu111/torch_stable.html |
具体加什么索引参考 [Pytorch 官网的版本页](Previous PyTorch Versions | PyTorch)
CPU 占用
1 | top |
进入 top 后,CPU%
一列即为上一次更新到现在进程占用 CPU 的时间,这个时间间隔默认为 5s,可以通过 -d 参数调节。
会发现 CPU%
大于 100 的情况,是因为是以单个核心来作为基数的,如果要以全部作为基数,需要在进入 top 后,输入大写的 I
来切换。会提示 Irix mode off
即可。
Bash Shell
不知为啥,在 WSL 的模型训练速度远慢过在 Windows 下的速度,尤其是一些 CPU 任务。
好在使用 Conda 的话,可以在 Windows 下同样执行 Shell 脚本
1 | conda install m2-base |