Vllm omni tts integration

From hsliuustc0106/vllm-omni-skills · View interactive version

Vllm omni tts integration is an AI agent skill from the GitHub repository hsliuustc0106/vllm-omni-skills. Integrate a new text-to-speech model into vLLM-Omni from HuggingFace reference implementation through production-ready serving with streaming and CUDA graph acceleration. Use when adding a new TTS model, wiring stage separation for speech synthesis, enabling online voice generation serving, debuggin

How to use this skill

Skill file

TTS Model Integration Workflow

Overview

HF Reference -> Stage Separation -> Online Serving -> Async Chunk -> CUDA Graph
   (Phase 1)      (Phase 2)          (Phase 3)        (Phase 4)     (Phase 5)

Phase 1: HuggingFace Reference

Goal: Understand the reference implementation and verify it produces correct audio.

Steps

  1. Run the reference model end-to-end using the official HuggingFace / GitHub code
  2. Document the architecture:
  1. Capture reference outputs for comparison during integration
  2. Identify the config structure: config.json fields, model_type, sub-model configs

Key Questions

Deliverables

Phase 2: Stage Separation (Offline Inference)

Goal: Split the model into vLLM-Omni stages and get offline inference working.

Steps

  1. Register the model in vllm_omni/model_executor/models/registry.py
  2. Create config classes (configuration_<model>.py) with model_type registration
  3. Implement Stage 0 (AR model):
  1. Implement Stage 1 (Decoder):
  1. Create stage config YAML defining both stages, memory allocation, and model paths
  2. Create stage input processor for prompt building
  3. Write end2end.py test script

Critical Parameters to Get Right

| Parameter | Impact if Wrong |

|-----------|----------------|

| Hop length | Audio duration wrong, streaming noise |

| Token ID mapping | Garbage codes -> noise output |

| Codebook count/size | Shape mismatch crashes |

| Stop token | Generation never stops or stops too early |

| dtype / autocast | Numerical issues, silent quality degradation |

| Repetition penalty | Must match reference (often 1.0 for TTS) |

Debugging Priority (from experience)

When audio output is wrong, check in this order:

  1. RoPE / attention: Are position encodings correct? Is the attention mask right?
  2. Normalization: RMSNorm epsilon, layer norm placement (pre vs post)
  3. Hop length: Product of all upsample rates in the codec decoder
  4. Token mapping: Are codec IDs correctly offset from the vocabulary base?
  5. Sampling parameters: Temperature, top_k, top_p, repetition_penalty
  6. Tensor layout: Codebook-major vs frame-major ordering
  7. dtype: Float32 for codec decoders (autocast can corrupt audio)

Deliverables

Phase 3: Online Serving

Goal: Expose the model via /v1/audio/speech API endpoint.

Steps

  1. Register in serving_speech.py:
  1. Handle model-specific parameters:
  1. Use tokens_input() for prompt construction: All TTS prompt builders must use vllm.inputs.tokens_input(prompt_token_ids=...) instead of raw dicts. This avoids deprecated preprocess() fallback warnings. The returned dict has "type": "token" automatically. Add model-specific keys (e.g., additional_information) to the returned dict.
  2. Create client scripts: speech_client.py, run_server.sh
  3. Test all response formats: wav, mp3, flac, pcm
  4. Add Gradio demo: Interactive web UI with streaming support

Voice Cloning Pattern

import base64
from pathlib import Path
from vllm.inputs import tokens_input

def build_voice_clone_prompt(ref_audio_path: str, text: str, codec, tokenizer) -> dict:
    """Build prompt with reference audio for voice cloning in serving_speech.py."""
    audio_bytes = Path(ref_audio_path).read_bytes()
    codes = codec.encode(audio_bytes)  # Encode on CPU using model's codec (e.g., DAC)
    token_ids = [code + codec.vocab_offset for code in codes.flatten().tolist()]

    # Build prompt with voice tokens and tokenize
    voice_tokens = "".join(chr(t) for t in token_ids)
    prompt = f"<|voice|>{voice_tokens}{text}"
    prompt_token_ids = tokenizer.encode(prompt)

    # Use tokens_input() to avoid deprecated preprocess() fallback
    result = tokens_input(prompt_token_ids=prompt_token_ids)
    return result

Deliverables

Phase 4: Async Chunk (Streaming)

Goal: Enable inter-stage streaming so audio chunks are produced while AR generation continues.

Steps

  1. Update stage config YAML:

```yaml

async_chunk: true

codec_chunk_frames: 25 # inter-stage streaming window

codec_left_context_frames: 25 # overlap for smooth boundaries

initial_codec_chunk_frames: 10 # first chunk only (optional, lowers TTFA)

```

  1. Implement chunk handling in Stage 1:
  1. Separate connector chunking from decoder chunking:
  1. Test streaming:
  1. Update online serving to support stream=true with PCM output

Streaming Architecture

Stage 0 (AR)                    Stage 1 (Decoder)
  |                                |
  |-- chunk 0 (25 frames) ------> decode -> audio chunk 0 -> client
  |-- chunk 1 (25 frames) ------> decode -> audio chunk 1 -> client
  |-- chunk 2 (25 frames) ------> decode -> audio chunk 2 -> client
  ...

Key Considerations

Deliverables

Phase 5: CUDA Graph Acceleration

Goal: Capture the AR loop as a CUDA graph for significant speedup.

Steps

  1. Identify the hot loop: The AR decoding loop that runs N steps per token
  2. Create static buffers:
  1. Implement graph capture:
  1. Handle constraints:

Example: Code Predictor CUDA Graph (Qwen3-TTS)

import torch

class CodePredictorGraph:
    """Captures the 16-step code predictor AR loop as a single CUDA graph."""

    def setup_graph(self, device: torch.device, kv_heads: int = 4, head_dim: int = 64):
        self.num_steps = 16
        self.kv_cache = torch.zeros(1, kv_heads, self.num_steps, head_dim, device=device)
        self.positions = torch.arange(self.num_steps, device=device)
        self.causal_mask = torch.tril(torch.ones(self.num_steps, self.num_steps, device=device))
        self.input_buf = torch.zeros(1, 1, kv_heads * head_dim, device=device)
        self.output_buf = torch.zeros(1, self.num_steps, device=device, dtype=torch.long)
        # Warm up, then: self.graph = torch.cuda.CUDAGraph(); self.graph.capture(...)

    def run_graph(self, initial_input: torch.Tensor) -> torch.Tensor:
        self.input_buf.copy_(initial_input)
        self.graph.replay()
        return self.output_buf.clone()

Performance Expectations

Based on Qwen3-TTS code predictor experience:

Deliverables

Integration Checklist

Use this checklist when integrating a new TTS model:

Phase 1: HF Reference

Phase 2: Stage Separation

Phase 3: Online Serving

Phase 4: Async Chunk

Phase 5: CUDA Graph

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.