[Not for merge] Speculative Decoding Cosyvoice LLM example - #1943
Open
yuekaizhang wants to merge 2 commits into
Open
yuekaizhang wants to merge 2 commits into
yuekaizhang wants to merge 2 commits into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See https://github.com/yuekaizhang/SpeechSpec for more details.