perf: async GPU lipsync inference + fix 16x performance regression (#1997) #1998
Reference in New Issue
Block a user
Delete Branch "fix/1978-musetalk-perf-async"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
修复 #1997 引入的性能回归 + 解决 nginx 504 超时。
根因分析
_run_inference示例代码在推理前生成了与原视频等长的visual_silent.mp4,然后在_mux_video_with_audio中用-stream_loop+ NVENC 循环到音频长度。MuseTalk 实际集成时,如果也按此模式先 loop 视频再推理,帧数 ×2.2 叠加软编码预处理导致 236s(vs 修复前 14.2s)。POST /lipsync/jobs同步调用_submit_audio_direct→_submit_to_gpu→gpu_svc.wait_for_result(),HTTP 请求阻塞直到 GPU 推理完成(236s)。即使 nginx 已配 300s,同步阻塞也吃光 worker 并发。修复方案
1. MuseTalk v2 架构(musetalk_server.py)
_run_inference不再预处理 loop 视频,直接将 audio_path 传给 MuseTalk_mux_video_with_audio简化为 fast path:视觉输出 ≥ 音频时长时-c:v copy秒级封装;仅当视觉输出短于音频(模型异常截断)时才-stream_loop+ NVENC 兜底enable_video_loop参数和MUSE_ENABLE_VIDEO_LOOP环境变量(loop 现在是自动兜底逻辑)2. GPU 推理异步化(业务侧)
lipsync_gpu_process_async:创建 GPU 任务后立即返回 job_id(status=processing),后台等待 GPU 完成并更新状态POST /lipsync/jobsAPI 响应时间从 >200s 降到 <1sGET /lipsync/jobs/{id}获取进度refresh_job_status识别 GPU 异步路径(processing + 无 mediakit_task_id),跳过 MediaKit 轮询;超 30 分钟的 processing 任务自动标记 failed3. nginx 超时
测试
部署说明
RTX2060 需更新 musetalk_server.py 并重启:
Worker 侧需重启以加载新 Celery 任务
lipsync_gpu_process_async。Acceptance Criteria
Related: #1997, #1978, #1970
- Move GPU wait_for_result to Celery background task (lipsync_gpu_process_async) POST /lipsync/jobs now returns <1s instead of blocking 200s+ - Rewrite musetalk_server.py: MuseTalk receives full audio directly (v2 architecture) — no pre-looping video before inference Output video length = audio length, mux is fast stream copy - Frontend polls GET /lipsync/jobs/{id} for status updates - refresh_job_status: GPU async path (processing + no mediakit_task_id) skips MediaKit polling; stale jobs (>30min) auto-marked failed - 21 unit tests pass (11 GPU integration + 10 musetalk audio mux) Co-Authored-By: Coze <coze-opensource@bytedance.com>🚀 预览环境已部署
9ef33b82ddto60cacdf280🗑️ 预览环境已清理
PR #1998 已关闭或合并,对应的预览环境已被清理。