Spaces:
Running on Zero
fix: a run off ZeroGPU says it loads, samples and decodes on this machine, not that it reserves GPU time from a quota
Browse filesWhile a run was in progress the report said "Reserving GPU time from your quota, then
loading, sampling and decoding." on every machine; on a Mac it said so through 208 s
of local work. There is no quota and no reservation anywhere but ZeroGPU.
The start step now asks where a run started in this process will run
(handlers.run_platform: the device helpers handlers already use to label "Took N s on
..." for a finished run) and passes it to the start message. On ZeroGPU the sentence
stays. Elsewhere it says only what happens: "Loading, sampling and decoding" on this
Mac's GPU, on the CPU, on the GPU (a CUDA box that is not a Space), or on this machine
when no device is resolved, the same words as the finished run's Took line. With Enhance
on, the local message says Gemma rewrites the prompt on this machine first, with no
reservation. A call that does not say where the run runs keeps the Space's sentence.
tests/test_ui_running_words.py drives the page's own start step with this process
resolved as app.py resolves it: a stand-in platform package for ZeroGPU (the sentence
stays), LTX25_DEVICE and the CUDA probe for cpu, mps, a local CUDA box and no device (no
quota, reservation or billing words). The six local cases fail at the parent commit.
- ltx25_studio/ui/blocks.py +5 -1
- ltx25_studio/ui/handlers.py +20 -3
- ltx25_studio/ui/render.py +17 -2
- tests/test_ui_running_words.py +128 -0
|
@@ -1211,6 +1211,10 @@ def build_ui() -> gr.Blocks:
|
|
| 1211 |
) -> list[Any]:
|
| 1212 |
_forget(request)
|
| 1213 |
mode = modes.get_mode(mode_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1214 |
return [
|
| 1215 |
gr.update(interactive=False, value="Generating…"),
|
| 1216 |
render.readiness_reason(
|
|
@@ -1221,7 +1225,7 @@ def build_ui() -> gr.Blocks:
|
|
| 1221 |
gr.update(value=None, visible=True),
|
| 1222 |
gr.update(value=None, visible=False),
|
| 1223 |
render.monitor_caption(kind="running", mode=mode),
|
| 1224 |
-
gr.update(value=
|
| 1225 |
gr.update(visible=False),
|
| 1226 |
gr.update(visible=False),
|
| 1227 |
gr.update(visible=False),
|
|
|
|
| 1211 |
) -> list[Any]:
|
| 1212 |
_forget(request)
|
| 1213 |
mode = modes.get_mode(mode_id)
|
| 1214 |
+
device, on_zerogpu = handlers.run_platform()
|
| 1215 |
+
starting = handlers.on_generate_start(
|
| 1216 |
+
mode_id, enhance, prompt, device=device, on_zerogpu=on_zerogpu
|
| 1217 |
+
)
|
| 1218 |
return [
|
| 1219 |
gr.update(interactive=False, value="Generating…"),
|
| 1220 |
render.readiness_reason(
|
|
|
|
| 1225 |
gr.update(value=None, visible=True),
|
| 1226 |
gr.update(value=None, visible=False),
|
| 1227 |
render.monitor_caption(kind="running", mode=mode),
|
| 1228 |
+
gr.update(value=starting, visible=True),
|
| 1229 |
gr.update(visible=False),
|
| 1230 |
gr.update(visible=False),
|
| 1231 |
gr.update(visible=False),
|
|
@@ -58,6 +58,7 @@ __all__ = [
|
|
| 58 |
"quota_multiplier",
|
| 59 |
"review",
|
| 60 |
"run",
|
|
|
|
| 61 |
"seconds_for_frames",
|
| 62 |
"unshown_report",
|
| 63 |
]
|
|
@@ -854,11 +855,27 @@ def on_lora_weight(staged: list[dict] | None, index: int, weight: Any) -> list[d
|
|
| 854 |
# ---------------------------------------------------------------------------
|
| 855 |
|
| 856 |
|
| 857 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 858 |
"""Shown the instant Generate is pressed, so the page is never silent.
|
| 859 |
|
| 860 |
Says the prompt is being enhanced only when it will be: the mode takes a
|
| 861 |
-
prompt and, when the prompt is passed, it is not empty.
|
|
|
|
|
|
|
|
|
|
| 862 |
"""
|
| 863 |
try:
|
| 864 |
mode = modes.get_mode(mode_id)
|
|
@@ -867,7 +884,7 @@ def on_generate_start(mode_id: str, enhance_prompt: Any = False, prompt: Any = N
|
|
| 867 |
enhancing = bool(enhance_prompt) and modes.accepts(mode, "text")
|
| 868 |
if prompt is not None:
|
| 869 |
enhancing = enhancing and bool(str(prompt).strip())
|
| 870 |
-
return render.running(mode, enhancing=enhancing)
|
| 871 |
|
| 872 |
|
| 873 |
@dataclass
|
|
|
|
| 58 |
"quota_multiplier",
|
| 59 |
"review",
|
| 60 |
"run",
|
| 61 |
+
"run_platform",
|
| 62 |
"seconds_for_frames",
|
| 63 |
"unshown_report",
|
| 64 |
]
|
|
|
|
| 855 |
# ---------------------------------------------------------------------------
|
| 856 |
|
| 857 |
|
| 858 |
+
def run_platform() -> tuple[str | None, bool]:
|
| 859 |
+
"""``(device, on ZeroGPU)`` for a run started in this process, as :func:`run_facts`
|
| 860 |
+
labels a finished one."""
|
| 861 |
+
return _run_device(None)
|
| 862 |
+
|
| 863 |
+
|
| 864 |
+
def on_generate_start(
|
| 865 |
+
mode_id: str,
|
| 866 |
+
enhance_prompt: Any = False,
|
| 867 |
+
prompt: Any = None,
|
| 868 |
+
*,
|
| 869 |
+
device: str | None = None,
|
| 870 |
+
on_zerogpu: bool = True,
|
| 871 |
+
) -> str:
|
| 872 |
"""Shown the instant Generate is pressed, so the page is never silent.
|
| 873 |
|
| 874 |
Says the prompt is being enhanced only when it will be: the mode takes a
|
| 875 |
+
prompt and, when the prompt is passed, it is not empty. ``device`` and
|
| 876 |
+
``on_zerogpu`` say where the run will run (the page passes
|
| 877 |
+
:func:`run_platform`); without them the words are the Space's, a
|
| 878 |
+
reservation from the user's quota.
|
| 879 |
"""
|
| 880 |
try:
|
| 881 |
mode = modes.get_mode(mode_id)
|
|
|
|
| 884 |
enhancing = bool(enhance_prompt) and modes.accepts(mode, "text")
|
| 885 |
if prompt is not None:
|
| 886 |
enhancing = enhancing and bool(str(prompt).strip())
|
| 887 |
+
return render.running(mode, enhancing=enhancing, on_zerogpu=on_zerogpu, device=device)
|
| 888 |
|
| 889 |
|
| 890 |
@dataclass
|
|
@@ -965,8 +965,23 @@ def lora_summary_label(applied: Sequence[dict]) -> str:
|
|
| 965 |
# ---------------------------------------------------------------------------
|
| 966 |
|
| 967 |
|
| 968 |
-
def running(
|
| 969 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 970 |
if enhancing:
|
| 971 |
return (
|
| 972 |
f"**Enhancing your prompt: {mode.label}.** Gemma rewrites it on the GPU first, "
|
|
|
|
| 965 |
# ---------------------------------------------------------------------------
|
| 966 |
|
| 967 |
|
| 968 |
+
def running(
|
| 969 |
+
mode: Any, *, enhancing: bool = False, on_zerogpu: bool = True, device: str | None = None
|
| 970 |
+
) -> str:
|
| 971 |
+
"""Shown the moment Generate is pressed, so the page is never silent.
|
| 972 |
+
|
| 973 |
+
On ZeroGPU a run first reserves GPU time from the user's quota. Anywhere else there is
|
| 974 |
+
no quota and no reservation: it loads, samples and decodes on this machine, on
|
| 975 |
+
``device`` when known (the words of :func:`took_words`).
|
| 976 |
+
"""
|
| 977 |
+
if not on_zerogpu:
|
| 978 |
+
if enhancing:
|
| 979 |
+
return (
|
| 980 |
+
f"**Enhancing your prompt: {mode.label}.** Gemma rewrites it on this machine "
|
| 981 |
+
f"first, then generation starts. The prompt actually sent is in the report."
|
| 982 |
+
)
|
| 983 |
+
where = _ON_DEVICE.get(str(device or ""), "on this machine")
|
| 984 |
+
return f"**Running: {mode.label}.** Loading, sampling and decoding {where}."
|
| 985 |
if enhancing:
|
| 986 |
return (
|
| 987 |
f"**Enhancing your prompt: {mode.label}.** Gemma rewrites it on the GPU first, "
|
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""While a run is in progress, the report says what is happening, where it runs.
|
| 2 |
+
|
| 3 |
+
On ZeroGPU a run first reserves GPU time from the user's quota, and the sentence says so.
|
| 4 |
+
Anywhere else there is no quota and no reservation, yet the lead's run on a Mac read
|
| 5 |
+
"Reserving GPU time from your quota" through 208 s of local work. There the sentence says
|
| 6 |
+
only what happens: loading, sampling and decoding on this machine, named by the device that
|
| 7 |
+
runs it, in the words the finished run's "Took" line uses.
|
| 8 |
+
|
| 9 |
+
Driven through the page's own start step, with this process resolved as ``app.py``
|
| 10 |
+
resolves it (``device.current()``): a stand-in platform package in ``sys.modules`` for
|
| 11 |
+
ZeroGPU, ``LTX25_DEVICE`` and the CUDA probe for everything else.
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
from __future__ import annotations
|
| 15 |
+
|
| 16 |
+
import sys
|
| 17 |
+
import types
|
| 18 |
+
|
| 19 |
+
import pytest
|
| 20 |
+
|
| 21 |
+
from ltx25_studio import config, device, modes, zerogpu
|
| 22 |
+
from ltx25_studio.ui import blocks, handlers, render
|
| 23 |
+
|
| 24 |
+
gr = pytest.importorskip("gradio", reason="gradio is a declared dev dependency")
|
| 25 |
+
|
| 26 |
+
MODE = "text_to_audio_video"
|
| 27 |
+
LABEL = modes.get_mode(MODE).label
|
| 28 |
+
SPACE_SENTENCE = "Reserving GPU time from your quota, then loading, sampling and decoding."
|
| 29 |
+
#: Words that belong to ZeroGPU's quota and reservation, never to a local run.
|
| 30 |
+
QUOTA_WORDS = ("quota", "reserv", "billed")
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
@pytest.fixture(scope="module")
|
| 34 |
+
def start():
|
| 35 |
+
"""The page's start step: the report it shows the instant Generate is pressed."""
|
| 36 |
+
demo = blocks.build_ui()
|
| 37 |
+
run = next(f for f in demo.fns.values() if f.api_name == "on_generate")
|
| 38 |
+
step = demo.fns[run.trigger_after]
|
| 39 |
+
status = next(b for b in demo.blocks.values() if getattr(b, "elem_id", None) == "run-status")
|
| 40 |
+
|
| 41 |
+
def started(*, enhance: bool = False, prompt: str = "a harbour at dawn") -> str:
|
| 42 |
+
out = step.fn(MODE, enhance, prompt)
|
| 43 |
+
return out[step.outputs.index(status)]["value"]
|
| 44 |
+
|
| 45 |
+
return started
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
@pytest.fixture
|
| 49 |
+
def local(monkeypatch):
|
| 50 |
+
"""This process off the Space (no platform package, no CUDA), on ``LTX25_DEVICE``."""
|
| 51 |
+
monkeypatch.delitem(sys.modules, "spaces", raising=False)
|
| 52 |
+
monkeypatch.setattr(zerogpu, "host_has_cuda", lambda: False)
|
| 53 |
+
monkeypatch.setattr(device, "host_has_mps", lambda: True)
|
| 54 |
+
|
| 55 |
+
def on(requested: str | None) -> None:
|
| 56 |
+
if requested is None:
|
| 57 |
+
monkeypatch.delenv(config.ENV_DEVICE, raising=False)
|
| 58 |
+
else:
|
| 59 |
+
monkeypatch.setenv(config.ENV_DEVICE, requested)
|
| 60 |
+
|
| 61 |
+
return on
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
@pytest.fixture
|
| 65 |
+
def space(monkeypatch):
|
| 66 |
+
"""This process on ZeroGPU: the platform package is imported (``app.py`` does it first)."""
|
| 67 |
+
module = types.ModuleType("spaces")
|
| 68 |
+
module.GPU = lambda *a, **k: lambda f: f
|
| 69 |
+
monkeypatch.setitem(sys.modules, "spaces", module)
|
| 70 |
+
monkeypatch.delenv(config.ENV_DEVICE, raising=False)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def test_on_zerogpu_the_sentence_stays(start, space):
|
| 74 |
+
assert start() == f"**Running: {LABEL}.** {SPACE_SENTENCE}"
|
| 75 |
+
assert "inside this run's reservation" in start(enhance=True)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
@pytest.mark.parametrize(
|
| 79 |
+
("requested", "where"),
|
| 80 |
+
[("cpu", "on the CPU"), ("mps", "on this Mac's GPU"), (None, "on this machine")],
|
| 81 |
+
)
|
| 82 |
+
def test_off_zerogpu_it_says_only_what_happens_on_this_machine(start, local, requested, where):
|
| 83 |
+
local(requested)
|
| 84 |
+
text = start()
|
| 85 |
+
assert text == f"**Running: {LABEL}.** Loading, sampling and decoding {where}."
|
| 86 |
+
for word in QUOTA_WORDS:
|
| 87 |
+
assert word not in text.lower(), f"a local run's report says {word!r}: {text}"
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def test_a_cuda_box_that_is_not_a_space_has_no_quota_either(start, local, monkeypatch):
|
| 91 |
+
monkeypatch.setattr(zerogpu, "host_has_cuda", lambda: True)
|
| 92 |
+
local(None)
|
| 93 |
+
text = start()
|
| 94 |
+
assert text.endswith("Loading, sampling and decoding on the GPU.")
|
| 95 |
+
assert "quota" not in text.lower()
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def test_off_zerogpu_enhancing_names_the_rewrite_and_no_reservation(start, local):
|
| 99 |
+
local("cpu")
|
| 100 |
+
text = start(enhance=True)
|
| 101 |
+
assert text.startswith(f"**Enhancing your prompt: {LABEL}.**")
|
| 102 |
+
assert "Gemma rewrites it on this machine first" in text
|
| 103 |
+
for word in QUOTA_WORDS:
|
| 104 |
+
assert word not in text.lower(), f"a local run's report says {word!r}: {text}"
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def test_the_finished_run_and_the_running_one_name_the_device_alike():
|
| 108 |
+
for name in ("cpu", "mps", "cuda"):
|
| 109 |
+
took = render.took_words(
|
| 110 |
+
render.RunFacts(
|
| 111 |
+
mode=modes.get_mode(MODE),
|
| 112 |
+
seed=1,
|
| 113 |
+
returned_size=None,
|
| 114 |
+
seconds=None,
|
| 115 |
+
stage_2=False,
|
| 116 |
+
loras=(),
|
| 117 |
+
took=3.0,
|
| 118 |
+
took_is_gpu=True,
|
| 119 |
+
device=name,
|
| 120 |
+
)
|
| 121 |
+
)
|
| 122 |
+
running = render.running(modes.get_mode(MODE), on_zerogpu=False, device=name)
|
| 123 |
+
assert running.endswith(took.split(" s ", 1)[1] + "."), (name, took, running)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def test_a_caller_that_does_not_say_where_gets_the_spaces_words():
|
| 127 |
+
"""The page always says (``run_platform``); a bare call keeps the Space's sentence."""
|
| 128 |
+
assert SPACE_SENTENCE in handlers.on_generate_start(MODE)
|