Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: size music waits for Metal and Vulkan, not only CPU (#13551)

Daniel Hancb53b9b90976
diff --git a/studio/backend/core/inference/audio_cpp_backend.py b/studio/backend/core/inference/audio_cpp_backend.py
index d1485798395..4a49bd4326d 100644
--- a/studio/backend/core/inference/audio_cpp_backend.py
+++ b/studio/backend/core/inference/audio_cpp_backend.py
@@ -1003,7 +1003,7 @@ class AudioCppBackend:
# The route sizes the wait from the full work (extend, continue length); the orchestrator
# outlasts that same budget.
timeout = float(music.get("timeout_s") or 0) or cm.timeout_seconds(
- model.family, seconds, variations, server.backend == "cpu"
+ model.family, seconds, variations, server.backend
)
outputs: list[tuple[str, bytes, Optional[int]]] = []
try:
diff --git a/studio/backend/core/inference/audio_cpp_music.py b/studio/backend/core/inference/audio_cpp_music.py
index 1c851627df9..06d6b3b441b 100644
--- a/studio/backend/core/inference/audio_cpp_music.py
+++ b/studio/backend/core/inference/audio_cpp_music.py
@@ -26,7 +26,8 @@ logger = get_logger(__name__)
_TIMEOUT_FLOOR = 300.0
_TIMEOUT_CEILING = 4 * 3600.0
-_CPU_FACTOR = 10.0
+# Spec rtf values are CUDA timings; Metal and Vulkan run far slower (#13510).
+_BACKEND_FACTOR = {"cpu": 10.0, "metal": 10.0, "vulkan": 10.0}
# MiDashengLM's spec caps seeds at 2**31 - 1.
_SEED_LIMIT = 2**31 - 1
@@ -50,10 +51,13 @@ def seconds_text(value: float) -> str:
return f"{float(value):.3f}".rstrip("0").rstrip(".")
-def timeout_seconds(family: Optional[str], seconds: float, variations: int, cpu: bool) -> float:
+def timeout_seconds(
+ family: Optional[str], seconds: float, variations: int, backend: Optional[str]
+) -> float:
music = MUSIC_SPECS.get(str(family or ""))
rtf = music.rtf * music.overrun if music is not None else 4.0
- work = rtf * max(0.0, float(seconds)) * max(1, int(variations)) * (_CPU_FACTOR if cpu else 1.0)
+ rtf *= _BACKEND_FACTOR.get(str(backend or "").lower(), 1.0)
+ work = rtf * max(0.0, float(seconds)) * max(1, int(variations))
return max(_TIMEOUT_FLOOR, min(_TIMEOUT_CEILING, _TIMEOUT_FLOOR + work))
diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.py
index d26f9221ad1..933ba6b119a 100644
--- a/studio/backend/routes/inference.py
+++ b/studio/backend/routes/inference.py
@@ -23548,7 +23548,6 @@ async def _run_music_workflow(
seconds = max(low, min(high, float(wanted if wanted is not None else low)))
work_s = seconds
variations = body.variations if body.mode != "edit" else 1
- cpu = model_info.get("audio_cpp_backend") == "cpu"
music = {
"mode": body.mode,
"text": body.text,
@@ -23557,7 +23556,9 @@ async def _run_music_workflow(
"duration_s": seconds,
"variations": variations,
"edit": body.edit.model_dump() if body.edit is not None else None,
- "timeout_s": timeout_seconds(family, work_s, variations, cpu),
+ "timeout_s": timeout_seconds(
+ family, work_s, variations, model_info.get("audio_cpp_backend")
+ ),
}
run_dir.mkdir(parents = True, exist_ok = True)
payload = ChatCompletionRequest(
diff --git a/studio/backend/tests/test_audio_cpp_music_requests.py b/studio/backend/tests/test_audio_cpp_music_requests.py
index ea9fd8a1efb..8ed4ecbb259 100644
--- a/studio/backend/tests/test_audio_cpp_music_requests.py
+++ b/studio/backend/tests/test_audio_cpp_music_requests.py
@@ -493,10 +493,10 @@ def test_a_fixed_seed_family_gets_a_recorded_random_seed(tmp_path):
def test_the_wait_grows_with_the_audio_asked_for_and_is_capped():
- t = lambda s, n = 1, cpu = False: cm.timeout_seconds("yue2", s, n, cpu)
- assert t(10) < t(60) < t(60, 3) < t(60, 3, cpu = True)
- assert t(0) == 300.0 and t(240, 4, cpu = True) == 4 * 3600.0
- assert cm.timeout_seconds("stable_audio", 10, 1, False) == 310.0
+ t = lambda s, n = 1, backend = "cuda": cm.timeout_seconds("yue2", s, n, backend)
+ assert t(10) < t(60) < t(60, 3) < t(60, 3, backend = "cpu")
+ assert t(0) == 300.0 and t(240, 4, backend = "cpu") == 4 * 3600.0
+ assert cm.timeout_seconds("stable_audio", 10, 1, "cuda") == 310.0
assert t(60) == 300.0 + 6.0 * 1.5 * 60
b = _backend(_model("yue2"))
_run(b, text = "rock", lyrics = "x", duration_s = 60)
@@ -507,6 +507,16 @@ def test_the_wait_grows_with_the_audio_asked_for_and_is_capped():
assert b._server.calls[0][2]["timeout"] == 1234.0
+def test_metal_and_vulkan_waits_cover_minimax_on_apple_silicon():
+ t = lambda backend: cm.timeout_seconds("minimax_music3", 31, 1, backend)
+ assert t("cuda") == t("hip") == t(None) == 300.0 + 4.0 * 31
+ assert t("metal") == t("vulkan") == t("cpu") == 300.0 + 40.0 * 31
+ assert t("metal") > 24 * 31
+ b = _backend(_model("minimax_music3"), backend = "metal")
+ _run(b, text = "pop", lyrics = "la", duration_s = 30)
+ assert b._server.calls[0][2]["timeout"] == cm.timeout_seconds("minimax_music3", 30, 1, "metal")
+
+
@pytest.fixture
def source(tmp_path) -> str:
path = tmp_path / "source.48000.stereo.wav"
diff --git a/studio/backend/tests/test_audio_run_route.py b/studio/backend/tests/test_audio_run_route.py
index 7c8c7599fa8..c2fb19838c6 100644
--- a/studio/backend/tests/test_audio_run_route.py
+++ b/studio/backend/tests/test_audio_run_route.py
@@ -556,6 +556,22 @@ def _music(client, **body):
return client.post("/api/inference/audio/run", json = payload)
+def test_music_wait_scales_with_the_runtime_backend(stub):
+ from core.inference.audio_cpp_music import timeout_seconds
+
+ waits = {}
+ for runtime in ("cuda", "metal"):
+ info = {**_music_info(), "audio_cpp_backend": runtime}
+ backend = stub["use"](STABLE_AUDIO, info)
+ backend.__class__ = _MusicBackend
+ backend.takes, backend.run_dirs = 1, []
+ with _client(ALICE) as client:
+ assert _music(client, duration_s = 30).status_code == 200
+ waits[runtime] = backend.calls[-1]["music"]["timeout_s"]
+ assert waits == {r: timeout_seconds("stable_audio", 30.0, 1, r) for r in waits}
+ assert waits["metal"] > waits["cuda"]
+
+
def test_music_variations_are_saved_as_one_group(stub, tmp_path):
backend = stub["use"](STABLE_AUDIO, _music_info())
backend.__class__ = _MusicBackend