Skip to content

feat: add concurrency tts test - #138

Merged
weedge merged 4 commits into
mainfrom
feat/tts
Apr 6, 2025
Merged

weedge merged 4 commits into
mainfrom
feat/tts

Conversation

@weedge

@weedge weedge commented Apr 6, 2025 •

Copy link
Copy Markdown
Collaborator

feat:

  • add concurrency tts test
    cases:
# CONCURRENCY_CN=4
CONCURRENCY_CN=4 GENERATOR_ENGINE=vllm TTS_TAG=tts_generator_spark ACHATBOT_VERSION=0.0.9.post5 IMAGE_GPU=L40S modal run src/tts/run_generator_tts.py
CONCURRENCY_CN=4 GENERATOR_ENGINE=sglang TTS_TAG=tts_generator_spark ACHATBOT_VERSION=0.0.9.post5 IMAGE_GPU=L40S modal run src/tts/run_generator_tts.py
CONCURRENCY_CN=4 GENERATOR_ENGINE=trtllm TTS_TAG=tts_generator_spark ACHATBOT_VERSION=0.0.9.post5 IMAGE_GPU=L40S modal run src/tts/run_generator_tts.py
CONCURRENCY_CN=4 GENERATOR_ENGINE=trtllm_runner TTS_TAG=tts_generator_spark ACHATBOT_VERSION=0.0.9.post5 IMAGE_GPU=L40S modal run src/tts/run_generator_tts.py
  • change run_generator_tts.sh add CONCURRENCE -c opt
bash run_generator_tts.sh -s run -t 'hello,你好,我是机器人。|万物之始,大道至简,衍化至繁。|君不见黄河之水天上来,奔流到海不复回。君不见高堂明镜悲白发,朝如青丝暮成雪。人生得意须尽欢,莫使金樽空对月。天生我材必有用,千金散尽还复来。' -g trtllm -d L40s -a tts_generator_spark -c 2 
bash run_generator_tts.sh -s run -g vllm -d L40s -a tts_generator_spark -c 4 
bash run_generator_tts.sh -s run -g sglang -d L40s -a tts_generator_spark -c 4 
bash run_generator_tts.sh -s run -g trtllm -d L40s -a tts_generator_spark -c 4 
bash run_generator_tts.sh -s run -g vllm -d L40s -a tts_generator_spark -c 8 
bash run_generator_tts.sh -s run -g sglang -d L40s -a tts_generator_spark -c 8 
bash run_generator_tts.sh -s run -g trtllm -d L40s -a tts_generator_spark -c 8
bash run_generator_tts.sh -s run -g vllm -d L40s -a tts_generator_spark -c 12 
bash run_generator_tts.sh -s run -g sglang -d L40s -a tts_generator_spark -c 12 
bash run_generator_tts.sh -s run -g trtllm -d L40s -a tts_generator_spark -c 12 

fix:

  • spark_generator_tts use gen_global_token_ids for gender controler on the same session ctx

Tip

  • 并发测试单独会话,没有设置语音克隆tts, 这里spark-tts控制control(性别音色,语速,语气强度)的配置是大概范围设置,为了保持音色控制,在测试时使用了初始预热时生成的control global token ids 来保持每个并发生成的语音音色的一致;
  • 至于流式输出平滑处理,可移至上层具体case去处理, 流式只输出对应生成音频块,未做fade in/out处理;
  • 如果想精准控制比例,可以改为按照控制比例来调整;
  • 如果设置语音克隆音频,则不会有生成的control global token ids,直接将音频waveform通过audio tokenizer encode来生成global token ids 和 semantic token ids。 具体见:feat: add spark tts BiCodec and spark tts support batch stream #130

weedge added 3 commits April 5, 2025 22:50
Signed-off-by: weedge <weege007@gmail.com>
Signed-off-by: weedge <weege007@gmail.com>
…r on the same session ctx

Signed-off-by: weedge <weege007@gmail.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @weedge, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request introduces concurrency testing for the TTS (Text-to-Speech) generator, and fixes an issue with gender control in the spark_generator_tts module. The concurrency testing is implemented in run_generator_tts.py, allowing for multiple TTS requests to be processed simultaneously. The fix in spark_generator_tts.py ensures that gen_global_token_ids are correctly used for gender control within the same session context. Additionally, the PR updates dependencies and adds support for flash-attn in the transformers generator engine.

Highlights

  • Concurrency TTS Test: Introduces concurrency testing for TTS generation using asyncio to simulate multiple concurrent requests. This allows for performance evaluation and identification of potential bottlenecks.
  • Gender Control Fix: Fixes an issue in spark_generator_tts where gender control was not working correctly within the same session context. The fix ensures that gen_global_token_ids are properly used for consistent gender control.
  • Dependency Updates and Flash Attention Support: Updates dependencies in run_generator_tts.py and adds support for flash-attn when using the transformers generator engine. This includes installing flash-attn and setting the appropriate environment variables.

Changelog

