Atomgit-Ascend/whisper-large-v3-turbo
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

Whisper Large V3 Turbo 昇腾910B部署指南

项目简介

本项目提供基于华为昇腾910B的Whisper Large V3 Turbo语音识别模型部署方案,支持生产级API服务。Whisper Large V3 Turbo是OpenAI发布的快速语音识别模型,在保持高质量的同时大幅提升推理速度。

模型信息:

  • 模型来源: HuggingFace - openai/whisper-large-v3-turbo
  • 模型大小: 809M参数
  • 支持语言: 99种语言
  • 许可证: MIT License

硬件要求

  • NPU: 华为昇腾910B (至少1卡)
  • 内存: 32GB+ (推荐64GB)
  • 存储: 50GB+ SSD (用于模型和缓存)
  • 操作系统: openEuler 22.03 LTS SP1 或 Ubuntu 20.04+
  • CANN版本: 7.0.0+ (推荐7.0.4)

环境准备

1. 安装昇腾驱动和CANN工具包

# 下载并安装CANN工具包
# 参考华为官方文档: https://www.hiascend.com/software/cann

# 验证NPU状态
npu-smi info

# 验证CANN环境
source /usr/local/Ascend/ascend-toolkit/set_env.sh

2. 安装Docker和NPU运行时

# 安装Docker (如果未安装)
sudo apt-get update
sudo apt-get install -y docker.io

# 安装NPU Docker运行时
# 参考华为官方文档配置NPU设备映射

项目结构

whisper-large-v3-turbo/
├── api/
│   ├── main.py              # FastAPI主服务
│   ├── model_loader.py      # 模型加载器
│   └── inference.py         # 推理引擎
├── config/
│   ├── config.yaml          # 服务配置
│   └── model_config.yaml    # 模型配置
├── scripts/
│   ├── build.sh             # Docker构建脚本
│   ├── deploy.sh            # 部署脚本
│   └── download_model.sh    # 模型下载脚本
├── Dockerfile               # Docker构建文件
├── requirements.txt         # Python依赖
└── README.md               # 本文档

Docker部署

1. 构建Docker镜像

# 进入项目目录
cd whisper-large-v3-turbo

# 构建镜像
docker build -t whisper-turbo-ascend:latest .

# 或使用构建脚本
./scripts/build.sh

2. 运行容器

模型路径说明: 如果模型已下载到宿主机 /data0/workspace 目录,使用以下命令挂载模型:

# 使用本地模型(推荐)- 使用NPU 0 (davinci0)
docker run -d \
  --name whisper-turbo-api \
  --device=/dev/davinci0 \
  --restart=unless-stopped \
  -p 8001:8000 \
  -v /data0/workspace:/app/models \
  -e LOCAL_MODEL_PATH=/app/models/whisper-large-v3-turbo \
  -e NPU_VISIBLE_DEVICES=0 \
  whisper-turbo-ascend:latest

# 生产环境运行(推荐)
docker run -d \
  --name whisper-turbo-api \
  --device=/dev/davinci0 \
  --restart=unless-stopped \
  -p 8001:8000 \
  --cpus="8" \
  --memory="16g" \
  -v /data0/workspace:/app/models \
  -v /data/logs/whisper:/app/logs \
  -e LOCAL_MODEL_PATH=/app/models/whisper-large-v3-turbo \
  -e NPU_VISIBLE_DEVICES=0 \
  -e WORKERS=4 \
  -e MAX_BATCH_SIZE=8 \
  whisper-turbo-ascend:latest

# 如果不挂载模型,将从AtomGit自动下载
docker run -d \
  --name whisper-turbo-api \
  --device=/dev/davinci0 \
  -p 8001:8000 \
  -e NPU_VISIBLE_DEVICES=0 \
  whisper-turbo-ascend:latest

注意:

  • -v /data0/workspace:/app/models 将宿主机的模型目录挂载到容器内
  • -e LOCAL_MODEL_PATH=/app/models/whisper-large-v3-turbo 指定容器内的模型路径
  • 如果本地模型不存在,会自动从AtomGit下载

3. 验证部署

# 检查容器状态
docker ps | grep whisper-turbo-api

# 查看日志
docker logs -f whisper-turbo-api

# 健康检查
curl http://localhost:8001/health

API接口说明

本服务遵循 Transformers API 协议,提供标准化的语音识别接口。

基础信息

  • 服务地址: http://localhost:8001
  • API文档: http://localhost:8001/docs
  • 健康检查: http://localhost:8001/health

核心接口

1. 语音转录 (Transcription)

端点: POST /v1/audio/transcriptions

请求格式:

curl -X POST "http://localhost:8001/v1/audio/transcriptions" \
  -H "Content-Type: multipart/form-data" \
  -F "file=@audio.mp3" \
  -F "model=whisper-large-v3-turbo" \
  -F "language=zh" \
  -F "response_format=json"

