Dali杂货铺🐰10——指定GPU进行训练

"TF, Keras, Torch"

Posted by fuhao7i on March 22, 2021

1. CUDA_VISIBLE_DEVICES

1. os.environ[‘CUDA_VISIBLE_DEVICES’]

1
2
3
4
5
6
import os

os.environ['CUDA_VISIBLE_DEVICES'] = -1     # cpu模式

os.environ['CUDA_VISIBLE_DEVICES'] = 0      # 只有GPU:0 对程序可见
os.environ['CUDA_VISIBLE_DEVICES'] = 0,1    # GPU:0 和 GPU:1 对程序可见

2. 在bash命令中使用

CUDA_VISIBLE_DEVICES=1 python run.py

3. 使用.device(‘gpu:0’) or .cuda(‘gpu:0’)指定

#. 引用

  1. pytorch指定gpu训练_PyTorch多GPU并行训练方法及问题整理