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.

相关推荐
罗西的思考24 分钟前
【轻量化复刻大模型 / KIMI K3】KDA(Kimi Delta Attention):并行
人工智能·算法·机器学习
方方洛4 小时前
ray教程-23-附录C-术语表
人工智能·分布式·机器学习
程序猿编码6 小时前
解决 LLM 算力浪费,一套统一 KV 管理层实现缓存复用
人工智能·神经网络·机器学习·缓存·llm·大模型推理
Blockbuater_drug7 小时前
《经典机器学习实战》第 1 课:导论——是什么、简史、负责任 AI 与标准流程
机器学习·scikit-learn·监督学习·数据清洗·过拟合·训练集测试集·公平性
盼小辉丶8 小时前
PyTorch强化学习实战——从零开始实现魔方求解器
pytorch·深度学习·强化学习
呆萌很8 小时前
深度学习中检测、识别、感知区别
人工智能·深度学习
武天旭9 小时前
AI安全--AI大模型的关键技术组成
人工智能·深度学习·安全·机器学习
计算机毕业编程指导师10 小时前
基于深度学习的花卉图像分类识别系统(PyTorch + ResNet50 + Django)
pytorch·python·深度学习·分类·毕业设计·迁移学习·图像分类
程序猿编码10 小时前
RK3588 NPU LLM 推理引擎:自研底层算子,性能碾压原厂 SDK
机器学习·llm·rk3588·大模型推理
集芯微电科技有限公司10 小时前
40V/24A高频率增强型GaN HEMT功率开关管/高频DC转换/电动工具/GaN充电器 方案首选
人工智能·科技·单片机·嵌入式硬件·深度学习·神经网络·生成对抗网络