Skip to content

Qwen3-TTS: add optimized streaming mode - #1011

Merged
0xShug0 merged 1 commit into
mainfrom
perf/qwen3-tts-improvements
Oct 20, 2026
Merged

0xShug0 merged 1 commit into
mainfrom
perf/qwen3-tts-improvements

Conversation

@0xShug0

@0xShug0 0xShug0 commented Oct 20, 2026

Copy link
Copy Markdown
Owner

Summary

Add qwen3_tts.perf_mode=optimized as a shortcut for flash attention, FP16 convolution weight storage, and stateful streaming decoding. Individual session options remain available and override the preset. Existing off and flash_attention modes retain their preset meanings. KV alignment now defaults to 256 in every mode.

The mode offers a streaming throughput/VRAM tradeoff. Stateful decoding retains convolution and attention history rather than repeatedly decoding overlapping windows; its exact-length graphs are owned and reused by the session.

CUDA streaming: main vs this branch with optimized mode

Metric Main (c677d5e6) This branch, optimized
TTFA p50 15.76 ms 12.95 ms
TTFA p95 17.97 ms 15.56 ms
RTF (lower is better) 0.13081 0.09590
Peak process VRAM 4454 MiB 5986 MiB

26.69% lower RTF, with 1532 MiB higher sampled peak VRAM.

Conditions: RTX 5090, Qwen3-TTS 12Hz 1.7B CustomVoice BF16 GGUF, Aiden, English, seed 42; temperature 0.9, top-k 50, top-p 1.0, repetition penalty 1.05, max tokens 2048. Same 50 CV3 English inputs in the same order; 47 measured after excluding the first three corpus requests, following three preliminary warmups. Streaming chunks grow 1 → 2 → 4 → 8 → 12 frames. Four threads, cached Debug build with -O3 -g, CUDA graphs and OpenMP enabled. Measurements ran sequentially, with a fresh server for each configuration.

TTFA is client-observed arrival of the first nonempty streamed audio. RTF is summed generation time divided by summed generated audio duration. Process VRAM was sampled with nvidia-smi every 100 ms during loading, warmup, and inference; shorter spikes may be missed. These are single-pass measurements. Generated duration differs between numerical paths: main 290.08 s, optimized 287.84 s.

This comparison includes the whole branch, including the unconditional changes below; it does not attribute the full gain solely to selecting the preset.

Enable

"session_options": {
  "qwen3_tts.perf_mode": "optimized"
}

The constituent options remain configurable:

"session_options": {
  "qwen3_tts.perf_mode": "optimized",
  "qwen3_tts.conv_weight_type": "f32",
  "qwen3_tts.stream_decoder": "windowed",
  "qwen3_tts.talker_kv_cache_alignment": "1"
}

Scope and behavior

  • Qwen3-TTS also adopts framework HF sampling, fused SwiGLU, immutable predictor inputs initialized once, and direct backend KV-prefix import. These changes are unconditional.
  • Talker KV alignment defaults to 256; explicitly selecting 1 disables padding. This changes numerical behavior and can change seeded generation lengths.
  • Framework additions are isolated: identity-reshape elision defaults to false and is explicitly enabled only by Qwen3-TTS; backend KV-prefix import is a new method with no changes to existing import_state() callers. No vendored ggml changes or new dependencies.
  • Flash attention, FP16 convolution weights, and stateful decoding can change output audio. Optimized output is not claimed byte-identical to main or perceptually equivalent based on timing tests. FP16 here describes stored weights; some CUDA convolution paths still cast weights to FP32 within the graph.
  • Windowed decoding remains the default outside optimized. Stateful decoding uses more graph memory and rejects the unsupported RKNN combination rather than silently falling back.
  • The experimental resident code-predictor path is not included.

Validation

  • Cached Debug server build passed; actual main and candidate binaries checked using --version, with source/binary provenance saved locally.
  • Main and optimized streaming completed all 50 inputs; WAVs saved from concatenated SSE audio. Server logs include session.wall_ms.
  • Shortcut validation: 50/50 WAVs byte-identical to setting all constituent options individually.
  • Override validation: explicit F32/windowed/alignment1 settings overrode the preset; startup logs confirmed resolved settings, and streamed PCM matched the corresponding flash-attention reference input exactly.
  • Backend KV-prefix import tests passed on CPU/CUDA, checking F32/F16/BF16 bytes, positions, and zeroed tails.
  • Fused decoder tests passed on CPU/CUDA; Vulkan same-backend fused/unfused comparisons passed.
  • Stateful decoder versus offline decoding with identical held speech codes passed the real-weight CPU/CUDA tolerance checks, including F32/F16 convolution storage, varying chunk sizes, reference prefixes, and resets. These are tolerance checks, not universal waveform-equivalence claims.
  • Earlier isolated sampler/fusion tests preserved 50/50 CUDA WAVs before the alignment/default and opt-in numerical changes.
  • JSON parsing and git diff --check passed.

The end-to-end performance sweep covers CustomVoice BF16 on this CUDA setup. Base, VoiceDesign, other weight precisions, and other accelerators have not received the same end-to-end sweep.

@0xShug0
0xShug0 merged commit 1e2628c into main Oct 20, 2026
7 checks passed
@0xShug0
0xShug0 deleted the perf/qwen3-tts-improvements branch October 20, 2026 19:35
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