部署合同

SenseVoice TensorRT / Triton

把 SenseVoiceSmall 构建为原生 FP16 TensorRT engine,并通过 Triton 提供可批处理的 GPU 推理服务。

成熟度
生产验证
FunASR
main@6408aaa9
运行时
TensorRT 10.0.1 / Triton 24.05
验证日期
2026-08-04

适用边界

先判断它是否适合你的生产约束

适合

  • 固定 NVIDIA GPU 环境中的 SenseVoice 批量转写
  • 需要 Triton 动态批处理、健康检查和模型仓库
  • 愿意按生产音频分布定制 batch 与帧长 profile

不适合

  • CPU、macOS、Windows 或通用边缘设备
  • 需要跨 GPU 型号直接复制同一个 engine
  • 只有动态量化 model_quant.onnx 的部署
模型SenseVoiceSmall
硬件nvidia-gpu / kubernetes
操作系统Linux
接口Triton gRPC/HTTP / TensorRT plan / Docker

运行路径

从安装到已知音频验证

以下命令来自当前验证清单;上线前固定依赖、模型和硬件。

安装

git clone https://github.com/modelscope/FunASR.git && cd FunASR && git checkout 6408aaa96d54f89db467346010eff3c7d1fc485a
pip install -e . "onnx>=1.16" soundfile "tritonclient[grpc]"
python - <<'PY'
from funasr import AutoModel

model = AutoModel(model="iic/SenseVoiceSmall", device="cuda:0")
model.export(
    type="onnx",
    quantize=False,
    device="cuda:0",
    output_dir="./sensevoice_onnx",
    max_seq_len=4096,
)
PY
curl -fL https://huggingface.co/FunAudioLLM/SenseVoiceSmall/resolve/main/chn_jpn_yue_eng_ko_spectok.bpe.model \
  -o runtime/triton_gpu/model_repo_sense_voice_small/scoring/chn_jpn_yue_eng_ko_spectok.bpe.model \
&& echo "aa87f86064c3730d799ddf7af3c04659151102cba548bce325cf06ba4da4e6a8  runtime/triton_gpu/model_repo_sense_voice_small/scoring/chn_jpn_yue_eng_ko_spectok.bpe.model" | sha256sum -c -

启动

python runtime/triton_gpu/scripts/build_sensevoice_tensorrt.py \
    ./sensevoice_onnx/model.onnx \
    runtime/triton_gpu/model_repo_sense_voice_small/encoder/1/model.plan \
    --precision fp16 \
    --min-batch 1 --opt-batch 8 --max-batch 16 \
    --min-frames 1 --opt-frames 512 --max-frames 4096 \
    --workspace-gb 8
cp runtime/triton_gpu/model_repo_sense_voice_small/encoder/config.pbtxt.tensorrt \
   runtime/triton_gpu/model_repo_sense_voice_small/encoder/config.pbtxt
cd runtime/triton_gpu && tritonserver --model-repository ./model_repo_sense_voice_small \
  --pinned-memory-pool-byte-size=512000000 \
  --cuda-memory-pool-byte-size=0:1024000000

健康检查

curl -fsS http://localhost:8000/v2/health/ready
curl -fsS http://localhost:8000/v2/models/sensevoice/ready

Smoke test

发布前必须通过的最小验证

python - <<'PY'
import numpy as np
import soundfile as sf
import tritonclient.grpc as grpc

audio, sample_rate = sf.read(
    "runtime/triton_gpu/client/test_wavs/mid.wav", dtype="float32"
)
assert sample_rate == 16000
values = {
    "WAV": audio[None, :],
    "WAV_LENS": np.array([[audio.size]], dtype=np.int32),
    "LANGUAGE": np.array([[0]], dtype=np.int32),
    "TEXT_NORM": np.array([[1]], dtype=np.int32),
}
inputs = []
for name, value in values.items():
    tensor = grpc.InferInput(name, value.shape, grpc.np_to_triton_dtype(value.dtype))
    tensor.set_data_from_numpy(value)
    inputs.append(tensor)
result = grpc.InferenceServerClient("localhost:8001").infer("sensevoice", inputs)
transcript = result.as_numpy("TRANSCRIPTS")[0][0].decode()
assert transcript.strip(), "SenseVoice returned an empty transcript"
print(transcript)
PY

运行与容量

把可运行推进到可运营

运行检查

  • 在与生产相同的 GPU 架构和 TensorRT 版本上构建 engine
  • 按真实 batch、并发和音频时长重设优化 profile
  • 保存 ONNX、engine、构建日志、SHA-256 与 Triton 配置用于回滚

容量变量

  • 音频时长、语言、声道和 VAD 分段分布
  • 并发、队列等待、预热与模型缓存状态
  • 精确硬件、驱动、运行时和线程配置

故障排查

  • 构建前确认导出使用 quantize=False,不能使用 model_quant.onnx
  • parser 报错时先运行 ONNX checker 并核对 SenseVoice tensor 名称和 dtype
  • Triton 加载失败时确认 model.plan 与 config.pbtxt.tensorrt 位于同一 encoder 版本目录

安全边界

生产入口默认不信任

已知限制

TensorRT plan 不保证跨 GPU 架构或 TensorRT 版本可移植,必须在目标环境重新构建并复测精度、显存和容量。

公开基准仅用于复现起点,不替代目标业务负载测试。

证据与反馈

从原始资料核对部署合同