Commit Graph
68 Commits
Author SHA1 Message Date
Pascal 26dd8adbf0 predictor: unroll the frame into one cgraph and sample in standard ops
One static frame graph per batch width replaces the per step chain:
prefill and the 15 acoustic steps run in a single backend compute.
This is the target architecture for the llama.cpp Qwen3-TTS port and
serves as its working GGML reference while under test.

Sampling is a plain op chain batched over slots: temperature, argsort
top_k (descending order is guaranteed on every backend, unlike top_k),
softmax, cumsum, cdf crossing against a per step philox uniform.
Greedy draws with u = 0 and lands on the argmax. Faster than the
fused sampling op under CUDA graph capture, greedy codes stay exact
against the Python reference on CPU, CUDA and Vulkan.

Opt in single slot latency mode (--codec-fused on qwen-tts and
tts-server, codec_fused in qt_init_params): the codec stream tail
joins the frame graph at T=1, codes read through a device view, one
80 ms chunk per compute with no host round trip.

Predictor 3.34 -> 3.11 ms/frame on CUDA, end to end -4%.
2026-07-30 22:53:58 +02:00
Pascal 35ebe5376b nit: drop obsolete ABI comments 2026-07-25 19:06:43 +02:00
Pascal d03ffb97f9 api: derived codec left context, chunk width hoisted to qt_init
The left context of the buffered chunked decode is no longer a caller
knob: it derives from the codec's own sliding window (2x144 frames),
placing the default decode at the residual floor of the split.
codec_chunk_sec moves from qt_tts_params to qt_init_params, resolved
once to frames at load. The mid-struct removal bumps the ABI to a
closed range [QT_ABI_MIN_VERSION, QT_ABI_VERSION] = [4, 4]; the probe
asserts both bounds reject through the range check.
2026-07-25 18:56:28 +02:00
Pascal 53c84fe1be engine: batched multi lane codec streaming, shared lockstep chunk ramp
One codec stream state set per lane plus a staging set, static graphs
per (chunk class, lane count) decoding every streaming lane in one
compute. The engine drops the per slot decoders and ownership
save/load for a shared 1 -> 2 -> 4 -> 8 ramp: lanes accumulate and
flush together, an admit drains and restarts at width 1, a retirement
drains then compacts the lane span device side. ICL references prime
through the staging set into per set snapshots. Depthwise and
transposed convs fold lanes into the channel axis; the dense convs
rely on the ggml conv_1d batched layout fix (submodule bump).
2026-07-20 19:13:05 +02:00
Pascal b2e36056eb graphs: express the SwiGLU MLPs through ggml_swiglu_split
The talker, code predictor, and tokenizer transformer built their MLPs
as two mul_mats followed by a separate silu and mul. Replacing the
silu + mul pair with the GGML_OP_GLU node keeps the gate and up
mul_mats adjacent to it, which is the exact pattern the CUDA backend
fusion pass matches (ggml_cuda_should_fuse_mul_mat): gate, up, and
activation collapse into one kernel on the GEMV decode shapes.

Applies to all five MLP sites: talker prefill and batched decode,
code predictor layer, tokenizer transformer offline and stream paths.
Validated bit-exact against HEAD on greedy and seed 42 (identical
WAVs, F32 master). Around +3 percent on the F32 AR frame; neutral on
correctness, two lines simpler per site.
2026-07-20 16:54:11 +02:00
Pascal 37ea692be6 engine: true parallel batching of the talker and predictor, per slot codec streams 2026-07-20 16:53:36 +02:00
Pascal 95b4840ad3 loader: validate raw u32 counts before the (int) cast 2026-07-17 21:46:24 +02:00
Pascal d5b05efff7 nit: realign endpoint tables on the widened voice routes 2026-07-17 21:13:57 +02:00
karlandPascal 8d556c9806 server: compatible with OpenAI API, add model alias 2026-07-17 21:13:57 +02:00
RaduAdumitroaeiandPascal 19bbf94dcc pipeline-codec: reset sched before encode alloc
The codec encode path allocated its graph without first resetting the
shared scheduler, unlike every sibling path (decode, prompt-builder,
speaker_encoder_extract). After a synthesis call leaves the codec sched
allocated, the next RVQ encode — e.g. registering a second cloned voice
after a generation — trips GGML_ASSERT(!sched->is_alloc) in
ggml_backend_sched_alloc_graph and crashes the server.

