Nano-vLLM style optimized inference engine for VoxCPM2 TTS
VoxCPM2'yi maksimum hızda çalıştırmak için sıfırdan yazılmış, nano-vLLM felsefesiyle optimize edilmiş inference kütüphanesi.
| Konfigürasyon | GPU | RTF | Hızlanma |
|---|---|---|---|
| Ham VoxCPM2 (eager) | RTX 4090 | ~0.90 | 1.0× |
| + torch.compile | RTX 4090 | ~0.45 | 2.0× |
| + FlashAttention | RTX 4090 | ~0.35 | 2.6× |
| + INT8 quantization | RTX 4090 | ~0.30 | 3.0× |
| voxcpm2-vllm (full) | RTX 4090 | ~0.25 | 3.6× |
Referans: VoxCPM2 official RTF ~0.3 on RTX 4090, ~0.13 with official Nano-vLLM
Her VoxCPM2 alt modeli (LocEnc, TSLM, RALM, LocDiT) ayrı ayrı torch.compile ile derlenir. Diffusion transformer (LocDiT) için max-autotune modu kullanılır — Triton kernel'leri en agresif optimizasyonları arar.
MiniCPM-4 backbone'daki tüm attention operasyonları FlashAttention ile değiştirilir. Bellek kullanımı %40-60 azalır, hız %50 artar.
- INT8: %50 VRAM azalması, kalite kaybı <%1
- INT4 (NF4): %75 VRAM azalması, 6-8 GB GPU'larda çalışır
- FP8 desteği (H100/B200 için hazır)
swiglu_fused: SwiGLU aktivasyonu tek kernel'defused_layernorm_linear: LayerNorm + Linear füzyonuDiffusionStepOptimizer: DiT adımı için optimize edilmiş bellek yönetimi
Ses klonlama senaryolarında aynı prompt embedding'leri tekrar tekrar hesaplanmaz. LRU + TTL ile akıllı önbellekleme.
vLLM'in continuous batching mantığı TTS'e uyarlanmıştır. İstekler gruplanır, LM encoding toplu yapılır, diffusion per-request çalışır.
Diffusion döngüsü CUDA Graph olarak capture edilir. Kernel launch overhead'i sıfırlanır.
Kısa metinler için gereksiz diffusion adımları atlanır. "Merhaba" için 2 adım yeterliyken, uzun metin için 10 adım kullanılır.
POST /v1/audio/speech endpoint'i, OpenAI TTS API'siyle birebir uyumlu. Mevcut projelere drop-in entegrasyon.
expandable_segmentsbellek yönetimi- TF32, cuDNN benchmark, memory-efficient SDP
- WSL2'ye özel GPU bellek tahsisi ayarları
# 1. Gereksinimler
pip install torch>=2.5.0 --index-url https://download.pytorch.org/whl/cu124
pip install voxcpm>=2.0.0
# 2. voxcpm2-vllm
cd ~/Desktop/voxcpm2-vllm
pip install -e .
# 3. Opsiyonel hızlandırıcılar
pip install triton>=2.1.0 # Custom kernel'ler için
pip install flash-attn>=2.5.0 # FlashAttention
pip install bitsandbytes>=0.41.0 # Quantizationfrom voxcpm2_vllm import VoxCPM2VLLM, EngineConfig
# Hızlı başlangıç — tüm optimizasyonlar açık
engine = VoxCPM2VLLM.from_pretrained("openbmb/VoxCPM2")
# Türkçe sentez
wav = engine.generate("Merhaba dünya!", timesteps=4)
engine.save("merhaba.wav")
# Ses klonlama
wav = engine.generate(
"Bu klonlanmış bir ses.",
reference_wav="referans.wav",
timesteps=6,
)
# Streaming
for chunk in engine.generate_streaming("Uzun bir metin...", timesteps=4):
print(f"Chunk: {len(chunk)/engine.sample_rate:.1f}s")
# Toplu sentez
results = engine.generate_batch(["Metin 1", "Metin 2", "Metin 3"])config = EngineConfig(
model_id="openbmb/VoxCPM2",
quantize="int8", # INT8 quantization
use_torch_compile=True, # Triton kernel fusion
use_flash_attn=True, # FlashAttention 2/3
use_cuda_graph=True, # CUDA Graph
adaptive_timesteps=True, # Akıllı adım sayısı
max_batch_size=4, # Batch büyüklüğü
prefix_cache_size=32, # Önbellek boyutu
)
engine = VoxCPM2VLLM.from_pretrained(config=config)# API sunucusu başlat
voxcpm2-vllm serve --model openbmb/VoxCPM2 --port 8808
# Tek seferlik sentez
voxcpm2-vllm generate --text "Merhaba!" --output out.wav
# Benchmark
voxcpm2-vllm benchmark
# Sistem bilgisi
voxcpm2-vllm infofrom openai import OpenAI
client = OpenAI(base_url="http://localhost:8808/v1", api_key="x")
response = client.audio.speech.create(
model="voxcpm2",
voice="default",
input="Hello from VoxCPM2-vLLM!",
)
response.stream_to_file("output.wav")voxcpm2-vllm/
├── voxcpm2_vllm/
│ ├── engine.py # Ana motor (yükleme, sentez, optimizasyon)
│ ├── config.py # Konfigürasyon (tüm ayarlar burada)
│ ├── cli.py # Komut satırı arayüzü
│ ├── kernels/ # Custom CUDA/Triton kernel'leri
│ │ ├── attention.py # FlashAttention wrapper
│ │ └── fusion.py # Kernel füzyonu (SwiGLU, LayerNorm+Linear)
│ ├── compile/ # torch.compile yönetimi
│ │ └── compiler.py # Bileşen-bazlı derleme
│ ├── quantize/ # Quantization (INT8, FP8, INT4)
│ │ └── quantizer.py
│ ├── cache/ # Prefix cache
│ │ └── prefix_cache.py
│ ├── scheduler/ # Batch scheduler
│ │ └── batch_scheduler.py
│ └── server/ # OpenAI-compatible REST API
│ └── api.py
├── examples/
│ ├── basic_tts.py # Temel kullanım
│ ├── streaming.py # Streaming TTS
│ ├── batch_tts.py # Toplu sentez
│ └── benchmark.py # Performans karşılaştırması
├── tests/
│ └── test_engine.py # Birim testleri
└── pyproject.toml
Basit bir wrapper yazmak yerine nano-vLLM yaklaşımını benimsedik:
- Her bileşen izole optimize edilir — TSLM, RALM, LocDiT farklı stratejilerle compile edilir
- Memory-first design — vLLM'in PagedAttention'ı gibi, biz de prefix cache ve adaptive timesteps ile memory-bound operasyonları azaltıyoruz
- Kernel fusion — Triton ile operasyonları birleştirip GPU kernel launch overhead'ini düşürüyoruz
- Request-level scheduling — TTS istekleri için optimistik batching
| Metrik | Colab (eager) | voxcpm2-vllm | Fark |
|---|---|---|---|
| torch.compile | ❌ | ✅ max-autotune | ~2× |
| FlashAttention | ❌ | ✅ v2/v3 | ~1.5× |
| Quantization | ❌ | ✅ INT8 | ~1.3× VRAM |
| CUDA Graph | ❌ | ✅ | ~1.1× |
| Prefix Cache | ❌ | ✅ LRU | Anında (cache hit) |
| Adaptive Steps | ❌ | ✅ | ~1.5× (kısa metin) |
| Toplam | 1.0× | 3-4× |
- Python: 3.10 - 3.12
- PyTorch: ≥ 2.5.0
- CUDA: ≥ 12.0
- GPU: NVIDIA (RTX 3060+, A10, A100, H100)
- İşletim Sistemi: Linux / WSL2
git clone https://github.com/kstbhdr/voxcpm2-vllm.git
cd voxcpm2-vllm
pip install -e ".[dev]"
pytest tests/Apache 2.0 — VoxCPM2 ile aynı lisans.
Bu proje OpenBMB'nin resmi Nano-vLLM-VoxCPM'inden bağımsızdır. Topluluk tarafından geliştirilmiş alternatif bir optimizasyon kütüphanesidir. Resmi implementasyon için: https://github.com/OpenBMB/VoxCPM