关于使用pytorch在30系列显卡(高级别显卡)算力不够问题

问题

在后台搭建docker镜像环境时,在10、20系列卡上兼容常见版本的pytorch。搭建环境时在dockerhub、nvidia官网随便拉取镜像基本都能使用。但把镜像迁移到30系列卡时就会有算力不够的情况,主要原因就是30系列卡的算力升级了。。。详情见这个博客

具体日志

/opt/conda/lib/python3.7/site-packages/torch/cuda/init.py:125:
UserWarning:
NVIDIA GeForce RTX 3080 Ti with CUDA capability sm_86 is not compatible with the current PyTorch installation.
The current PyTorch install supports CUDA capabilities sm_37 sm_50 sm_60 sm_61 sm_70 sm_75 compute_37.
If you want to use the NVIDIA GeForce RTX 3080 Ti GPU with PyTorch, please check the instructions at https://pytorch.org/get-started/locally/


意思是:NVIDIA GeForce RTX 3080 Ti与CUDA能力sm_86不兼容目前的PyTorch安装。
当前的PyTorch安装支持CUDA能力sm_37 sm_50 sm_60 sm_61 sm_70 sm_75 compute_37。
也就是安装的cuda版本低了,但pytorch安装是要和cuda对应的,所以也能说是pytoch安装版本不对。。。


解决方法

  • 升级torch版本
  • 升级torch对应cuda版本

在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PyTorch使用多张可以通过数据并行的方式实现模型的训练和推理加速。下面是使用多张的一般步骤: 1. 导入必要的库: ```python import torch import torch.nn as nn import torch.optim as optim import torch.nn.functional as F from torch.utils.data import DataLoader ``` 2. 定义模型: ```python class MyModel(nn.Module): def __init__(self): super(MyModel, self).__init__() # 定义你的模型结构 def forward(self, x): # 定义前向传播过程 return x ``` 3. 初始化多个GPU设备: ```python device = torch.device("cuda" if torch.cuda.is_available() else "cpu") device_ids = [0, 1, 2] # 假设有3个可用的GPU设备 ``` 4. 将模型放到多个GPU上: ```python model = MyModel() model = nn.DataParallel(model, device_ids=device_ids) model.to(device) ``` 5. 定义损失函数和优化器: ```python criterion = nn.CrossEntropyLoss() optimizer = optim.Adam(model.parameters(), lr=0.001) ``` 6. 加载数据并创建数据加载器: ```python train_dataset = ... train_loader = DataLoader(train_dataset, batch_size=64, shuffle=True) ``` 7. 训练模型: ```python model.train() for epoch in range(num_epochs): for data, labels in train_loader: data = data.to(device) labels = labels.to(device) optimizer.zero_grad() outputs = model(data) loss = criterion(outputs, labels) loss.backward() optimizer.step() ``` 8. 在推理阶段,将输入数据也放到GPU上: ```python model.eval() with torch.no_grad(): inputs = inputs.to(device) outputs = model(inputs) ``` 这样就可以在多张上并行地训练和推理模型了。注意,当使用`nn.DataParallel`时,模型的`forward`函数会自动在多个GPU上运行,而不需要我们手动指定。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值