Reset the sched before alloc to match the other call sites.

Repro: register a voice (base model) -> generate speech -> register
another voice. Second register crashes without this fix.
2026-07-17 21:13:57 +02:00
Pascal 0e2b672329 backend: drop the process-wide backend cache inherited from acestep.cpp
backend_init returned a refcounted global BackendPair shared by every
context in the process. That cache is load bearing in acestep.cpp where
each module inits its own backend, but here the pipeline already shares
one BackendPair explicitly, so the cache never hit and only made
independent contexts collide: one CUDA VMM pool is a strict LIFO stack,
so two contexts interleaving alloc/free abort on the pool assert.

Each backend_init call now returns a fresh backend pair with its own
device context and memory pool, backend_release frees it directly, and
the one-time ggml_log_set + ggml_backend_load_all setup moves under a
magic static so concurrent context creation stays safe.

Single-context binaries (CLI, server) are bit-identical. Multi-context
embedders (python bindings running parallel pipelines) no longer crash.
2026-07-17 21:13:57 +02:00
Pascal d17c33d4ee tts: reuse decode scratch buffers across streaming steps
Keep the talker causal mask in each static attention window graph and
reuse positions, KV rows and sliding attention mask buffers in each codec
stream graph class.

This removes the remaining host allocations from the talker and codec
streaming hot loops without changing graph execution.
2026-07-12 09:25:38 +02:00
Pascal bb250f57e4 backend: dedup consecutive identical ggml log lines
Install a ggml log callback that collapses exact consecutive
duplicates and reports the total count when the run ends. The CUDA
graph capture logs one reused line per replay step, flooding stderr
and stalling a reader that blocks on a full pipe.
2026-07-09 15:28:07 +02:00
Pascal 0725d2e53b codec: adaptive chunk width on the streaming decode
The stream graphs come in width classes T in {1, 2, 4, 8} sharing the
state and KV ring tensors, built lazily per class. The decoder ramps
1 -> 2 -> 4 -> 8 so the first frame keeps its latency while the steady
state interleaves the codec 8x less often and the batch amortizes the
kernel count; drain flushes the tail at EOS and the reference priming
runs in max width chunks.
2026-07-06 22:43:52 +02:00
Pascal 206ad06fde talker: static decode graphs per attention window class
The decode flavor builds one static graph per 256 step kv window,
lazily on the first step entering the span, and replays directly on
the backend: ids, overlay, positions, kv row, and mask re-upload each
step since n_past moves. The prefill keeps the dynamic arena and sched
path, and the frame id assembly leaves the shared core.
2026-07-06 22:26:19 +02:00
Pascal 2862be4152 predictor: static graphs replayed with a single id upload per step
The 15 predictor flavors build and allocate once at load, positions,
kv rows, and mask baked as never freed graph outputs, and replay
directly on the backend. The prefill slices the last position before
lm_head so every flavor reads one logits row at offset zero. Replaces
the per step graph rebuild, sched allocation, and debug prints.
2026-07-06 21:46:08 +02:00
Pascal 73fe0c67bb server: sampling overrides on the speech endpoint
The speech body accepts seed, max_new_tokens, temperature, top_k,
top_p, and repetition_penalty. Unset fields keep the engine defaults,
a temperature of zero selects greedy decoding, and the subtalker
mirrors the talker knobs. A fixed seed makes a request reproducible.
2026-07-05 15:01:37 +02:00
Pascal 1a680e8816 codec: primed state snapshot LRU keyed by the reference content
seed_reference hashes the ICL reference codes and restores the conv
contexts, KV ring, and position from a per reference snapshot slot on
a repeat, saving the primed state device to device after a fresh
prime. The reference priming cost amortizes across repeated cloned
voice requests.
2026-07-05 14:34:27 +02:00
Pascal 0f1c8572c7 qwen: lazy speaker encoder load in the voice ref extraction path
qt_extract_voice_ref now pays the speaker encoder weight load on its
first call, mirroring the qt_synthesize ref_audio path. The server
extraction endpoint works without a prior ref wav synthesis.
2026-07-05 13:45:38 +02:00
Pascal 62dec12580 server: cloned voice registry over the OpenAI surface
POST /v1/voices registers a voice from a WAV extracted server side
through qt_extract_voice_ref or from pre extracted .spk and .rvq
latents taken verbatim, DELETE drops it and GET lists it alongside the
model speakers. A registered voice wins over a speaker of the same
name and injects the reference latents into qt_tts_params, ref_text
present selects ICL clone mode. The registry lives in process RAM
under the synthesis mutex, so registration and lookups never race a
running synthesis. The audio and rvq readers gain buffer variants
factored from the file paths. The README and the architecture
document catch up on the streaming decode, the hidden bridge, and the
server endpoints.
2026-07-05 12:28:55 +02:00
Pascal a37ff074ff codec: guard the KV ring against models with a wider sliding window 2026-07-05 10:36:58 +02:00
Pascal 2700d4c746 codec: stateful frame by frame streaming decode on a static graph
Every causal conv carries its left context in a persistent backend
tensor and every transposed conv its overlap tail, so a T=1 frame
decode reproduces the offline full decode exactly with zero re decoded
context. The tokenizer transformer attends over a sliding window KV
ring written through set_rows. The frame graph builds and allocates
once, then every frame is input uploads, one direct backend compute,
and one readback. The quantizer conts each codebook id view so the
Vulkan get_rows path accepts the direct compute. Each generated frame
emits its samples immediately and ICL priming feeds the full reference
through the same state. The buffered path keeps the chunked decode and
both codec framing knobs now apply to it alone.
2026-07-05 10:25:21 +02:00
Pascal 415ef56330 tts: static decode graphs and device resident hidden bridge
KV writes go through set_rows with the destination rows carried as data
and the code predictor steps get one arena per sub step, so every
decode graph keeps a fixed topology and fixed tensor addresses step
after step. The talker last hidden stays resident on device in a
persistent bridge tensor, written by the talker graph and concatenated
as a leaf by the predictor prefill. The hot loop uploads sixteen code
ids and one overlay row and reads back the logits alone, host hidden
readbacks survive only under the dump path. Fewer nodes, transfers and
syncs pay on every backend, and the stable topology lets the CUDA
backend replay its captured graphs without an update.
2026-07-05 07:43:09 +02:00
Pascal e2e381f4f0 codec: persistent graph arena for the streaming decode path
pipeline_codec_decode builds its graph in a persistent arena instead of
a fresh ggml context per call. Constant size streaming slices rebuild
every node at the same address with identical shapes, which trims host
side graph churn on every backend and lets the CUDA backend replay its
captured graph executable without an update. The encode path keeps its
per call context.
2026-07-05 07:42:50 +02:00
Pascal 4057d0331f tts: seed the vocoder left context with the ICL reference tail
The upstream pipeline decodes reference plus generated codes then trims,
giving the first generated frames causal context from the reference; the
generated only decode started the vocoder from an empty state and
colored the clone onset. Seed both decode paths with the last
min(ref_T, left_ctx_frames) reference frames: the streaming decoder
takes them below its emit cursor so they are never emitted, the buffered
path prepends them and strips their samples. Raising
codec_left_context_sec past the reference duration reproduces the
upstream full reference decode exactly.
2026-07-04 22:47:41 +02:00
Pascal 3e3b6c1712 tts: lazy encoder loading and in graph embedding gathers
Load the codec encoder half (seanet, enc_transformer, enc_downsample,
qenc) and the speaker encoder lazily on their first real use: synthesis
from a pre extracted reference (--ref-spk --ref-rvq) now brings up only
the talker and the codec decoder, matching the load profile of a preset
voice server. Assemble the AR inputs on device: the talker decode graph
gathers and sums the 16 frame code embeddings plus the trailing text or
pad overlay via get_rows, and the code predictor gathers c0 and each
sampled sub code from its group table in graph. Per frame host traffic
drops from 16 gguf row reads plus a CPU sum plus 15 synchronous backend
readbacks to 16 code ids and one overlay row uploaded. The next-emb
parity dump reproduces the in graph composition on host under --dump
only, staying byte comparable against the Python hook.
2026-07-04 21:35:03 +02:00
Pascal 3ee7bdd8c8 tts: persistent graph arenas and padded attention windows
Rebuild each forward into a persistent arena per graph shape class (one
for the talker, two for the code predictor prefill and step flavors that
alternate within a frame) so nodes keep stable addresses and the CUDA
graph cache replays its executable instead of reinstantiating. Pad the
talker attention window to 256 and fix the predictor window to the frame
cache size so decode shapes hold across steps, with the causal mask
carrying neg inf over the padded tail. Drop the per step ggml context
churn and the trailing sched resets: one talker step plus 15 predictor
micro steps per frame no longer pay a full build/alloc/free cycle each.
2026-07-04 14:14:59 +02:00
Pascal 3a3069b8fd utf8: normalize inbound text bytes to UTF-8
Same gap as omnivoice.cpp: the UTF-8 boundary covers argv, console
output, and fopen but not the bytes arriving from stdin or text files.
Windows shells and editors hand those over as UTF-16 with BOM
(PowerShell redirection, Notepad, Out-File) or the ANSI codepage (cmd
pipes), and the raw bytes reach the tokenizer as garbage.

