首页 > 其他分享 >Pytorch快速使用手册 01基本配置

Pytorch快速使用手册 01基本配置

时间:2023-02-13 21:22:11浏览次数:56  
标签:01 torch cuDNN Pytorch version 使用手册 cuda print import

import os
import tqdm
import torch
import random
import shutil

import numpy as np

1. Base Config

1.1 Check version of pytorch

print("torch version ",torch.__version__)               # PyTorch version
print("cuda version ", torch.version.cuda)              # Corresponding CUDA version
print("cuDNN version ", torch.backends.cudnn.version())  # Corresponding cuDNN version
print("gpu type ", torch.cuda.get_device_name(0))   # GPU type

torch version 1.12.0+cu116
cuda version 11.6
cuDNN version 8302
gpu type NVIDIA GeForce GTX 1660 Ti

1.2 Update pytroch

pip install --update torch

1.3 Set random number

torch.manual_seed(0)
torch.cuda.manual_seed_all(0)

1.4 Run a tensor in Specified GPU

a = torch.rand(2,2)
a = a.to("cuda:0")
print(a)

tensor([[0.3074, 0.6341],
[0.4901, 0.8964]], device='cuda:0')

1.5 CUDA support ?

print("cuda ok? ", torch.cuda.is_available())

cuda ok? True

1.6 Set mode with cuDNN benchmark

Benchmark will accelarate up train speed, but each there exists random situlation in each train step.

torch.backends.cudnn.benchmark = True

To avoid this situlaiton, you should run the code

torch.backends.cudnn.deterministic = True

1.7 Clear cache of GPU

torch.cuda.empty_cache()

OR

find the progress and kill it

ps aux | grep python

kill -9 [pid]

OR

use nvidia cmd

nvidia-smi --gpu-reset -i [gpu_id]

Github

标签:01,torch,cuDNN,Pytorch,version,使用手册,cuda,print,import
From: https://www.cnblogs.com/Kalafinaian/p/17117843.html

相关文章

  • JAVA-studyDay01
    JAVAjava-day01一.java简介1991年Sun公司的JamesGosling等人开始开发名称为Oak的语言,希望用于控制嵌入在有线电视交换盒、PDA等的微处理器;1994年将Oak语言更名为J......
  • P2347 砝码称重 (01背包)
    题目描述设有1g1g1g、2g2g2g、3g3g3g、5g5g5g、10g10g10g、20g20g20g的砝码各若干枚(其总重≤1000\le1000≤1000),输入输出格式输入格式: 输入方式:a1,a......
  • 001.SpringIoc初体验
    1.创建entity(Apple、Child)packagecom.imooc.spring.ioc.entity;publicclassApple{privateStringtitle;privateStringcolor;privateStringori......
  • ASEMI低压MOS管AO3401封装,AO3401图片
    编辑-ZASEMI低压MOS管AO3401参数:型号:AO3401封装:SOT-23漏极-源极电压(VDS):30V栅源电压(VGS):±12V连续漏电流(I):4.2A脉冲漏极电流(IDM):30A功耗(PD):1.4W接头和储存温度范围(TJ,TSTG):-55to......
  • FRM-92101的处理
    问题概述问题原因根据错误提示,form启动异常,但是查看服务运行状态的alive的,排查其他方面解决方案adadmin运行adadmin重新生成messages、forms、reports和productJAR文件:$ad......
  • ASEMI低压MOS管AO3401封装,AO3401图片
    编辑-ZASEMI低压MOS管AO3401参数:型号:AO3401封装:SOT-23漏极-源极电压(VDS):30V栅源电压(VGS):±12V连续漏电流(I):4.2A脉冲漏极电流(IDM):30A功耗(PD):1.4W接头和储存温度范围(TJ,......
  • [at code festival 2017 I]Full Tournament
    为了方便,以下编号和下标范围均为\([0,2^{n})\)定义\[\begin{cases}f_{0}(a)=a\\f_{i+1}(a)_{j}=\begin{cases}\min(f_{i}(a)_{j},f_{i}(a)_{j+2^{i}})&j二进制下第i位为0......
  • HTML_01_TEXT
    1.TEXT<strong>bold</strong><!--bydefauly,thecontentshowedinbold--><b>bold</b><i>italics</i><em>italics</em><del>del</del><s>del</s><ins>ins......
  • VS2015-预编译头和安全开发生命周期检查
    新建控制台项目时,会显示预编译头选项和安全开发生命周期检查选项,默认勾选。什么是预编译头?预编译头分为预编译和头,一个动词一个名词,头文件想必不用多说,预编译顾名思义也......
  • Vscode报错: error:0308010C:digital envelope routines::unsupported错误记录解决
    Vscode报错:error:0308010C:digitalenveloperoutines::unsupported错误记录解决因为安装了新版本的node才报的错误:node版本:v18.14.0运行npmrunserve报错解决办法:......