# 确定设备为GPU
num_gpus = torch.cuda.device_count()
target_gpu_id = None
for gpu_id in range(num_gpus):
gpu_props = torch.cuda.get_device_properties(gpu_id)
if gpu_props.total_memory >= 80 * 1000**3: # 实验室空闲的GPU内存没这么大
target_gpu_id = gpu_id
break
if target_gpu_id is not None:
device = torch.device(f"cuda:{target_gpu_id}")
print(f"Selected GPU {target_gpu_id}: {gpu_props.name}, Total Memory: {gpu_props.total_memory} bytes")
#运行的代码
else
print("Error: CUDA is not available even though a suitable GPU was detected.")
sys.exit(1)
Trick:获取实验室内存最大的GPU进行代码运行
最新推荐文章于 2025-12-16 10:46:15 发布
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
PyTorch 2.5
PyTorch
Cuda
PyTorch 是一个开源的 Python 机器学习库,基于 Torch 库,底层由 C++ 实现,应用于人工智能领域,如计算机视觉和自然语言处理
1523

被折叠的 条评论
为什么被折叠?



