Pytorch 安装环境配置 (old)
建立环境
建立一个新环境 name = pytorch
conda create -n pytorch python
进入 pytorch 工作环境 conda activate pytorch
查看安装包 pip list
查询显卡型号:
任务管理器中,查看 Geforce GTX 950M https://developer.nvidia.com/cuda-gpus
查看驱动版本: C:\Program Files\NVIDIA Corporation\NVSMI>nvidia-smi.exe
Driver Version: 388.57 ==>需要升级驱动 https://developer.nvidia.com/drive/downloads
查看驱动版本:check graphic card and driver both suppot the CUDA varsion
cd C:\Program Files\NVIDIA Corporation\NVSMIconda //windows
nvidia-smi.exe
NVIDIA-SMI version: 512.15 Card type: NVIDIA GeForce CUDA Version: 11.6
Check Compute Capabilities:
https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html
### CUDA Toolkit version need match Card Driver Version CUDA 12.0.x >=527.41 (Windows Driver) CUDA 11.6.x >=452.39 (Windows Driver)
| NVIDIA-SMI 512.15 Driver Version: 512.15 === CUDA Version: 11.6 |
安装CUDA Toolkit and NVIDIA Driver
NVIDIA Driver Downloads: https://www.nvidia.com/download/index.aspx
CUDA Toolkit Downloads: https://developer.nvidia.com/cuda-downloads
安装 pytorch
选择系统,软件包,下载版本,产生下载安装命令 https://pytorch.org/get-started/locally/
Anaconda Prompt (anaconda3)
conda install pytorch torchvision torchaudio pytorch-cuda=11.6 -c pytorch -c nvidia
Why pip install does not working?
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117
查询是否有torch
// Run Anaconda Prompt
(base) conda activate pytorch ## activate pytorch env
(pytorch) python
>>import torch ## 查看是否可以使用GPU
>>torch.cuda.is_available()
>>torch.version.cuda
Install pytorch genmetric https://pytorch-geometric.readthedocs.io/en/latest/install/installation.html
pip install torch-scatter torch-sparse torch-cluster torch-spline-conv torch-geometric -f https://data.pyg.org/whl/torch-1.13.0+cu117.html
torch.cuda.device_count() //
torch.cuda.current_device()
torch.cuda.device(0)
torch.cuda.get_device_name(0)
torch.zeros(1).cuda() //
# setting device on GPU if available, else CPU
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
print('Using device:', device)
print()
#Additional Info when using cuda
if device.type == 'cuda':
print(torch.cuda.get_device_name(0))
print('Memory Usage:')
print('Allocated:', round(torch.cuda.memory_allocated(0)/1024**3,1), 'GB')
print('Cached: ', round(torch.cuda.memory_reserved(0)/1024**3,1), 'GB')
## check torch version //v1.11
print(torch.version) // in jupyter python -c "import torch; print(torch.version)"
##To move tensors to the respective device: torch.rand(10).to(device)
##To create a tensor directly on the device: torch.rand(10, device=device)
// install torch geometric
refer to: https://pytorch-geometric.readthedocs.io/en/latest/notes/installation.html
conda install pyg -c pyg //conda
pip install torch-scatter torch-sparse torch-cluster torch-spline-conv torch-geometric -f https://data.pyg.org/whl/torch-1.11.0+cu115.html
// install jurpyter in pytorch enveriment
//check installed parkage
conda install jupyter
Does PyTorch see any GPUs? torch.cuda.is_available()
Are tensors stored on GPU by default? torch.rand(10).device
Set default tensor type to CUDA: torch.set_default_tensor_type(torch.cuda.FloatTensor)
Is this tensor a GPU tensor? my_tensor.is_cuda
Is this model stored on the GPU? all(p.is_cuda for p in my_model.parameters())
Last updated
Was this helpful?