utf8_normalize() closes the gap: UTF-8 BOM stripped on every platform,
UTF-16 BOM losslessly recoded to UTF-8, bytes failing UTF-8 validation
decoded from the ANSI codepage. Valid UTF-8 passes through untouched.
Wired into read_stdin_text (binary mode stdin so CRLF translation
cannot eat UTF-16 0x0D bytes) and read_text_file, which also moves
from raw fopen to utf8_fopen so a non-ASCII --ref-text path opens.
2026-07-04 01:14:00 +02:00
Andres Marafioti 5ce30d34a4 Add voice reference extraction ABI 2026-06-24 17:18:32 +02:00
Pascal 4536dcdce2 cleaning 2026-06-21 17:30:21 +02:00
Pascal 0bf4a18b22 codec: add pre-encoded voice reference (--ref-spk / --ref-rvq)
qwen-codec --talker extracts the speaker embedding (.spk, raw f32)
and the ICL codes (.rvq) in one pass, encode truncated to the hop
boundary conforming to the --ref-wav path. qwen-tts loads them via
--ref-spk / --ref-rvq and skips the speaker encoder and codec encode
on every synthesis: TTFA 205 ms -> 89 ms. Extends qt_tts_params with
ABI v2 latent fields, adds qt_num_codebooks(), ships freeman.spk +
freeman.rvq and switches clone scripts to the latent path. Output is
bit-identical to the raw path at fixed seed.
2026-06-11 21:45:13 +02:00
Pascal e8e33629c1 graph: reset scheduler before remaining shared-sched graph allocs
The talker path already resets the scheduler before allocating its graph
(thanks Andi Marafioti, #4 of qwentts.cpp). The same shared scheduler is
also allocated elsewhere without a reset first.

The scheduler keeps split and tensor->backend assignments from the
previous graph. Allocating a different graph topology on a dirty
scheduler can reuse stale assignments, which is exactly the CPU
divergence Andi fixed for the talker. Resetting before alloc_graph is
the canonical GGML contract and is idempotent when the scheduler is
already clean.

Suggested-by: Andres Marafioti <andimarafioti@gmail.com>
2026-06-09 19:53:56 +02:00
PascalandGitHub f79b23a567 Merge pull request #4 from andimarafioti/reset-scheduler-before-talker-alloc
Reset scheduler before talker graph allocation
2026-06-09 12:01:12 +02:00
Andres Marafioti d862d0e10a Reset scheduler before talker graph allocation 2026-06-09 11:44:59 +02:00
PascalandJeffrey van Binsbergen df66c67706 tts: add --stream-by-line, one utterance and one WAV header per line
With -o '-', stdin is read line by line and every line synthesises
immediately as its own utterance, model and speaker staying resident
across lines. Each utterance after the first opens with a fresh RIFF
header, armed at end of line and consumed lazily at the next audio,
so a client can split the stream into standalone WAV clips on the
RIFF magic. Port of the feature contributed to omnivoice.cpp in
ServeurpersoCom/omnivoice.cpp#11.

Co-authored-by: Jeffrey van Binsbergen <comgenie@comgenie.com>
2026-06-06 23:13:46 +02:00
Pascal ca0c779f49 tts: default language to auto, NULL lang selects auto, reject NULL text 2026-06-06 13:31:51 +02:00
Pascal f3cfa5cf47 server: add OpenAI compatible TTS server (chunked PCM streaming, WAV one-shot) 2026-06-06 12:47:10 +02:00
Pascal 08b79d1209 prompt: cut TTFA by projecting text and ICL codec embeds on the backend
What we gain: lower TTFA (time to first audio), the latency before the
first frame is emitted. The win is entirely in the one shot prompt build;
per frame inference throughput (talker + code predictor) is unchanged.

How:
- Fuse projection: non ICL projects [instruct ; role] in one pass, ICL
  projects [ref_text ; utterance] in one pass. Trailing utterance keeps
  its own pass.
- ICL codec stream on the backend: the per frame per codebook host
  embed_row_to_f32 + vec_add sum becomes num_code_groups ggml_get_rows
  summed on the GPU in one graph (codebook 0 from talker.codec_embedding,
  rest from code_predictor.codec_embedding, any quant via get_rows).
- Drop the host text projection (linear_f32, silu, read_tensor_f32,
  text_projection_*, PromptTextProjection). tts_bos/eos/pad are projected
  once on the backend in prompt_cache_load, now run after backend_sched_new.

No regression: direct prompt embed outputs match the host path within 2e-6
cosine on all 32 cells, bit exact in BF16/F32. The per frame AR loop is
untouched (ms/frame flat).

TTFA gain, CUDA0 RTX PRO 6000, greedy, 64 frames (old -> new):

  mode/quant      BF16     F32       Q8_0     Q4_K_M
  base            -18%     ~flat     -27%     -37%
  clone           -36%      -7%      -26%     -41%
  customvoice     +11%      -1%      -26%     -32%
  tts             -25%     -11%      -24%      +5%
2026-05-31 17:48:43 +02:00
Pascal 5442c2f84c perf: add per-stage timer instrumentation to qwentts and omnivoice
Add steady_clock Timer (backend agnostic) and emit [Perf] lines per
synthesis stage: prompt build, prefill, TTFA, talker decode, code
predictor, host compose, codec decode, total with RTF. omnivoice logs
generate, codec decode and total for the one chunk path. Spans end on a
device readback so GPU work is covered, no cudaEvent dependency.
2026-05-31 15:05:48 +02:00
Pascal a62fde62e6 prompt: drop dead host projection fallback, qt_throw on backend failure 2026-05-30 16:44:16 +02:00
Pascal cea3260b64 clang-format 2026-05-30 16:15:31 +02:00
PascalandGitHub 300bb09944 Merge pull request #3 from andimarafioti/optimize-prompt-ttfa
Optimize prompt TTFA with cached prefixes and batched projection
2026-05-30 16:13:12 +02:00
Pascal 207da32e75 nits 2026-05-30 16:10:10 +02:00
Andres Marafioti a0f504ce4c Optimize prompt TTFA 2026-05-30 15:41:29 +02:00
Pascal f9f4a0c820 cleanup: remove dead code and DRY pre_conv release via wctx_free 2026-05-14 23:27:09 +02:00
Pascal dda50c2225 codec: add chunked decode with rolling left context 2026-05-14 22:53:28 +02:00
Pascal d99eececc8 nits 2026-05-14 22:26:28 +02:00
Pascal b1339f7cae abi: drop QT_CODEC_SAMPLE_RATE macro, hardcode 24000 like omnivoice 2026-05-14 21:55:23 +02:00
Pascal 38bf6d762a abi, pipeline, cli: conform qwentts on omnivoice convention 2026-05-14 21:42:52 +02:00
Pascal 259e7059f6 align symbol naming on omnivoice convention 2026-05-14 18:09:07 +02:00