• RuntimeError: “slow_conv2d_cpu“ not implemented for ‘Half‘


    RuntimeError: “slow_conv2d_cpu” not implemented for ‘Half’

    在这里插入图片描述

    背景

    测试语音识别模型whisper时,出现上述错误!!
    测试代码如下:

    import whisper
    
    model = whisper.load_model("base")
    # print(model)
    
    # load audio and pad/trim it to fit 30 seconds
    mps_path = r"/test/1.mp3"
    audio = whisper.load_audio(mps_path)
    print("audio:\n", audio)
    audio = whisper.pad_or_trim(audio)
    
    # make log-Mel spectrogram and move to the same device as the model
    mel = whisper.log_mel_spectrogram(audio).to(model.device)
    
    # detect the spoken language
    _, probs = model.detect_language(mel)
    print(f"Detected language: {max(probs, key=probs.get)}")
    
    # decode the audio
    options = whisper.DecodingOptions()  # fp16=False
    result = whisper.decode(model, mel, options)
    
    # print the recognized text
    print(result.text)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    报错原因

    将输入数据的类型设置为Half(半精度浮点数,可以加快计算速度),但是Half只有GPU支持,CPU不支持半(Half)精度训练。

    解决方法

    通过使用 fp16=False,来指定解码选项,顺利解决了这个错误。

    options = whisper.DecodingOptions(fp16=False)
    
    • 1

    网上给出的参考解决办法如下:

    1. 执行代码的命令后添加“- -fp32”
    2. 将use_half=False 或者 将half() 方法 修改为float()
    3. 搜索代码“half”、“16”等字样,找到代码中涉及半精度的代码,进行修改
  • 相关阅读:
    【译】在 Visual Studio 2022 中安全地在 HTTP 请求中使用机密
    HCIP-路由01:路由基础
    【Node.JS 练习】考试成绩整理
    ChatGPT和文心一言的优缺点比较
    题目 1971: 外出旅游
    数据中心的防雷接地
    Scala中文unicode互转
    webgl计算包围盒大小
    程序员的浪漫
    Metasploit——客户端渗透
  • 原文地址:https://blog.csdn.net/zdm_0301/article/details/133773568