From 14d8c3d95cbbeff3b4fdf593ba7b0dff08a7f771 Mon Sep 17 00:00:00 2001 From: tzhouam Date: Tue, 11 Nov 2025 11:56:08 +0800 Subject: [PATCH] Make Example Easier To Use MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: tzhouam Signed-off-by: 齐保元 --- .../offline_inference/qwen_2_5_omni/README.md | 20 +++++++++----- .../qwen_2_5_omni/end2end.py | 26 ++++++++++--------- .../qwen_2_5_omni/extract_prompts.py | 11 +++----- .../{run.sh => run_multiple_prompts.sh} | 2 +- .../qwen_2_5_omni/run_single_prompt.sh | 9 +++++++ 5 files changed, 41 insertions(+), 27 deletions(-) rename examples/offline_inference/qwen_2_5_omni/{run.sh => run_multiple_prompts.sh} (86%) create mode 100644 examples/offline_inference/qwen_2_5_omni/run_single_prompt.sh diff --git a/examples/offline_inference/qwen_2_5_omni/README.md b/examples/offline_inference/qwen_2_5_omni/README.md index 08c5c3400..734060b6b 100644 --- a/examples/offline_inference/qwen_2_5_omni/README.md +++ b/examples/offline_inference/qwen_2_5_omni/README.md @@ -63,22 +63,30 @@ uv pip install -r requirements.txt ``` ## Run examples (Qwen2.5-omni) -Download dataset from seed_tts[https://drive.google.com/file/d/1GlSjVfSHkW3-leKKBlfrjuuTGqQ_xaLP/edit]. To get the prompt, you can: +### Multiple Prompts +Download dataset from [seed_tts](https://drive.google.com/file/d/1GlSjVfSHkW3-leKKBlfrjuuTGqQ_xaLP/edit). To get the prompt, you can: ```bash tar -xf /seedtts_testset.tar cp seedtts_testset/en/meta.lst examples/offline_inference/qwen_2_5_omni/meta.lst python3 examples/offline_inference/qwen_2_5_omni/extract_prompts.py \ --input examples/offline_inference/qwen_2_5_omni/meta.lst \ --output examples/offline_inference/qwen_2_5_omni/top100.txt \ - --topk 100 \ - --pt-output examples/offline_inference/qwen_2_5_omni/top100.pt + --topk 100 ``` Get into the example folder ```bash cd examples/offline_inference/qwen_2_5_omni ``` -Modify PYTHONPATH in run.sh as your path of vllm_omni. Then run. +Modify PYTHONPATH in run_multiple_prompts.sh as your path of vllm_omni. Then run. ```bash -bash run.sh +bash run_multiple_prompts.sh +``` +### Single Prompts +Get into the example folder +```bash +cd examples/offline_inference/qwen_2_5_omni +``` +Modify PYTHONPATH in run_single_prompt.sh as your path of vllm_omni. Then run. +```bash +bash run_single_prompt.sh ``` -The output audio is saved in ./output_audio diff --git a/examples/offline_inference/qwen_2_5_omni/end2end.py b/examples/offline_inference/qwen_2_5_omni/end2end.py index 8614d4653..bbd4e0f53 100644 --- a/examples/offline_inference/qwen_2_5_omni/end2end.py +++ b/examples/offline_inference/qwen_2_5_omni/end2end.py @@ -51,9 +51,6 @@ def parse_args(): parser.add_argument( "--prompts", nargs="+", default=None, help="Input text prompts." ) - parser.add_argument( - "--pt-prompts", type=str, default=None, help="Path to .pt file containing List[str] prompts (overrides --prompts when prompt_type=text)." - ) parser.add_argument( "--voice-type", default="default", help="Voice type, e.g., m02, f030, default." ) @@ -146,6 +143,12 @@ def parse_args(): default=False, help="Enable writing detailed statistics (default: disabled)", ) + parser.add_argument( + "--txt-prompts", + type=str, + default=None, + help="Path to a .txt file with one prompt per line (preferred).", + ) args = parser.parse_args() return args @@ -153,20 +156,19 @@ def parse_args(): def main(): args = parse_args() model_name = args.model - # If pt-prompts provided and prompt_type is text, load and override args.prompts try: - if getattr(args, "pt_prompts", None) and args.prompt_type == "text": - loaded = torch.load(args.pt_prompts) - if not isinstance(loaded, list) or (len(loaded) > 0 and not isinstance(loaded[0], str)): - raise ValueError("--pt-prompts must point to a .pt containing List[str]") - args.prompts = loaded - print(f"[Info] Loaded {len(args.prompts)} prompts from {args.pt_prompts}") + # Preferred: load from txt file (one prompt per line) + if getattr(args, "txt_prompts", None) and args.prompt_type == "text": + with open(args.txt_prompts, "r", encoding="utf-8") as f: + lines = [ln.strip() for ln in f.readlines()] + args.prompts = [ln for ln in lines if ln != ""] + print(f"[Info] Loaded {len(args.prompts)} prompts from {args.txt_prompts}") except Exception as e: - print(f"[Error] Failed to load pt-prompts: {e}") + print(f"[Error] Failed to load prompts: {e}") raise if args.prompts is None: - raise ValueError("No prompts provided. Use --prompts ... or --pt-prompts (with --prompt_type text)") + raise ValueError("No prompts provided. Use --prompts ... or --txt-prompts (with --prompt_type text)") omni_llm = OmniLLM( model=model_name, log_stats=args.enable_stats, diff --git a/examples/offline_inference/qwen_2_5_omni/extract_prompts.py b/examples/offline_inference/qwen_2_5_omni/extract_prompts.py index a1bc7a78f..7380e701b 100644 --- a/examples/offline_inference/qwen_2_5_omni/extract_prompts.py +++ b/examples/offline_inference/qwen_2_5_omni/extract_prompts.py @@ -18,10 +18,9 @@ def extract_prompt(line: str) -> Optional[str]: def main() -> None: parser = argparse.ArgumentParser() - parser.add_argument("--input", "-i", required=True, help="输入 .lst 文件路径") - parser.add_argument("--output", "-o", required=True, help="输出文件路径") - parser.add_argument("--topk", "-k", type=int, default=100, help="提取前 K 个 prompt(默认 100)") - parser.add_argument("--pt-output", "-p", type=str, default=None, help="可选:输出 .pt 文件路径(默认与 --output 同名 .pt)") + parser.add_argument("--input", "-i", required=True, help="Input .lst file path") + parser.add_argument("--output", "-o", required=True, help="Output file path") + parser.add_argument("--topk", "-k", type=int, default=100, help="Extract the top K prompts (default: 100)") args = parser.parse_args() prompts = [] @@ -37,10 +36,6 @@ def main() -> None: for p in prompts: f.write(p + "\n") - # 另存为 PyTorch 序列化的 .pt,内容为字符串列表 - pt_path = args.pt_output if args.pt_output else os.path.splitext(args.output)[0] + ".pt" - torch.save(prompts, pt_path) - if __name__ == "__main__": main() diff --git a/examples/offline_inference/qwen_2_5_omni/run.sh b/examples/offline_inference/qwen_2_5_omni/run_multiple_prompts.sh similarity index 86% rename from examples/offline_inference/qwen_2_5_omni/run.sh rename to examples/offline_inference/qwen_2_5_omni/run_multiple_prompts.sh index e27d21143..ba07616ce 100644 --- a/examples/offline_inference/qwen_2_5_omni/run.sh +++ b/examples/offline_inference/qwen_2_5_omni/run_multiple_prompts.sh @@ -6,4 +6,4 @@ python end2end.py --model Qwen/Qwen2.5-Omni-7B \ --output-wav output_audio \ --prompt_type text \ --init-sleep-seconds 0 \ - --pt-prompts .pt + --txt-prompts top100.txt diff --git a/examples/offline_inference/qwen_2_5_omni/run_single_prompt.sh b/examples/offline_inference/qwen_2_5_omni/run_single_prompt.sh new file mode 100644 index 000000000..8dc2c74e5 --- /dev/null +++ b/examples/offline_inference/qwen_2_5_omni/run_single_prompt.sh @@ -0,0 +1,9 @@ +export PYTHONPATH=/path/to/vllm-omni:$PYTHONPATH +python end2end.py --model Qwen/Qwen2.5-Omni-7B \ + --voice-type "m02" \ + --dit-ckpt none \ + --bigvgan-ckpt none \ + --output-wav output_audio \ + --prompt_type text \ + --init-sleep-seconds 0 \ + --prompts "Explain the system architecture for a scalable audio generation pipeline. Answer in 15 words."