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.

相关推荐
魔乐社区10 分钟前
DeepSeek在昇腾上的模型部署 - 常见问题及解决方案
人工智能·深度学习·deepseek
夜幕龙22 分钟前
深度生成模型(二)——基本概念与数学建模
人工智能·深度学习·transformer
山海青风29 分钟前
从零开始玩转TensorFlow:小明的机器学习故事 3
人工智能·机器学习·tensorflow
@心都30 分钟前
机器学习数学基础:35.效度
人工智能·机器学习
春末的南方城市39 分钟前
VidSketch:具有扩散控制的手绘草图驱动视频生成
人工智能·深度学习·计算机视觉·aigc
紫雾凌寒44 分钟前
计算机视觉 |解锁视频理解三剑客——TimeSformer
python·深度学习·神经网络·计算机视觉·transformer·timesformer
Francek Chen1 小时前
【大模型科普】AIGC技术发展与应用实践(一文读懂AIGC)
人工智能·深度学习·语言模型·大模型·aigc
孤寂大仙v2 小时前
深度学习实战:使用TensorFlow构建卷积神经网络(CNN)
深度学习·cnn·tensorflow
cufewxy20182 小时前
逻辑回归(Logistic)模型
算法·机器学习·逻辑回归
AIBigModel2 小时前
从零开始自主「起身站立」,上海AI Lab发布最新控制算法,机器人:起猛了
人工智能·机器学习·机器人