Step 1:创建实例

如果平台的镜像中没有您需要的Python、Cuda、框架版本,则可以选择Miniconda,然后按照自己需求进行环境安装。

Step 2:安装Python

登录实例终端,根据需要的Python版本创建虚拟环境:

conda create -n gpugeek python==3.8.10
conda activate gpugeek
python3 --version
Python 3.8.10

Step 3:安装Cuda

根据需求安装Cuda版本,到NVIDIA去下载所需的:CUDA Toolkit安装包

复制上述图片中的命令,然后到终端中下载并执行安装,下载前可使用GpuGeek学术资源加速

wget https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda_12.4.0_550.54.14_linux.run
sh cuda_12.4.0_550.54.14_linux.run --silent --toolkit && rm cuda_12.4.0_550.54.14_linux.run

验证新安装的Cuda版本:

nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Tue_Feb_27_16:19:38_PST_2024
Cuda compilation tools, release 12.4, V12.4.99
Build cuda_12.4.r12.4/compiler.33961263_0

Step 4:安装框架

根据自己需求去安装所需框架和对应版本:

pip config set global.index-url https://mirrors.aliyun.com/pypi/simple
pip install torch==2.4.0 torchvision==0.19.0 torchaudio==2.4.0 --index-url https://download.pytorch.org/whl/cu124

Step 5:安装其他环境

上述的Python、Cuda、框架等版本需根据自己需求进行安装,以上仅给出安装示例。

Step 6:验证已安装的版本

(gpugeek) root@gz-ins-636197260402693:~# cat check_version.py 
import torch
import sys
x = torch.rand(5, 3)
print("Result:", x)
print("CUDA is available:", torch.cuda.is_available())
print(torch.zeros(1).cuda())
print("GPU available numbers:", torch._C._cuda_getDeviceCount())
print("PyTorch version:", torch.__version__)
print("CUDA version:", torch.version.cuda)
print("Python version:", sys.version)
cudnn_version = torch.backends.cudnn.version()
print(f"cuDNN version: {cudnn_version}")
print("NCCL version:", torch.cuda.nccl.version())


(gpugeek) root@gz-ins-636197260402693:~# python check_version.py 
Result: tensor([[0.7838, 0.1052, 0.2517],
        [0.0549, 0.0639, 0.9170],
        [0.8569, 0.8401, 0.7786],
        [0.2685, 0.7826, 0.3778],
        [0.5491, 0.1513, 0.2379]])
CUDA is available: True
tensor([0.], device='cuda:0')
GPU available numbers: 1
PyTorch version: 2.4.0+cu124
CUDA version: 12.4
Python version: 3.8.10 (default, Jun 4 2021, 15:09:15) 
[GCC 7.5.0]
cuDNN version: 90100
NCCL version: (2, 20, 5)

想要了解更多,请前往:自定义环境 | GpuGeek智算云


GpuGeek
1 声望1 粉丝

GpuGeek,成就AI极客!