在Linux上使用PyTorch進行GPU加速,需按以下步驟操作:
nvidia-smi命令檢查驅動是否正常。PATH和LD_LIBRARY_PATH)。pip install torch --extra-index-url https://download.pytorch.org/whl/cu117),安裝時需指定cudatoolkit版本。import torch; print(torch.cuda.is_available()),若輸出True則配置成功。device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)
input_tensor = input_tensor.to(device)
注意:
torch.nn.DataParallel或DistributedDataParallel。