Spaces:
Running on Zero
Running on Zero
Dynamic GPU duration fitted from probes
Browse files
app.py
CHANGED
|
@@ -183,7 +183,26 @@ def encode_remote(prompt, image_path, last_image_path, canvas, num_frames):
|
|
| 183 |
return handle.get_tensor("prompt_embeds"), handle.get_tensor("text_token_tags"), metadata, plan
|
| 184 |
|
| 185 |
|
| 186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
def _generate(prompt_embeds, text_token_tags, image, last_image, height, width, num_frames, steps, seed):
|
| 188 |
"""The only thing on GPU time: the packed-sequence denoise loop and the two decoders.
|
| 189 |
|
|
|
|
| 183 |
return handle.get_tensor("prompt_embeds"), handle.get_tensor("text_token_tags"), metadata, plan
|
| 184 |
|
| 185 |
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
# Fitted on live probes (5 configs spanning canvas, duration and steps; max residual 3.7 s):
|
| 189 |
+
# gpu_seconds = A + B * steps * tokens + C * steps * tokens^2, where tokens is the packed video row count.
|
| 190 |
+
# PLACEMENT_ALLOWANCE covers the one-time 72 GiB lazy .to("cuda") a cold worker pays inside its first call.
|
| 191 |
+
_DUR_A, _DUR_B, _DUR_C = -6.023, 2.0877e-4, 2.1221e-9
|
| 192 |
+
_PLACEMENT_ALLOWANCE, _PAD = 90, 10
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
def get_duration(prompt_embeds, text_token_tags, image, last_image, height, width, num_frames, steps, seed, *a, **k):
|
| 196 |
+
latent_frames = (int(num_frames) - 5) // 17 * 5 + 2
|
| 197 |
+
patches = (int(height) // 32) * (int(width) // 32)
|
| 198 |
+
tokens = latent_frames * patches
|
| 199 |
+
tokens += (int(image is not None) + int(last_image is not None)) * patches
|
| 200 |
+
st = int(steps) * tokens
|
| 201 |
+
compute = _DUR_A + _DUR_B * st + _DUR_C * st * tokens
|
| 202 |
+
return max(60, int(compute) + _PLACEMENT_ALLOWANCE + _PAD)
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
@spaces.GPU(duration=get_duration, size=GPU_SIZE)
|
| 206 |
def _generate(prompt_embeds, text_token_tags, image, last_image, height, width, num_frames, steps, seed):
|
| 207 |
"""The only thing on GPU time: the packed-sequence denoise loop and the two decoders.
|
| 208 |
|