Spaces:
Running on Zero
Running on Zero
Retune GPU duration estimate from measured runs
Browse files
app.py
CHANGED
|
@@ -467,13 +467,22 @@ def _fit_reference_ui(image_path, current_canvas):
|
|
| 467 |
|
| 468 |
|
| 469 |
# ββ GPU duration estimation βββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 470 |
-
# The denoise cost model is linear+quadratic in the packed row count
|
| 471 |
-
#
|
| 472 |
-
#
|
| 473 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 474 |
_DUR_B, _DUR_C = 1.1745e-4, 3.8396e-9
|
| 475 |
_DECODE_BASE, _DECODE_PER_DEFAULT_CANVAS, _DEFAULT_CANVAS_PIXELS = 15, 15, 960 * 544 * 124
|
| 476 |
-
|
|
|
|
| 477 |
|
| 478 |
|
| 479 |
def get_duration(prompt_embeds, text_token_tags, reference_paths, height, width, num_frames, seed, *a, **k):
|
|
@@ -485,7 +494,7 @@ def get_duration(prompt_embeds, text_token_tags, reference_paths, height, width,
|
|
| 485 |
rows = latent_frames * patches + len(reference_paths or []) * patches
|
| 486 |
denoise = steps * (_DUR_B * rows + _DUR_C * rows**2)
|
| 487 |
decode = _DECODE_BASE + _DECODE_PER_DEFAULT_CANVAS * (height * width * num_frames) / _DEFAULT_CANVAS_PIXELS
|
| 488 |
-
return max(60, int(denoise + decode)
|
| 489 |
|
| 490 |
|
| 491 |
# ββ Inference βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 467 |
|
| 468 |
|
| 469 |
# ββ GPU duration estimation βββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 470 |
+
# The denoise cost model is linear+quadratic in the packed row count, plus a decode term proportional
|
| 471 |
+
# to the frame area. Steps is fixed at NUM_STEPS (3). A `ref2va` request packs one latent frame per
|
| 472 |
+
# image reference on top of the generated rows.
|
| 473 |
+
#
|
| 474 |
+
# Calibrated here against the GPU window this Space actually measured (`denoise + decode` in the
|
| 475 |
+
# generation report β both VAEs onto the device, the references encoded at their own 2048 short edge,
|
| 476 |
+
# the 3 steps, the unpack and both decodes):
|
| 477 |
+
# 544x960 (rows 19890, area 1.00x) -> 70, 61, 70, 70 s
|
| 478 |
+
# 768x1344 (rows 39312, area 1.98x) -> 103 s
|
| 479 |
+
# 544x544 (rows 11271, area 0.30x) -> 47 s
|
| 480 |
+
# The first four runs of the default canvas spread 61-70 s, so the worst case is what the margin is
|
| 481 |
+
# measured against; `_DURATION_OVERHEAD` is the part that does not scale with the canvas at all.
|
| 482 |
_DUR_B, _DUR_C = 1.1745e-4, 3.8396e-9
|
| 483 |
_DECODE_BASE, _DECODE_PER_DEFAULT_CANVAS, _DEFAULT_CANVAS_PIXELS = 15, 15, 960 * 544 * 124
|
| 484 |
+
_DURATION_MARGIN = 1.15
|
| 485 |
+
_DURATION_OVERHEAD = 33
|
| 486 |
|
| 487 |
|
| 488 |
def get_duration(prompt_embeds, text_token_tags, reference_paths, height, width, num_frames, seed, *a, **k):
|
|
|
|
| 494 |
rows = latent_frames * patches + len(reference_paths or []) * patches
|
| 495 |
denoise = steps * (_DUR_B * rows + _DUR_C * rows**2)
|
| 496 |
decode = _DECODE_BASE + _DECODE_PER_DEFAULT_CANVAS * (height * width * num_frames) / _DEFAULT_CANVAS_PIXELS
|
| 497 |
+
return max(60, int((denoise + decode) * _DURATION_MARGIN) + _DURATION_OVERHEAD)
|
| 498 |
|
| 499 |
|
| 500 |
# ββ Inference βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|