Spaces:
Running on Zero
Running on Zero
Right-size ZeroGPU duration requests (dynamic where workload-dependent)
Browse files
app.py
CHANGED
|
@@ -189,7 +189,17 @@ def update_steps_from_mode(mode_choice):
|
|
| 189 |
return DEFAULT_STEPS[mode_choice], DEFAULT_CFG[mode_choice]
|
| 190 |
|
| 191 |
|
| 192 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
def infer(prompt, input_images=None, mode_choice="Distilled (4 steps)", seed=42, randomize_seed=False, width=1024, height=1024, num_inference_steps=4, guidance_scale=4.0, prompt_upsampling=False, progress=gr.Progress(track_tqdm=True)):
|
| 194 |
|
| 195 |
if randomize_seed:
|
|
|
|
| 189 |
return DEFAULT_STEPS[mode_choice], DEFAULT_CFG[mode_choice]
|
| 190 |
|
| 191 |
|
| 192 |
+
def get_duration(prompt, input_images=None, mode_choice="Distilled (4 steps)", seed=42, randomize_seed=False, width=1024, height=1024, num_inference_steps=4, guidance_scale=4.0, prompt_upsampling=False, progress=None):
|
| 193 |
+
# Observed ~1.2-2.0 it/s at 1MP in production logs, so a distilled 4-step
|
| 194 |
+
# run finishes in seconds while the old flat 85s request exhausted anonymous
|
| 195 |
+
# visitors' ZeroGPU quota check up front. Scale with steps and resolution.
|
| 196 |
+
res_scale = (int(width) * int(height)) / (1024 * 1024)
|
| 197 |
+
n_images = len(input_images) if input_images else 0
|
| 198 |
+
estimate = 8 + n_images * 2 + int(num_inference_steps) * 1.1 * res_scale
|
| 199 |
+
return int(min(max(estimate, 15), 85))
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
@spaces.GPU(duration=get_duration)
|
| 203 |
def infer(prompt, input_images=None, mode_choice="Distilled (4 steps)", seed=42, randomize_seed=False, width=1024, height=1024, num_inference_steps=4, guidance_scale=4.0, prompt_upsampling=False, progress=gr.Progress(track_tqdm=True)):
|
| 204 |
|
| 205 |
if randomize_seed:
|