跳到主要内容

2024.7.2

下载pytorch

pytorch官网

单元格!命令运行环境

研究单元格里的命令运行在哪里,初步判断是运行在启动jupyter的环境中而不是对应的虚拟环境中,并不是直接运行在当前的虚拟环境中

image-20240702132908034

必须要使用这种形式才能在notebook中将命令运行在指定的环境中

要运行的东西放在&&后面

! source ~/anaconda3/bin/activate Deep_Learing && pip install pandas

image-20240702134255268

检查pytorch是否配置完成

image-20240702135630993

使用下面的代码进行测试

CUDA

import torch

# 打印PyTorch版本
print(torch.__version__)

# 检查是否可以使用CUDA(GPU)
print(torch.cuda.is_available())

MPS

import torch

# 打印PyTorch版本
print(torch.__version__)

# 检查MPS是否可用
if torch.backends.mps.is_available():
mps_device = torch.device("mps")
print("MPS device is available.")
else:
print("MPS device is not available.")

跑起来了

image-20240702154137306

image-20240702154158172

image-20240702214630164

速度测试

M2 cpu:62.8s

image-20240702220406101

M2 GPU:23.8s

image-20240702220544868

4090: 15.37s

image-20240703210034773

image-20240703210337914

12 vCPU Intel(R) Xeon(R) Platinum 8352V:28s

image-20240703211545134