Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -427,6 +427,17 @@ def load_models() -> str | None:
|
|
| 427 |
print(f"[gen] loading {[c.name for c in blocks.expected_components]} from {MODEL_REPO} ...", flush=True)
|
| 428 |
pipe = blocks.init_pipeline(MODEL_REPO, components_manager=manager, collection="h3")
|
| 429 |
pipe.load_components(dtype=torch.bfloat16)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 430 |
pipe.transformer.set_attention_backend(ATTENTION)
|
| 431 |
|
| 432 |
# --- Diagnostic: dump the LoRA files' key names/shapes and the transformer's own shapes to the Space
|
|
@@ -696,6 +707,7 @@ def _generate(
|
|
| 696 |
maximize_gpu,
|
| 697 |
video_shift,
|
| 698 |
audio_shift,
|
|
|
|
| 699 |
sampler,
|
| 700 |
total_steps,
|
| 701 |
stage_from,
|
|
@@ -734,6 +746,15 @@ def _generate(
|
|
| 734 |
}
|
| 735 |
PIPE.transformer.set_adapters(list(active), weights=list(active.values()))
|
| 736 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 737 |
if PLACEMENT == "lazy":
|
| 738 |
PIPE.to("cuda")
|
| 739 |
elif PLACEMENT == "pack":
|
|
@@ -888,6 +909,7 @@ def generate(
|
|
| 888 |
semantic_bridge_alpha=0.10,
|
| 889 |
semantic_bridge_magnitude_match="per_token",
|
| 890 |
semantic_bridge_adapter="semantic_bridge_v1",
|
|
|
|
| 891 |
progress=gr.Progress(track_tqdm=True),
|
| 892 |
*,
|
| 893 |
advance: bool = False,
|
|
@@ -1037,6 +1059,7 @@ def generate(
|
|
| 1037 |
bool(maximize_gpu),
|
| 1038 |
float(video_shift),
|
| 1039 |
float(audio_shift),
|
|
|
|
| 1040 |
SAMPLERS.get(sampler, "euler"),
|
| 1041 |
int(target_steps) if stage_enabled else None,
|
| 1042 |
steps_done if advance else 0,
|
|
@@ -1394,42 +1417,22 @@ with gr.Blocks(title="PlagueKind · MiniMax-H3") as demo:
|
|
| 1394 |
value=DEFAULT_INTERPOLATION,
|
| 1395 |
info="MiniMax-H3 generates 24 fps; FILM synthesizes the frames in between.",
|
| 1396 |
)
|
| 1397 |
-
seed = gr.Number(label="Seed", value=42, precision=0)
|
| 1398 |
upsample = gr.Checkbox(
|
| 1399 |
label="Upsample prompt",
|
| 1400 |
value=False,
|
| 1401 |
info="Rewrite the prompt on the conditioner Space first, MiniMax's Context-IR style.",
|
| 1402 |
)
|
| 1403 |
-
with gr.Accordion("Semantic Bridge", open=False):
|
| 1404 |
-
gr.Markdown(
|
| 1405 |
-
"A small, independent adapter that nudges text conditioning toward better constraint "
|
| 1406 |
-
"adherence — left/right ordering, which hand holds what, material and reflection "
|
| 1407 |
-
"correctness — without touching the video transformer. Runs on the conditioner Space. "
|
| 1408 |
-
"Experimental; may help some prompts, do little on others."
|
| 1409 |
-
)
|
| 1410 |
-
semantic_bridge = gr.Checkbox(label="Enable Semantic Bridge", value=False)
|
| 1411 |
-
semantic_bridge_alpha = gr.Slider(
|
| 1412 |
-
label="alpha", minimum=0.0, maximum=1.0, step=0.01, value=0.10, visible=False
|
| 1413 |
-
)
|
| 1414 |
-
semantic_bridge_magnitude_match = gr.Dropdown(
|
| 1415 |
-
label="magnitude_match",
|
| 1416 |
-
choices=["per_token", "global", "none"],
|
| 1417 |
-
value="per_token",
|
| 1418 |
-
visible=False,
|
| 1419 |
-
)
|
| 1420 |
-
semantic_bridge_adapter = gr.Dropdown(
|
| 1421 |
-
label="adapter",
|
| 1422 |
-
choices=["semantic_bridge_v1", "bunny_action_logic_v1"],
|
| 1423 |
-
value="semantic_bridge_v1",
|
| 1424 |
-
visible=False,
|
| 1425 |
-
info="semantic_bridge_v1: broad (composition, spatial, materials). "
|
| 1426 |
-
"bunny_action_logic_v1: action/combat, character-action ownership in multi-character scenes.",
|
| 1427 |
-
)
|
| 1428 |
maximize_gpu = gr.Checkbox(
|
| 1429 |
label="Maximize Free Tier ZeroGPU (150 seconds)",
|
| 1430 |
value=False,
|
| 1431 |
info="Forces this request to book exactly 140s (plus 8s on the conditioner) for debugging purposes; does not prevent timeouts.",
|
| 1432 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1433 |
|
| 1434 |
with gr.Column():
|
| 1435 |
video = gr.Video(label="Video + soundtrack", elem_id="h3-generated-video")
|
|
@@ -1572,7 +1575,33 @@ with gr.Blocks(title="PlagueKind · MiniMax-H3") as demo:
|
|
| 1572 |
)
|
| 1573 |
advance_btn = gr.Button("Advance", variant="secondary", visible=False)
|
| 1574 |
|
| 1575 |
-
with gr.Accordion("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1576 |
gr.Markdown(
|
| 1577 |
"Splits a longer product into independent, full-quality chunks joined afterward — each "
|
| 1578 |
"press is a complete generation, not a partial one. The previous chunk's last frame carries "
|
|
@@ -1676,6 +1705,7 @@ with gr.Blocks(title="PlagueKind · MiniMax-H3") as demo:
|
|
| 1676 |
semantic_bridge_alpha,
|
| 1677 |
semantic_bridge_magnitude_match,
|
| 1678 |
semantic_bridge_adapter,
|
|
|
|
| 1679 |
]
|
| 1680 |
|
| 1681 |
# `functools.partial` binds `advance`/`chunk_advance` by keyword regardless of their position in `generate`'s
|
|
|
|
| 427 |
print(f"[gen] loading {[c.name for c in blocks.expected_components]} from {MODEL_REPO} ...", flush=True)
|
| 428 |
pipe = blocks.init_pipeline(MODEL_REPO, components_manager=manager, collection="h3")
|
| 429 |
pipe.load_components(dtype=torch.bfloat16)
|
| 430 |
+
|
| 431 |
+
import h3_eros
|
| 432 |
+
|
| 433 |
+
eros_status = h3_eros.apply_eros(pipe.transformer)
|
| 434 |
+
if eros_status:
|
| 435 |
+
print(f"[gen] {eros_status}", flush=True)
|
| 436 |
+
|
| 437 |
+
import h3_proj_cache
|
| 438 |
+
|
| 439 |
+
h3_proj_cache.patch(pipe.transformer)
|
| 440 |
+
|
| 441 |
pipe.transformer.set_attention_backend(ATTENTION)
|
| 442 |
|
| 443 |
# --- Diagnostic: dump the LoRA files' key names/shapes and the transformer's own shapes to the Space
|
|
|
|
| 707 |
maximize_gpu,
|
| 708 |
video_shift,
|
| 709 |
audio_shift,
|
| 710 |
+
proj_cache,
|
| 711 |
sampler,
|
| 712 |
total_steps,
|
| 713 |
stage_from,
|
|
|
|
| 746 |
}
|
| 747 |
PIPE.transformer.set_adapters(list(active), weights=list(active.values()))
|
| 748 |
|
| 749 |
+
# Toggled per request, not patched per-call: `h3_proj_cache.patch` wrapped `forward` once in `load_models()`,
|
| 750 |
+
# and this just flips the attribute that wrapped method checks. `MOMENTUM_PIPE.transformer` is the same
|
| 751 |
+
# object as `PIPE.transformer` (see `load_models()`'s `update_components` call), so this covers the
|
| 752 |
+
# momentum path too, regardless of which `active_pipe` ends up running below. Called unconditionally, same
|
| 753 |
+
# reasoning as `set_adapters` above.
|
| 754 |
+
import h3_proj_cache
|
| 755 |
+
|
| 756 |
+
h3_proj_cache.set_enabled(PIPE.transformer, proj_cache)
|
| 757 |
+
|
| 758 |
if PLACEMENT == "lazy":
|
| 759 |
PIPE.to("cuda")
|
| 760 |
elif PLACEMENT == "pack":
|
|
|
|
| 909 |
semantic_bridge_alpha=0.10,
|
| 910 |
semantic_bridge_magnitude_match="per_token",
|
| 911 |
semantic_bridge_adapter="semantic_bridge_v1",
|
| 912 |
+
proj_cache=True,
|
| 913 |
progress=gr.Progress(track_tqdm=True),
|
| 914 |
*,
|
| 915 |
advance: bool = False,
|
|
|
|
| 1059 |
bool(maximize_gpu),
|
| 1060 |
float(video_shift),
|
| 1061 |
float(audio_shift),
|
| 1062 |
+
bool(proj_cache),
|
| 1063 |
SAMPLERS.get(sampler, "euler"),
|
| 1064 |
int(target_steps) if stage_enabled else None,
|
| 1065 |
steps_done if advance else 0,
|
|
|
|
| 1417 |
value=DEFAULT_INTERPOLATION,
|
| 1418 |
info="MiniMax-H3 generates 24 fps; FILM synthesizes the frames in between.",
|
| 1419 |
)
|
|
|
|
| 1420 |
upsample = gr.Checkbox(
|
| 1421 |
label="Upsample prompt",
|
| 1422 |
value=False,
|
| 1423 |
info="Rewrite the prompt on the conditioner Space first, MiniMax's Context-IR style.",
|
| 1424 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1425 |
maximize_gpu = gr.Checkbox(
|
| 1426 |
label="Maximize Free Tier ZeroGPU (150 seconds)",
|
| 1427 |
value=False,
|
| 1428 |
info="Forces this request to book exactly 140s (plus 8s on the conditioner) for debugging purposes; does not prevent timeouts.",
|
| 1429 |
)
|
| 1430 |
+
proj_cache = gr.Checkbox(
|
| 1431 |
+
label="Cache keyframe projection",
|
| 1432 |
+
value=True,
|
| 1433 |
+
info="Skips recomputing the unchanging keyframe rows' proj_in output on every denoising step. "
|
| 1434 |
+
"Lossless — same output either way. Turn off only if you suspect it of causing an issue.",
|
| 1435 |
+
)
|
| 1436 |
|
| 1437 |
with gr.Column():
|
| 1438 |
video = gr.Video(label="Video + soundtrack", elem_id="h3-generated-video")
|
|
|
|
| 1575 |
)
|
| 1576 |
advance_btn = gr.Button("Advance", variant="secondary", visible=False)
|
| 1577 |
|
| 1578 |
+
with gr.Accordion("Semantic Bridge", open=False):
|
| 1579 |
+
gr.Markdown(
|
| 1580 |
+
"A small, independent adapter that nudges text conditioning toward better constraint "
|
| 1581 |
+
"adherence — left/right ordering, which hand holds what, material and reflection "
|
| 1582 |
+
"correctness — without touching the video transformer. Runs on the conditioner Space. "
|
| 1583 |
+
"Experimental; may help some prompts, do little on others."
|
| 1584 |
+
)
|
| 1585 |
+
semantic_bridge = gr.Checkbox(label="Enable Semantic Bridge", value=False)
|
| 1586 |
+
semantic_bridge_alpha = gr.Slider(
|
| 1587 |
+
label="alpha", minimum=0.0, maximum=1.0, step=0.01, value=0.10, visible=False
|
| 1588 |
+
)
|
| 1589 |
+
semantic_bridge_magnitude_match = gr.Dropdown(
|
| 1590 |
+
label="magnitude_match",
|
| 1591 |
+
choices=["per_token", "global", "none"],
|
| 1592 |
+
value="per_token",
|
| 1593 |
+
visible=False,
|
| 1594 |
+
)
|
| 1595 |
+
semantic_bridge_adapter = gr.Dropdown(
|
| 1596 |
+
label="adapter",
|
| 1597 |
+
choices=["semantic_bridge_v1", "bunny_action_logic_v1"],
|
| 1598 |
+
value="semantic_bridge_v1",
|
| 1599 |
+
visible=False,
|
| 1600 |
+
info="semantic_bridge_v1: broad (composition, spatial, materials). "
|
| 1601 |
+
"bunny_action_logic_v1: action/combat, character-action ownership in multi-character scenes.",
|
| 1602 |
+
)
|
| 1603 |
+
|
| 1604 |
+
with gr.Accordion("Chunked Generation", open=False, visible=False):
|
| 1605 |
gr.Markdown(
|
| 1606 |
"Splits a longer product into independent, full-quality chunks joined afterward — each "
|
| 1607 |
"press is a complete generation, not a partial one. The previous chunk's last frame carries "
|
|
|
|
| 1705 |
semantic_bridge_alpha,
|
| 1706 |
semantic_bridge_magnitude_match,
|
| 1707 |
semantic_bridge_adapter,
|
| 1708 |
+
proj_cache,
|
| 1709 |
]
|
| 1710 |
|
| 1711 |
# `functools.partial` binds `advance`/`chunk_advance` by keyword regardless of their position in `generate`'s
|