Spaces:
Running on Zero
Running on Zero
Calibrate GPU durations to measured inference times
Browse files
app.py
CHANGED
|
@@ -150,9 +150,9 @@ def _estimate_duration(task: str, *args, **kwargs) -> int:
|
|
| 150 |
|
| 151 |
Receives the same inputs as the decorated function (positional layout of
|
| 152 |
the handler signature when ZeroGPU passes args positionally, keywords as
|
| 153 |
-
a fallback — both are accepted).
|
| 154 |
-
|
| 155 |
-
time.
|
| 156 |
"""
|
| 157 |
text = kwargs.get("text") or kwargs.get("score_text") or (args[0] if args else "") or ""
|
| 158 |
flow_steps = kwargs.get("flow_steps")
|
|
@@ -174,8 +174,8 @@ def _estimate_duration(task: str, *args, **kwargs) -> int:
|
|
| 174 |
# Speech: characters ≈ syllables ≈ 155 ms each (CJK 1 char/syllable).
|
| 175 |
seconds = (len(text) if isinstance(text, str) else 0) * 0.155
|
| 176 |
patches = min(MAX_PATCHES, max(2, int(seconds * 12.5)))
|
| 177 |
-
total =
|
| 178 |
-
return min(
|
| 179 |
|
| 180 |
|
| 181 |
def _tts_duration(*args, **kwargs) -> int:
|
|
@@ -272,7 +272,13 @@ def svs_generate(score_text: str, voice: str, ref_audio, ref_text: str,
|
|
| 272 |
return _save_and_report(waveform, patches.size(1), started)
|
| 273 |
|
| 274 |
|
| 275 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
def unified_generate(case_id: str, flow_steps=None, cfg_value=None,
|
| 277 |
temperature=None, seed=None, progress=gr.Progress()):
|
| 278 |
"""Run one packaged speech→singing→speech sequence end to end.
|
|
|
|
| 150 |
|
| 151 |
Receives the same inputs as the decorated function (positional layout of
|
| 152 |
the handler signature when ZeroGPU passes args positionally, keywords as
|
| 153 |
+
a fallback — both are accepted). Measured on ZeroGPU (RTX 6000 Ada):
|
| 154 |
+
~6.5 ms per patch×flow-step plus a small cold-start allowance and codec
|
| 155 |
+
decode time.
|
| 156 |
"""
|
| 157 |
text = kwargs.get("text") or kwargs.get("score_text") or (args[0] if args else "") or ""
|
| 158 |
flow_steps = kwargs.get("flow_steps")
|
|
|
|
| 174 |
# Speech: characters ≈ syllables ≈ 155 ms each (CJK 1 char/syllable).
|
| 175 |
seconds = (len(text) if isinstance(text, str) else 0) * 0.155
|
| 176 |
patches = min(MAX_PATCHES, max(2, int(seconds * 12.5)))
|
| 177 |
+
total = 10.0 + patches * steps * 0.008 + seconds * 0.3
|
| 178 |
+
return min(240, int(total * 1.3))
|
| 179 |
|
| 180 |
|
| 181 |
def _tts_duration(*args, **kwargs) -> int:
|
|
|
|
| 272 |
return _save_and_report(waveform, patches.size(1), started)
|
| 273 |
|
| 274 |
|
| 275 |
+
def _unified_duration(case_id: str, *args, **kwargs) -> int:
|
| 276 |
+
"""Duration for the mixed speech+song cases: longest packaged sequence is
|
| 277 |
+
15 s of audio at flow 20 ≈ 26 s measured; reserve ~1.4× for cold starts."""
|
| 278 |
+
return 45
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
@spaces.GPU(duration=_unified_duration)
|
| 282 |
def unified_generate(case_id: str, flow_steps=None, cfg_value=None,
|
| 283 |
temperature=None, seed=None, progress=gr.Progress()):
|
| 284 |
"""Run one packaged speech→singing→speech sequence end to end.
|