Spaces:
Running on Zero
Running on Zero
Check requests before reserving the GPU, and size each reservation
Browse filesprocess_fn now refuses an Audio2Audio request without a readable reference, and any request estimated above 200 s of GPU time, before the GPU is reserved. The reservation is computed from the duration and steps. The fixed 120 s decorator on the pipeline's __call__ is removed, since app.py's generate reserves for it.
- app.py +46 -0
- pipeline_ace_step.py +1 -1
app.py
CHANGED
|
@@ -10,6 +10,7 @@ import spaces # imported before torch, as ZeroGPU requires
|
|
| 10 |
import tempfile
|
| 11 |
|
| 12 |
import gradio as gr
|
|
|
|
| 13 |
from huggingface_hub import snapshot_download
|
| 14 |
|
| 15 |
from pyharp import *
|
|
@@ -56,11 +57,56 @@ model_card = ModelCard(
|
|
| 56 |
)
|
| 57 |
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
def process_fn(audio_duration, prompt, lyrics, infer_step, guidance_scale, omega_scale,
|
| 60 |
manual_seeds, guidance_interval, guidance_interval_decay, min_guidance_scale,
|
| 61 |
use_erg_tag, use_erg_lyric, use_erg_diffusion, oss_steps, guidance_scale_text,
|
| 62 |
guidance_scale_lyric, audio2audio_enable, ref_audio_strength, ref_audio_input,
|
| 63 |
lora_name_or_path):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
outputs = pipeline(
|
| 65 |
audio_duration=audio_duration,
|
| 66 |
prompt=prompt,
|
|
|
|
| 10 |
import tempfile
|
| 11 |
|
| 12 |
import gradio as gr
|
| 13 |
+
import soundfile as sf
|
| 14 |
from huggingface_hub import snapshot_download
|
| 15 |
|
| 16 |
from pyharp import *
|
|
|
|
| 57 |
)
|
| 58 |
|
| 59 |
|
| 60 |
+
# The most a request may reserve: 1.5 times this is a free account's whole daily allowance
|
| 61 |
+
MAX_GPU_SECONDS = 200
|
| 62 |
+
|
| 63 |
+
# Longest an automatic duration can come out, since the pipeline draws it from 30 to 240 seconds
|
| 64 |
+
MAX_AUTOMATIC_SECONDS = 240
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def gpu_seconds(audio_duration, prompt, lyrics, infer_step, *_):
|
| 68 |
+
# Measured at about 8 s of loading plus 0.0032 s per second of audio per step (16 s of audio at
|
| 69 |
+
# 60 steps in 11 s, 95 s in 26 s), padded
|
| 70 |
+
seconds = audio_duration if audio_duration > 0 else MAX_AUTOMATIC_SECONDS
|
| 71 |
+
return 15 + 0.004 * seconds * int(infer_step)
|
| 72 |
+
|
| 73 |
+
|
| 74 |
def process_fn(audio_duration, prompt, lyrics, infer_step, guidance_scale, omega_scale,
|
| 75 |
manual_seeds, guidance_interval, guidance_interval_decay, min_guidance_scale,
|
| 76 |
use_erg_tag, use_erg_lyric, use_erg_diffusion, oss_steps, guidance_scale_text,
|
| 77 |
guidance_scale_lyric, audio2audio_enable, ref_audio_strength, ref_audio_input,
|
| 78 |
lora_name_or_path):
|
| 79 |
+
# Checked before the GPU is reserved, so a request that cannot run spends none of the
|
| 80 |
+
# caller's ZeroGPU allowance
|
| 81 |
+
if audio2audio_enable:
|
| 82 |
+
if not ref_audio_input:
|
| 83 |
+
raise gr.Error("Audio2Audio needs a reference recording.")
|
| 84 |
+
try:
|
| 85 |
+
sf.info(ref_audio_input)
|
| 86 |
+
except Exception as exc:
|
| 87 |
+
raise gr.Error(f"Could not read the reference recording: {exc}") from exc
|
| 88 |
+
if gpu_seconds(audio_duration, prompt, lyrics, infer_step) > MAX_GPU_SECONDS:
|
| 89 |
+
raise gr.Error(
|
| 90 |
+
f"{int(infer_step)} steps on "
|
| 91 |
+
+ (f"{audio_duration:g} s" if audio_duration > 0 else "an automatic length of up to "
|
| 92 |
+
f"{MAX_AUTOMATIC_SECONDS} s")
|
| 93 |
+
+ " of audio need more GPU time than one request may reserve. Lower the steps or "
|
| 94 |
+
"the duration."
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
return generate(audio_duration, prompt, lyrics, infer_step, guidance_scale, omega_scale,
|
| 98 |
+
manual_seeds, guidance_interval, guidance_interval_decay, min_guidance_scale,
|
| 99 |
+
use_erg_tag, use_erg_lyric, use_erg_diffusion, oss_steps, guidance_scale_text,
|
| 100 |
+
guidance_scale_lyric, audio2audio_enable, ref_audio_strength, ref_audio_input,
|
| 101 |
+
lora_name_or_path)
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
@spaces.GPU(duration=gpu_seconds)
|
| 105 |
+
def generate(audio_duration, prompt, lyrics, infer_step, guidance_scale, omega_scale,
|
| 106 |
+
manual_seeds, guidance_interval, guidance_interval_decay, min_guidance_scale,
|
| 107 |
+
use_erg_tag, use_erg_lyric, use_erg_diffusion, oss_steps, guidance_scale_text,
|
| 108 |
+
guidance_scale_lyric, audio2audio_enable, ref_audio_strength, ref_audio_input,
|
| 109 |
+
lora_name_or_path):
|
| 110 |
outputs = pipeline(
|
| 111 |
audio_duration=audio_duration,
|
| 112 |
prompt=prompt,
|
pipeline_ace_step.py
CHANGED
|
@@ -1447,7 +1447,7 @@ class ACEStepPipeline:
|
|
| 1447 |
latents, _ = self.music_dcae.encode(input_audio, sr=sr)
|
| 1448 |
return latents
|
| 1449 |
|
| 1450 |
-
|
| 1451 |
def __call__(
|
| 1452 |
self,
|
| 1453 |
audio_duration: float = 60.0,
|
|
|
|
| 1447 |
latents, _ = self.music_dcae.encode(input_audio, sr=sr)
|
| 1448 |
return latents
|
| 1449 |
|
| 1450 |
+
# Reserved by app.py's generate, which sizes the reservation to the request
|
| 1451 |
def __call__(
|
| 1452 |
self,
|
| 1453 |
audio_duration: float = 60.0,
|