mirror of
https://github.com/mudler/LocalAI.git
synced 2026-07-31 10:28:43 -04:00
Two defects that made source separation unusable through LocalAI's own API, even though the backend served it correctly over gRPC. /audio/transform normalized every upload to 16 kHz mono s16 through utils.AudioToWav, with no way past it. htdemucs and mel_band_roformer refuse any rate but their checkpoint's own and separate a centred vocal from a wide mix using the stereo image, so every separation request through the HTTP API died with "HTDemucs prepare() sample rate mismatch: expected 44100, got 16000" while the same call over gRPC worked. The fold is not wrong, it is backend-specific: LocalVQE's echo cancellation genuinely wants 16 kHz mono and needs the reference in the same shape. So it becomes a declaration, BackendCapability.AudioTransformInputMono16k, set for localvqe and for nothing else. A backend that declares nothing gets its upload unchanged, which means no backend has to opt in to work. utils.AudioToWavPreservingShape is the non-folding conversion: a 16-bit PCM WAV passes through byte for byte at any rate and channel count, anything else is transcoded to WAV with its rate and channel layout kept. The other defect is that the run-once stem design bought nothing. A separation backend writes every stem beside dst from one inference, but AudioTransformResult carried only dst, so the other three were files no caller could find and a caller wanting all four had to run four separations. AudioTransformResult grows a repeated AudioTransformStem, the backend fills it, core/backend validates that each path really is inside the generated-content directory it handed over, and the endpoint publishes them as an X-Audio-Stems JSON header beside the existing X-Audio-Input-Url. JSON because a stem name is the model's own string and could contain any separator a hand-rolled format would use. Verified end to end through the HTTP endpoint with htdemucs f16 on a 44.1 kHz stereo file: 200 with a 44.1 kHz stereo body, all four stems named and fetchable through /generated-audio/, body byte identical to the selected stem, and params[stem]=drums returning a different one. The same upload sent to a model whose backend is localvqe still reaches the backend as 16 kHz mono, confirmed both by the engine's own rate refusal and by the persisted input file. Assisted-by: Claude:claude-opus-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
179 lines
7.7 KiB
Go
179 lines
7.7 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 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())
|
|
})
|
|
|
|
It("does not fold for an unregistered backend", func() {
|
|
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),
|
|
)
|
|
})
|
|
|
|
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())
|
|
})
|
|
})
|