SuperAPI AI 工具集

qwen3-tts-profile

测试与质量

查看项目

更新于 10-16 04:16

技能介绍

用途

qwen3-tts-profile 用于对 qwen3-tts-rs(Rust 实现的 TTS 推理引擎)进行性能分析与基准测试。它通过 e2e_bench 工具在 CUDA Docker 容器内运行,帮助开发者定位推理瓶颈、审计 GPU 同步开销并对比不同模型变体的性能表现。

主要能力

  • Chrome Trace 分析(默认):生成 trace.json,可在 chrome://tracing 或 Perfetto 中查看 span 层级,包含 generate_frames、code_predictor、talker_step、sampling 等 span,以及标记每次 to_vec1() GPU→CPU 同步的 gpu_sync 事件。
  • 分阶段计时:即使不启用 profiling 特性,e2e_bench 也会报告 prefill / generation / decode 各阶段耗时。
  • 流式 TTFA 测量:通过 --streaming 标志测量首音频时间(Time to First Audio)。
  • JSON 输出:通过 --json-output 将结果导出为 JSON 文件。
  • GPU 同步审计:运行 scripts/audit-gpu-syncs.sh 列出所有 to_vec1() GPU→CPU 同步点。

使用方式

前置条件

  • 支持 --gpus all 的 Docker
  • qwen3-tts:latest Docker 镜像(含 Rust 工具链 + CUDA)
  • 模型权重位于 test_data/models/(默认 1.7B-CustomVoice)
  • tokenizer.json 必须位于模型目录中

Docker 执行模式

CUDA 工具链位于 Docker 容器内,所有 cargo 命令必须在容器中运行。工作区以 /workspace 绑定挂载:

docker run --rm --gpus all --entrypoint /bin/bash \
  -v "$(pwd):/workspace" -w /workspace \
  qwen3-tts:latest \
  -c 'export PATH=/root/.rustup/toolchains/stable-aarch64-unknown-linux-gnu/bin:$PATH && <COMMAND>'

1. Chrome Trace(默认,最适合 span 层级)

docker run --rm --gpus all --entrypoint /bin/bash \
  -v "$(pwd):/workspace" -w /workspace \
  qwen3-tts:latest \
  -c 'export PATH=/root/.rustup/toolchains/stable-aarch64-unknown-linux-gnu/bin:$PATH && \
      cargo run --profile=profiling --features=profiling,cuda,cli --bin e2e_bench -- \
        --model-dir test_data/models/1.7B-CustomVoice --iterations 1 --warmup 1'

输出 trace.json(3 句话约 12MB)。

2. 分阶段计时(无需 profiling 特性)

docker run --rm --gpus all --entrypoint /bin/bash \
  -v "$(pwd):/workspace" -w /workspace \
  qwen3-tts:latest \
  -c 'export PATH=/root/.rustup/toolchains/stable-aarch64-unknown-linux-gnu/bin:$PATH && \
      cargo run --release --features=cuda,cli --bin e2e_bench -- \
        --model-dir test_data/models/1.7B-CustomVoice --iterations 3 --warmup 1'

3. 流式 TTFA

添加 --streaming 标志:

... --bin e2e_bench -- --model-dir test_data/models/1.7B-CustomVoice \
    --iterations 3 --warmup 1 --streaming

4. JSON 输出

... --bin e2e_bench -- --model-dir test_data/models/1.7B-CustomVoice \
    --json-output results.json --iterations 3

GPU 同步审计

bash scripts/audit-gpu-syncs.sh

结果解读

阶段分解表

Label Words Wall (ms) Audio (s) RTF Tok/s Mem (MB) Prefill Generate Decode
short 13 5235.2 3.68 1.423 8.8 858 21ms (1%) 2724ms (71%) 1109ms (29%)
medium 53 23786.3 34.00 0.700 17.9 859 20ms (0%) 22694ms (95%) 1057ms (4%)
long 115 43797.4 60.96 0.718 17.4 864 19ms (0%) 41861ms (96%) 1886ms (4%)

关键指标:

  • RTF < 1.0 = 快于实时
  • Prefill:GPU 上应 <50ms。若偏高,检查 embedding/attention。
  • Generation:占主导。每帧约 18 次 GPU→CPU 同步(16 次 code_predictor + 2 次 sampling)。
  • Decode:ConvNeXt 解码器。随帧数扩展。长文本约 4%。
  • Tok/s:语义 token 每秒。越高越好。

Chrome Trace 分析

在 Perfetto/chrome://tracing 中:

  • 查看 talker_step 与 code_predictor 之间的间隙——那是 CPU 开销
  • 检查 sampling(top_k + top_p)相对于模型前向传播是否显著
  • gpu_sync 事件标记 GPU 等待 CPU 的停顿位置

优化目标

每帧约 18 次 to_vec1() 调用是主要瓶颈:

  • 16 次在 code_predictor(每个声学码组的 argmax)
  • 2 次在 sampling(读取采样 token)

批量处理这些调用以减少 GPU→CPU 往返。

模型变体

Model Dir Notes
1.7B-CustomVoice test_data/models/1.7B-CustomVoice 默认基准目标
1.7B-Base test_data/models/1.7B-Base 声音克隆(需要参考音频)
1.7B-VoiceDesign test_data/models/1.7B-VoiceDesign 文本描述声音

参考基线(1.7B-CustomVoice,CUDA)

2025 年 1 月在 DGX(A100)上:

  • 短(13 词):RTF 1.42,8.8 tok/s
  • 中(53 词):RTF 0.70,17.9 tok/s
  • 长(115 词):RTF 0.72,17.4 tok/s
  • Prefill:约 20ms,Decode:约 1-2s,Generation:71-96%

适用场景

  • 定位 qwen3-tts-rs 推理性能瓶颈
  • 审计并优化 GPU→CPU 同步开销
  • 对比不同模型变体(CustomVoice / Base / VoiceDesign)的性能
  • 测量流式首音频时间(TTFA)

限制

  • 需要支持 --gpus all 的 Docker 环境与 CUDA 工具链
  • 需要 qwen3-tts:latest 镜像及模型权重
  • 所有 cargo 命令必须在容器内运行
  • 具体收费、价格、平台支持等信息暂未提供