> 技术文档 > 【语音识别】vLLM 部署 Whisper 语音识别模型指南_vllm whisper

【语音识别】vLLM 部署 Whisper 语音识别模型指南_vllm whisper

目录

1. 模型下载

2. 环境安装

3. 部署脚本

4. 服务测试


语音识别技术在现代人工智能应用中扮演着重要角色,OpenAI开源的Whisper模型以其出色的识别准确率和多语言支持能力成为当前最先进的语音识别解决方案之一。本文将详细介绍如何使用vLLM(一个高效的大模型推理和服务框架)来部署Whisper-large-v3-turbo模型,构建一个可扩展的语音识别API服务。

vLLM是专为大规模语言模型推理优化的服务框架,它通过创新的注意力算法和高效的内存管理,能够显著提升模型推理速度并降低资源消耗。将Whisper与vLLM结合,可以充分发挥两者的优势,为语音识别应用提供高性能、低延迟的服务能力。

1. 模型下载

# pip install -U huggingface_hub # 国内镜像见 https://hf-mirror.com/set -xexport HF_ENDPOINT=https://hf-mirror.com # https://huggingface.co/openai/whisper-large-v3-turboREPO=openai/whisper-large-v3-turbohuggingface-cli download --resume-download $REPO --local-dir $REPO --exclude \"*fp32*\"

2. 环境安装

# vllm 安装pip install -U vllm# 如果下载太慢,可以尝试清华源pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/# 以下操作可跳过# 部署时候如果遇到 ValueError: Model architectures [\'WhisperForConditionalGeneration\'] failed to be inspected. Please check the logs for more details.# 则需要执行如下操作,本质上是 flash-attn 与 vllm 内置的 flash-attn 冲突# https://github.com/vllm-project/vllm/issues/13216# pip uninstall flash-attn -y

3. 部署脚本

# path 为自己的目录model_path=/path/openai/whisper-large-v3-turbomodel_name=whisper-large-v3-turbovllm serve $model_path \\ --served-model-name $model_name \\ --api-key token-abc123 \\ --gpu-memory-utilization 0.9 \\ --host 0.0.0.0 \\ --port 8000 \\ --task transcription \\ --trust-remote-code \\ --enforce-eager# 部署成功后可以看到 VLLM API server 以及支持的 endpoint/route

4. 服务测试

# 使用如下 POST 请求服务,tmp.mp3 为本地文件curl -X POST \"http://0.0.0.0:8000/v1/audio/transcriptions\" \\ -H \"Content-Type: multipart/form-data\" \\ -H \"Authorization: Bearer token-abc123\" \\ -F file=\"@tmp.mp3\" \\ -F model=\"whisper-large-v3-turbo\" \\ -F language=\"zh\" \\ -F response_format=\"text\"# 执行后可得到# {# \"text\": \"此存储库实现一个语音到语音集联管道该管道由以下部分组成\"# }

tmp.mp3 已经上传到资源,跳转到文章开头部分下载即可,或者自己录制一个 mp3 也可以。

字体下载