鱼C论坛

 找回密码
 立即注册
查看: 220|回复: 3

[Python] 怎么自动探查cpu/gpu的 compute_type 并应用呢?

[复制链接]
发表于 2024-6-12 14:22:27 | 显示全部楼层 |阅读模式
5鱼币
compute_type="float16"

ValueError: Requested float16 compute type, but the target device or backend do not support efficient float16 computation.
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2024-6-12 14:22:28 | 显示全部楼层
import torch

def get_compute_type():
    if torch.cuda.is_available():
        # 检查 GPU 是否支持 float16
        if torch.cuda.get_device_capability(0)[0] >= 5.3:
            print("Using float16 precision")
            return "float16"
        else:
            print("float16 not supported on this GPU, using float32")
            return "float32"
    else:
        print("No GPU found, using float32")
        return "float32"

compute_type = get_compute_type()

# 你的模型代码,确保使用合适的精度
if compute_type == "float16":
    model = model.half()
    # 在训练循环中也需要将输入和目标转换为 float16
    # inputs = inputs.half()
    # targets = targets.half()
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2024-6-16 07:32:01 | 显示全部楼层
auto
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2024-6-16 23:51:50 | 显示全部楼层
利用深度学习框架(如 TensorFlow、PyTorch)的 API 检查硬件支持情况就可以了。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-8 08:25

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表