Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyTorch、CUDA Toolkit 及顯卡驅動的安裝流程 #22

Open
JeffKko opened this issue Apr 11, 2023 · 0 comments
Open

PyTorch、CUDA Toolkit 及顯卡驅動的安裝流程 #22

JeffKko opened this issue Apr 11, 2023 · 0 comments

Comments

@JeffKko
Copy link
Owner

JeffKko commented Apr 11, 2023

PyTorch、CUDA Toolkit 及顯卡驅動的安裝流程

Intro

安裝的 CUDA 版本必須符合 PyTorch 版本

CUDA 版又必須符合顯卡驅動程式的版本

所以寫個文章記錄一下

指令下

nvidia-smi

可以看到顯卡驅動的版本 (Driver Version)

顯卡驅動版本和 CUDA 對應版的可以看這個表

基本上都是版本高的可向下兼容

https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html

安裝 CUDA

到官網安裝查一下自己電腦適合安裝甚麼版本 CUDA
https://pytorch.org/get-started/locally/
進去後面後自動選的就是了

在到官網下載 CUDA

最新版 https://developer.nvidia.com/cuda-downloads
歷史版本 https://developer.nvidia.com/cuda-toolkit-archive

安裝好後可以下指令確認版本

nvcc -V

可以看到 release ${version}

安裝 PyTorch

CUDA 安裝完成後

回到 Pytron 官網可以看到對應的版本下有安裝指令

例如 pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu117

這個指令會一併安裝 torchvision 和 torchaudio

有人說會安裝失敗可以改 pip3 改成 pip

測試

都安裝好後可以建立一個 test.py

import torch

print(torch.__version__)

tensor = torch.rand(3,4)
print(f"Device tensor is stored on: {tensor.device}")
# Device tensor is stored on: cpu

print(torch.cuda.is_available())
#True

tensor = tensor.to('cuda')
print(f"Device tensor is stored on: {tensor.device}")
# Device tensor is stored on: cuda:0

執行檔案測試

python test.py
2.0.0+cu117
Device tensor is stored on: cpu
True
Device tensor is stored on: cuda:0

看到這個輸出就代表成功了 (這個是 PyTorch 2.0.0 + cuda 11.7版本)

參考

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant