mirror of
https://github.com/mudler/LocalAI.git
synced 2026-09-12 22:33:54 -04:00
* fix(config): do not read a TTS speaker-encoder mmproj as vision support Qwen3-TTS on llama-cpp ships an mmproj holding the speaker encoder and code predictor. VisionSupported() treated any non-empty MMProj as proof of image input, so every such model would be advertised as vision-capable. Assisted-by: Claude:claude-fable-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(llama-cpp): add TTS request option parsing helper Validates text and speaker reference presence and strictly parses the top_k / top_p per-request params, in a header with no llama.cpp or gRPC dependencies so the standalone C++ unit test gate picks it up. Assisted-by: Claude:claude-fable-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(llama-cpp): range-check the TTS top_k and top_p request params Format validation alone let NaN, infinity and out-of-range values through. The consumer copies both values into the audio generation input unconditionally and only guards its separate sampler assignment with "> 0", a test NaN also fails, so a NaN reached llama.cpp with the guard never firing. top_k must now be >= 0 and top_p must fall within 0.0 to 1.0 inclusive, with the bound written as a negated in-range test so NaN is rejected rather than silently accepted. Also cover the two checks the suite could not previously kill: the whole-string check in the float parser and the int32 range check. Assisted-by: Claude:claude-fable-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * chore(llama-cpp): bump pin to f9e832c10 and carry the TTS server task Picks up ggml-org/llama.cpp#26254 (Qwen3-TTS via mtmd) and #26536 (the short-input audio chunk fix). Adds 0002-add-server-task-type-tts.patch, the server-side half of the still-draft #26603, so TTS runs through the slot scheduler instead of racing it. Remove that patch when #26603 merges. The patch is rebased on top of the score patch: its tokenize-switch hunk collided with the SERVER_TASK_TYPE_SCORE case, and its lone SRV_WRN call passes no variadic argument, which the macro cannot expand. The score patch itself needed no refresh. Also fixes fallout from the bump in grpc-server.cpp: upstream dropped the per-slot n_ctx argument from server_schema::eval_llama_cmpl_schema. Only the schema branch loses it, since forks predating the server-schema split still expect the old argument list. Assisted-by: Claude:claude-fable-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(llama-cpp): implement the TTS and TTSStream RPCs Both were declared in backend.proto but unimplemented. They now submit a SERVER_TASK_TYPE_TTS task and drain the response reader, the same shape PredictStream uses. The streaming path emits a leading sample_rate message and then raw PCM, because ModelTTSStream builds the WAV header itself; the non-streaming path emits a complete WAV to the requested dst. The streamed samples are converted from the pipeline's float32 to signed 16-bit first. MTMD_HELPER_GEN_AUDIO_OUTTYPE_PCM hands back floats, while the header ModelTTSStream writes announces 16-bit samples, so shipping the floats verbatim would decode as noise. prepare.sh and CMakeLists.txt now stage tts_request_options.h alongside the other grpc-server helpers, and register its standalone test with ctest the way passthrough_options_test is registered. Assisted-by: Claude:claude-fable-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(llama-cpp): mask non-codec tokens for Qwen3-TTS generation The Qwen3-TTS gen-audio pipeline maps a sampled backbone token to a codebook row with an unchecked subtraction, in mtmd-helper-gen.cpp: inp.code0 = sampled - codec_0; For ggml-org/Qwen3-TTS-12Hz-1.7B-Base-GGUF the vocab is 155008 tokens, <|codec_0|> is 151936 and the codec codes end at 153983. The model's own tokenizer.ggml.suppress_tokens holds 1023 ids covering 153984..155007, every special above the codec range except <|codec_eos_token|> (154086) which stays reachable as the stop token. Nothing masks the text range 0..151935, so the backbone can sample a text token at any step, the subtraction goes negative, and ggml_compute_forward_get_rows aborts the whole backend process on GGML_ASSERT(i01 >= 0 && i01 < ne01). Complete the mask upstream started: bias every token below <|codec_0|> to -INFINITY for TTS tasks so only codec codes and the codec EOS remain reachable. The biases are appended to task.params.sampling.logit_bias, which common_sampler_init already merges with the model's suppress tokens into one llama_sampler_init_logit_bias, so no sampler is added to the chain. Measured cost is 0.082 ms per sampled token and 1.16 MB, set against a forward pass in the multi-millisecond range. It lands in launch_slot_with_task rather than in a route handler so that llama.cpp's own POST /tts and LocalAI's TTS/TTSStream RPCs are both covered, and <|codec_0|> is resolved from the vocab rather than hardcoded so a model without it is left alone. This is reproducible with upstream's own llama-tts and no LocalAI code loaded, aborting at frame 55 on Q4_K_M and frame 71 on Q8_0, so it is neither a quantization artifact nor an artifact of the gRPC adapter. Two further defects in the same draft pipeline still prevent end-to-end audio; they are independent of this one and are recorded in the task report for an upstream bug report. Assisted-by: Claude:claude-fable-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * chore(llama-cpp): bump pin to 9de0fcf2b and drop the TTS codec mask Upstream fixed the Qwen3-TTS abort in ggml-org/llama.cpp c8e03ce81 ("mtmd/ggml: add ggml_build_forward_order", #26649), landed one hour after the previous pin. ggml_build_forward_expand marks a tensor and all its ancestors for compute, so using it as a pure ordering hint defeated ggml_build_forward_select and made GEN_WAV calls execute the GEN_CODE branch against a stale inp_code0, hitting the get_rows bound assert in ggml_compute_forward_get_rows. That single defect accounts for every abort seen on this model, so 0003-mask-non-codec-tokens-for-tts.patch is removed rather than rebased. The mask changed the observed behavior, but it was perturbing a graph ordering bug rather than fixing a sampling one: at the new pin the whole path works without it. Keeping it would have meant carrying a 152k-entry logit bias, and rebasing it on every pin bump, for no benefit. Verified at 9de0fcf2b with only 0001 and 0002 applied, which both apply clean with no fuzz and needed no rebase: non-streaming HTTP 200, 410924 bytes, 8.56 s RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 24000 Hz streaming HTTP 200, 560684 bytes, 11.68 s, exactly one RIFF at byte 0, same format, which also exercises the float32-to-s16 conversion at runtime for the first time Pristine unpatched llama-tts at the same pin now also completes, 130 frames to a valid WAV, where it aborted at frame 55 before. Assisted-by: Claude:claude-fable-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(llama-cpp): clear the TTS slot sequence between requests Only the first TTS request in a backend process succeeded. Every later one failed instantly, in about 0.13 s, with "TTS prompt processing failed" from step_prompt, regardless of streaming or non-streaming and regardless of the text. With LOCALAI_SINGLE_ACTIVE_BACKEND=true the process is kept alive between requests, so a deployment would have served exactly one utterance per backend start. The cause is missing KV hygiene, not anything in the gRPC adapter. TTS slots never enter the shared batch: pre_decode() returns early for them and process_tts_slots() drives them instead, so they skip the prompt-cache bookkeeping that clears a slot's sequence between requests. Nothing in the gen-audio path makes up for it: mtmd_helper_gen_audio_reset only clears host-side buffers, and the pipeline always decodes from position 0 into the sequence identified by slot.id. So the second task on a slot writes positions 0..N over the first task's tokens and llama_decode fails. Fix is one call to slot.prompt_clear(), the same helper the normal path uses, in the SERVER_TASK_TYPE_TTS branch of launch_slot_with_task before set_input. It goes into 0002 rather than a new patch file because it is a defect in the code that patch introduces, and the header now records it as ours so we know whether it still needs carrying if #26603 merges without it. Verified in one backend process, different text on every request: three consecutive non-streaming requests, three consecutive streaming requests, and an interleaved non-streaming, streaming, non-streaming, streaming run. All ten returned HTTP 200 with RIFF ... WAVE audio, Microsoft PCM, 16 bit, mono 24000 Hz, the streamed ones carrying exactly one RIFF header at byte 0, and every output measured as real speech rather than silence or a truncated fragment. Assisted-by: Claude:claude-fable-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(llama-cpp): expose max_frames for TTS requests The Qwen3-TTS backbone does not always emit <|codec_eos_token|>, and when it does not, generation runs to upstream's 512-frame n_predict default. At the model's 12.5 Hz frame rate that is 40.96 s of audio, which a short input can trigger: one request in this session produced 40.96 s for a ten-word sentence. prepareTTSTask hardcoded n_predict to -1, so callers had no way to bound it. Add a max_frames key alongside top_k and top_p, parsed with the same strict whole-string parsing so a typo is an error rather than a silently truncated value, and rejected with a field-naming message when negative. 0 keeps the existing sentinel convention and means unset, so a request that omits it behaves exactly as before. Named max_frames rather than n_predict because frames are what the parameter means at a TTS endpoint: one frame is 0.08 s of audio. The 512-frame default is deliberately unchanged. Lowering it would truncate legitimately long inputs, which is a worse failure than an occasionally overlong one. Verified end to end on one text of thirty words: max_frames=25 HTTP 200, 96044 bytes, 2.00 s, exactly 25 frames max_frames=50 HTTP 200, 192044 bytes, 4.00 s, exactly 50 frames no max_frames HTTP 200, 572204 bytes, 11.92 s, stopped at its own codec EOS after 149 frames, unchanged behavior max_frames=-1 InvalidArgument "max_frames must be >= 0, got \"-1\"" max_frames=many InvalidArgument "max_frames must be an integer, got \"many\"" Assisted-by: Claude:claude-fable-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(llama-cpp): send the TTS sample rate up front, and tidy three review items Four items from the Task 4 review. Streaming first-byte latency. TTSStream sent the sample-rate reply only once the first audio result arrived, and a chunk needs a whole 72-frame window, roughly 5.8 s of audio and far longer in wall time on CPU. The Go side blocks on that reply before it can emit the WAV header, so a streaming client sat at zero bytes for the whole stretch. The rate is a property of the loaded model and is available synchronously from mtmd_gen_audio_get_info, so it now goes out immediately after post_task and the rate_sent bookkeeping is gone. Measured on a warm model, first byte drops from 30.48 s to 0.014 s, and the output is still a valid WAV with exactly one RIFF header at byte 0. Unchecked close. The non-streaming path ignored ofstream::close(), so a failure that only surfaces on flush was reported as success while leaving a truncated file at dst. It now returns INTERNAL like the other write failures. Wrong comment on set_lang. gen_audio::inp::get() already maps a stored blank to nullptr, so our guard is behavior-preserving, not behavior-fixing. The comment claimed otherwise; the code was right. Repetition penalty. penalty_last_n = -1 is inert at this pin, because llama_sampler_init_penalties clamps it with std::max(penalty_last_n, 0) and then builds a disabled sampler, so the 1.05 penalty never applies. Upstream's README attributes looping to a missing repeat_penalty, so it was worth testing as a root-cause fix for the model running to the frame cap. Dropping the line lets the sampling default of 64 apply, which was confirmed in the sampler chain trace as penalty_last_n = 64 with repeat_penalty = 1.050. Over 15 uncapped short requests each way it did not help: 0 of 15 ran to the cap with the penalty inert, 1 of 15 with it active. Both lines are therefore kept for parity with upstream's draft, and a comment now records that the pair is inert and why, so the next reader does not believe a penalty is applied. max_frames remains the way to bound output. Assisted-by: Claude:claude-fable-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * build(llama-cpp): let unpatched forks opt out of the TTS task turboquant and bonsai copy grpc-server.cpp into llama.cpp forks that do not carry our patches. disable-tts-task.sh injects the same kind of preprocessor switch disable-score-task.sh already uses, so those builds answer UNIMPLEMENTED rather than failing to compile. Assisted-by: Claude:claude-fable-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(config): keep a TTS speaker-encoder projector out of vision detection Task 1 exempted a declared-TTS model's mmproj from VisionSupported, but the first real gallery entry with an mmproj still came back vision-capable through two paths the earlier fix did not close. GuessUsecases has no FLAG_VISION branch, so it falls through to true for any chat-ish model. That is not just a wrong answer at the call site: syncKnownUsecasesFromString rewrites KnownUsecaseStrings from HasUsecases, and the loader calls it more than once per config file, so the guessed FLAG_VISION is written out and parsed back into KnownUsecases as if the operator had declared it. Give GuessUsecases a FLAG_VISION branch that defers to the same explicit signals VisionSupported uses. Second, llama.cpp builds an mtmd context for the speaker-encoder projector and reports its media marker on the first chat probe, which resurrected vision after the model had been used once. Apply the same declared-TTS exemption to MediaMarker that the mmproj check already had. Verified against the qwen3-tts-llamacpp-q4 gallery entry: no vision capability and no image input modality, before load, after a TTS request, and after a chat probe. Assisted-by: Claude:claude-fable-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(gallery): add Qwen3-TTS entries for the llama-cpp backend Two entries over upstream's own GGUF conversion, Q8_0 and Q4_K_M, each pairing a backbone with the Q8_0 projector. Named to sit alongside the existing qwen3-tts-cpp entries rather than replace them. Also tags the llama-cpp backend text-to-speech / TTS so the backend browser surfaces the capability. Assisted-by: Claude:claude-fable-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * docs: cover Qwen3-TTS on the llama-cpp backend Adds the gallery variants, the two-file mmproj configuration, the required voice reference, and the language and sampling knobs. Also corrects the streaming-support list, which named only voxcpm. Assisted-by: Claude:claude-fable-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(config): register llama-cpp as a TTS and voice-cloning backend The branch taught the llama-cpp backend to serve Qwen3-TTS and shipped two gallery entries for it, but never told the capability table. llama-cpp still declared only the text RPCs and usecases, so: - VoiceCloningForModel returned nil at the capability check, before it ever reached the model's own tts.voice_cloning override, and /tts answered 400 "selected model does not support reference-audio voice cloning" for any localai://voice-profiles/... voice. No model YAML could opt back in. - GET /api/backends/usecases did not list tts for llama-cpp, so the gallery greyed out the TTS filter for the entries this branch adds. - The React TTS page saw voice_cloning: null and kept both models out of the Voice Library. Add the TTS RPCs and usecase, and the reference-audio contract. The contract needs narrowing, because the per-backend switch in VoiceCloningForModel ends in a permissive default: an unnarrowed entry would have advertised reference-audio cloning on every GGUF chat model in the gallery. Narrow on the declared TTS usecase rather than the model name. The TTS checkpoints are the only llama-cpp models carrying known_usecases: [tts]; name matching would have to guess at third-party repacks, and "base", the substring the neighbouring Qwen and vLLM cases key on, is a routine word in text-model names. The check reads the declared bit directly instead of going through HasUsecases, which falls through to GuessUsecases and would hand the decision to a heuristic that never had a llama.cpp TTS model in mind. DefaultUsecases stays [chat]: a bare GGUF served by llama.cpp is a chat model, and both the gallery filter and the importer read that field. Assisted-by: Claude:claude-fable-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(gallery): declare what nemotron-3-nano-omni actually accepts The entry is backend: vllm-omni with known_usecases: [chat, completion], no mmproj and no media marker, so it used to report vision only through the blanket GuessUsecases fallthrough that the vision branch in this branch removed. Nemotron 3 Nano Omni is a multimodal understanding model: image, video and audio in, text out. Declaring that is what the sibling vllm-omni-qwen3-omni-30b already does. known_usecases gains vision only. FLAG_VIDEO is video GENERATION, an output modality, and this model generates none; video and audio input belong in known_input_modalities, which is where AudioInputSupported and VideoInputSupported read them from. Assisted-by: Claude:claude-fable-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(importers): import a Qwen3-TTS GGUF repo as TTS, not chat The llama-cpp importer hardcodes known_usecases: [chat] and assigns any mmproj-matching file as a vision projector, so ggml-org/Qwen3-TTS-12Hz-1.7B- Base-GGUF imported as a chat model with vision. Both fields were wrong, and the model was unreachable from /tts and from the Voice Library. Filenames cannot fix this. A Qwen3-TTS repo has the exact shape of a vision repo, one backbone GGUF plus one mmproj-*.gguf, so the projector's own header is the only honest signal: mtmd writes clip.has_gen_audio_encoder for the projectors it can drive as a speech pipeline and refuses to build one without it. Probe the selected mmproj for that flag, reusing the range-fetch the MTP detection already does, and declare tts when it is set. The mmproj assignment then stops reading as vision on its own, since a declared-TTS model already exempts its projector from vision detection. The probe is best-effort like the MTP one: a network blip leaves the chat default in place rather than failing the import. Verified against the real artifacts on disk: the Qwen3-TTS projector reports gen-audio, its backbone does not. Assisted-by: Claude:claude-fable-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(llama-cpp): stop non-TTS models crashing on the new pin Two regressions, both hit every ordinary llama-cpp model and neither was caught locally because every test on this branch loaded a TTS model. The first is a null dereference. server_slot::tts_ctx::reset() called mtmd_helper_gen_audio_reset() unconditionally, but the gen-audio pipeline is only allocated for models carrying a gen-audio mmproj, and upstream's implementation reads ctx->pipeline before null-checking anything. Since server_slot::reset() runs during slot initialization for every model, any non-TTS model segfaulted the backend the moment it loaded. Guard the call on the is_supported() predicate already defined beside it, and keep the plain field resets unconditional. The second is unrelated to TTS and came in with the pin bump. PredictOptions.Penalty is a bare proto float, so a caller that names no repetition penalty sends 0 rather than omitting the field. Since 9de0fcf2b, common_sampler_init() rejects a non-positive penalty_repeat outright because it would divide logits by zero, turning every such request into "Failed to initialize samplers". Treat 0 as unset and leave llama.cpp's own neutral default in place. Verified with the same suite CI runs, which is what caught both: tests/e2e-backends passes 6 of 6 including the load and predict specs that were red. Qwen3-TTS still synthesises on both paths, 24 kHz mono 16-bit WAV with exactly one RIFF header on the streamed output. Assisted-by: Claude:claude-fable-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Co-authored-by: Ettore Di Giacinto <mudler@localai.io>
409 lines
19 KiB
Go
409 lines
19 KiB
Go
package config
|
|
|
|
import (
|
|
"slices"
|
|
"strings"
|
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("BackendCapabilities", func() {
|
|
It("every backend declares possible/default usecases and gRPC methods", func() {
|
|
for name, cap := range BackendCapabilities {
|
|
Expect(cap.PossibleUsecases).NotTo(BeEmpty(), "backend %q has no possible usecases", name)
|
|
Expect(cap.DefaultUsecases).NotTo(BeEmpty(), "backend %q has no default usecases", name)
|
|
Expect(cap.GRPCMethods).NotTo(BeEmpty(), "backend %q has no gRPC methods", name)
|
|
}
|
|
})
|
|
|
|
It("default usecases are a subset of possible usecases", func() {
|
|
for name, cap := range BackendCapabilities {
|
|
for _, d := range cap.DefaultUsecases {
|
|
Expect(cap.PossibleUsecases).To(ContainElement(d), "backend %q: default %q not in possible %v", name, d, cap.PossibleUsecases)
|
|
}
|
|
}
|
|
})
|
|
|
|
It("every backend's possible usecases map to a known FLAG_*", func() {
|
|
allFlags := GetAllModelConfigUsecases()
|
|
for name, cap := range BackendCapabilities {
|
|
for _, u := range cap.PossibleUsecases {
|
|
info, ok := UsecaseInfoMap[u]
|
|
Expect(ok).To(BeTrue(), "backend %q: usecase %q not in UsecaseInfoMap", name, u)
|
|
flagName := "FLAG_" + strings.ToUpper(u)
|
|
if _, ok := allFlags[flagName]; ok {
|
|
continue
|
|
}
|
|
// Some usecase names don't transform exactly to FLAG_<UPPER>; fall back to flag value lookup.
|
|
found := false
|
|
for _, flag := range allFlags {
|
|
if flag == info.Flag {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
Expect(found).To(BeTrue(), "backend %q: usecase %q flag %d not in GetAllModelConfigUsecases", name, u, info.Flag)
|
|
}
|
|
}
|
|
})
|
|
|
|
It("every UsecaseInfoMap entry has a non-zero flag and a gRPC method", func() {
|
|
for name, info := range UsecaseInfoMap {
|
|
Expect(info.Flag).NotTo(Equal(FLAG_ANY), "usecase %q has FLAG_ANY (zero) — should have a real flag", name)
|
|
Expect(info.GRPCMethod).NotTo(BeEmpty(), "usecase %q has no gRPC method", name)
|
|
}
|
|
})
|
|
})
|
|
|
|
var _ = Describe("GetBackendCapability", func() {
|
|
It("returns the capability for a known backend", func() {
|
|
cap := GetBackendCapability("llama-cpp")
|
|
Expect(cap).NotTo(BeNil())
|
|
Expect(cap.PossibleUsecases).To(ContainElement("chat"))
|
|
})
|
|
|
|
It("normalizes hyphenated names so llama.cpp resolves to llama-cpp", func() {
|
|
Expect(GetBackendCapability("llama.cpp")).NotTo(BeNil())
|
|
})
|
|
|
|
It("returns nil for unknown backends", func() {
|
|
Expect(GetBackendCapability("nonexistent")).To(BeNil())
|
|
})
|
|
|
|
// The gallery ships one concrete image per hardware capability behind a
|
|
// meta name, and an operator may pin any of them in a model's `backend:`.
|
|
// An exact-match-only lookup silently treated every one of them as an
|
|
// unknown backend, which cost vulkan-localvqe the 16 kHz mono fold its AEC
|
|
// needs and would cost a pinned audio-cpp variant its voice-cloning
|
|
// contract. Same class as #10945.
|
|
It("resolves a pinned hardware variant to its meta backend", func() {
|
|
for _, name := range []string{"cpu-localvqe", "vulkan-localvqe", "metal-localvqe"} {
|
|
capability := GetBackendCapability(name)
|
|
Expect(capability).NotTo(BeNil(), "pinned variant %q must resolve", name)
|
|
Expect(capability.PossibleUsecases).To(ContainElement(UsecaseAudioTransform), name)
|
|
}
|
|
})
|
|
|
|
It("resolves a pinned variant that also carries a release channel", func() {
|
|
for _, name := range []string{
|
|
"cuda12-audio-cpp", "cuda13-audio-cpp-development",
|
|
"metal-audio-cpp", "cpu-audio-cpp-development",
|
|
"cuda13-nvidia-l4t-arm64-llama-cpp", "intel-sycl-f16-llama-cpp",
|
|
"metal-darwin-arm64-llama-cpp", "nvidia-l4t-arm64-llama-cpp",
|
|
"rocm-llama-cpp-development", "intel-llama-cpp",
|
|
} {
|
|
Expect(GetBackendCapability(name)).NotTo(BeNil(), "pinned variant %q must resolve", name)
|
|
}
|
|
})
|
|
|
|
It("does not invent a capability for a name that only looks like a variant", func() {
|
|
Expect(GetBackendCapability("cpu-nonexistent")).To(BeNil())
|
|
Expect(GetBackendCapability("vulkan-")).To(BeNil())
|
|
})
|
|
|
|
// Stripping is a fallback, never a rewrite: a backend registered under its
|
|
// own name keeps its own entry even if that name starts with a prefix.
|
|
It("prefers an exact match over the stripped one", func() {
|
|
BackendCapabilities["cpu-exact-match-probe"] = BackendCapability{
|
|
PossibleUsecases: []string{UsecaseChat},
|
|
Description: "test fixture",
|
|
}
|
|
BackendCapabilities["exact-match-probe"] = BackendCapability{
|
|
PossibleUsecases: []string{UsecaseTTS},
|
|
Description: "test fixture",
|
|
}
|
|
DeferCleanup(func() {
|
|
delete(BackendCapabilities, "cpu-exact-match-probe")
|
|
delete(BackendCapabilities, "exact-match-probe")
|
|
})
|
|
|
|
capability := GetBackendCapability("cpu-exact-match-probe")
|
|
Expect(capability).NotTo(BeNil())
|
|
Expect(capability.PossibleUsecases).To(Equal([]string{UsecaseChat}))
|
|
})
|
|
})
|
|
|
|
// nemo-speech-cpp fronts four model families from one server, and its
|
|
// PossibleUsecases is their union. The entry has to stay in step with what
|
|
// docs/content/features/nemo-speech-cpp.md tells operators to put in
|
|
// known_usecases: nothing validates known_usecases against PossibleUsecases, so
|
|
// a flag the docs recommend and the map omits fails silently, and the place it
|
|
// surfaces is the gallery. GET /api/backends/usecases is derived from this list
|
|
// and greys out the filters missing from it, so a recommended-but-unlisted flag
|
|
// hides the very models it was recommended for.
|
|
var _ = Describe("nemo-speech-cpp capabilities", func() {
|
|
It("advertises every usecase its four families serve", func() {
|
|
capability := GetBackendCapability("nemo-speech-cpp")
|
|
Expect(capability).NotTo(BeNil())
|
|
Expect(capability.PossibleUsecases).To(ContainElements(
|
|
UsecaseTranscript, UsecaseDiarization, UsecaseTTS,
|
|
UsecaseCompletion, UsecaseChat))
|
|
})
|
|
|
|
// Chat is the translation family's usecase, and it needs both Predict RPCs:
|
|
// /v1/chat/completions streams through PredictStream and answers
|
|
// non-streaming requests through Predict.
|
|
It("backs the chat usecase with the RPCs chat actually drives", func() {
|
|
capability := GetBackendCapability("nemo-speech-cpp")
|
|
Expect(capability.GRPCMethods).To(ContainElements(MethodPredict, MethodPredictStream))
|
|
})
|
|
|
|
// Defaults stay conservative: a bare `backend: nemo-speech-cpp` with no
|
|
// known_usecases is overwhelmingly an ASR model, and every other family is
|
|
// expected to pin its own flags.
|
|
It("still defaults to transcript alone", func() {
|
|
Expect(DefaultUsecasesForBackendCap("nemo-speech-cpp")).To(Equal([]string{UsecaseTranscript}))
|
|
})
|
|
})
|
|
|
|
// audio-cpp advertises voice cloning from the backend itself and ships
|
|
// audio-cpp-chatterbox, whose family serves cloning and NOT plain TTS, so a
|
|
// reference clip is the only way to use it. Without a capability entry
|
|
// VoiceCloningForModel returns nil before it ever reads the model's own
|
|
// tts.voice_cloning override, so `voice: "profile:<id>"` was refused with a 400
|
|
// for every audio-cpp model and no model YAML could rescue it.
|
|
var _ = Describe("audio-cpp capabilities", func() {
|
|
It("is registered", func() {
|
|
Expect(GetBackendCapability("audio-cpp")).NotTo(BeNil())
|
|
})
|
|
|
|
It("advertises the RPCs its families actually serve", func() {
|
|
capability := GetBackendCapability("audio-cpp")
|
|
Expect(capability.GRPCMethods).To(ContainElements(
|
|
MethodTTS, MethodTTSStream, MethodAudioTranscription,
|
|
MethodVAD, MethodDiarize, MethodSoundGeneration, MethodAudioTransform))
|
|
Expect(capability.PossibleUsecases).To(ContainElements(
|
|
UsecaseTTS, UsecaseTranscript, UsecaseVAD, UsecaseDiarization,
|
|
UsecaseSoundGeneration, UsecaseAudioTransform))
|
|
})
|
|
|
|
It("carries the reference-audio contract, for pinned variants too", func() {
|
|
for _, name := range []string{"audio-cpp", "cuda12-audio-cpp", "metal-audio-cpp"} {
|
|
cloning := VoiceCloningForModel(&ModelConfig{Backend: name})
|
|
Expect(cloning).NotTo(BeNil(), "%q must reach the backend with a profile voice", name)
|
|
Expect(cloning.AcceptedAudioFormats).To(ContainElement("audio/wav"))
|
|
}
|
|
})
|
|
|
|
// The families audio-cpp reaches through AudioTransform are separation and
|
|
// conversion, which refuse any rate but their checkpoint's own.
|
|
It("does not ask for the 16 kHz mono fold", func() {
|
|
Expect(AudioTransformRequiresMono16kInput("audio-cpp")).To(BeFalse())
|
|
})
|
|
})
|
|
|
|
// The fold to 16 kHz mono in /audio/transform is opt-IN. It used to be
|
|
// unconditional, which made source separation unreachable through the HTTP
|
|
// API: htdemucs and mel_band_roformer refuse any rate but their checkpoint's
|
|
// own and separate using the stereo image, so every such request died with an
|
|
// INTERNAL raised inside the engine while the same call over gRPC worked.
|
|
var _ = Describe("AudioTransformRequiresMono16kInput", func() {
|
|
It("folds for localvqe, whose AEC is trained on 16 kHz mono", func() {
|
|
Expect(AudioTransformRequiresMono16kInput("localvqe")).To(BeTrue())
|
|
})
|
|
|
|
// Pinned gallery variants are the same engine and must fold identically.
|
|
// They did not: the lookup was exact-match only, so vulkan-localvqe was an
|
|
// unknown backend, lost the fold that used to be unconditional, and started
|
|
// failing inside LocalVQE. The usecase gate is no substitute, because
|
|
// BuildFilteredFirstAvailableDefaultModel returns early once the client
|
|
// names a model explicitly.
|
|
It("folds for every pinned localvqe variant the gallery ships", func() {
|
|
Expect(AudioTransformRequiresMono16kInput("cpu-localvqe")).To(BeTrue())
|
|
Expect(AudioTransformRequiresMono16kInput("vulkan-localvqe")).To(BeTrue())
|
|
Expect(AudioTransformRequiresMono16kInput("metal-localvqe")).To(BeTrue())
|
|
})
|
|
|
|
It("does not fold for a backend that has not asked for it", func() {
|
|
// Registered, and deliberately NOT folding: its separation and
|
|
// conversion families refuse any rate but their checkpoint's own.
|
|
Expect(AudioTransformRequiresMono16kInput("audio-cpp")).To(BeFalse())
|
|
Expect(AudioTransformRequiresMono16kInput("nonexistent")).To(BeFalse())
|
|
Expect(AudioTransformRequiresMono16kInput("")).To(BeFalse())
|
|
})
|
|
|
|
It("is claimed by no other registered backend", func() {
|
|
for name, capability := range BackendCapabilities {
|
|
if name == "localvqe" {
|
|
continue
|
|
}
|
|
Expect(capability.AudioTransformInputMono16k).To(BeFalse(),
|
|
"backend %q asks for the 16 kHz mono fold; that has to be a deliberate, documented need", name)
|
|
}
|
|
})
|
|
})
|
|
|
|
var _ = Describe("VoiceCloningForModel", func() {
|
|
voiceCloningSetting := func(enabled bool) *bool { return &enabled }
|
|
|
|
DescribeTable("advertises only compatible model variants",
|
|
func(cfg ModelConfig, expected bool) {
|
|
Expect(VoiceCloningForModel(&cfg) != nil).To(Equal(expected))
|
|
},
|
|
Entry("Qwen C++ Base", ModelConfig{Name: "qwen3-tts-cpp-0.6b-base", Backend: "qwen3-tts-cpp"}, true),
|
|
Entry("Qwen C++ CustomVoice", ModelConfig{Name: "qwen3-tts-cpp-customvoice", Backend: "qwen3-tts-cpp"}, false),
|
|
Entry("VibeVoice realtime 0.5B", ModelConfig{Name: "vibevoice-cpp-0.5b", Backend: "vibevoice-cpp"}, false),
|
|
Entry("VibeVoice 1.5B", ModelConfig{Name: "vibevoice-1.5b", Backend: "vibevoice-cpp"}, true),
|
|
Entry("F5 through CrispASR", ModelConfig{Name: "f5-tts-crispasr", Backend: "crispasr"}, true),
|
|
Entry("ASR through CrispASR", ModelConfig{Name: "parakeet-crispasr", Backend: "crispasr"}, false),
|
|
Entry("VoxCPM", ModelConfig{Name: "voxcpm-1.5", Backend: "voxcpm"}, true),
|
|
Entry("unsupported Piper", ModelConfig{Name: "piper", Backend: "piper"}, false),
|
|
Entry("typed custom opt-in", ModelConfig{Name: "private-build", Backend: "qwen3-tts-cpp", TTSConfig: TTSConfig{VoiceCloning: voiceCloningSetting(true)}}, true),
|
|
Entry("typed opt-out", ModelConfig{Name: "voxcpm-1.5", Backend: "voxcpm", TTSConfig: TTSConfig{VoiceCloning: voiceCloningSetting(false)}}, false),
|
|
Entry("typed setting wins over compatibility option", ModelConfig{Name: "private-build", Backend: "qwen3-tts-cpp", TTSConfig: TTSConfig{VoiceCloning: voiceCloningSetting(true)}, Options: []string{"voice_cloning:false"}}, true),
|
|
Entry("legacy option custom opt-in", ModelConfig{Name: "private-build", Backend: "qwen3-tts-cpp", Options: []string{"voice_cloning:true"}}, true),
|
|
Entry("legacy option opt-out", ModelConfig{Name: "voxcpm-1.5", Backend: "voxcpm", Options: []string{"voice_cloning=false"}}, false),
|
|
)
|
|
|
|
// A pinned gallery variant must reach the SAME per-backend rule as the meta
|
|
// name, in both directions. Resolving the capability by stripping the prefix
|
|
// while still keying the model-variant switch on the pinned spelling made
|
|
// every variant fall through to the permissive default: cuda12-vibevoice-cpp
|
|
// advertised cloning for the realtime 0.5B model, which cannot do it, and
|
|
// /v1/audio/speech accepted a profile: voice it had to fail on in the backend
|
|
// instead of rejecting it with a 400.
|
|
DescribeTable("resolves the model-variant rule through pinned gallery variants",
|
|
func(cfg ModelConfig, expected bool) {
|
|
Expect(VoiceCloningForModel(&cfg) != nil).To(Equal(expected))
|
|
},
|
|
Entry("cuda12-vibevoice-cpp 0.5B stays unsupported", ModelConfig{Name: "vibevoice-cpp-0.5b", Backend: "cuda12-vibevoice-cpp"}, false),
|
|
Entry("cuda12-vibevoice-cpp 1.5B stays supported", ModelConfig{Name: "vibevoice-1.5b", Backend: "cuda12-vibevoice-cpp"}, true),
|
|
Entry("metal-coqui tacotron2 stays unsupported", ModelConfig{Name: "tacotron2-en", Backend: "metal-coqui"}, false),
|
|
Entry("metal-coqui xtts stays supported", ModelConfig{Name: "xtts-v2", Backend: "metal-coqui"}, true),
|
|
Entry("cuda12-crispasr ASR stays unsupported", ModelConfig{Name: "parakeet-asr", Backend: "cuda12-crispasr"}, false),
|
|
Entry("cuda12-crispasr F5 stays supported", ModelConfig{Name: "f5-tts-crispasr", Backend: "cuda12-crispasr"}, true),
|
|
Entry("cpu-qwen3-tts-cpp CustomVoice stays unsupported", ModelConfig{Name: "qwen3-tts-flash", Backend: "cpu-qwen3-tts-cpp"}, false),
|
|
Entry("cpu-qwen3-tts-cpp Base stays supported", ModelConfig{Name: "qwen3-tts-cpp-0.6b-base", Backend: "cpu-qwen3-tts-cpp"}, true),
|
|
Entry("release channel suffix too", ModelConfig{Name: "vibevoice-cpp-0.5b", Backend: "vibevoice-cpp-development"}, false),
|
|
Entry("pinned audio-cpp keeps its unconditional cloning", ModelConfig{Name: "audio-cpp-chatterbox", Backend: "cuda12-audio-cpp"}, true),
|
|
)
|
|
})
|
|
|
|
// llama.cpp serves Qwen3-TTS as well as the text LLMs it is known for, so the
|
|
// backend has to advertise TTS. That advertisement is what makes narrowing
|
|
// mandatory: the per-backend switch in VoiceCloningForModel ends in a
|
|
// permissive default, so an unnarrowed llama-cpp entry would offer
|
|
// reference-audio cloning on every GGUF chat model in the gallery.
|
|
var _ = Describe("llama-cpp TTS capabilities", func() {
|
|
It("advertises the TTS RPCs and usecase", func() {
|
|
capability := GetBackendCapability("llama-cpp")
|
|
Expect(capability).NotTo(BeNil())
|
|
Expect(capability.GRPCMethods).To(ContainElements(MethodTTS, MethodTTSStream))
|
|
Expect(capability.PossibleUsecases).To(ContainElement(UsecaseTTS))
|
|
})
|
|
|
|
// The gallery filter and the model importer both read DefaultUsecases, and a
|
|
// bare GGUF served by llama.cpp is a chat model, not a TTS model.
|
|
It("keeps chat as its only default usecase", func() {
|
|
Expect(GetBackendCapability("llama-cpp").DefaultUsecases).To(Equal([]string{UsecaseChat}))
|
|
})
|
|
|
|
ttsModel := func(backend string) ModelConfig {
|
|
cfg := ModelConfig{Name: "qwen3-tts-llamacpp", Backend: backend}
|
|
cfg.KnownUsecaseStrings = []string{"tts"}
|
|
cfg.syncKnownUsecasesFromString()
|
|
return cfg
|
|
}
|
|
|
|
It("resolves voice cloning for a model that declares the TTS usecase", func() {
|
|
cfg := ttsModel("llama-cpp")
|
|
cloning := VoiceCloningForModel(&cfg)
|
|
Expect(cloning).NotTo(BeNil())
|
|
Expect(cloning.AcceptedAudioFormats).To(ContainElement("audio/wav"))
|
|
})
|
|
|
|
// The spec that constrains the fix. Every one of these is an ordinary
|
|
// llama.cpp text model, and none of them may be offered in the Voice
|
|
// Library or accept a localai://voice-profiles/... reference.
|
|
DescribeTable("never resolves voice cloning for an ordinary llama.cpp model",
|
|
func(cfg ModelConfig) {
|
|
Expect(VoiceCloningForModel(&cfg)).To(BeNil())
|
|
},
|
|
Entry("plain chat model", ModelConfig{Name: "qwen3-8b", Backend: "llama-cpp"}),
|
|
Entry("auto-detected GGUF with no backend pinned", ModelConfig{Name: "mistral-7b"}),
|
|
Entry("a vision model with an mmproj", ModelConfig{Name: "gemma-3-12b", Backend: "llama-cpp", LLMConfig: LLMConfig{MMProj: "mmproj-gemma-3-12b.gguf"}}),
|
|
Entry("a chat model whose name happens to say base", ModelConfig{Name: "llama-3.1-8b-base", Backend: "llama-cpp"}),
|
|
Entry("a pinned hardware variant", ModelConfig{Name: "qwen3-8b", Backend: "cuda12-llama-cpp"}),
|
|
)
|
|
|
|
// A declared-TTS model must keep its contract through the pinned gallery
|
|
// variants an operator can put in `backend:`, the same way vibevoice-cpp
|
|
// and crispasr do.
|
|
DescribeTable("resolves through pinned gallery variants",
|
|
func(backend string) {
|
|
cfg := ttsModel(backend)
|
|
Expect(VoiceCloningForModel(&cfg)).NotTo(BeNil())
|
|
},
|
|
Entry("cuda12", "cuda12-llama-cpp"),
|
|
Entry("vulkan", "vulkan-llama-cpp"),
|
|
Entry("metal darwin arm64", "metal-darwin-arm64-llama-cpp"),
|
|
Entry("development channel", "llama-cpp-development"),
|
|
)
|
|
|
|
// tts.voice_cloning is the documented escape hatch for a custom build. It
|
|
// only ever reaches the operator once the backend carries the contract at
|
|
// all, which is precisely what the unregistered entry prevented.
|
|
It("still honours an explicit opt-out on a declared-TTS model", func() {
|
|
cfg := ttsModel("llama-cpp")
|
|
disabled := false
|
|
cfg.TTSConfig.VoiceCloning = &disabled
|
|
Expect(VoiceCloningForModel(&cfg)).To(BeNil())
|
|
})
|
|
})
|
|
|
|
var _ = Describe("IsValidUsecaseForBackend", func() {
|
|
It("accepts a backend's declared usecases", func() {
|
|
Expect(IsValidUsecaseForBackend("piper", "tts")).To(BeTrue())
|
|
})
|
|
|
|
It("rejects usecases outside a backend's possible set", func() {
|
|
Expect(IsValidUsecaseForBackend("piper", "chat")).To(BeFalse())
|
|
})
|
|
|
|
It("is permissive for unknown backends", func() {
|
|
Expect(IsValidUsecaseForBackend("unknown", "anything")).To(BeTrue())
|
|
})
|
|
})
|
|
|
|
var _ = Describe("IsLlamaCppBackend", func() {
|
|
DescribeTable("classifies a backend name",
|
|
func(backend string, expected bool) {
|
|
Expect(IsLlamaCppBackend(backend)).To(Equal(expected))
|
|
},
|
|
Entry("meta name", "llama-cpp", true),
|
|
Entry("dotted spelling", "llama.cpp", true),
|
|
Entry("auto-detect (empty)", "", true),
|
|
Entry("development channel", "llama-cpp-development", true),
|
|
Entry("quantization channel", "llama-cpp-quantization", true),
|
|
Entry("vulkan variant", "vulkan-llama-cpp", true),
|
|
Entry("cuda 12 variant", "cuda12-llama-cpp", true),
|
|
Entry("cuda 13 variant", "cuda13-llama-cpp", true),
|
|
Entry("jetson variant", "cuda13-nvidia-l4t-arm64-llama-cpp", true),
|
|
Entry("rocm variant", "rocm-llama-cpp", true),
|
|
Entry("metal variant", "metal-llama-cpp", true),
|
|
Entry("intel sycl f16 variant", "intel-sycl-f16-llama-cpp", true),
|
|
Entry("intel sycl f32 variant", "intel-sycl-f32-llama-cpp", true),
|
|
Entry("cpu variant", "cpu-llama-cpp", true),
|
|
Entry("variant on the development channel", "rocm-llama-cpp-development", true),
|
|
Entry("darwin quantization variant", "metal-darwin-arm64-llama-cpp-quantization", true),
|
|
// ik-llama.cpp is a distinct engine that merely shares the suffix.
|
|
Entry("ik-llama-cpp", "ik-llama-cpp", false),
|
|
Entry("ik-llama-cpp development", "ik-llama-cpp-development", false),
|
|
Entry("cpu ik-llama-cpp", "cpu-ik-llama-cpp", false),
|
|
Entry("cpu ik-llama-cpp development", "cpu-ik-llama-cpp-development", false),
|
|
Entry("vllm", "vllm", false),
|
|
Entry("mlx", "mlx", false),
|
|
Entry("whisper", "whisper", false),
|
|
Entry("bark-cpp", "bark-cpp", false),
|
|
)
|
|
})
|
|
|
|
var _ = Describe("AllBackendNames", func() {
|
|
It("returns 30+ backends in sorted order", func() {
|
|
names := AllBackendNames()
|
|
Expect(len(names)).To(BeNumerically(">=", 30))
|
|
Expect(slices.IsSorted(names)).To(BeTrue())
|
|
})
|
|
})
|