Spaces:
Running on Zero
Running on Zero
Right-size ZeroGPU duration requests (dynamic where workload-dependent)
Browse files
app.py
CHANGED
|
@@ -130,7 +130,14 @@ def toggle_name_box(selected_options: list[str]):
|
|
| 130 |
return gr.update(visible=NAME_OPTION in selected_options)
|
| 131 |
|
| 132 |
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
@torch.no_grad()
|
| 135 |
def chat_joycaption(input_image: Image.Image, prompt: str, temperature: float, top_p: float, max_new_tokens: int, log_prompt: bool) -> Generator[str, None, None]:
|
| 136 |
torch.cuda.empty_cache()
|
|
|
|
| 130 |
return gr.update(visible=NAME_OPTION in selected_options)
|
| 131 |
|
| 132 |
|
| 133 |
+
def get_duration(input_image, prompt, temperature, top_p, max_new_tokens, log_prompt):
|
| 134 |
+
# Generation speed is ~40 tok/s on ZeroGPU; a full 512-token caption measured
|
| 135 |
+
# ~13s wall. Scale the GPU request with the token budget instead of the 60s
|
| 136 |
+
# default so anonymous visitors with small quotas aren't rejected up front.
|
| 137 |
+
return min(90, 12 + int(max_new_tokens) // 25)
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
@spaces.GPU(duration=get_duration)
|
| 141 |
@torch.no_grad()
|
| 142 |
def chat_joycaption(input_image: Image.Image, prompt: str, temperature: float, top_p: float, max_new_tokens: int, log_prompt: bool) -> Generator[str, None, None]:
|
| 143 |
torch.cuda.empty_cache()
|