Spaces:
Running on Zero
fix: off ZeroGPU the page names no meter: the cost panel says where the run happens and that nothing is metered, and no caption, card or reason speaks of quota, reserving, billing or paying
Browse filesThe lead's real-weights session on this Mac read "Reserves 180 s of GPU time",
"Needs 360 s of quota free to start", "Billed for GPU time used x 2", "you pay
for that GPU time" and "Any GPU time this run used is billed". adaf178 made the
running sentence follow handlers.run_platform(); now everything else does (F75).
Where the app is not on ZeroGPU:
- the cost panel: Reserves / Needs / Billed give way to one row, "Runs on the
CPU; nothing is metered" (on this Mac's GPU, on the GPU: the Done card's device
words); the lamps carry no seconds; the refused panel says Generate stays off
until the problem is fixed; the phone bar reads "704 x 480, 5.0 s, on the CPU";
- "How quota works" is not on the page; the column notes, the Enhance, Upscale and
LoRA lines say what happens without a meter;
- every failure card, the lost run and the empty-file card have no billing
sentence; a request refused before running says "Nothing ran."; the quota and
per-run-limit cards, which a local run cannot raise, fall back to the generic one;
- Upscale x2 where this machine cannot run it for the request (the backend's own
gate, generate._checked_stage_2_size, asked with Upscale on) is parked: unticked,
disabled, with "Upscale x2 needs a CUDA GPU; this machine runs on the CPU." It
frees itself at a size the backend accepts.
On ZeroGPU every sentence is as before. The cost figures are tungsten by class,
not by row position. The design document says the rule.
Tests: tests/test_ui_device_words.py renders, for the CPU, this Mac's GPU and a
CUDA box of one's own, the built page in all eleven modes, the cost panel of every
mode with each lever on, the running and done states, every failure category
through handlers.run, the refusal, the lost run, the empty file and the unshown
result, and finds none of quota, reserv, billed, bill, pay; with the stand-in
spaces module the panel still shows Reserves, Needs and Billed. Upscale is parked
exactly where prepare_request refuses it. test_ui_cost.py runs as the Space (it
pins the Space's panel); test_ui_cards.py checks the Enhance line on both;
test_ui_generate_seam.py compares the empty-file card in this platform's words.
- docs/UI_DESIGN.md +21 -0
- ltx25_studio/ui/blocks.py +30 -3
- ltx25_studio/ui/chrome.py +18 -15
- ltx25_studio/ui/components.py +2 -2
- ltx25_studio/ui/handlers.py +46 -6
- ltx25_studio/ui/render.py +138 -44
- tests/test_ui_cards.py +18 -2
- tests/test_ui_cost.py +17 -1
- tests/test_ui_device_words.py +368 -0
- tests/test_ui_generate_seam.py +6 -2
|
@@ -171,6 +171,27 @@ says how many seconds it adds, and the Enhance line says what it reserves and th
|
|
| 171 |
cold start can take about 2 minutes (it mentions an image only where the mode takes
|
| 172 |
one).
|
| 173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
**Generate** is disabled whenever the form would be refused. The line under it uses
|
| 175 |
the backend's own refusal words, from `generate.prepare_request`. Generate is also
|
| 176 |
disabled while a run is in flight. The click runs three steps:
|
|
|
|
| 171 |
cold start can take about 2 minutes (it mentions an image only where the mode takes
|
| 172 |
one).
|
| 173 |
|
| 174 |
+
**Off ZeroGPU there is no meter, and the page names none.** The platform is resolved as
|
| 175 |
+
`app.py` resolves it (`device.current()`, read by `handlers.run_platform`). Where the app
|
| 176 |
+
is not on ZeroGPU (a Mac, the CPU, a CUDA box of one's own):
|
| 177 |
+
|
| 178 |
+
- the Reserves, Needs and Billed rows give way to one row, "Runs: on the CPU; nothing is
|
| 179 |
+
metered" (or "on this Mac's GPU", "on the GPU": the Done card's device words), and the
|
| 180 |
+
lamps carry no seconds;
|
| 181 |
+
- "How quota works" is not shown; the column notes, the Enhance, Upscale and LoRA lines,
|
| 182 |
+
the phone bar's line ("704 × 480, 5.0 s, on the CPU") and the refused panel say what
|
| 183 |
+
happens without a meter;
|
| 184 |
+
- a failure card has no quota line: a request refused before running says "Nothing
|
| 185 |
+
ran.", any other card only its step; the cards about the platform's quota and its
|
| 186 |
+
per-run limit, which a local run cannot raise, fall back to the generic card; the lost
|
| 187 |
+
run and the empty-file cards have no billing sentence.
|
| 188 |
+
- Upscale ×2 where this machine cannot run it for the request (the backend's own gate,
|
| 189 |
+
`generate._checked_stage_2_size`: off CUDA, above a small decoder size) is parked:
|
| 190 |
+
unticked, disabled, and its line says "Upscale ×2 needs a CUDA GPU; this machine runs on
|
| 191 |
+
the CPU." It frees itself at a size the backend accepts.
|
| 192 |
+
|
| 193 |
+
On ZeroGPU every one of these sentences is as above.
|
| 194 |
+
|
| 195 |
**Generate** is disabled whenever the form would be refused. The line under it uses
|
| 196 |
the backend's own refusal words, from `generate.prepare_request`. Generate is also
|
| 197 |
disabled while a run is in flight. The click runs three steps:
|
|
@@ -274,6 +274,10 @@ def build_ui() -> gr.Blocks:
|
|
| 274 |
multiplier = handlers.quota_multiplier()
|
| 275 |
view0 = handlers.mode_view(DEFAULT_MODE)
|
| 276 |
mode0 = modes.get_mode(DEFAULT_MODE)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
|
| 278 |
pool: dict[str, Any] = {}
|
| 279 |
captions: dict[str, Any] = {}
|
|
@@ -284,6 +288,8 @@ def build_ui() -> gr.Blocks:
|
|
| 284 |
quota_text=render.quota_explainer(
|
| 285 |
multiplier=multiplier, example_reserve=zerogpu.estimate_duration()
|
| 286 |
)
|
|
|
|
|
|
|
| 287 |
),
|
| 288 |
head=chrome.head_html(),
|
| 289 |
elem_id="identity",
|
|
@@ -299,7 +305,7 @@ def build_ui() -> gr.Blocks:
|
|
| 299 |
with gr.Column(elem_id="commission", scale=3):
|
| 300 |
with gr.Column(elem_id="matrix"):
|
| 301 |
gr.HTML(
|
| 302 |
-
chrome.matrix_frame_html(),
|
| 303 |
elem_id="matrix-frame",
|
| 304 |
apply_default_css=False,
|
| 305 |
container=False,
|
|
@@ -397,6 +403,7 @@ def build_ui() -> gr.Blocks:
|
|
| 397 |
"enhance_prompt",
|
| 398 |
visible=view0.active["enhance_prompt"],
|
| 399 |
elem_id="enhance",
|
|
|
|
| 400 |
)
|
| 401 |
components.render_fields(pool, "negative_prompt", "conditions", visible=False)
|
| 402 |
for key, caption in captions.items():
|
|
@@ -424,6 +431,9 @@ def build_ui() -> gr.Blocks:
|
|
| 424 |
visible=view0.upscale,
|
| 425 |
elem_id="upscale",
|
| 426 |
label=_upscale_label(704, 480),
|
|
|
|
|
|
|
|
|
|
| 427 |
)
|
| 428 |
length_source = gr.Radio(
|
| 429 |
choices=[render.LENGTH_MATCH, render.LENGTH_SET],
|
|
@@ -464,6 +474,7 @@ def build_ui() -> gr.Blocks:
|
|
| 464 |
rows=handlers.MAX_STAGED_LORAS,
|
| 465 |
cap=f"{cap_gb:.0f} GB",
|
| 466 |
step=LORA_STEP,
|
|
|
|
| 467 |
)
|
| 468 |
components.render_fields(pool, "loras")
|
| 469 |
lora_note = gr.Markdown(
|
|
@@ -648,7 +659,7 @@ def build_ui() -> gr.Blocks:
|
|
| 648 |
# =================================================================
|
| 649 |
# readiness and cost: one review, fired by anything that moves it
|
| 650 |
# =================================================================
|
| 651 |
-
review_outputs = [cost, commit_line, generate_button, reason]
|
| 652 |
|
| 653 |
def _review(mode_id: str, is_running: bool, source: str, *values: Any) -> list[Any]:
|
| 654 |
try:
|
|
@@ -658,14 +669,28 @@ def build_ui() -> gr.Blocks:
|
|
| 658 |
mode_name=modes.get_mode(mode_id).label,
|
| 659 |
state="refused",
|
| 660 |
reason=str(exc) or exc.__class__.__name__,
|
|
|
|
| 661 |
)
|
| 662 |
ready = facts.state == "ready" and not is_running
|
| 663 |
text = render.readiness_reason(facts, running=bool(is_running))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 664 |
return [
|
| 665 |
render.cost_panel(facts),
|
| 666 |
render.commit_line(facts),
|
| 667 |
gr.update(interactive=ready),
|
| 668 |
text,
|
|
|
|
| 669 |
]
|
| 670 |
|
| 671 |
review_inputs = [mode_selector, running, length_source, *field_inputs]
|
|
@@ -823,7 +848,9 @@ def build_ui() -> gr.Blocks:
|
|
| 823 |
kwargs["label"] = view.prompt_label
|
| 824 |
kwargs["placeholder"] = view.prompt_placeholder
|
| 825 |
if key == "enhance_prompt" and view.active[key]:
|
| 826 |
-
kwargs["info"] = render.enhance_info(
|
|
|
|
|
|
|
| 827 |
if key in _MEDIA and view.active[key]:
|
| 828 |
kwargs["label"] = handlers.media_label(mode, key)
|
| 829 |
if key == "decoder":
|
|
|
|
| 274 |
multiplier = handlers.quota_multiplier()
|
| 275 |
view0 = handlers.mode_view(DEFAULT_MODE)
|
| 276 |
mode0 = modes.get_mode(DEFAULT_MODE)
|
| 277 |
+
# Where runs happen. Only ZeroGPU has a quota, a reservation and a bill: anywhere else
|
| 278 |
+
# the page says where a run happens and nothing about a meter.
|
| 279 |
+
_device, on_zerogpu = handlers.run_platform()
|
| 280 |
+
upscale_seconds = zerogpu.estimate_duration(enable_stage_2=True) - zerogpu.estimate_duration()
|
| 281 |
|
| 282 |
pool: dict[str, Any] = {}
|
| 283 |
captions: dict[str, Any] = {}
|
|
|
|
| 288 |
quota_text=render.quota_explainer(
|
| 289 |
multiplier=multiplier, example_reserve=zerogpu.estimate_duration()
|
| 290 |
)
|
| 291 |
+
if on_zerogpu
|
| 292 |
+
else None
|
| 293 |
),
|
| 294 |
head=chrome.head_html(),
|
| 295 |
elem_id="identity",
|
|
|
|
| 305 |
with gr.Column(elem_id="commission", scale=3):
|
| 306 |
with gr.Column(elem_id="matrix"):
|
| 307 |
gr.HTML(
|
| 308 |
+
chrome.matrix_frame_html(on_zerogpu=on_zerogpu),
|
| 309 |
elem_id="matrix-frame",
|
| 310 |
apply_default_css=False,
|
| 311 |
container=False,
|
|
|
|
| 403 |
"enhance_prompt",
|
| 404 |
visible=view0.active["enhance_prompt"],
|
| 405 |
elem_id="enhance",
|
| 406 |
+
info=render.enhance_info(mode0, _ENHANCE_SECONDS, on_zerogpu=on_zerogpu),
|
| 407 |
)
|
| 408 |
components.render_fields(pool, "negative_prompt", "conditions", visible=False)
|
| 409 |
for key, caption in captions.items():
|
|
|
|
| 431 |
visible=view0.upscale,
|
| 432 |
elem_id="upscale",
|
| 433 |
label=_upscale_label(704, 480),
|
| 434 |
+
info=render.upscale_info(
|
| 435 |
+
upscale_seconds=upscale_seconds, on_zerogpu=on_zerogpu
|
| 436 |
+
),
|
| 437 |
)
|
| 438 |
length_source = gr.Radio(
|
| 439 |
choices=[render.LENGTH_MATCH, render.LENGTH_SET],
|
|
|
|
| 474 |
rows=handlers.MAX_STAGED_LORAS,
|
| 475 |
cap=f"{cap_gb:.0f} GB",
|
| 476 |
step=LORA_STEP,
|
| 477 |
+
on_zerogpu=on_zerogpu,
|
| 478 |
)
|
| 479 |
components.render_fields(pool, "loras")
|
| 480 |
lora_note = gr.Markdown(
|
|
|
|
| 659 |
# =================================================================
|
| 660 |
# readiness and cost: one review, fired by anything that moves it
|
| 661 |
# =================================================================
|
| 662 |
+
review_outputs = [cost, commit_line, generate_button, reason, pool["enable_stage_2"]]
|
| 663 |
|
| 664 |
def _review(mode_id: str, is_running: bool, source: str, *values: Any) -> list[Any]:
|
| 665 |
try:
|
|
|
|
| 669 |
mode_name=modes.get_mode(mode_id).label,
|
| 670 |
state="refused",
|
| 671 |
reason=str(exc) or exc.__class__.__name__,
|
| 672 |
+
on_zerogpu=on_zerogpu,
|
| 673 |
)
|
| 674 |
ready = facts.state == "ready" and not is_running
|
| 675 |
text = render.readiness_reason(facts, running=bool(is_running))
|
| 676 |
+
# Upscale where this machine cannot run it for this request: parked, unticked,
|
| 677 |
+
# with the backend's reason, so Generate is never pressed into that refusal.
|
| 678 |
+
info = render.upscale_info(
|
| 679 |
+
upscale_seconds=upscale_seconds,
|
| 680 |
+
on_zerogpu=on_zerogpu,
|
| 681 |
+
refused=facts.upscale_refused,
|
| 682 |
+
)
|
| 683 |
+
upscale = (
|
| 684 |
+
gr.update(interactive=False, value=False, info=info)
|
| 685 |
+
if facts.upscale_refused
|
| 686 |
+
else gr.update(interactive=True, info=info)
|
| 687 |
+
)
|
| 688 |
return [
|
| 689 |
render.cost_panel(facts),
|
| 690 |
render.commit_line(facts),
|
| 691 |
gr.update(interactive=ready),
|
| 692 |
text,
|
| 693 |
+
upscale,
|
| 694 |
]
|
| 695 |
|
| 696 |
review_inputs = [mode_selector, running, length_source, *field_inputs]
|
|
|
|
| 848 |
kwargs["label"] = view.prompt_label
|
| 849 |
kwargs["placeholder"] = view.prompt_placeholder
|
| 850 |
if key == "enhance_prompt" and view.active[key]:
|
| 851 |
+
kwargs["info"] = render.enhance_info(
|
| 852 |
+
mode, _ENHANCE_SECONDS, on_zerogpu=on_zerogpu
|
| 853 |
+
)
|
| 854 |
if key in _MEDIA and view.active[key]:
|
| 855 |
kwargs["label"] = handlers.media_label(mode, key)
|
| 856 |
if key == "decoder":
|
|
@@ -68,22 +68,20 @@ def _empty_cells() -> list[tuple[int, int]]:
|
|
| 68 |
]
|
| 69 |
|
| 70 |
|
| 71 |
-
def matrix_frame_html() -> str:
|
| 72 |
"""Axis headers, the inert empty cells and the column notes, behind the radio.
|
| 73 |
|
| 74 |
The headers and empty cells are drawing (each cell's own name already says what it
|
| 75 |
starts from and returns); the column notes are words a screen reader must reach, so
|
| 76 |
they stay in the accessibility tree and describe their column's cells (the script
|
| 77 |
-
points each cell's ``aria-describedby`` at its note).
|
|
|
|
| 78 |
"""
|
| 79 |
cells = matrix_cells()
|
|
|
|
| 80 |
parts = ['<div class="mx-frame">']
|
| 81 |
for c, (_key, label) in enumerate(render.COLUMNS, start=1):
|
| 82 |
-
cost =
|
| 83 |
-
" is-cost"
|
| 84 |
-
if label in render.COLUMN_NOTES and "pay" in render.COLUMN_NOTES[label]
|
| 85 |
-
else ""
|
| 86 |
-
)
|
| 87 |
parts.append(
|
| 88 |
f'<div class="mx-col{cost}" style="grid-column:{c + 1};grid-row:1" aria-hidden="true">'
|
| 89 |
f"{html.escape(label)}</div>"
|
|
@@ -100,7 +98,7 @@ def matrix_frame_html() -> str:
|
|
| 100 |
)
|
| 101 |
notes_row = len(render.ROWS) + 2
|
| 102 |
for c, (_key, label) in enumerate(render.COLUMNS, start=1):
|
| 103 |
-
note =
|
| 104 |
if note:
|
| 105 |
column_modes = " ".join(m for m, (_r, col, _n) in cells.items() if col == c)
|
| 106 |
parts.append(
|
|
@@ -633,8 +631,8 @@ button:disabled { cursor: not-allowed !important; }
|
|
| 633 |
.mr-cost-grid dt, .mr-done-grid dt { color: var(--mr-dust); font-size: 13px; line-height: 21px; }
|
| 634 |
.mr-cost-grid dd, .mr-done-grid dd { margin: 0; color: var(--mr-paper); font-size: 14px; line-height: 21px; }
|
| 635 |
.mr-cost-grid .mr-num { color: var(--mr-paper); }
|
| 636 |
-
|
| 637 |
-
|
| 638 |
.mr-sub { color: var(--mr-dust); font-size: 13px; }
|
| 639 |
.mr-cost-note { margin: 10px 0 0; font-size: 13px; line-height: 19px; color: var(--mr-dust); }
|
| 640 |
.mr-cost-pending { display: none; margin: 10px 0 0; font-size: 13px; line-height: 19px; color: var(--mr-paper);
|
|
@@ -871,13 +869,18 @@ def head_html() -> str:
|
|
| 871 |
)
|
| 872 |
|
| 873 |
|
| 874 |
-
def identity_html(*, quota_text: str) -> str:
|
| 875 |
-
"""The one-line identity bar with the "How quota works" disclosure
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 876 |
return (
|
| 877 |
'<header class="mr-id">'
|
| 878 |
'<h1 class="mr-wordmark">LTX-2.5 Studio</h1>'
|
| 879 |
f'<p class="mr-tagline">{html.escape(render.TAGLINE)}</p>'
|
| 880 |
-
|
| 881 |
-
f'<div class="mr-quota-panel"><p>{html.escape(quota_text)}</p></div></details>'
|
| 882 |
-
"</header>"
|
| 883 |
)
|
|
|
|
| 68 |
]
|
| 69 |
|
| 70 |
|
| 71 |
+
def matrix_frame_html(*, on_zerogpu: bool = True) -> str:
|
| 72 |
"""Axis headers, the inert empty cells and the column notes, behind the radio.
|
| 73 |
|
| 74 |
The headers and empty cells are drawing (each cell's own name already says what it
|
| 75 |
starts from and returns); the column notes are words a screen reader must reach, so
|
| 76 |
they stay in the accessibility tree and describe their column's cells (the script
|
| 77 |
+
points each cell's ``aria-describedby`` at its note). The notes are in the platform's
|
| 78 |
+
words (``render.column_notes``).
|
| 79 |
"""
|
| 80 |
cells = matrix_cells()
|
| 81 |
+
notes = render.column_notes(on_zerogpu=on_zerogpu)
|
| 82 |
parts = ['<div class="mx-frame">']
|
| 83 |
for c, (_key, label) in enumerate(render.COLUMNS, start=1):
|
| 84 |
+
cost = " is-cost" if label == render.COST_COLUMN else ""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
parts.append(
|
| 86 |
f'<div class="mx-col{cost}" style="grid-column:{c + 1};grid-row:1" aria-hidden="true">'
|
| 87 |
f"{html.escape(label)}</div>"
|
|
|
|
| 98 |
)
|
| 99 |
notes_row = len(render.ROWS) + 2
|
| 100 |
for c, (_key, label) in enumerate(render.COLUMNS, start=1):
|
| 101 |
+
note = notes.get(label)
|
| 102 |
if note:
|
| 103 |
column_modes = " ".join(m for m, (_r, col, _n) in cells.items() if col == c)
|
| 104 |
parts.append(
|
|
|
|
| 631 |
.mr-cost-grid dt, .mr-done-grid dt { color: var(--mr-dust); font-size: 13px; line-height: 21px; }
|
| 632 |
.mr-cost-grid dd, .mr-done-grid dd { margin: 0; color: var(--mr-paper); font-size: 14px; line-height: 21px; }
|
| 633 |
.mr-cost-grid .mr-num { color: var(--mr-paper); }
|
| 634 |
+
/* the reservation and the quota needed, on ZeroGPU: the only figures in tungsten */
|
| 635 |
+
.mr-cost-grid .mr-num.mr-cost-figure { color: var(--mr-tungsten); font-family: var(--mr-mono); }
|
| 636 |
.mr-sub { color: var(--mr-dust); font-size: 13px; }
|
| 637 |
.mr-cost-note { margin: 10px 0 0; font-size: 13px; line-height: 19px; color: var(--mr-dust); }
|
| 638 |
.mr-cost-pending { display: none; margin: 10px 0 0; font-size: 13px; line-height: 19px; color: var(--mr-paper);
|
|
|
|
| 869 |
)
|
| 870 |
|
| 871 |
|
| 872 |
+
def identity_html(*, quota_text: str | None) -> str:
|
| 873 |
+
"""The one-line identity bar, with the "How quota works" disclosure on ZeroGPU only
|
| 874 |
+
(``quota_text`` is None anywhere else: there is no quota to explain)."""
|
| 875 |
+
disclosure = (
|
| 876 |
+
'<details class="mr-quota"><summary>How quota works</summary>'
|
| 877 |
+
f'<div class="mr-quota-panel"><p>{html.escape(quota_text)}</p></div></details>'
|
| 878 |
+
if quota_text
|
| 879 |
+
else ""
|
| 880 |
+
)
|
| 881 |
return (
|
| 882 |
'<header class="mr-id">'
|
| 883 |
'<h1 class="mr-wordmark">LTX-2.5 Studio</h1>'
|
| 884 |
f'<p class="mr-tagline">{html.escape(render.TAGLINE)}</p>'
|
| 885 |
+
f"{disclosure}</header>"
|
|
|
|
|
|
|
| 886 |
)
|
|
@@ -118,7 +118,7 @@ def assert_pool_complete(pool: dict[str, Any]) -> None:
|
|
| 118 |
# ---------------------------------------------------------------------------
|
| 119 |
|
| 120 |
|
| 121 |
-
def lora_bay(*, rows: int, cap: str, step: float) -> dict[str, Any]:
|
| 122 |
"""Both routes (Hub id, upload), the verdict, and ``rows`` staged-adapter rows.
|
| 123 |
|
| 124 |
Each row is a name, a strength slider and a Remove button; rows show and
|
|
@@ -127,7 +127,7 @@ def lora_bay(*, rows: int, cap: str, step: float) -> dict[str, Any]:
|
|
| 127 |
here), so the range built here is only a placeholder nobody sees.
|
| 128 |
"""
|
| 129 |
widgets: dict[str, Any] = {}
|
| 130 |
-
gr.Markdown(render.lora_heading(cap), elem_classes=["mr-bay-head"])
|
| 131 |
with gr.Row(elem_classes=["mr-hub-row"]):
|
| 132 |
widgets["repo_id"] = gr.Textbox(
|
| 133 |
label="Hub repo id",
|
|
|
|
| 118 |
# ---------------------------------------------------------------------------
|
| 119 |
|
| 120 |
|
| 121 |
+
def lora_bay(*, rows: int, cap: str, step: float, on_zerogpu: bool = True) -> dict[str, Any]:
|
| 122 |
"""Both routes (Hub id, upload), the verdict, and ``rows`` staged-adapter rows.
|
| 123 |
|
| 124 |
Each row is a name, a strength slider and a Remove button; rows show and
|
|
|
|
| 127 |
here), so the range built here is only a placeholder nobody sees.
|
| 128 |
"""
|
| 129 |
widgets: dict[str, Any] = {}
|
| 130 |
+
gr.Markdown(render.lora_heading(cap, on_zerogpu=on_zerogpu), elem_classes=["mr-bay-head"])
|
| 131 |
with gr.Row(elem_classes=["mr-hub-row"]):
|
| 132 |
widgets["repo_id"] = gr.Textbox(
|
| 133 |
label="Hub repo id",
|
|
@@ -613,6 +613,30 @@ def _request(mode_id: str, values: dict[str, Any]):
|
|
| 613 |
return generate_module.GenerationRequest(mode=mode_id, **values)
|
| 614 |
|
| 615 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 616 |
def _staged_names(loras: Any) -> tuple[tuple[str, float], ...]:
|
| 617 |
out = []
|
| 618 |
for entry in loras or ():
|
|
@@ -642,10 +666,12 @@ def review(
|
|
| 642 |
mode = modes.get_mode(mode_id)
|
| 643 |
name = mode.label
|
| 644 |
multiplier = quota_multiplier()
|
|
|
|
|
|
|
| 645 |
try:
|
| 646 |
request = _request(mode_id, values)
|
| 647 |
except Exception as exc: # noqa: BLE001
|
| 648 |
-
return render.CostFacts(mode_name=name, state="refused", reason=str(exc))
|
| 649 |
|
| 650 |
# A mode that renders at its pinned size does not take the size boxes.
|
| 651 |
shape = _shape_problems(
|
|
@@ -672,6 +698,7 @@ def review(
|
|
| 672 |
if problems:
|
| 673 |
state = "refused"
|
| 674 |
|
|
|
|
| 675 |
if state == "refused":
|
| 676 |
return render.CostFacts(
|
| 677 |
mode_name=name,
|
|
@@ -683,6 +710,8 @@ def review(
|
|
| 683 |
enhance_offered=modes.accepts(mode, "text"),
|
| 684 |
multiplier=multiplier,
|
| 685 |
loras=_staged_names(request.loras),
|
|
|
|
|
|
|
| 686 |
)
|
| 687 |
|
| 688 |
stage_2 = generate_module.stage_2_enabled(mode, prepared)
|
|
@@ -762,6 +791,8 @@ def review(
|
|
| 762 |
notes=tuple(notes),
|
| 763 |
missing=missing,
|
| 764 |
length_pending=pending,
|
|
|
|
|
|
|
| 765 |
)
|
| 766 |
|
| 767 |
|
|
@@ -938,7 +969,7 @@ def unshown_report(outcome: RunOutcome | None, server_message: str | None) -> st
|
|
| 938 |
was used. No outcome at all: it ended without a result.
|
| 939 |
"""
|
| 940 |
if outcome is None:
|
| 941 |
-
return render.lost_run(server_message)
|
| 942 |
if not has_result(outcome):
|
| 943 |
return outcome.status
|
| 944 |
return render.result_not_shown(run_facts(outcome), server_message)
|
|
@@ -954,6 +985,7 @@ def run(mode_id: str, *values: Any, progress: Any = None) -> RunOutcome:
|
|
| 954 |
"""
|
| 955 |
params = dict(zip(FIELD_KEYS, values, strict=True))
|
| 956 |
started = time.monotonic()
|
|
|
|
| 957 |
|
| 958 |
def done(**kwargs) -> RunOutcome:
|
| 959 |
return RunOutcome(mode_id=mode_id, params=params, took=time.monotonic() - started, **kwargs)
|
|
@@ -964,7 +996,7 @@ def run(mode_id: str, *values: Any, progress: Any = None) -> RunOutcome:
|
|
| 964 |
return done(
|
| 965 |
video=None,
|
| 966 |
audio=None,
|
| 967 |
-
status=render.failure(exc, refused=True),
|
| 968 |
error=exc,
|
| 969 |
refused=True,
|
| 970 |
)
|
|
@@ -977,7 +1009,7 @@ def run(mode_id: str, *values: Any, progress: Any = None) -> RunOutcome:
|
|
| 977 |
return done(
|
| 978 |
video=None,
|
| 979 |
audio=None,
|
| 980 |
-
status=render.failure(exc, refused=True),
|
| 981 |
error=exc,
|
| 982 |
refused=True,
|
| 983 |
)
|
|
@@ -985,7 +1017,12 @@ def run(mode_id: str, *values: Any, progress: Any = None) -> RunOutcome:
|
|
| 985 |
try:
|
| 986 |
result = generate_module.generate(mode=mode_id, progress=progress, **params)
|
| 987 |
except Exception as exc: # noqa: BLE001 -- typed or not, the user sees it
|
| 988 |
-
return done(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 989 |
|
| 990 |
video_path = getattr(result, "video_path", None)
|
| 991 |
audio_path = getattr(result, "audio_path", None)
|
|
@@ -996,7 +1033,10 @@ def run(mode_id: str, *values: Any, progress: Any = None) -> RunOutcome:
|
|
| 996 |
]
|
| 997 |
if missing:
|
| 998 |
return done(
|
| 999 |
-
video=None,
|
|
|
|
|
|
|
|
|
|
| 1000 |
)
|
| 1001 |
|
| 1002 |
return done(
|
|
|
|
| 613 |
return generate_module.GenerationRequest(mode=mode_id, **values)
|
| 614 |
|
| 615 |
|
| 616 |
+
def _upscale_refusal(mode: Any, request: Any) -> str | None:
|
| 617 |
+
"""Why Upscale ×2 cannot run on this machine for ``request``, or None.
|
| 618 |
+
|
| 619 |
+
The backend's own gate decides: ``generate._checked_stage_2_size``, the step of
|
| 620 |
+
``prepare_request`` that refuses a stage-2 request this device cannot decode, asked with
|
| 621 |
+
Upscale on. Called on its own because ``prepare_request`` stops at the first problem (a
|
| 622 |
+
missing prompt), and the control is parked before the form is complete.
|
| 623 |
+
"""
|
| 624 |
+
if mode.skip_stage_2 or request is None:
|
| 625 |
+
return None
|
| 626 |
+
from dataclasses import replace
|
| 627 |
+
|
| 628 |
+
from .. import device as device_module
|
| 629 |
+
from .. import generate as generate_module
|
| 630 |
+
|
| 631 |
+
try:
|
| 632 |
+
generate_module._checked_stage_2_size(replace(request, enable_stage_2=True), mode)
|
| 633 |
+
except device_module.StageTwoNeedsCudaError as exc:
|
| 634 |
+
return render.upscale_needs_cuda(getattr(exc, "device", None))
|
| 635 |
+
except Exception: # noqa: BLE001 -- any other refusal is the panel's to state
|
| 636 |
+
return None
|
| 637 |
+
return None
|
| 638 |
+
|
| 639 |
+
|
| 640 |
def _staged_names(loras: Any) -> tuple[tuple[str, float], ...]:
|
| 641 |
out = []
|
| 642 |
for entry in loras or ():
|
|
|
|
| 666 |
mode = modes.get_mode(mode_id)
|
| 667 |
name = mode.label
|
| 668 |
multiplier = quota_multiplier()
|
| 669 |
+
device_name, on_zerogpu = run_platform()
|
| 670 |
+
platform = {"on_zerogpu": on_zerogpu, "device": device_name}
|
| 671 |
try:
|
| 672 |
request = _request(mode_id, values)
|
| 673 |
except Exception as exc: # noqa: BLE001
|
| 674 |
+
return render.CostFacts(mode_name=name, state="refused", reason=str(exc), **platform)
|
| 675 |
|
| 676 |
# A mode that renders at its pinned size does not take the size boxes.
|
| 677 |
shape = _shape_problems(
|
|
|
|
| 698 |
if problems:
|
| 699 |
state = "refused"
|
| 700 |
|
| 701 |
+
upscale_refused = _upscale_refusal(mode, prepared)
|
| 702 |
if state == "refused":
|
| 703 |
return render.CostFacts(
|
| 704 |
mode_name=name,
|
|
|
|
| 710 |
enhance_offered=modes.accepts(mode, "text"),
|
| 711 |
multiplier=multiplier,
|
| 712 |
loras=_staged_names(request.loras),
|
| 713 |
+
upscale_refused=upscale_refused,
|
| 714 |
+
**platform,
|
| 715 |
)
|
| 716 |
|
| 717 |
stage_2 = generate_module.stage_2_enabled(mode, prepared)
|
|
|
|
| 791 |
notes=tuple(notes),
|
| 792 |
missing=missing,
|
| 793 |
length_pending=pending,
|
| 794 |
+
upscale_refused=upscale_refused,
|
| 795 |
+
**platform,
|
| 796 |
)
|
| 797 |
|
| 798 |
|
|
|
|
| 969 |
was used. No outcome at all: it ended without a result.
|
| 970 |
"""
|
| 971 |
if outcome is None:
|
| 972 |
+
return render.lost_run(server_message, on_zerogpu=run_platform()[1])
|
| 973 |
if not has_result(outcome):
|
| 974 |
return outcome.status
|
| 975 |
return render.result_not_shown(run_facts(outcome), server_message)
|
|
|
|
| 985 |
"""
|
| 986 |
params = dict(zip(FIELD_KEYS, values, strict=True))
|
| 987 |
started = time.monotonic()
|
| 988 |
+
on_zerogpu = run_platform()[1]
|
| 989 |
|
| 990 |
def done(**kwargs) -> RunOutcome:
|
| 991 |
return RunOutcome(mode_id=mode_id, params=params, took=time.monotonic() - started, **kwargs)
|
|
|
|
| 996 |
return done(
|
| 997 |
video=None,
|
| 998 |
audio=None,
|
| 999 |
+
status=render.failure(exc, refused=True, on_zerogpu=on_zerogpu),
|
| 1000 |
error=exc,
|
| 1001 |
refused=True,
|
| 1002 |
)
|
|
|
|
| 1009 |
return done(
|
| 1010 |
video=None,
|
| 1011 |
audio=None,
|
| 1012 |
+
status=render.failure(exc, refused=True, on_zerogpu=on_zerogpu),
|
| 1013 |
error=exc,
|
| 1014 |
refused=True,
|
| 1015 |
)
|
|
|
|
| 1017 |
try:
|
| 1018 |
result = generate_module.generate(mode=mode_id, progress=progress, **params)
|
| 1019 |
except Exception as exc: # noqa: BLE001 -- typed or not, the user sees it
|
| 1020 |
+
return done(
|
| 1021 |
+
video=None,
|
| 1022 |
+
audio=None,
|
| 1023 |
+
status=render.failure(exc, on_zerogpu=on_zerogpu),
|
| 1024 |
+
error=exc,
|
| 1025 |
+
)
|
| 1026 |
|
| 1027 |
video_path = getattr(result, "video_path", None)
|
| 1028 |
audio_path = getattr(result, "audio_path", None)
|
|
|
|
| 1033 |
]
|
| 1034 |
if missing:
|
| 1035 |
return done(
|
| 1036 |
+
video=None,
|
| 1037 |
+
audio=None,
|
| 1038 |
+
status=render.empty_output_bug(mode, missing, on_zerogpu=on_zerogpu),
|
| 1039 |
+
result=result,
|
| 1040 |
)
|
| 1041 |
|
| 1042 |
return done(
|
|
@@ -43,7 +43,9 @@ from ..errors import (
|
|
| 43 |
__all__ = [
|
| 44 |
"COLUMN_NOTES",
|
| 45 |
"COLUMNS",
|
|
|
|
| 46 |
"FIELD_COPY",
|
|
|
|
| 47 |
"NOISE_CHOICES",
|
| 48 |
"READY",
|
| 49 |
"ROWS",
|
|
@@ -52,6 +54,7 @@ __all__ = [
|
|
| 52 |
"RunFacts",
|
| 53 |
"applied_loras",
|
| 54 |
"card_headline",
|
|
|
|
| 55 |
"commit_line",
|
| 56 |
"cost_panel",
|
| 57 |
"dimension_hint",
|
|
@@ -83,6 +86,9 @@ __all__ = [
|
|
| 83 |
"running",
|
| 84 |
"shot_anchor_readout",
|
| 85 |
"success",
|
|
|
|
|
|
|
|
|
|
| 86 |
]
|
| 87 |
|
| 88 |
|
|
@@ -96,6 +102,11 @@ def _num(value: Any) -> str:
|
|
| 96 |
return f'<span class="mr-num">{_e(value)}</span>'
|
| 97 |
|
| 98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
def _size(width: Any, height: Any) -> str:
|
| 100 |
return f"{int(width)} × {int(height)}"
|
| 101 |
|
|
@@ -148,11 +159,34 @@ COLUMNS: tuple[tuple[frozenset[str], str], ...] = (
|
|
| 148 |
(frozenset({"audio"}), "Sound only"),
|
| 149 |
)
|
| 150 |
|
| 151 |
-
#: Stated once, in words, under the column they belong to.
|
| 152 |
COLUMN_NOTES: dict[str, str] = {
|
| 153 |
"Video (silent)": "The sound is rendered, then dropped. Same GPU time as with sound.",
|
| 154 |
"Sound only": "Renders a 256 × 256 video that is thrown away; you pay for that GPU time.",
|
| 155 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
|
| 157 |
#: One line per mode, shown under the matrix for the selected cell.
|
| 158 |
_PURPOSE: dict[str, str] = {
|
|
@@ -255,15 +289,21 @@ def prompt_placeholder(mode: Any) -> str:
|
|
| 255 |
return _PLACEHOLDERS.get(mode.id, "Describe the shot.")
|
| 256 |
|
| 257 |
|
| 258 |
-
def enhance_info(mode: Any, enhance_seconds: int) -> str:
|
| 259 |
-
"""The Enhance line for ``mode``: what it reserves
|
| 260 |
-
|
|
|
|
| 261 |
if modes.requires(mode, "image"):
|
| 262 |
reads = ", and reads your image"
|
| 263 |
elif modes.accepts(mode, "image"):
|
| 264 |
reads = ", and reads your image if you add one"
|
| 265 |
else:
|
| 266 |
reads = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
return (
|
| 268 |
f"Gemma rewrites your prompt in detail on the GPU before the run{reads}. Reserves "
|
| 269 |
f"{enhance_seconds} s more; uses a few seconds when loaded, up to about 2 minutes on a "
|
|
@@ -271,6 +311,23 @@ def enhance_info(mode: Any, enhance_seconds: int) -> str:
|
|
| 271 |
)
|
| 272 |
|
| 273 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
_CAPTIONS: dict[tuple[str, str], str] = {
|
| 275 |
("video_to_video", "video"): "The clip to re-render.",
|
| 276 |
("video_to_audio", "video"): "The clip to make sound for.",
|
|
@@ -522,6 +579,12 @@ class CostFacts:
|
|
| 522 |
short_problems: tuple[tuple[str, str], ...] = ()
|
| 523 |
#: The length comes from a clip not loaded yet: ``"clip"`` (or None).
|
| 524 |
length_pending: str | None = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 525 |
|
| 526 |
|
| 527 |
def _returns_words(facts: CostFacts) -> str:
|
|
@@ -540,8 +603,9 @@ def _lamp(text: str, *, lit: bool, kind: str = "cost") -> str:
|
|
| 540 |
|
| 541 |
def _lamps(facts: CostFacts) -> str:
|
| 542 |
"""A lamp lights only for a cost that applies; a request that won't run costs nothing,
|
| 543 |
-
so in the refused state every lamp is dark.
|
| 544 |
-
|
|
|
|
| 545 |
live = facts.state != "refused"
|
| 546 |
lamps = []
|
| 547 |
if facts.stage_2_offered:
|
|
@@ -606,10 +670,15 @@ def cost_panel(facts: CostFacts) -> str:
|
|
| 606 |
items = "".join(f"<li>{_e(p)}</li>" for p in facts.problems) or (
|
| 607 |
f"<li>{_e(facts.reason or 'This request would be refused.')}</li>"
|
| 608 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 609 |
body = (
|
| 610 |
'<div class="mr-wont-run" role="note">'
|
| 611 |
'<p class="mr-wont-run-head"><span class="mr-lamp mr-lamp-cut is-lit">Won’t run</span>'
|
| 612 |
-
"
|
| 613 |
f"<ul>{items}</ul></div>"
|
| 614 |
)
|
| 615 |
return f'<section class="mr-cost is-refused" aria-label="Cost of this run">{head}{body}</section>'
|
|
@@ -624,28 +693,37 @@ def cost_panel(facts: CostFacts) -> str:
|
|
| 624 |
if facts.stage_2:
|
| 625 |
returns += ", upscaled ×2"
|
| 626 |
rows.append(("Returns", returns))
|
| 627 |
-
if
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
reserve
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 638 |
)
|
| 639 |
-
)
|
| 640 |
rows.append(("LoRA", _lora_words(facts.loras)))
|
| 641 |
if facts.seed is not None and facts.seed >= 0:
|
| 642 |
rows.append(("Seed", f"{_num(facts.seed)} (fixed)"))
|
| 643 |
grid = "".join(f"<dt>{_e(label)}</dt><dd>{value}</dd>" for label, value in rows)
|
| 644 |
notes = ""
|
| 645 |
if facts.discards_video:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 646 |
notes += (
|
| 647 |
-
'<p class="mr-cost-note">A 256 × 256 video is rendered and thrown away;
|
| 648 |
-
"that GPU time.</p>"
|
| 649 |
)
|
| 650 |
if facts.encodes_audio:
|
| 651 |
notes += (
|
|
@@ -693,7 +771,9 @@ def commit_line(facts: CostFacts) -> str:
|
|
| 693 |
parts.append(f"{facts.auto_seconds[0]:g}–{facts.auto_seconds[1]:g} s")
|
| 694 |
elif facts.seconds is not None:
|
| 695 |
parts.append(_seconds(facts.seconds))
|
| 696 |
-
if
|
|
|
|
|
|
|
| 697 |
parts.append(f"needs {facts.reserve * facts.multiplier} s quota")
|
| 698 |
return ", ".join(parts)
|
| 699 |
|
|
@@ -845,7 +925,13 @@ def lora_no_trigger() -> str:
|
|
| 845 |
)
|
| 846 |
|
| 847 |
|
| 848 |
-
def lora_heading(cap: str) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 849 |
return (
|
| 850 |
f"Add a LoRA from the Hub or upload a .safetensors file (up to {cap}). It is checked "
|
| 851 |
"against LTX-2.5's layers before any GPU time is used. The last check, that it "
|
|
@@ -998,8 +1084,7 @@ def running(
|
|
| 998 |
f"**Enhancing your prompt: {mode.label}.** Gemma rewrites it on this machine "
|
| 999 |
f"first, then generation starts. The prompt actually sent is in the report."
|
| 1000 |
)
|
| 1001 |
-
|
| 1002 |
-
return f"**Running: {mode.label}.** Loading, sampling and decoding {where}."
|
| 1003 |
if enhancing:
|
| 1004 |
return (
|
| 1005 |
f"**Enhancing your prompt: {mode.label}.** Gemma rewrites it on the GPU first, "
|
|
@@ -1042,10 +1127,6 @@ class RunFacts:
|
|
| 1042 |
quota_multiplier: int = 1
|
| 1043 |
|
| 1044 |
|
| 1045 |
-
#: Where a run's time was spent, by device.
|
| 1046 |
-
_ON_DEVICE = {"cpu": "on the CPU", "mps": "on this Mac's GPU", "cuda": "on the GPU"}
|
| 1047 |
-
|
| 1048 |
-
|
| 1049 |
def took_words(facts: RunFacts) -> str:
|
| 1050 |
""" "Took N s", labelled by the device that ran it; on ZeroGPU, with the quota it drew."""
|
| 1051 |
seconds = round(float(facts.took))
|
|
@@ -1140,15 +1221,17 @@ def _detail(text: str | None) -> str:
|
|
| 1140 |
)
|
| 1141 |
|
| 1142 |
|
| 1143 |
-
def lost_run(detail: str | None = None) -> str:
|
| 1144 |
"""The generation step ended without a result this page can show.
|
| 1145 |
|
| 1146 |
-
``detail`` is the server's own message, when it raised one.
|
|
|
|
| 1147 |
"""
|
|
|
|
| 1148 |
return (
|
| 1149 |
"### The run ended without a result\n\n"
|
| 1150 |
-
"
|
| 1151 |
-
"
|
| 1152 |
)
|
| 1153 |
|
| 1154 |
|
|
@@ -1166,14 +1249,15 @@ def result_not_shown(facts: RunFacts, detail: str | None) -> str:
|
|
| 1166 |
)
|
| 1167 |
|
| 1168 |
|
| 1169 |
-
def empty_output_bug(mode: Any, missing: list[str]) -> str:
|
| 1170 |
"""A run reported success and produced no file. That is a bug in this app."""
|
| 1171 |
tracks = " and ".join(missing)
|
|
|
|
| 1172 |
return (
|
| 1173 |
"### The run finished but produced no file\n\n"
|
| 1174 |
f"{mode.label} reported success without a {tracks} file, which this app treats as a "
|
| 1175 |
-
"bug.
|
| 1176 |
-
"
|
| 1177 |
)
|
| 1178 |
|
| 1179 |
|
|
@@ -1220,16 +1304,21 @@ _GENERIC_CARD = (
|
|
| 1220 |
"The run did not finish",
|
| 1221 |
"Press Generate again. If it happens again, report it with the detail below.",
|
| 1222 |
)
|
|
|
|
|
|
|
|
|
|
| 1223 |
#: Cards whose detail opens by itself: the detail holds the numbers to change.
|
| 1224 |
_OPEN_DETAIL = ("input", "quota", "limit")
|
| 1225 |
|
| 1226 |
|
| 1227 |
-
def failure(exc: BaseException, *, refused: bool = False) -> str:
|
| 1228 |
"""Any failure, rendered loudly: headline, quota line, one next step, detail.
|
| 1229 |
|
| 1230 |
The category and whether GPU time was used come from ``errors.categorise``.
|
| 1231 |
``refused`` is set when this page turned the request down before calling
|
| 1232 |
-
the backend at all, which is known to have used no GPU time.
|
|
|
|
|
|
|
| 1233 |
"""
|
| 1234 |
detail = str(exc).strip() or "No detail was attached to the error."
|
| 1235 |
found = errors.categorise(exc)
|
|
@@ -1239,17 +1328,22 @@ def failure(exc: BaseException, *, refused: bool = False) -> str:
|
|
| 1239 |
# A queue timeout: nothing ran, so it is not "out of GPU time".
|
| 1240 |
category = "queue"
|
| 1241 |
headline, step = _CARDS.get(category, _GENERIC_CARD)
|
|
|
|
|
|
|
| 1242 |
if category == "input" and not gpu_used:
|
| 1243 |
headline = "Refused before running: fix the input"
|
| 1244 |
-
|
| 1245 |
-
|
| 1246 |
-
|
| 1247 |
-
|
| 1248 |
-
|
|
|
|
|
|
|
|
|
|
| 1249 |
opened = " open" if category in _OPEN_DETAIL else ""
|
| 1250 |
return (
|
| 1251 |
f"### {headline}\n\n"
|
| 1252 |
-
f"{quota
|
| 1253 |
f'<details class="mr-detail"{opened}><summary>Detail</summary>'
|
| 1254 |
f"<p>{_e(detail)}</p></details>"
|
| 1255 |
)
|
|
|
|
| 43 |
__all__ = [
|
| 44 |
"COLUMN_NOTES",
|
| 45 |
"COLUMNS",
|
| 46 |
+
"COST_COLUMN",
|
| 47 |
"FIELD_COPY",
|
| 48 |
+
"LOCAL_COLUMN_NOTES",
|
| 49 |
"NOISE_CHOICES",
|
| 50 |
"READY",
|
| 51 |
"ROWS",
|
|
|
|
| 54 |
"RunFacts",
|
| 55 |
"applied_loras",
|
| 56 |
"card_headline",
|
| 57 |
+
"column_notes",
|
| 58 |
"commit_line",
|
| 59 |
"cost_panel",
|
| 60 |
"dimension_hint",
|
|
|
|
| 86 |
"running",
|
| 87 |
"shot_anchor_readout",
|
| 88 |
"success",
|
| 89 |
+
"upscale_info",
|
| 90 |
+
"upscale_needs_cuda",
|
| 91 |
+
"where_it_runs",
|
| 92 |
]
|
| 93 |
|
| 94 |
|
|
|
|
| 102 |
return f'<span class="mr-num">{_e(value)}</span>'
|
| 103 |
|
| 104 |
|
| 105 |
+
def _figure(value: Any) -> str:
|
| 106 |
+
"""A cost figure (the reservation, the quota needed): tungsten in the cost panel."""
|
| 107 |
+
return f'<span class="mr-num mr-cost-figure">{_e(value)}</span>'
|
| 108 |
+
|
| 109 |
+
|
| 110 |
def _size(width: Any, height: Any) -> str:
|
| 111 |
return f"{int(width)} × {int(height)}"
|
| 112 |
|
|
|
|
| 159 |
(frozenset({"audio"}), "Sound only"),
|
| 160 |
)
|
| 161 |
|
| 162 |
+
#: Stated once, in words, under the column they belong to (on ZeroGPU).
|
| 163 |
COLUMN_NOTES: dict[str, str] = {
|
| 164 |
"Video (silent)": "The sound is rendered, then dropped. Same GPU time as with sound.",
|
| 165 |
"Sound only": "Renders a 256 × 256 video that is thrown away; you pay for that GPU time.",
|
| 166 |
}
|
| 167 |
+
#: The same notes where no meter runs: what happens, and what it takes.
|
| 168 |
+
LOCAL_COLUMN_NOTES: dict[str, str] = {
|
| 169 |
+
"Video (silent)": "The sound is rendered, then dropped. The run takes as long as with sound.",
|
| 170 |
+
"Sound only": (
|
| 171 |
+
"Renders a 256 × 256 video that is thrown away, and the run takes the time to render it."
|
| 172 |
+
),
|
| 173 |
+
}
|
| 174 |
+
#: The column whose runs render a video nobody gets back: marked as a cost on every platform.
|
| 175 |
+
COST_COLUMN = "Sound only"
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def column_notes(*, on_zerogpu: bool = True) -> dict[str, str]:
|
| 179 |
+
"""The column notes in this platform's words."""
|
| 180 |
+
return COLUMN_NOTES if on_zerogpu else LOCAL_COLUMN_NOTES
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
#: Where a run's time is spent, by device (the Done card's "Took" uses the same words).
|
| 184 |
+
_ON_DEVICE = {"cpu": "on the CPU", "mps": "on this Mac's GPU", "cuda": "on the GPU"}
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def where_it_runs(device: str | None) -> str:
|
| 188 |
+
"""``device`` in the page's words: "on the CPU", "on this Mac's GPU", "on the GPU"."""
|
| 189 |
+
return _ON_DEVICE.get(str(device or ""), "on this machine")
|
| 190 |
|
| 191 |
#: One line per mode, shown under the matrix for the selected cell.
|
| 192 |
_PURPOSE: dict[str, str] = {
|
|
|
|
| 289 |
return _PLACEHOLDERS.get(mode.id, "Describe the shot.")
|
| 290 |
|
| 291 |
|
| 292 |
+
def enhance_info(mode: Any, enhance_seconds: int, *, on_zerogpu: bool = True) -> str:
|
| 293 |
+
"""The Enhance line for ``mode``: on ZeroGPU what it reserves and its cold start;
|
| 294 |
+
elsewhere where it runs and that its first use loads it. The image clause only where the
|
| 295 |
+
mode takes an image (the enhancer reads one, ``enhance.py``)."""
|
| 296 |
if modes.requires(mode, "image"):
|
| 297 |
reads = ", and reads your image"
|
| 298 |
elif modes.accepts(mode, "image"):
|
| 299 |
reads = ", and reads your image if you add one"
|
| 300 |
else:
|
| 301 |
reads = ""
|
| 302 |
+
if not on_zerogpu:
|
| 303 |
+
return (
|
| 304 |
+
f"Gemma rewrites your prompt in detail on this machine before the run{reads}. The "
|
| 305 |
+
f"first run with it also loads Gemma, so it takes longer."
|
| 306 |
+
)
|
| 307 |
return (
|
| 308 |
f"Gemma rewrites your prompt in detail on the GPU before the run{reads}. Reserves "
|
| 309 |
f"{enhance_seconds} s more; uses a few seconds when loaded, up to about 2 minutes on a "
|
|
|
|
| 311 |
)
|
| 312 |
|
| 313 |
|
| 314 |
+
#: What Upscale ×2 does, on every platform.
|
| 315 |
+
UPSCALE_DOES = "Upsamples and refines after the first pass, for twice the width and height."
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
def upscale_info(*, upscale_seconds: int, on_zerogpu: bool = True, refused: str | None = None) -> str:
|
| 319 |
+
"""The Upscale line: what it does, with what it reserves on ZeroGPU; or, where this
|
| 320 |
+
machine cannot run it for this request, why (the control is then parked)."""
|
| 321 |
+
if refused:
|
| 322 |
+
return refused
|
| 323 |
+
return f"{UPSCALE_DOES} Reserves {upscale_seconds} s more." if on_zerogpu else UPSCALE_DOES
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
def upscale_needs_cuda(device: str | None) -> str:
|
| 327 |
+
"""Why Upscale ×2 is parked here: the backend's refusal, in the page's device words."""
|
| 328 |
+
return f"Upscale ×2 needs a CUDA GPU; this machine runs {where_it_runs(device)}."
|
| 329 |
+
|
| 330 |
+
|
| 331 |
_CAPTIONS: dict[tuple[str, str], str] = {
|
| 332 |
("video_to_video", "video"): "The clip to re-render.",
|
| 333 |
("video_to_audio", "video"): "The clip to make sound for.",
|
|
|
|
| 579 |
short_problems: tuple[tuple[str, str], ...] = ()
|
| 580 |
#: The length comes from a clip not loaded yet: ``"clip"`` (or None).
|
| 581 |
length_pending: str | None = None
|
| 582 |
+
#: Where it runs. On ZeroGPU the panel states the reservation, the quota and the
|
| 583 |
+
#: billing; anywhere else, the device, and that nothing is metered.
|
| 584 |
+
on_zerogpu: bool = True
|
| 585 |
+
device: str | None = None
|
| 586 |
+
#: Why Upscale ×2 cannot run here for this request (the backend's refusal), or None.
|
| 587 |
+
upscale_refused: str | None = None
|
| 588 |
|
| 589 |
|
| 590 |
def _returns_words(facts: CostFacts) -> str:
|
|
|
|
| 603 |
|
| 604 |
def _lamps(facts: CostFacts) -> str:
|
| 605 |
"""A lamp lights only for a cost that applies; a request that won't run costs nothing,
|
| 606 |
+
so in the refused state every lamp is dark. The seconds a lever reserves are named only
|
| 607 |
+
where a reservation exists (ZeroGPU)."""
|
| 608 |
+
extras = dict(facts.extras) if facts.on_zerogpu else {}
|
| 609 |
live = facts.state != "refused"
|
| 610 |
lamps = []
|
| 611 |
if facts.stage_2_offered:
|
|
|
|
| 670 |
items = "".join(f"<li>{_e(p)}</li>" for p in facts.problems) or (
|
| 671 |
f"<li>{_e(facts.reason or 'This request would be refused.')}</li>"
|
| 672 |
)
|
| 673 |
+
held = (
|
| 674 |
+
" Nothing is reserved for a request that would be refused."
|
| 675 |
+
if facts.on_zerogpu
|
| 676 |
+
else " Generate stays off until this is fixed."
|
| 677 |
+
)
|
| 678 |
body = (
|
| 679 |
'<div class="mr-wont-run" role="note">'
|
| 680 |
'<p class="mr-wont-run-head"><span class="mr-lamp mr-lamp-cut is-lit">Won’t run</span>'
|
| 681 |
+
f"{held}</p>"
|
| 682 |
f"<ul>{items}</ul></div>"
|
| 683 |
)
|
| 684 |
return f'<section class="mr-cost is-refused" aria-label="Cost of this run">{head}{body}</section>'
|
|
|
|
| 693 |
if facts.stage_2:
|
| 694 |
returns += ", upscaled ×2"
|
| 695 |
rows.append(("Returns", returns))
|
| 696 |
+
if not facts.on_zerogpu:
|
| 697 |
+
rows.append(("Runs", f"{_e(where_it_runs(facts.device))}; nothing is metered"))
|
| 698 |
+
else:
|
| 699 |
+
if facts.reserve is not None:
|
| 700 |
+
reserve = f"{_figure(facts.reserve)} s of GPU time"
|
| 701 |
+
if facts.extras:
|
| 702 |
+
parts = [f"{facts.base} s base"] + [f"{s} s for {n}" for n, s in facts.extras]
|
| 703 |
+
reserve += f' <span class="mr-sub">({_e(" + ".join(parts))})</span>'
|
| 704 |
+
rows.append(("Reserves", reserve))
|
| 705 |
+
rows.append(
|
| 706 |
+
("Needs", f"{_figure(facts.reserve * facts.multiplier)} s of quota free to start")
|
| 707 |
+
)
|
| 708 |
+
rows.append(
|
| 709 |
+
(
|
| 710 |
+
"Billed",
|
| 711 |
+
f"for GPU time used × {facts.multiplier}; runs that fail on the GPU are billed too",
|
| 712 |
+
)
|
| 713 |
)
|
|
|
|
| 714 |
rows.append(("LoRA", _lora_words(facts.loras)))
|
| 715 |
if facts.seed is not None and facts.seed >= 0:
|
| 716 |
rows.append(("Seed", f"{_num(facts.seed)} (fixed)"))
|
| 717 |
grid = "".join(f"<dt>{_e(label)}</dt><dd>{value}</dd>" for label, value in rows)
|
| 718 |
notes = ""
|
| 719 |
if facts.discards_video:
|
| 720 |
+
spent = (
|
| 721 |
+
"you pay for that GPU time."
|
| 722 |
+
if facts.on_zerogpu
|
| 723 |
+
else "the run takes the time to render it."
|
| 724 |
+
)
|
| 725 |
notes += (
|
| 726 |
+
f'<p class="mr-cost-note">A 256 × 256 video is rendered and thrown away; {spent}</p>'
|
|
|
|
| 727 |
)
|
| 728 |
if facts.encodes_audio:
|
| 729 |
notes += (
|
|
|
|
| 771 |
parts.append(f"{facts.auto_seconds[0]:g}–{facts.auto_seconds[1]:g} s")
|
| 772 |
elif facts.seconds is not None:
|
| 773 |
parts.append(_seconds(facts.seconds))
|
| 774 |
+
if not facts.on_zerogpu:
|
| 775 |
+
parts.append(where_it_runs(facts.device))
|
| 776 |
+
elif facts.reserve is not None:
|
| 777 |
parts.append(f"needs {facts.reserve * facts.multiplier} s quota")
|
| 778 |
return ", ".join(parts)
|
| 779 |
|
|
|
|
| 925 |
)
|
| 926 |
|
| 927 |
|
| 928 |
+
def lora_heading(cap: str, *, on_zerogpu: bool = True) -> str:
|
| 929 |
+
if not on_zerogpu:
|
| 930 |
+
return (
|
| 931 |
+
f"Add a LoRA from the Hub or upload a .safetensors file (up to {cap}). It is "
|
| 932 |
+
"checked against LTX-2.5's layers before anything runs. The last check, that it "
|
| 933 |
+
"attaches, runs when you generate; if that fails, the run stops there."
|
| 934 |
+
)
|
| 935 |
return (
|
| 936 |
f"Add a LoRA from the Hub or upload a .safetensors file (up to {cap}). It is checked "
|
| 937 |
"against LTX-2.5's layers before any GPU time is used. The last check, that it "
|
|
|
|
| 1084 |
f"**Enhancing your prompt: {mode.label}.** Gemma rewrites it on this machine "
|
| 1085 |
f"first, then generation starts. The prompt actually sent is in the report."
|
| 1086 |
)
|
| 1087 |
+
return f"**Running: {mode.label}.** Loading, sampling and decoding {where_it_runs(device)}."
|
|
|
|
| 1088 |
if enhancing:
|
| 1089 |
return (
|
| 1090 |
f"**Enhancing your prompt: {mode.label}.** Gemma rewrites it on the GPU first, "
|
|
|
|
| 1127 |
quota_multiplier: int = 1
|
| 1128 |
|
| 1129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1130 |
def took_words(facts: RunFacts) -> str:
|
| 1131 |
""" "Took N s", labelled by the device that ran it; on ZeroGPU, with the quota it drew."""
|
| 1132 |
seconds = round(float(facts.took))
|
|
|
|
| 1221 |
)
|
| 1222 |
|
| 1223 |
|
| 1224 |
+
def lost_run(detail: str | None = None, *, on_zerogpu: bool = True) -> str:
|
| 1225 |
"""The generation step ended without a result this page can show.
|
| 1226 |
|
| 1227 |
+
``detail`` is the server's own message, when it raised one. The billing sentence is
|
| 1228 |
+
ZeroGPU's alone.
|
| 1229 |
"""
|
| 1230 |
+
billed = "Any GPU time this run used is billed. " if on_zerogpu else ""
|
| 1231 |
return (
|
| 1232 |
"### The run ended without a result\n\n"
|
| 1233 |
+
f"{billed}Press Generate again. If it happens again, report it with the detail "
|
| 1234 |
+
"below.\n\n" + _detail(detail)
|
| 1235 |
)
|
| 1236 |
|
| 1237 |
|
|
|
|
| 1249 |
)
|
| 1250 |
|
| 1251 |
|
| 1252 |
+
def empty_output_bug(mode: Any, missing: list[str], *, on_zerogpu: bool = True) -> str:
|
| 1253 |
"""A run reported success and produced no file. That is a bug in this app."""
|
| 1254 |
tracks = " and ".join(missing)
|
| 1255 |
+
billed = " The GPU time it used is billed." if on_zerogpu else ""
|
| 1256 |
return (
|
| 1257 |
"### The run finished but produced no file\n\n"
|
| 1258 |
f"{mode.label} reported success without a {tracks} file, which this app treats as a "
|
| 1259 |
+
f"bug.{billed} Nothing shown here is from this run. Report it, with the time of the "
|
| 1260 |
+
"run, so it can be fixed."
|
| 1261 |
)
|
| 1262 |
|
| 1263 |
|
|
|
|
| 1304 |
"The run did not finish",
|
| 1305 |
"Press Generate again. If it happens again, report it with the detail below.",
|
| 1306 |
)
|
| 1307 |
+
#: Cards about the platform's meter. Off ZeroGPU there is none, so such a failure (it
|
| 1308 |
+
#: cannot come from a local run) gets the generic card.
|
| 1309 |
+
_METER_CARDS = ("quota", "limit")
|
| 1310 |
#: Cards whose detail opens by itself: the detail holds the numbers to change.
|
| 1311 |
_OPEN_DETAIL = ("input", "quota", "limit")
|
| 1312 |
|
| 1313 |
|
| 1314 |
+
def failure(exc: BaseException, *, refused: bool = False, on_zerogpu: bool = True) -> str:
|
| 1315 |
"""Any failure, rendered loudly: headline, quota line, one next step, detail.
|
| 1316 |
|
| 1317 |
The category and whether GPU time was used come from ``errors.categorise``.
|
| 1318 |
``refused`` is set when this page turned the request down before calling
|
| 1319 |
+
the backend at all, which is known to have used no GPU time. The quota line is
|
| 1320 |
+
ZeroGPU's; where nothing is metered a card says only that nothing ran, when it was
|
| 1321 |
+
refused before running.
|
| 1322 |
"""
|
| 1323 |
detail = str(exc).strip() or "No detail was attached to the error."
|
| 1324 |
found = errors.categorise(exc)
|
|
|
|
| 1328 |
# A queue timeout: nothing ran, so it is not "out of GPU time".
|
| 1329 |
category = "queue"
|
| 1330 |
headline, step = _CARDS.get(category, _GENERIC_CARD)
|
| 1331 |
+
if not on_zerogpu and category in _METER_CARDS:
|
| 1332 |
+
headline, step = _GENERIC_CARD
|
| 1333 |
if category == "input" and not gpu_used:
|
| 1334 |
headline = "Refused before running: fix the input"
|
| 1335 |
+
if on_zerogpu:
|
| 1336 |
+
quota = (
|
| 1337 |
+
"Any GPU time this run used is billed."
|
| 1338 |
+
if gpu_used
|
| 1339 |
+
else "Nothing ran. No GPU time was used."
|
| 1340 |
+
)
|
| 1341 |
+
else:
|
| 1342 |
+
quota = "Nothing ran." if refused or (category == "input" and not gpu_used) else ""
|
| 1343 |
opened = " open" if category in _OPEN_DETAIL else ""
|
| 1344 |
return (
|
| 1345 |
f"### {headline}\n\n"
|
| 1346 |
+
f"{quota + ' ' if quota else ''}{step}\n\n"
|
| 1347 |
f'<details class="mr-detail"{opened}><summary>Detail</summary>'
|
| 1348 |
f"<p>{_e(detail)}</p></details>"
|
| 1349 |
)
|
|
@@ -140,17 +140,33 @@ def test_the_enhance_label_states_the_reservation_and_the_cold_start(mode_id):
|
|
| 140 |
)
|
| 141 |
|
| 142 |
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
from test_ui_form import Form
|
| 145 |
|
|
|
|
| 146 |
from ltx25_studio.ui import build_ui
|
| 147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
form = Form(build_ui())
|
| 149 |
enhance = form.fields["enhance_prompt"]
|
| 150 |
for mode_id in ("text_to_video", "image_text_to_audio_video", "audio_to_video"):
|
| 151 |
form.pick_mode(mode_id)
|
| 152 |
-
expected = render.enhance_info(
|
|
|
|
|
|
|
| 153 |
assert form.props[enhance._id]["info"] == expected, mode_id
|
|
|
|
| 154 |
|
| 155 |
|
| 156 |
# --------------------------------------------------------------------------
|
|
|
|
| 140 |
)
|
| 141 |
|
| 142 |
|
| 143 |
+
@pytest.mark.parametrize("space", [True, False], ids=["on ZeroGPU", "off ZeroGPU"])
|
| 144 |
+
def test_the_enhance_label_follows_the_mode(tmp_path, monkeypatch, space):
|
| 145 |
+
import sys
|
| 146 |
+
import types
|
| 147 |
+
|
| 148 |
from test_ui_form import Form
|
| 149 |
|
| 150 |
+
from ltx25_studio import config
|
| 151 |
from ltx25_studio.ui import build_ui
|
| 152 |
|
| 153 |
+
monkeypatch.delenv(config.ENV_DEVICE, raising=False)
|
| 154 |
+
if space:
|
| 155 |
+
module = types.ModuleType("spaces")
|
| 156 |
+
module.GPU = lambda *a, **k: lambda f: f
|
| 157 |
+
monkeypatch.setitem(sys.modules, "spaces", module)
|
| 158 |
+
else:
|
| 159 |
+
monkeypatch.delitem(sys.modules, "spaces", raising=False)
|
| 160 |
+
assert handlers.run_platform()[1] is space
|
| 161 |
form = Form(build_ui())
|
| 162 |
enhance = form.fields["enhance_prompt"]
|
| 163 |
for mode_id in ("text_to_video", "image_text_to_audio_video", "audio_to_video"):
|
| 164 |
form.pick_mode(mode_id)
|
| 165 |
+
expected = render.enhance_info(
|
| 166 |
+
modes.get_mode(mode_id), zerogpu.ENHANCE_DURATION_SECONDS, on_zerogpu=space
|
| 167 |
+
)
|
| 168 |
assert form.props[enhance._id]["info"] == expected, mode_id
|
| 169 |
+
assert ("Reserves" in expected) is space
|
| 170 |
|
| 171 |
|
| 172 |
# --------------------------------------------------------------------------
|
|
@@ -8,17 +8,23 @@
|
|
| 8 |
their nearest legal values, no figure, and Generate stays off with the same
|
| 9 |
words the server would use (B3, AC-09, readiness);
|
| 10 |
* the sound-only modes say they pay for a thrown-away video (AC-11).
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
"""
|
| 12 |
|
| 13 |
from __future__ import annotations
|
| 14 |
|
| 15 |
import re
|
|
|
|
|
|
|
| 16 |
|
| 17 |
import pytest
|
| 18 |
from conftest import image_input, inputs_for
|
| 19 |
|
|
|
|
| 20 |
from ltx25_studio import generate as generate_module
|
| 21 |
-
from ltx25_studio import modes, zerogpu
|
| 22 |
from ltx25_studio.errors import MissingInputError
|
| 23 |
from ltx25_studio.ui import handlers, render
|
| 24 |
from ltx25_studio.ui.fields import FIELDS
|
|
@@ -26,6 +32,16 @@ from ltx25_studio.ui.fields import FIELDS
|
|
| 26 |
MODE_IDS = tuple(modes.MODES)
|
| 27 |
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
def form(mode_id: str, **overrides) -> dict:
|
| 30 |
values = {spec.key: spec.default for spec in FIELDS}
|
| 31 |
values |= inputs_for(mode_id)
|
|
|
|
| 8 |
their nearest legal values, no figure, and Generate stays off with the same
|
| 9 |
words the server would use (B3, AC-09, readiness);
|
| 10 |
* the sound-only modes say they pay for a thrown-away video (AC-11).
|
| 11 |
+
|
| 12 |
+
These are the Space's words: the module runs as the Space does, with the platform package
|
| 13 |
+
imported (the stand-in ``spaces`` module). Off ZeroGPU the panel speaks of no meter at all;
|
| 14 |
+
``test_ui_device_words.py`` pins that.
|
| 15 |
"""
|
| 16 |
|
| 17 |
from __future__ import annotations
|
| 18 |
|
| 19 |
import re
|
| 20 |
+
import sys
|
| 21 |
+
import types
|
| 22 |
|
| 23 |
import pytest
|
| 24 |
from conftest import image_input, inputs_for
|
| 25 |
|
| 26 |
+
from ltx25_studio import config, modes, zerogpu
|
| 27 |
from ltx25_studio import generate as generate_module
|
|
|
|
| 28 |
from ltx25_studio.errors import MissingInputError
|
| 29 |
from ltx25_studio.ui import handlers, render
|
| 30 |
from ltx25_studio.ui.fields import FIELDS
|
|
|
|
| 32 |
MODE_IDS = tuple(modes.MODES)
|
| 33 |
|
| 34 |
|
| 35 |
+
@pytest.fixture(autouse=True)
|
| 36 |
+
def on_zerogpu(monkeypatch):
|
| 37 |
+
"""This process on ZeroGPU: the platform package is imported (``app.py`` does it first)."""
|
| 38 |
+
module = types.ModuleType("spaces")
|
| 39 |
+
module.GPU = lambda *a, **k: lambda f: f
|
| 40 |
+
monkeypatch.setitem(sys.modules, "spaces", module)
|
| 41 |
+
monkeypatch.delenv(config.ENV_DEVICE, raising=False)
|
| 42 |
+
assert handlers.run_platform() == ("cuda", True)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
def form(mode_id: str, **overrides) -> dict:
|
| 46 |
values = {spec.key: spec.default for spec in FIELDS}
|
| 47 |
values |= inputs_for(mode_id)
|
|
@@ -0,0 +1,368 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""One device rule for every quota sentence (F75).
|
| 2 |
+
|
| 3 |
+
The lead's real-weights session on a Mac read "Reserves 180 s of GPU time", "Needs 360 s of quota
|
| 4 |
+
free to start", "Billed for GPU time used × 2", "you pay for that GPU time" and "Any GPU time this
|
| 5 |
+
run used is billed": none of it is true off ZeroGPU. Where the app is not on ZeroGPU nothing the
|
| 6 |
+
page shows speaks of reserving, quota, billing or paying; on ZeroGPU every sentence stays as it
|
| 7 |
+
was (the other UI tests pin them under the stand-in ``spaces`` module, as here).
|
| 8 |
+
|
| 9 |
+
The platform is resolved as ``app.py`` resolves it (``device.current()``): the stand-in platform
|
| 10 |
+
package in ``sys.modules`` for ZeroGPU; ``LTX25_DEVICE`` and the CUDA probe for everything else.
|
| 11 |
+
Every string is taken from where the page gets it: the built Blocks walked through all eleven
|
| 12 |
+
modes, ``handlers.review`` with each lever on, the start step, ``handlers.run`` through the real
|
| 13 |
+
``generate()`` (GPU seams faked), and the finish step's reports.
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
from __future__ import annotations
|
| 17 |
+
|
| 18 |
+
import re
|
| 19 |
+
import sys
|
| 20 |
+
import types
|
| 21 |
+
from dataclasses import replace
|
| 22 |
+
|
| 23 |
+
import pytest
|
| 24 |
+
from conftest import inputs_for
|
| 25 |
+
|
| 26 |
+
from ltx25_studio import config, device, errors, modes, zerogpu
|
| 27 |
+
from ltx25_studio import generate as generate_module
|
| 28 |
+
from ltx25_studio.ui import handlers, render
|
| 29 |
+
from ltx25_studio.ui.fields import FIELD_KEYS, FIELDS
|
| 30 |
+
|
| 31 |
+
gr = pytest.importorskip("gradio", reason="gradio is a declared dev dependency")
|
| 32 |
+
|
| 33 |
+
MODE_IDS = tuple(modes.MODES)
|
| 34 |
+
#: The words of a meter (the brief's list): none may appear off ZeroGPU.
|
| 35 |
+
METER_WORDS = ("quota", "reserv", "billed", "bill", "pay")
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def visible(markup) -> str:
|
| 39 |
+
"""Text a user sees: closed <details> bodies and tags removed, entities read."""
|
| 40 |
+
import html
|
| 41 |
+
|
| 42 |
+
markup = re.sub(r"<details(?![^>]*\bopen\b)[^>]*>.*?</details>", "", str(markup), flags=re.S)
|
| 43 |
+
return html.unescape(" ".join(re.sub(r"<[^>]+>", " ", markup).split()))
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def meter_words(texts) -> list[tuple[str, str]]:
|
| 47 |
+
found = []
|
| 48 |
+
for text in texts:
|
| 49 |
+
words = visible(text).lower()
|
| 50 |
+
found += [(word, visible(text)[:160]) for word in METER_WORDS if word in words]
|
| 51 |
+
return found
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
# --------------------------------------------------------------------------
|
| 55 |
+
# the platforms
|
| 56 |
+
# --------------------------------------------------------------------------
|
| 57 |
+
|
| 58 |
+
LOCAL = ("cpu", "mps", "cuda")
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
@pytest.fixture
|
| 62 |
+
def no_examples(tmp_path, monkeypatch):
|
| 63 |
+
"""No shipped manifest: these tests read the page's own words only."""
|
| 64 |
+
from ltx25_studio.ui import showcase
|
| 65 |
+
|
| 66 |
+
monkeypatch.setenv(showcase.EXAMPLES_ENV, str(tmp_path / "no-examples"))
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
@pytest.fixture
|
| 70 |
+
def platform(monkeypatch, no_examples):
|
| 71 |
+
"""``platform("cpu" | "mps" | "cuda" | "zerogpu")``: this process as app.py resolves it."""
|
| 72 |
+
|
| 73 |
+
def on(name: str) -> None:
|
| 74 |
+
monkeypatch.delitem(sys.modules, "spaces", raising=False)
|
| 75 |
+
monkeypatch.delenv(config.ENV_DEVICE, raising=False)
|
| 76 |
+
monkeypatch.setattr(device, "host_has_mps", lambda: name == "mps")
|
| 77 |
+
monkeypatch.setattr(zerogpu, "host_has_cuda", lambda: name == "cuda")
|
| 78 |
+
if name == "zerogpu":
|
| 79 |
+
module = types.ModuleType("spaces")
|
| 80 |
+
module.GPU = lambda *a, **k: lambda f: f
|
| 81 |
+
monkeypatch.setitem(sys.modules, "spaces", module)
|
| 82 |
+
elif name in ("cpu", "mps"):
|
| 83 |
+
monkeypatch.setenv(config.ENV_DEVICE, name)
|
| 84 |
+
found = handlers.run_platform()
|
| 85 |
+
expected = ("cuda", True) if name == "zerogpu" else (name, False)
|
| 86 |
+
assert found == expected, f"the stand-in platform resolved as {found}"
|
| 87 |
+
|
| 88 |
+
return on
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
@pytest.fixture
|
| 92 |
+
def staged_lora(tmp_path):
|
| 93 |
+
from lora_fixtures import good_adapter
|
| 94 |
+
|
| 95 |
+
path = good_adapter(tmp_path)
|
| 96 |
+
return [{"source": "org/adapter", "path": str(path), "weight": 0.8, "content_key": "k"}]
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
@pytest.fixture
|
| 100 |
+
def wired(monkeypatch, tmp_path):
|
| 101 |
+
"""``generate()`` is the real one; only the GPU seams are fakes."""
|
| 102 |
+
from test_exports_contract import FakePipe, factory_returning, one_muxed_file_encoder
|
| 103 |
+
|
| 104 |
+
real = generate_module.generate
|
| 105 |
+
|
| 106 |
+
def generate(**params):
|
| 107 |
+
return real(
|
| 108 |
+
pipeline_factory=factory_returning(FakePipe()),
|
| 109 |
+
encoder=one_muxed_file_encoder,
|
| 110 |
+
output_root=tmp_path / "runs",
|
| 111 |
+
retention_bytes=10**9,
|
| 112 |
+
**params,
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
monkeypatch.setattr(generate_module, "generate", generate)
|
| 116 |
+
return generate
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def form_values(mode_id: str, **overrides) -> dict:
|
| 120 |
+
return {spec.key: spec.default for spec in FIELDS} | inputs_for(mode_id) | overrides
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
LEVERS = {
|
| 124 |
+
"plain": {},
|
| 125 |
+
"upscale": {"enable_stage_2": True},
|
| 126 |
+
"enhance": {"enhance_prompt": True, "prompt": "a harbour at dawn"},
|
| 127 |
+
"lora": {"loras": "staged"},
|
| 128 |
+
"all": {"enable_stage_2": True, "enhance_prompt": True, "prompt": "a harbour", "loras": "staged"},
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
def lever_values(mode_id: str, lever: str, staged: list) -> dict:
|
| 133 |
+
values = form_values(mode_id)
|
| 134 |
+
for key, value in LEVERS[lever].items():
|
| 135 |
+
if key == "prompt" and not modes.accepts(modes.get_mode(mode_id), "text"):
|
| 136 |
+
continue
|
| 137 |
+
values[key] = staged if value == "staged" else value
|
| 138 |
+
return values
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def page_strings(demo) -> list[str]:
|
| 142 |
+
"""Everything the built page holds for a user to read, in every mode: values, labels,
|
| 143 |
+
info lines, placeholders and choices of every component, the switch run between modes."""
|
| 144 |
+
from test_ui_form import Form
|
| 145 |
+
|
| 146 |
+
form = Form(demo)
|
| 147 |
+
held: list[str] = []
|
| 148 |
+
|
| 149 |
+
def collect() -> None:
|
| 150 |
+
for block in demo.blocks.values():
|
| 151 |
+
props = form.props[block._id]
|
| 152 |
+
if props.get("visible") is False:
|
| 153 |
+
continue
|
| 154 |
+
words = (form.get(block), props.get("label"), props.get("info"), props.get("placeholder"))
|
| 155 |
+
held.extend(text for text in words if isinstance(text, str))
|
| 156 |
+
held.extend(str(choice) for choice in props.get("choices") or ())
|
| 157 |
+
|
| 158 |
+
collect()
|
| 159 |
+
for mode_id in MODE_IDS:
|
| 160 |
+
form.pick_mode(mode_id)
|
| 161 |
+
collect()
|
| 162 |
+
return held
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
# --------------------------------------------------------------------------
|
| 166 |
+
# off ZeroGPU: no meter anywhere
|
| 167 |
+
# --------------------------------------------------------------------------
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
@pytest.mark.parametrize("name", LOCAL)
|
| 171 |
+
def test_off_zerogpu_the_built_page_speaks_of_no_meter_in_any_mode(platform, name):
|
| 172 |
+
platform(name)
|
| 173 |
+
from ltx25_studio.ui import build_ui
|
| 174 |
+
|
| 175 |
+
demo = build_ui()
|
| 176 |
+
held = page_strings(demo)
|
| 177 |
+
assert meter_words(held) == [], meter_words(held)[:6]
|
| 178 |
+
identity = next(b for b in demo.blocks.values() if getattr(b, "elem_id", None) == "identity")
|
| 179 |
+
assert "How quota works" not in identity.value
|
| 180 |
+
assert "mr-quota" not in identity.value, "the disclosure is not on the page at all"
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
@pytest.mark.parametrize("name", LOCAL)
|
| 184 |
+
@pytest.mark.parametrize("mode_id", MODE_IDS)
|
| 185 |
+
def test_off_zerogpu_the_cost_panel_says_where_it_runs_with_each_lever(
|
| 186 |
+
platform, staged_lora, name, mode_id
|
| 187 |
+
):
|
| 188 |
+
platform(name)
|
| 189 |
+
where = {"cpu": "on the CPU", "mps": "on this Mac's GPU", "cuda": "on the GPU"}[name]
|
| 190 |
+
for lever in LEVERS:
|
| 191 |
+
facts = handlers.review(mode_id, lever_values(mode_id, lever, staged_lora))
|
| 192 |
+
texts = [
|
| 193 |
+
render.cost_panel(facts),
|
| 194 |
+
render.commit_line(facts),
|
| 195 |
+
render.readiness_reason(facts),
|
| 196 |
+
render.readiness_reason(facts, running=True),
|
| 197 |
+
]
|
| 198 |
+
assert meter_words(texts) == [], (lever, meter_words(texts))
|
| 199 |
+
panel = visible(render.cost_panel(facts))
|
| 200 |
+
for gone in ("Reserves", "Needs", "Billed", "+60 s", "+90 s", "+180 s"):
|
| 201 |
+
assert gone not in panel, (lever, gone, panel)
|
| 202 |
+
if facts.state != "refused":
|
| 203 |
+
assert f"Runs {where}" in panel and "nothing is metered" in panel, (lever, panel)
|
| 204 |
+
assert render.commit_line(facts).endswith(where) or facts.state == "incomplete"
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
@pytest.mark.parametrize("name", LOCAL)
|
| 208 |
+
def test_off_zerogpu_the_running_and_done_states_speak_of_no_meter(platform, wired, name):
|
| 209 |
+
platform(name)
|
| 210 |
+
from ltx25_studio.ui import blocks
|
| 211 |
+
|
| 212 |
+
demo = blocks.build_ui()
|
| 213 |
+
run = next(f for f in demo.fns.values() if f.api_name == "on_generate")
|
| 214 |
+
start = demo.fns[run.trigger_after]
|
| 215 |
+
texts = []
|
| 216 |
+
for mode_id in MODE_IDS:
|
| 217 |
+
mode = modes.get_mode(mode_id)
|
| 218 |
+
started = start.fn(mode_id, True, "a harbour at dawn")
|
| 219 |
+
texts += [v.get("value") if isinstance(v, dict) else v for v in started]
|
| 220 |
+
texts.append(render.monitor_caption(kind="running", mode=mode))
|
| 221 |
+
values = form_values("text_to_audio_video")
|
| 222 |
+
outcome = handlers.run("text_to_audio_video", *(values[k] for k in FIELD_KEYS))
|
| 223 |
+
assert outcome.error is None, outcome.status
|
| 224 |
+
facts = handlers.run_facts(outcome)
|
| 225 |
+
texts += [render.run_summary(facts), outcome.status, render.took_words(facts)]
|
| 226 |
+
texts += [render.monitor_caption(kind=k, mode=modes.get_mode("text_to_video"), seed=1) for k in ("run", "earlier", "failed", "refused", "unshown")]
|
| 227 |
+
found = meter_words([t for t in texts if isinstance(t, str)])
|
| 228 |
+
assert found == [], found[:6]
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
def _raising(monkeypatch, exc):
|
| 232 |
+
def generate(**_params):
|
| 233 |
+
raise exc
|
| 234 |
+
|
| 235 |
+
monkeypatch.setattr(generate_module, "generate", generate)
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
@pytest.mark.parametrize("name", LOCAL)
|
| 239 |
+
@pytest.mark.parametrize("category", [*errors.CATEGORIES, "a-category-the-ui-has-never-seen"])
|
| 240 |
+
@pytest.mark.parametrize("gpu_used", [True, False])
|
| 241 |
+
def test_off_zerogpu_every_failure_card_has_no_billing_sentence(
|
| 242 |
+
platform, monkeypatch, name, category, gpu_used
|
| 243 |
+
):
|
| 244 |
+
platform(name)
|
| 245 |
+
exc = errors.DecodeError(mode="text_to_video", reason="the words of the failure")
|
| 246 |
+
exc.category, exc.gpu_used = category, gpu_used
|
| 247 |
+
_raising(monkeypatch, exc)
|
| 248 |
+
values = form_values("text_to_video")
|
| 249 |
+
outcome = handlers.run("text_to_video", *(values[k] for k in FIELD_KEYS))
|
| 250 |
+
assert outcome.error is exc and outcome.status.startswith("### ")
|
| 251 |
+
assert meter_words([outcome.status]) == [], outcome.status
|
| 252 |
+
assert "the words of the failure" in outcome.status, "the detail is kept"
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
@pytest.mark.parametrize("name", LOCAL)
|
| 256 |
+
def test_off_zerogpu_a_refusal_lost_run_empty_file_and_unshown_result_bill_nothing(
|
| 257 |
+
platform, monkeypatch, wired, tmp_path, name
|
| 258 |
+
):
|
| 259 |
+
platform(name)
|
| 260 |
+
values = form_values("text_to_video", width=700)
|
| 261 |
+
refused = handlers.run("text_to_video", *(values[k] for k in FIELD_KEYS))
|
| 262 |
+
assert refused.refused and "Nothing ran." in refused.status
|
| 263 |
+
lost = handlers.unshown_report(None, "the server's message")
|
| 264 |
+
good_values = form_values("text_to_audio_video")
|
| 265 |
+
finished = handlers.run("text_to_audio_video", *(good_values[k] for k in FIELD_KEYS))
|
| 266 |
+
assert finished.error is None, finished.status
|
| 267 |
+
unshown = handlers.unshown_report(finished, "the server's message")
|
| 268 |
+
monkeypatch.setattr(
|
| 269 |
+
generate_module,
|
| 270 |
+
"generate",
|
| 271 |
+
lambda **_p: replace(finished.result, video_path=None, audio_path=None),
|
| 272 |
+
)
|
| 273 |
+
empty = handlers.run("text_to_audio_video", *(good_values[k] for k in FIELD_KEYS))
|
| 274 |
+
assert empty.status.startswith("### The run finished but produced no file")
|
| 275 |
+
texts = [refused.status, lost, unshown, empty.status]
|
| 276 |
+
assert meter_words(texts) == [], meter_words(texts)
|
| 277 |
+
|
| 278 |
+
|
| 279 |
+
# --------------------------------------------------------------------------
|
| 280 |
+
# on ZeroGPU: the Space's words, unchanged
|
| 281 |
+
# --------------------------------------------------------------------------
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
def test_on_zerogpu_the_panel_still_shows_reserves_needs_and_billed(platform, staged_lora):
|
| 285 |
+
platform("zerogpu")
|
| 286 |
+
from ltx25_studio.ui import build_ui
|
| 287 |
+
|
| 288 |
+
facts = handlers.review("text_to_audio_video", lever_values("text_to_audio_video", "all", staged_lora))
|
| 289 |
+
panel = visible(render.cost_panel(facts))
|
| 290 |
+
for words in ("Reserves", "of GPU time", "Needs", "of quota free to start", "Billed", "billed too"):
|
| 291 |
+
assert words in panel, words
|
| 292 |
+
lit = re.findall(r"(Upscale|Enhance|LoRA) \+(\d+) s", panel)
|
| 293 |
+
assert [name for name, _s in lit] == ["Upscale", "Enhance", "LoRA"], panel
|
| 294 |
+
assert render.commit_line(facts).endswith(f"needs {facts.reserve * facts.multiplier} s quota")
|
| 295 |
+
demo = build_ui()
|
| 296 |
+
identity = next(b for b in demo.blocks.values() if getattr(b, "elem_id", None) == "identity")
|
| 297 |
+
assert "How quota works" in identity.value
|
| 298 |
+
frame = next(b for b in demo.blocks.values() if getattr(b, "elem_id", None) == "matrix-frame")
|
| 299 |
+
for note in render.COLUMN_NOTES.values():
|
| 300 |
+
assert note in frame.value
|
| 301 |
+
enhance = next(b for b in demo.blocks.values() if getattr(b, "elem_id", None) == "enhance")
|
| 302 |
+
upscale = next(b for b in demo.blocks.values() if getattr(b, "elem_id", None) == "upscale")
|
| 303 |
+
assert "Reserves 180 s more" in enhance.info and "Reserves" in upscale.info
|
| 304 |
+
exc = errors.DecodeError(mode="text_to_video", reason="x")
|
| 305 |
+
assert "Any GPU time this run used is billed." in render.failure(exc)
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
def test_on_zerogpu_upscale_is_never_parked(platform):
|
| 309 |
+
platform("zerogpu")
|
| 310 |
+
facts = handlers.review("text_to_audio_video", form_values("text_to_audio_video"))
|
| 311 |
+
assert facts.upscale_refused is None
|
| 312 |
+
|
| 313 |
+
|
| 314 |
+
# --------------------------------------------------------------------------
|
| 315 |
+
# Upscale where this machine cannot run it: parked with the backend's own reason
|
| 316 |
+
# --------------------------------------------------------------------------
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
def _backend_refuses_upscale(mode_id: str, values: dict) -> str | None:
|
| 320 |
+
"""What the backend says about this request with Upscale on (its own gate)."""
|
| 321 |
+
request = generate_module.GenerationRequest(mode=mode_id, **(values | {"enable_stage_2": True}))
|
| 322 |
+
try:
|
| 323 |
+
generate_module.prepare_request(request)
|
| 324 |
+
except device.StageTwoNeedsCudaError as exc:
|
| 325 |
+
return str(exc)
|
| 326 |
+
except Exception: # noqa: BLE001 -- another refusal is not the device's
|
| 327 |
+
return None
|
| 328 |
+
return None
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
@pytest.mark.parametrize("name", ["cpu", "mps"])
|
| 332 |
+
@pytest.mark.parametrize(
|
| 333 |
+
("width", "height", "frames"),
|
| 334 |
+
[(704, 480, 121), (960, 544, 49), (64, 64, 9), (32, 32, 9), (64, 64, 17), (96, 64, 9)],
|
| 335 |
+
)
|
| 336 |
+
def test_upscale_is_parked_exactly_where_the_backend_refuses_it(platform, name, width, height, frames):
|
| 337 |
+
platform(name)
|
| 338 |
+
values = form_values("text_to_video", width=width, height=height, num_frames=frames)
|
| 339 |
+
facts = handlers.review("text_to_video", values)
|
| 340 |
+
refused = _backend_refuses_upscale("text_to_video", values)
|
| 341 |
+
assert (facts.upscale_refused is not None) == (refused is not None), (width, height, frames)
|
| 342 |
+
if refused:
|
| 343 |
+
where = {"cpu": "the CPU", "mps": "this Mac's GPU"}[name]
|
| 344 |
+
assert facts.upscale_refused == f"Upscale ×2 needs a CUDA GPU; this machine runs on {where}."
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
def test_on_the_cpu_the_built_page_parks_upscale_unticked_with_the_reason(platform):
|
| 348 |
+
platform("cpu")
|
| 349 |
+
from test_ui_form import Form
|
| 350 |
+
|
| 351 |
+
from ltx25_studio.ui import build_ui
|
| 352 |
+
|
| 353 |
+
form = Form(build_ui())
|
| 354 |
+
upscale = form.fields["enable_stage_2"]
|
| 355 |
+
form.pick_mode("text_to_video")
|
| 356 |
+
form.user(form.fields["prompt"], "a tram")
|
| 357 |
+
assert not form.interactive(upscale) and form.field("enable_stage_2") is False
|
| 358 |
+
assert "needs a CUDA GPU; this machine runs on the CPU" in form.props[upscale._id]["info"]
|
| 359 |
+
form.user(form.fields["width"], 64)
|
| 360 |
+
form.user(form.fields["height"], 64)
|
| 361 |
+
form.user(form.fields["num_frames"], 9)
|
| 362 |
+
assert form.interactive(upscale), "a size this machine can upscale frees the control"
|
| 363 |
+
form.user(upscale, True)
|
| 364 |
+
assert form.field("enable_stage_2") is True
|
| 365 |
+
form.user(form.fields["width"], 704)
|
| 366 |
+
assert not form.interactive(upscale) and form.field("enable_stage_2") is False, (
|
| 367 |
+
"a size it cannot upscale parks it again, unticked: Generate is never pressed into a refusal"
|
| 368 |
+
)
|
|
@@ -295,7 +295,9 @@ def test_a_declared_track_missing_from_a_success_renders_the_loud_error(
|
|
| 295 |
f"mode {mode_id!r} lost its {dropped} track and the handler still populated a player. "
|
| 296 |
f"Nothing from a broken run may reach the screen."
|
| 297 |
)
|
| 298 |
-
assert status == render.empty_output_bug(
|
|
|
|
|
|
|
| 299 |
f"mode {mode_id!r} lost its {dropped} track but the handler did not report it:\n\n{status}"
|
| 300 |
)
|
| 301 |
|
|
@@ -330,7 +332,9 @@ def test_an_empty_string_path_is_as_loud_as_a_missing_one(mode_id, dropped, wire
|
|
| 330 |
video, audio, status = handlers.on_generate(mode_id, *values_for(mode_id))
|
| 331 |
|
| 332 |
assert (video, audio) == (None, None)
|
| 333 |
-
assert status == render.empty_output_bug(
|
|
|
|
|
|
|
| 334 |
|
| 335 |
|
| 336 |
@pytest.mark.parametrize("mode_id", MODE_IDS)
|
|
|
|
| 295 |
f"mode {mode_id!r} lost its {dropped} track and the handler still populated a player. "
|
| 296 |
f"Nothing from a broken run may reach the screen."
|
| 297 |
)
|
| 298 |
+
assert status == render.empty_output_bug(
|
| 299 |
+
spec, [dropped], on_zerogpu=handlers.run_platform()[1]
|
| 300 |
+
), (
|
| 301 |
f"mode {mode_id!r} lost its {dropped} track but the handler did not report it:\n\n{status}"
|
| 302 |
)
|
| 303 |
|
|
|
|
| 332 |
video, audio, status = handlers.on_generate(mode_id, *values_for(mode_id))
|
| 333 |
|
| 334 |
assert (video, audio) == (None, None)
|
| 335 |
+
assert status == render.empty_output_bug(
|
| 336 |
+
spec, [dropped], on_zerogpu=handlers.run_platform()[1]
|
| 337 |
+
)
|
| 338 |
|
| 339 |
|
| 340 |
@pytest.mark.parametrize("mode_id", MODE_IDS)
|