*My post explains how to create and acceess a tensor.
__version__
can check PyTorch version as shown below. *__version__
can be used withtorch but not with a tensor:
importtorchtorch.__version__# 2.2.1+cu121
cpu.is_available(),cpu.device_count() orcpu.current_device() can check if CPU is available, getting a scalar as shown below:
*Memos:
cpu.is_available()
,cpu.device_count()
orcpu.current_device()
can be used withtorch but not with a tensor.cpu.device_count()
can get the number of CPUs. *It always gets1
:cpu.current_device()
can get the index of a currently selected CPU. *It always getscpu
:
importtorchtorch.cpu.is_available()# Truetorch.cpu.device_count()# 1torch.cpu.current_device()# cpu
cuda.is_available() orcuda.device_count() can check if GPU(CUDA) is available, getting a scalar as shown below:
*Memos:
cuda.is_available()
orcuda.device_count()
can be used withtorch
but not with a tensor.cuda.device_count()
can get the number of GPUs.
importtorchtorch.cuda.is_available()# Truetorch.cuda.device_count()# 1
In addition, you can usecuda.current_device(),cuda.get_device_name() orcuda.get_device_properties(), getting a scalar as shown below:
*Memos:
cuda.current_device()
,cuda.get_device_name()
orcuda.get_device_properties()
can be used withtorch
but not with a tensor.cuda.current_device()
can get the index of a currently selected GPU.cuda.get_device_name()
can get the name of a GPU.*Memos:cuda.get_device_properties()
can get the properties of a GPU. *Memos:
torch.cuda.current_device()# 0torch.cuda.get_device_name()torch.cuda.get_device_name(device='cuda:0')torch.cuda.get_device_name(device='cuda')torch.cuda.get_device_name(device=0)torch.cuda.get_device_name(device=torch.device(device='cuda:0'))torch.cuda.get_device_name(device=torch.device(device='cuda'))torch.cuda.get_device_name(device=torch.device(device=0))torch.cuda.get_device_name(device=torch.device(type='cuda'))torch.cuda.get_device_name(device=torch.device(type='cuda',index=0))# Tesla T4torch.cuda.get_device_properties(device='cuda:0')torch.cuda.get_device_properties(device='cuda')torch.cuda.get_device_properties(device=0)torch.cuda.get_device_properties(device=torch.device(device='cuda:0'))torch.cuda.get_device_properties(device=torch.device(device='cuda'))torch.cuda.get_device_properties(device=torch.device(device=0))torch.cuda.get_device_name(device=torch.device(type='cuda'))torch.cuda.get_device_name(device=torch.device(type='cuda',index=0))# _CudaDeviceProperties(name='Tesla T4', major=7, minor=5, # total_memory=15102MB, multi_processor_count=40)
!nvidia-smi can get the information about GPUs as shown below:
!nvidia-smiWedMay1513:18:152024+---------------------------------------------------------------------------------------+|NVIDIA-SMI535.104.05DriverVersion:535.104.05CUDAVersion:12.2||-----------------------------------------+----------------------+----------------------+|GPUNamePersistence-M|Bus-IdDisp.A|VolatileUncorr.ECC||FanTempPerfPwr:Usage/Cap|Memory-Usage|GPU-UtilComputeM.||||MIGM.||=========================================+======================+======================||0TeslaT4Off|00000000:00:04.0Off|0||N/A56CP028W/70W|105MiB/15360MiB|0%Default||||N/A|+-----------------------------------------+----------------------+----------------------++---------------------------------------------------------------------------------------+|Processes:||GPUGICIPIDTypeProcessnameGPUMemory||IDIDUsage||=======================================================================================|+---------------------------------------------------------------------------------------+
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse