当前位置: 首页 > news >正文

使用pip3安装PyTorch与PyG,实现NVIDIA CUDA GPU加速

使用python3pip3命令安装python依赖库。

# python3 -V
Python 3.12.3
# 
# pip3 -V 
pip 25.0.1 from /root/.pyenv/versions/3.12.3/lib/python3.12/site-packages/pip (python 3.12)
Usage:   
  pip3 install [options] <package> ...
  pip3 install [options] -r <requirements file> ... 
  
  pip3 uninstall [options] <package> ...
  pip3 uninstall [options] -r <requirements file> ... 

GPU驱动和Cuda工具

GPU规格:NVIDIA TU104GL [Tesla T4]
驱动和Cuda版本:NVIDIA-SMI 550.127.08 Driver Version: 550.127.08 CUDA Version: 12.4

# lspci | grep -i nvidia
00:07.0 3D controller: NVIDIA Corporation TU104GL [Tesla T4] (rev a1)
# 
# nvidia-smi
Thu Apr 10 12:13:49 2025       
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.127.08             Driver Version: 550.127.08     CUDA Version: 12.4     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  Tesla T4                       On  |   00000000:00:07.0 Off |                    0 |
| N/A   29C    P8              9W /   70W |       1MiB /  15360MiB |      0%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+
                                                                                         
+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|  No running processes found                                                             |
+-----------------------------------------------------------------------------------------+
# 
# nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Thu_Mar_28_02:18:24_PDT_2024
Cuda compilation tools, release 12.4, V12.4.131
Build cuda_12.4.r12.4/compiler.34097967_0
# 
# nvidia-smi --query-gpu=name,memory.total,utilization.gpu,temperature.gpu --format=csv
name, memory.total [MiB], utilization.gpu [%], temperature.gpu
Tesla T4, 15360 MiB, 0 %, 29

PyTorch安装

PyTorch, Tensors and Dynamic neural networks in Python with strong GPU acceleration

  • https://pytorch.org/
  • https://github.com/pytorch/pytorch
pip3 install torch torchvision 
torch-2.6.0

pip3 install -r pytorch/requirements.txt 
pip3 install scikit-learn tqdm gpytorch skorch 

在这里插入图片描述
在这里插入图片描述

PyG安装

PyG is the ultimate library for Graph Neural Networks
Build graph learning pipelines with ease

  • https://pyg.org/
  • https://pytorch-geometric.readthedocs.io/en/latest/install/installation.html
  • https://github.com/pyg-team/pytorch_geometric
pip3 install torch_geometric 
torch_geometric-2.6.1

# python3 -c "import torch; print(torch.__version__)" 
2.6.0+cu124
# python3 -c "import torch; print(torch.version.cuda)" 
12.4
# python3 -c "import torch; print(torch.cuda.device_count())" 
1

pip3 install pyg_lib torch_scatter torch_sparse torch_cluster torch_spline_conv -f https://data.pyg.org/whl/torch-2.6.0+cu124.html 

在这里插入图片描述
在这里插入图片描述

Python示例代码依赖

pip3 install -r pyg-examples/requirements.txt 

如何导出Python项目的库依赖文件requirements.txt,自行搜索DeepSeek、ChatGPT或Google/谷歌。

相关文章:

  • LeetCode Hot100 刷题笔记(1)—— 哈希、双指针、滑动窗口
  • <component>用于挂载切换几个不同的组件
  • mobaxterm连接ssh提示sshpass: command not found
  • vmware、centos: 快照、redis集群克隆、虚拟机克隆后无法上网
  • 最简rnn_lstm模型python源码
  • 京存双活磁盘阵列助力国家交通指挥中心
  • Excel流式多线程带进度条功能的导入框架
  • 当开源邂逅AI,公益长出翅膀 | 回顾3.30 上海「开源×AI 赋能公益」Meetup
  • 如何更改wsl2中的ubuntu默认安装位置
  • 前端Js,检查一个字符串中是否出现高重复率
  • 理解Commit:版本控制的核心概念
  • 模拟的DDoS攻击网络数据样例,包含正常流量与不同类型攻击的对比数据
  • 室分系统(室内分布系统)详解
  • Springboot把外部jar包打包进最终的jar包,并实现上传服务器
  • JS小练习0.3——秒数转换为时分秒
  • Gerrit的安装与使用说明(Ubuntu)
  • QScrCpy源码解析(3)监听手机usb端口
  • Python数据分析及相关库(二)
  • 轻量级Java跨包调用(完全解耦)
  • vue 走马灯 纵向滚动
  • wordpress主题网址导航葬爱/搜索关键词排名优化
  • 营口东站营销网站建设/广告模板
  • 做政府网站的厂家/网站制作培训
  • 天津 公司网站建设/google推广seo
  • .net 手机网站开发/腾讯域名
  • 哪里可以做宝盈网站/打开百度app