有勇气的牛排博客

torch机器学习GPU信息查看


1 查看GPU版本

1.1 Win

1.1.1 使用命令行 nvidia-smi(推荐)

按下 Win + R,输入 cmd 打开命令提示符。

nvidia-smi

输出案例:

+---------------------------------------------------------------------------------------+ | NVIDIA-SMI 537.70 Driver Version: 537.70 CUDA Version: 12.2 | |-----------------------------------------+----------------------+----------------------+ | GPU Name TCC/WDDM | Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. | | | | MIG M. | |=========================================+======================+======================| | 0 NVIDIA GeForce RTX 4060 ... WDDM | 00000000:01:00.0 Off | N/A | | N/A 43C P8 1W / 80W | 839MiB / 8188MiB | 0% Default | | | | N/A | +-----------------------------------------+----------------------+----------------------+

Windows查看GPU信息

1.1.2 通过 NVIDIA 控制面板查看

  1. 桌面右键 → 点击“NVIDIA 控制面板”。
  2. 进入菜单栏“帮助” → 选择“系统信息”。
  3. 在弹出窗口中查看“驱动版本”、“CUDA Cores”等信息。

2 安装支持 CUDA 的 PyTorch 版本

根据电脑上的 CUDA 版本,在官网选适合的命令:

官网地址:https://pytorch.org/get-started/locally/

假设 CUDA 版本是 12.2,使用以下命令:

pip install torch==2.3.1 torchvision==0.18.1+cu121 torchaudio==2.3.1+cu121 --index-url https://download.pytorch.org/whl/cu121

3 验证安装成功

检测脚本:

import torch print(f"是否检测到 CUDA GPU: {torch.cuda.is_available()}") # 是否检测到 CUDA GPU print(f"PyTorch 支持的 CUDA 版本: {torch.version.cuda}") # PyTorch 支持的 CUDA 版本 print(f"GPU 数量: {torch.cuda.device_count()}") # GPU 数量 print(f"当前设备ID: {torch.cuda.current_device()}") # 当前设备ID if torch.cuda.is_available(): for i in range(torch.cuda.device_count()): print(f"\nGPU {i} 信息:") print(f" 名称: {torch.cuda.get_device_name(i)}") print(f" 计算能力: {torch.cuda.get_device_capability(i)}") print(f" 显存总量: {torch.cuda.get_device_properties(i).total_memory / 1024**3:.2f} GB") else: print("无可用 GPU")

python脚本查看GPU CUDA版本信息

评论区

×
×