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.

相关推荐
高洁015 小时前
AI赋能产业升级与中美未来经济赛道博弈
人工智能·python·深度学习·机器学习·transformer
田里的水稻5 小时前
LLM_Transformer的神经网络
人工智能·深度学习·神经网络·机器学习·transformer
LaughingZhu6 小时前
任务在飞书创建,开发在 Orca 继续:我把飞书项目接到了 Linear
大数据·人工智能·深度学习·神经网络·飞书
一水鉴天6 小时前
UML/MOF 元层级与 Model & Notation:整体设计核心术语的定稿探讨 20261012(豆包“查看聊天内容”继续)
人工智能·机器学习
陈嘿萌6 小时前
TIP 2026|没有分割标签,也能做任务导向图像融合:SSVIF的自监督语义注入
图像处理·人工智能·深度学习·计算机视觉·图像融合·学术研究与理论基础
Phoenixtree_DongZhao6 小时前
StretchTime:可变时钟与辛注意力的时序预测
深度学习
小弥儿7 小时前
GitHub今日热榜 | 2026-10-12:pytorch 上升四位
人工智能·pytorch·学习·开源·github
EEET智选7 小时前
科技晨间速报 | AI 安全警钟、开源新模型与苹果智能家居
人工智能·科技·算法·机器学习·ai
HySpark8 小时前
qwen-omini情感识别效果不佳,重新梳理语音情感方案
人工智能·机器学习·语音情感识别
林伽一8 小时前
免人工审查即上生产的企业占比降至 47%,治理支出转向人工审查|2026年10月11日
人工智能·机器学习