Click here to see the changelog
  • deploy/modal/src/tts/run_generator_tts.py
    • Added asyncio and math imports for concurrency support.
    • Added conditional installation of flash-attn for transformers generator engine.
    • Added accelerate as a dependency for vllm.
    • Introduced WARMUP_TEXT environment variable for warming up the TTS engine.
    • Implemented concurrent TTS generation using asyncio.gather.
    • Added logic to handle gen_global_token_ids for gender control across concurrent requests.
    • Added nvidia-smi command execution for debugging GPU memory usage.
    • Updated default TTS text to a news excerpt.
    • Added CONCURRENCY_CN environment variable to control the number of concurrent requests.
  • pyproject.toml
    • Updated the version of the achatbot package to 0.0.9.7.2.
  • src/core/llm/init.py
    • Added lm_device_map to the arguments passed to the transformers generator.
  • src/core/llm/transformers/generator.py
    • Modified the transformers generator to use device_map when loading the model if lm_device_map is set, enabling multi-GPU support with accelerate.
  • src/modules/speech/tts/spark_generator_tts.py
    • Fixed an issue where gen_global_token_ids was not being correctly used for gender control within the same session context. Now the gen_global_token_ids are stored in the session context if they are not already present.
    • Modified the _inference method to use session.ctx.state['gen_global_token_ids'] instead of controll_gen_global_token_ids for token2wav calls.
    • Added return statements when sub_tts_speech.size == 0 or pre_sub_tts_speech_size > sub_tts_speech.size to prevent further processing of empty speech chunks.
  • test/modules/speech/tts/test_spark.py
    • Added a warmup phase to the test to ensure that gen_global_token_ids is initialized before the main synthesis.
    • Increased the temperature setting to 0.9.
    • Added assertions to check for the presence of gen_global_token_ids in the session context after synthesis.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


Async calls in the night,
Voices weaving, taking flight,
Concurrency's hum,
A chorus to come,
TTS tests shining bright.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces concurrency to the TTS test and fixes an issue with gender control in spark_generator_tts.py. The changes involve adding asyncio, updating dependencies, and modifying the logic for text generation and audio synthesis. Overall, the changes seem well-structured, but there are a few areas that could be improved for robustness and maintainability.

Summary of Findings

  • Flash Attention Installation: The code installs flash-attn in multiple places. It's important to ensure that these installations are necessary and don't conflict with each other, potentially leading to unexpected behavior or performance issues.
  • Inconsistent ACHATBOT_VERSION Updates: The ACHATBOT_VERSION is updated in some places but not others. It's crucial to maintain consistency across all relevant configurations to avoid compatibility issues.
  • Potential Race Condition in gen_global_token_ids: The logic for handling gen_global_token_ids in spark_generator_tts.py might have a race condition if multiple concurrent requests are processed within the same session context. This could lead to incorrect gender control.
  • Missing Error Handling: The code lacks proper error handling for various operations, such as environment variable retrieval and file operations. This could make it difficult to diagnose and resolve issues in production.

Merge Readiness

The pull request introduces important features and fixes, but there are some potential issues that need to be addressed before merging. Specifically, the flash attention installation, ACHATBOT_VERSION updates, potential race condition in gen_global_token_ids, and missing error handling should be carefully reviewed and resolved. I am unable to approve this pull request, and recommend that the pull request not be merged until these issues are addressed (at a minimum), and that others review and approve this code before merging.

Comment thread deploy/modal/src/tts/run_generator_tts.py Outdated
Comment on lines +270 to +271
if session.ctx.state.get("gen_global_token_ids") is None:
session.ctx.state["gen_global_token_ids"] = controll_gen_global_token_ids

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This logic for setting gen_global_token_ids might have a race condition if multiple concurrent requests are processed within the same session context. Consider using a thread-safe mechanism to ensure that the gen_global_token_ids is correctly initialized and updated.

if "gen_global_token_ids" not in session.ctx.state:
    session.ctx.state["gen_global_token_ids"] = controll_gen_global_token_ids

"find /usr/ -name 'libcuda.so.*'",
"echo $LD_LIBRARY_PATH",
f"LD_LIBRARY_PATH=/usr/local/cuda-12.5/compat:$LD_LIBRARY_PATH CMAKE_ARGS='-DGGML_CUDA=on' pip install llama-cpp-python --extra-index-url='https://abetlen.github.io/llama-cpp-python/whl/cu125'",
"pip install flash-attn --no-build-isolation",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider whether this installation of flash-attn is necessary here, as it's also installed in the transformers block. Installing it in multiple places might lead to conflicts or unexpected behavior.

Comment on lines 284 to +285
if sub_tts_speech.size == 0:
break
return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding error handling here to gracefully handle the case where sub_tts_speech.size is 0. This could involve logging an error message and returning a default value or raising an exception.

if sub_tts_speech.size == 0:
    logging.error("sub_tts_speech size is 0")
    return

Comment thread src/modules/speech/tts/spark_generator_tts.py
Signed-off-by: weedge <weege007@gmail.com>
@weedge
weedge merged commit 89b1379 into main Apr 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant