Skip to content

[Not for merge] Speculative Decoding Cosyvoice LLM example - #1943

Open
yuekaizhang wants to merge 2 commits into
QwenAudio:mainfrom
yuekaizhang:speculative
Open

yuekaizhang wants to merge 2 commits into
QwenAudio:mainfrom
yuekaizhang:speculative

Conversation

@yuekaizhang

Copy link
Copy Markdown
Contributor

yuekaizhang and others added 2 commits August 3, 2026 03:53
Integrates DSpark speculative decoding into the CosyVoice3 inference
pipeline without requiring any manual export scripts.

cosyvoice/utils/file_utils.py
- export_cosyvoice3_vllm_spec(): exports CosyVoice3LM to HF format with
  extended embed_tokens/lm_head for DSpark compatibility (speech tokens at
  offset text_vocab_size=151924). Skips if output dir exists, mirroring
  export_cosyvoice2_vllm(). Saves cosyvoice3_metadata.json with
  speech_token_offset for downstream mapping.

cosyvoice/cli/model.py
- CosyVoice3Model.load_vllm_spec(model_dir, draft_model_dir): auto-exports
  via export_cosyvoice3_vllm_spec() into <model_dir>/hf_spec, then creates
  a vllm V1 LLM with DSpark speculative_config (probabilistic sampling +
  draft_apply_repetition_penalty=True). Frees PyTorch layers after loading.

cosyvoice/llm/llm.py
- CosyVoice3LM._inference_spec(): token-based speculative generation using
  the Qwen2 chat template. Decodes text tokens back to string, encodes
  prompt speech tokens as <|s_N|>, calls vllm_spec.generate(), and maps
  output token IDs back to speech IDs via speech_token_offset.
- Qwen2LM.inference(): branches to _inference_spec() when vllm_spec is set.

vllm_example.py
- cosyvoice3_spec_example(): two-line usage matching load_vllm() style.

Usage:
    cosyvoice.model.load_vllm_spec(
        'pretrained_models/Fun-CosyVoice3-0.5B',
        'yuekai/cosyvoice3_llm_dspark',
    )

Requires the speculative vllm fork (yuekaizhang/vllm branch
dspark-draft-sampling-mirrors) with vllm-omni 0.25.1 compiled extensions
via PYTHONPATH (enable_prompt_embeds is incompatible with DSpark's V2
model runner requirement; token-based path avoids this constraint).

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Yuekai Zhang <zhangyuekai@foxmail.com>
…e as default

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Yuekai Zhang <zhangyuekai@foxmail.com>
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

Successfully merging this pull request may close these issues.

1 participant