How to verify your CUDA and pytorch

1.Test CUDA

This script will attempt to create a tensor on the GPU and perform a simple computation.

python 复制代码
import torch

def test_cuda():
    # Check CUDA availability
    if torch.cuda.is_available():
        print("CUDA is available on this device.")
        # Set device to CUDA
        device = torch.device("cuda")
        # Create a tensor and move it to CUDA
        x = torch.rand(10, 10).to(device)
        print("Successfully created a tensor on CUDA:", x)
        # Perform a simple computation
        y = x * x
        print("Output of the computation:", y)
    else:
        print("CUDA is not available. Check your installation and driver.")

if __name__ == "__main__":
    test_cuda()

Run the script: Use a terminal or command prompt to run the script with Python.

bash 复制代码
python test_cuda.py

The script should print whether CUDA is available, show the tensor created on the GPU, and display the output of a simple multiplication operation. If there are any errors during these steps, they will help pinpoint what might be wrong with your CUDA setup.

2.Check PyTorch Compatibility

python 复制代码
# test_torch.py
import torch
print(torch.__version__)
print(torch.cuda.is_available())

Run the script: Use a terminal or command prompt to run the script with Python.

bash 复制代码
python test_torch.py

If torch.cuda.is_available() returns True, then PyTorch is able to use CUDA.

相关推荐
是翎11 分钟前
图解大语言模型部署
人工智能·驱动开发·深度学习·开源协议·imagen
CIO_Alliance25 分钟前
AI微调系列(2)| QLoRA:一张卡微调700亿参数,显存是怎么省下来的
大数据·人工智能·深度学习·ai·企业ai转型·企业cio联盟
Zentceh1 小时前
AI-ISP vs 传统ISP全面对比
人工智能·深度学习·计算机视觉·车载系统·transformer·无人机·智能硬件
魔镜er1 小时前
11-循环神经网络
人工智能·pytorch·python·深度学习·神经网络
恒知学术2 小时前
文献检索结果太杂怎么办?用摘要、DOI 和作者机构把结果筛干净
机器学习·参考文献·谷歌学术·sci论文·免费论文检索工具
宁渡AI大模型2 小时前
河南宁渡科技有限公司|宁渡课堂 AI 全栈面试分享,AI 应用开发高频考点汇总
java·c++·人工智能·python·深度学习·神经网络·rag
Q26433650232 小时前
【有源码】基于文本挖掘的消费者金融投诉主题发现与风险预警研究,基于Python的CFPB消费者投诉数据可视化分析系统
大数据·hadoop·机器学习·数据挖掘·spark·毕业设计·课程设计
薛定e的猫咪2 小时前
(ICML2024)QSM:基于 Q 函数梯度对齐分数场的扩散模型离策略强化学习
人工智能·深度学习·算法
棣廷2 小时前
初识OpenCV——Dlib人脸检测、关键点定位与表情识别
opencv·目标检测·机器学习
桃西西呀3 小时前
提前一天预报雾霾:手搓神经网络,讲清学习率、初始化、正则化
人工智能·深度学习·llm