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.

相关推荐
大鱼>17 分钟前
DSPy:LLM程序自动编译与提示词优化
开发语言·人工智能·python·深度学习
DogDaoDao17 分钟前
VVC 帧间编码分区加速方法
深度学习·音视频·视频编解码·h266·vvc·预测编码·帧间编码
AI科技星18 分钟前
全域光速运动理论体系 (GAQ-UFT)——范式重构、核心方程与传统物理的本质分野
人工智能·线性代数·机器学习·重构·数据挖掘·回归·ai科技星
Lee_jerome30 分钟前
python神经网络编程入门(二十)——RNN LSTM 数学原理与结构拆解
深度学习·numpy·lstm·参数量·sigmoid·tanh·门控机制
circuitsosk43 分钟前
大规模离线数据管道构建:样本获取、清洗、加工与合成
人工智能·python·机器学习·搜索引擎
海兰1 小时前
【思考】银行落地业务Agent的思考
人工智能·机器学习·agent
满怀冰雪2 小时前
15-Paddle 高层 API 入门:paddle.Model 的训练与评估流程
人工智能·python·深度学习·机器学习·paddle
YFJ_mily5 小时前
【会议征稿】第八届人本计算与数据智能国际会议(HCC 2026)| 广州12月召开,EI/Scopus稳定检索,多届收录无忧
机器学习·人机交互·ei会议·数据智能·rdlink研发家·人本计算·广州会议
陕西企来客10 小时前
2026年7月AI智能搜索曝光趋势研判
大数据·人工智能·机器学习·ai智能搜索曝光