Signed-off-by: Nick Cao <ncao@redhat.com> Co-authored-by: Claude <noreply@anthropic.com>
2.5 KiB
CosyVoice3
Source https://github.com/vllm-project/vllm-omni/tree/main/examples/offline_inference/cosyvoice3.
Setup
Install dependencies:
uv pip install -e .
Note: This includes required libraries such as
soundfile,onnxruntime,x-transformers, andeinopsviarequirements/common.txtand platform-specific requirements files.
Download the model snapshot:
from huggingface_hub import snapshot_download
snapshot_download('FunAudioLLM/Fun-CosyVoice3-0.5B-2512', local_dir='pretrained_models/Fun-CosyVoice3-0.5B')
Add config.json in pretrained_models/Fun-CosyVoice3-0.5B/:
{
"model_type": "cosyvoice3",
"architectures": [
"CosyVoice3Model"
]
}
Why
config.jsonis required:AutoConfig.register("cosyvoice3", CosyVoice3Config)only registers a class mapping. The loader still needsmodel_type: "cosyvoice3"fromconfig.jsonto select that class. If noconfig.jsonis present, model type cannot be inferred automatically. If your downloaded checkpoint already includes a validconfig.jsonwithmodel_type: "cosyvoice3", this manual step can be skipped.
Run the offline verification script:
python examples/offline_inference/cosyvoice3/verify_e2e_cosyvoice.py \
--model pretrained_models/Fun-CosyVoice3-0.5B \
--tokenizer pretrained_models/Fun-CosyVoice3-0.5B/CosyVoice-BlankEN
Implementation Overview
CosyVoice3 runs as a 2-stage Omni pipeline.
- Stage 0 (
talker) converts text + prompt audio to speech tokens. - Stage 1 (
code2wav) converts speech tokens + prompt features to waveform via flow matching and HiFiGAN.
Key components live in vllm_omni/model_executor/models/cosyvoice3/cosyvoice3.py.
CosyVoice3MultiModalProcessorbuilds the multimodal inputs:- Tokenizes
promptandprompt_text. - Extracts speech tokens and mel features from the prompt audio.
- Extracts a speaker embedding.
- Tokenizes
CosyVoice3Modelimplements both stages:- Stage 0 uses
CosyVoice3LMand outputs speech tokens + conditioning features. - Stage 1 runs the flow model (DiT-based CFM) and HiFiGAN to synthesize waveform.
- Stage 0 uses
Stage wiring is configured in vllm_omni/model_executor/stage_configs/cosyvoice3.yaml.
- Stage 0 emits latent speech tokens.
- Stage 1 consumes them via
custom_process_input_funcand outputs audio.
Example materials
??? abstract "verify_e2e_cosyvoice.py"
py --8<-- "examples/offline_inference/cosyvoice3/verify_e2e_cosyvoice.py"