请求参数:

  • file (必需): 音频文件 (支持 mp3, wav, m4a, flac, webm)
  • model (可选): 模型名称,默认 "whisper-large-v3-turbo"
  • language (可选): 语言代码 (如 "zh", "en", "ja")
  • prompt (可选): 上下文提示文本
  • response_format (可选): 响应格式 (json, text, srt, verbose_json, vtt)
  • temperature (可选): 采样温度 (0.0-1.0)
  • timestamp_granularities (可选): 时间戳粒度 (word, segment)

响应示例:

{
  "text": "这是转录的文本内容",
  "language": "zh"
}

2. 语音翻译 (Translation)

端点: POST /v1/audio/translations

请求格式:

curl -X POST "http://localhost:8001/v1/audio/translations" \
  -H "Content-Type: multipart/form-data" \
  -F "file=@audio.mp3" \
  -F "model=whisper-large-v3-turbo"

响应示例:

{
  "text": "This is the translated text in English"
}

3. 批量处理

端点: POST /v1/audio/batch

请求格式:

{
  "files": [
    {"file": "base64_encoded_audio1", "language": "zh"},
    {"file": "base64_encoded_audio2", "language": "en"}
  ],
  "model": "whisper-large-v3-turbo"
}

4. 健康检查

端点: GET /health

响应示例:

{
  "status": "healthy",
  "model_loaded": true,
  "npu_available": true,
  "version": "1.0.0"
}

5. 指标监控

端点: GET /metrics

返回Prometheus格式的监控指标。

生产环境配置

1. 性能优化

# config/config.yaml
model:
  device: "npu"
  dtype: "float16"
  batch_size: 8
  max_audio_length: 30  # 秒
  chunk_length: 30      # 秒
  num_workers: 4

api:
  workers: 4
  max_concurrent_requests: 32
  timeout: 300
  max_request_size: 100MB

2. 资源限制

# Docker资源限制
--cpus="8"              # CPU核心数
--memory="16g"          # 内存限制
--device=/dev/davinci0  # NPU设备

3. 日志配置

# 日志级别: DEBUG, INFO, WARNING, ERROR
-e LOG_LEVEL=INFO

# 日志目录挂载
-v /data/logs/whisper:/app/logs

4. 模型缓存

# 模型目录挂载(加速启动)
-v /data/models/whisper:/app/models

性能指标

  • 延迟:
    • 30秒音频: ~200-500ms (NPU加速)
    • 1分钟音频: ~400-1000ms
  • 吞吐量:
    • 单卡: ~20-40 请求/秒 (30秒音频)
    • 批处理: ~60-100 请求/秒
  • 并发: 建议每卡4-8并发请求
  • 内存占用: ~8-12GB (含模型)

故障排查

1. NPU不可用

# 检查NPU状态
npu-smi info

# 检查设备映射
ls -l /dev/davinci*

# 检查CANN环境
source /usr/local/Ascend/ascend-toolkit/set_env.sh

2. 模型加载失败

# 检查模型文件
ls -lh /app/models/

# 检查磁盘空间
df -h

# 查看详细日志
docker logs whisper-turbo-api

3. 性能问题

# 检查NPU利用率
npu-smi info

# 调整批处理大小
# 修改 config/config.yaml 中的 batch_size

# 检查内存使用
docker stats whisper-turbo-api

监控和告警

Prometheus指标

  • whisper_requests_total: 总请求数
  • whisper_request_duration_seconds: 请求耗时
  • whisper_audio_duration_seconds: 音频时长
  • whisper_npu_utilization: NPU利用率
  • whisper_memory_usage_bytes: 内存使用量

健康检查脚本

#!/bin/bash
# scripts/health_check.sh
response=$(curl -s http://localhost:8001/health)
if [[ $response == *"healthy"* ]]; then
    echo "Service is healthy"
    exit 0
else
    echo "Service is unhealthy"
    exit 1
fi

升级和维护

更新模型

# 停止服务
docker stop whisper-turbo-api

# 更新模型文件
# 将新模型放置到 /data/models/whisper/

# 重启服务
docker start whisper-turbo-api

更新代码

# 重新构建镜像
docker build -t whisper-turbo-ascend:latest .

# 滚动更新(零停机)
docker stop whisper-turbo-api
docker rm whisper-turbo-api
docker run -d [原配置参数] whisper-turbo-ascend:latest

许可证

本项目遵循MIT License。模型使用请遵守OpenAI Whisper的许可证要求。

参考资源

  • Whisper模型页面
  • HuggingFace Transformers文档
  • 昇腾CANN开发指南
  • FastAPI文档

支持与反馈

如有问题或建议,请提交Issue或联系维护团队。