Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE] API请求无法并行处理多个,服务器端总是一个处理完才处理下一个 #124

Open
6 tasks done
zsy-code opened this issue Aug 2, 2024 · 4 comments

Comments

@zsy-code
Copy link

zsy-code commented Aug 2, 2024

确认清单

  • 我已经阅读过 README.md 和 dependencies.md 文件
  • 我已经确认之前没有 issue 或 discussion 涉及此 BUG
  • 我已经确认问题发生在最新代码或稳定版本中
  • 我已经确认问题与 API 无关
  • 我已经确认问题与 WebUI 无关
  • 我已经确认问题与 Finetune 无关

你的issues

python launch.py --port 9003 --preload_models --lru_size 0 --workers 2
且多个worker的情况下,也无法并行处理,他们处理的是同一个请求

@zhzLuke96
Copy link
Member

无法复现,可以提供更多信息吗?运行环境、代码版本、请求参数

@zsy-code
Copy link
Author

zsy-code commented Aug 6, 2024

def generate_audio():
    data = request.json()
    inputs = data.get('inputs', [])
    voice = data.get('voice', 'female2')
   
    outputs = generate_audio_batch(inputs, spk=speaker_mgr.get_speaker(voice), infer_seed=42)
    results = []
    for i, (sample_rate, wav) in enumerate(outputs):
        file_path = f"temp_audios/{uuid.uuid4()}_{i}.wav"
        sf.write(file_path, wav, sample_rate, format="wav")
        results.append(file_path)
    
    output_path = os.path.join("temp_audios", f"{uuid.uuid4()}_merge.wav")
    merge_audios(results, output_path)

    return output_path

我使用上面的代码进行的测试,在单独deploy 一个API 后,每次generate_audio_batch 都在执行完后才处理下一个任务

@zsy-code
Copy link
Author

zsy-code commented Aug 6, 2024

调用launch.py 启动的API也是一样的,可以同时发送两个以上的请求,并观察终端的tqdm 记录,即可发现同一时刻仅支持一个任务处理

@zhzLuke96
Copy link
Member

zhzLuke96 commented Aug 8, 2024

不太清楚你这个代码是怎么调用的,如果是在同一个线程里调用,那你遇到的同步生成的现象就是预期的结果,同一个worker里生成过程是锁住的

launch.py 的完整启动参数是什么?
tqdm 并行会抢占终端输出不一定能看出是并行

要测试的话最简单的方法直接用浏览器开两个请求 /tts 的链接(或者同时开两个playground页面),请求结果可以大概一起返回基本就是并行了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants