feat(audio-cpp): AUDIOCPP_DEFAULT_BACKEND fallback for models without a backend option (#12133)

Models whose options carry no explicit backend: open their session on the
CPU backend even in accelerator images. The gallery entries carry
backend:best since #11892; this covers hand-written model configurations
the same way, per deployment: the environment variable supplies the
fallback, an explicit backend: option always wins (merged beside the
existing threads and maingpu fallbacks), and validation reuses the
option parser.

Assisted-by: Claude:claude-fable-5

Signed-off-by: Plamen K. Kosseff <p.kosseff@gmail.com>
This commit is contained in:
Plamen K. Kosseff authored and GitHub committed 2026-09-23 12:16:31 +02:00
1 parent 2e279920b0
commit e7306a087a
6 files changed
+39 -1

No files matched your search

+19
View File
@@ -596,6 +596,25 @@ public:
if (!parsed.options.device_set && !request->maingpu().empty()) {
parsed.options.device = parse_device_index(request->maingpu());
}
// AUDIOCPP_DEFAULT_BACKEND is the deployment's backend fallback:
// an accelerator image sets it (typically to "best") so models
// without an explicit backend: option use the compiled
// accelerator instead of the CPU default — gallery entries carry
// backend:best, hand-written model configs get the same fix
// here. An explicit backend: option wins, matching threads and
// maingpu above. Validation reuses the option parser itself.
if (!parsed.options.backend_set) {
const char * env = std::getenv("AUDIOCPP_DEFAULT_BACKEND");
if (env != nullptr && *env != '\0') {
auto fallback = audiocpp_backend::parse_model_options(
{std::string("backend:") + env});
if (!fallback.error.empty()) {
throw audiocpp_backend::ConfigError(
"audio-cpp: AUDIOCPP_DEFAULT_BACKEND: " + fallback.error);
}
parsed.options.backend = fallback.options.backend;
}
}
const std::string path = audiocpp_backend::resolve_model_path(
request->modelpath(), request->modelfile(), request->model());