Qwen3-TTS 12Hz 0.6B CustomVoice
This package contains the Qwen/Qwen3-TTS-12Hz-0.6B-CustomVoice integration inside the TT-Metal tree.
It includes two complementary paths:
- A reduced PyTorch reference path that can run end to end and write a waveform.
- A TTNN path for the Talker and MTP stages, plus host-side orchestration, tokenizer decode, metadata/reporting, and focused validation tests.
The supported TTNN user-facing entrypoint is:
python models/bos_model/audio/qwen3_tts/run_model.py ...
run_model.py is intentionally thin and forwards to demo/demo.py, which builds the CLI request and calls the end-to-end pipeline in inference/pipeline.py.
What is in this package
models/bos_model/audio/qwen3_tts/
├── README.md # Package overview, architecture, setup, and validation notes
├── run_model.py # Stable top-level entrypoint for the supported TTNN demo
├── demo/ # User-facing CLI flow and demo-specific documentation
├── inference/ # End-to-end orchestration, tokenizer decode, artifacts, and reporting
├── tt/ # TTNN model implementation: Talker, MTP, generation, kernels, and configs
├── reference/ # Reduced PyTorch reference path and deterministic golden capture tools
├── tests/ # Unit, integration, and end-to-end validation
├── profile_modules.py # Focused profiling helper for selected modules/tests
└── requirements.txt # Package-local pinned Python dependencies
If you are new to the package, the most important files to open first are:
run_model.pyfor the stable entrypoint shapedemo/demo.pyfor the supported CLI behaviorinference/pipeline.pyfor the real execution flowtt/talker.pyandtt/mtp.pyfor the core TTNN model stagesreference/demo_reference.pywhen you need the PyTorch baseline
Implementation
Reference path
Use the reference path when you need a PyTorch baseline from text to waveform.
- Entry point:
reference/demo_reference.py - Main wrapper:
reference/inference/qwen3_tts_model.py - Output: waveform array and sample rate, then
.wavwritten withsoundfile - Device support: CPU and CUDA through PyTorch and Hugging Face
This path is the easiest place to validate prompt behavior, compare against the original checkpoint behavior, and capture deterministic goldens for TTNN validation.
TTNN path
Use the TTNN path when you are validating or developing the Talker and MTP execution on Tenstorrent hardware.
- CLI entrypoint:
run_model.py - CLI implementation:
demo/demo.py - Pipeline/orchestration:
inference/pipeline.py - Talker implementation:
tt/talker.py - MTP implementation:
tt/mtp.py - Host generation utilities:
tt/generation.py
The TTNN path prepares the CustomVoice prompt on host, runs Talker and MTP on device, decodes codec frames into audio, writes artifacts, and prints a structured inference report.
Inspect the validated host/device flow without opening a device:
python models/bos_model/audio/qwen3_tts/run_model.py \
--text "Hello" \
--language English \
--speaker Aiden \
--max-frames 25 \
--describe-flow
Execution flow
The supported TTNN inference flow is:
- Parse CLI arguments in
demo/demo.py. - Build
Qwen3TTSInferenceConfigand validate user-visible request values. - Resolve and validate the local checkpoint snapshot.
- Open one TTNN device.
- Build
Qwen3TTSInferencePipelinefrom the checkpoint. - Prepare the CustomVoice prompt and prompt metadata on host.
- Run Talker prefill, q0 selection, and MTP residual generation.
- Decode codec frames into waveform audio.
- Write output artifacts and print the runtime report.
This package supports offline, batch-size-1 inference for the validated CustomVoice path. It is not described here as a streaming server, batching API, or generic voice-cloning interface.
Environment setup
From the repository root:
cd $TT_METAL_HOME
source env_set.sh
python -m pip install -r models/bos_model/audio/qwen3_tts/requirements.txt
Qwen3-TTS uses the repository default python_env and the same pinned
Transformers version as Spark-TTS. Installing these requirements keep the Transformers version used by other models
unchanged in the shared environment.
Checkpoint expectations
The code is written against the Hugging Face checkpoint:
Qwen/Qwen3-TTS-12Hz-0.6B-CustomVoice
Checkpoint behavior differs slightly by path:
- The reference demo can accept either the Hugging Face model id or a local snapshot directory.
- The TTNN demo expects a local snapshot because it reads selected tensors directly from checkpoint files.
- By default, the TTNN CLI resolves the pinned supported snapshot under the Hugging Face cache.
--download-if-missingcan fetch the pinned supported revision before device initialization.
The checkpoint is expected to include:
config.json- model weights
- tokenizer and processor assets
speech_tokenizer/assets used by the 12 Hz codec decode path
Several tests under tests/ assume a local snapshot already exists under the Hugging Face cache and use that path directly or indirectly.
Run the supported TTNN demo
python models/bos_model/audio/qwen3_tts/run_model.py \
--checkpoint /path/to/Qwen3-TTS-12Hz-0.6B-CustomVoice \
--text "Even though the lead architect encountered several unexpected structural issues during the initial phase of the renovation, the entire project remained strictly on schedule and within the designated budget." \
--language English \
--speaker Aiden \
--inference-mode fast \
--sampling-mode sample \
--seed 16 \
--max-frames 256 \
--max-sequence-length 512 \
--output-wav /tmp/qwen3_tts.wav \
--save-metadata /tmp/qwen3_tts.json \
--device-id 0 \
--warmup-runs 1 \
--download-if-missing
Outputs:
- WAV audio file
- metadata JSON sidecar
- optional saved codec-token tensor when
--save-codec-tokensis set - console inference report with latency, throughput, timing breakdown, context usage, and RTF metrics
For the full runbook, mode-specific examples, and CLI details, see the demo README.
Testing and validation
The test suite is organized by functional area:
tests/inference/for CLI and pipeline behaviortests/e2e/for end-to-end execution checkstests/talker/for Talker coveragetests/mtp/for MTP coverage and backend-specific checkstests/decoder/for decoder-layer behaviortests/rope/for RoPE behaviortests/tokenizer/for tokenizer-related behaviortests/reference/for golden capture and reference helperstests/common/contains shared utilities, not runnable validation tests
After environment setup, generate the reference goldens once from the repository root:
python models/bos_model/audio/qwen3_tts/reference/capture_reference.py
python -m pytest models/bos_model/audio/qwen3_tts/tests/reference/test_reference_capture.py -q
Keep the default text ("Hello, this is a Qwen3 TTS test."), language (English),
speaker (Aiden), and output directory for these tests. Capture writes the tensors
and regenerates reference/goldens/metadata.json.
These two tests verify artifact completeness, metadata, and tensor serialization. They do not compare TTNN model outputs against the reference; run the relevant Talker, MTP, decoder, or end-to-end tests for model validation.
Focused examples:
pytest models/bos_model/audio/qwen3_tts/tests/inference/test_run_model.py
pytest models/bos_model/audio/qwen3_tts/tests/e2e/test_codec_generation.py -q
pytest models/bos_model/audio/qwen3_tts/tests/mtp/test_mtp_full.py -q
pytest models/bos_model/audio/qwen3_tts/tests/talker/test_full_talker.py -q
pytest models/bos_model/audio/qwen3_tts/tests/reference/test_reference_capture.py -q
Most TTNN-side tests require:
- a valid TT device fixture from the repository test harness
- an accessible local checkpoint snapshot
- existing goldens under
reference/goldens/for the tests that compare against captured references
Performance and profiling utilities
Use run_model.py for end-to-end performance measurements.
Choose the timing scope
Benchmarking is opt-in: if --benchmark is omitted, one normal inference runs
and no benchmark timing is collected. --warmup-runs and --measured-runs
only take effect when --benchmark is present.
| Goal | Option | What is measured | Recommended sampling |
|---|---|---|---|
| User-visible warm inference performance | --benchmark include_host_time | Synchronized wall time from raw text through prompt preparation, Acoustic generation, Codec/Vocoder, and waveform D2H | 3 warmups + 10 measured runs |
| Accelerator work and device-stage bottlenecks | --benchmark device_only | Sum of active DEVICE KERNEL DURATION [ns] records for Talker, MTP, and Codec/Vocoder | 1 warmup + 1 measured run |
device_only intentionally excludes Python/host time, dispatch and
synchronization waits, transfer wall time, command-queue idle time, and
op-to-op gaps. It is active-kernel time, not device elapsed wall-clock
time. The CLI enables the required TT-Metal profiler environment before TTNN
is imported, so users should not need to export profiler variables manually.
include_host_time includes host orchestration, transfers, synchronization
waits, and device execution inside the request. Both modes exclude model/device
setup, weight loading, compilation warmup, and WAV file serialization.
Run the recommended quality/fast benchmark matrix
Run all four cases on the same idle device with the same checkpoint, prompt, speaker, seed, frame limit, and cache length. The following copy-paste example runs them sequentially and saves each WAV and JSON result separately:
cd $TT_METAL_HOME
source env_set.sh
checkpoint=/path/to/Qwen3-TTS-12Hz-0.6B-CustomVoice
prompt="Even though the lead architect encountered several unexpected structural issues during the initial phase of the renovation, the entire project remained strictly on schedule and within the designated budget."
run_qwen3_tts_benchmark() {
local inference_mode=$1
local benchmark_mode=$2
local warmup_runs=$3
local measured_runs=$4
python models/bos_model/audio/qwen3_tts/run_model.py \
--checkpoint "$checkpoint" \
--text "$prompt" \
--language English \
--speaker Aiden \
--inference-mode "$inference_mode" \
--sampling-mode sample \
--seed 16 \
--max-frames 256 \
--max-sequence-length 512 \
--output-wav "/tmp/qwen3_tts_${inference_mode}_${benchmark_mode}.wav" \
--save-metadata "/tmp/qwen3_tts_${inference_mode}_${benchmark_mode}.json" \
--device-id 0 \
--benchmark "$benchmark_mode" \
--warmup-runs "$warmup_runs" \
--measured-runs "$measured_runs"
}
run_qwen3_tts_benchmark quality include_host_time 3 10
run_qwen3_tts_benchmark quality device_only 1 1
run_qwen3_tts_benchmark fast include_host_time 3 10
run_qwen3_tts_benchmark fast device_only 1 1
Fast mode requires --sampling-mode sample. It keeps q0 sampled but changes
q1--q15 residual selection to the device-resident greedy path and enables
selected N1A0-optimized backends. Quality and fast can therefore produce
different frame counts and audio durations; compare them primarily by RTF or
RTFx rather than raw seconds.
For regression tracking, keep the exact prompt and all generation options fixed. Within a given inference mode, the host-inclusive and device-only runs should have matching frame count, codec shape, codec SHA-256, sample count, EOS result, and WAV SHA-256 in their JSON files. Do not require quality hashes to match fast hashes because the residual-selection policies differ.
Read the benchmark output
The console report is organized into these groups:
| Group | Important fields | Meaning |
|---|---|---|
| Request / output | Prompt tokens, generated frames, codec tokens, EOS | The actual measured workload; one frame contains 16 codec tokens and represents 80 ms at 12.5 Hz |
| Latency / throughput | Time to first q0, time to first complete codec frame, codec-frame ITL, frames/s | Host-visible latency and sustained frame rate; shown only for include_host_time |
| Time breakdown | Talker, MTP, Acoustic, Codec/Vocoder, D2H, total | Stage attribution in the selected timing scope |
| Real-time performance | RTF and RTFx | Audio-normalized performance |
| Artifacts | WAV and metadata paths | Files needed for correctness and regression comparison |
The stage names mean:
- Talker: prefill, autoregressive decode, and q0 selection.
- MTP: residual codec generation for q1 through q15.
- Acoustic generation: Talker + MTP, including a small explicitly reported orchestration remainder in host-inclusive mode.
- Codec/Vocoder: conversion from the completed
[1, frames, 16]codec tensor to the device waveform. - Waveform D2H: final waveform transfer for host-side WAV serialization; reported separately from Codec/Vocoder in host-inclusive mode.
RTF and RTFx are reciprocal views of the same result:
RTF = processing seconds / generated audio seconds # lower is better
RTFx = generated audio seconds / processing seconds # higher is better
Real-time generation requires RTF <= 1.0, equivalently RTFx >= 1.0.
For a 12.5 Hz codec stream, sustained codec-frame throughput must also be at
least 12.5 frames/s.
Use the JSON for analysis and automation
The JSON sidecar is the source to use in scripts and dashboards. Its timing
object contains:
benchmark_modeandtiming_scopewarmup_runsandmeasured_run_countaggregate, which is the arithmetic mean printed by the consolemeasured_runs, containing every individual measured resultstatistics, containing mean, median, minimum, maximum, standard deviation, coefficient of variation, and the primary metric name- the applicable host-inclusive or device-only RTF and RTFx
For host benchmarking, use the distribution in statistics rather than
reporting one run. A low coefficient of variation (CV) indicates stable warm
measurements. Device-only profiling is expensive and verbose, so one measured
run is the quick default; use multiple measured runs when device-time variance
itself matters.
Compare host and device results correctly
Host-inclusive and device-only values are produced by separate executions. The device profiler and its frequent data drains can perturb kernel execution, so the two values are not guaranteed to be nested. In particular:
- Do not define CPU overhead as
host time - device timewithout a caveat. - A small result where host-inclusive time is below device-only time is normal cross-run/profiler variation, not negative host overhead.
- Do not add op-to-op gaps to device-only RTF; those gaps are deliberately out of scope.
- Use the per-mode stage shares to find bottlenecks and use RTF/RTFx to compare modes or outputs with different audio durations.
Benchmark mode cannot be combined with --debug or --tracing, because those
diagnostics perturb the measurement. Also avoid running another workload on
the same device during collection.
The checked-in benchmark methodology, results, charts, and raw JSON examples are available in the report README.