dagloop5 commited on
Commit
f17ca0b
·
verified ·
1 Parent(s): 14b273b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -25
app.py CHANGED
@@ -767,6 +767,7 @@ def generate(
767
  stage_enabled=False,
768
  target_steps=DEFAULT_TARGET_STEPS,
769
  stage_state=None,
 
770
  progress=gr.Progress(track_tqdm=True),
771
  *,
772
  advance: bool = False,
@@ -815,29 +816,44 @@ def generate(
815
  else:
816
  this_stage_steps = int(steps)
817
 
818
- progress(
819
- 0.0,
820
- desc=(
821
- f"Upsampling the prompt on {CONDITIONER_SPACE} ..."
822
- if upsample
823
- else f"Conditioning on {CONDITIONER_SPACE} ..."
824
- ),
825
- )
826
- conditioned = time.time()
827
- prompt_embeds, text_token_tags, metadata, plan = encode_remote(
828
- prompt, first_frame, last_frame, canvas, num_frames, rewrite_prompt=upsample
829
- )
830
- condition_seconds = time.time() - conditioned
831
- height, width, num_frames = (int(metadata[key]) for key in ("height", "width", "num_frames"))
832
- refined = plan.get("refined_prompt") or ""
833
-
834
- if advance and (height, width, num_frames) != (
835
- int(stage_state["height"]), int(stage_state["width"]), int(stage_state["num_frames"])
836
- ):
837
- raise gr.Error(
838
- "Canvas or duration resolved differently than the staged sequence's first stage — both have to stay "
839
- "fixed across a staged sequence, since they determine the saved latents' shape."
840
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
841
 
842
  def keyframe(path):
843
  # The conditioning latents encoded here have to be of the image the conditioner looked at, which it
@@ -907,7 +923,7 @@ def generate(
907
  report = (
908
  f"`{width}x{height}`, {num_frames} frames ({num_frames / FPS:.3f} s) -> {out_frames} frames at {fps} fps · "
909
  f"{' · '.join(info)}\n\n"
910
- f"conditioner {condition_seconds:.0f}s ({plan['num_text_tokens']} tokens"
911
  f"{', upsampled' if refined else ''}) · denoise + decode {denoise_seconds:.0f}s "
912
  f"({denoise_seconds / max(1, this_stage_steps):.1f} s/step) · post {post_seconds:.0f}s · "
913
  f"GPU {gpu_seconds:.0f}s of {booked_seconds}s booked"
@@ -924,6 +940,11 @@ def generate(
924
  "width": width,
925
  "num_frames": num_frames,
926
  "steps_done": steps_done_after,
 
 
 
 
 
927
  }
928
  if stage_enabled
929
  else None
@@ -1221,6 +1242,16 @@ with gr.Blocks(title="PlagueKind · MiniMax-H3") as demo:
1221
  visible=False,
1222
  info="The fixed schedule's total length — 'Steps' above is how many of these one press runs.",
1223
  )
 
 
 
 
 
 
 
 
 
 
1224
  advance_btn = gr.Button("Advance", variant="secondary", visible=False)
1225
 
1226
  stage_state = gr.State(None)
@@ -1241,9 +1272,9 @@ with gr.Blocks(title="PlagueKind · MiniMax-H3") as demo:
1241
  )
1242
 
1243
  stage_enabled.change(
1244
- lambda enabled: (gr.update(visible=enabled), gr.update(visible=enabled)),
1245
  stage_enabled,
1246
- [target_steps, advance_btn],
1247
  api_name=False,
1248
  )
1249
 
@@ -1276,6 +1307,7 @@ with gr.Blocks(title="PlagueKind · MiniMax-H3") as demo:
1276
  stage_enabled,
1277
  target_steps,
1278
  stage_state,
 
1279
  ]
1280
 
1281
  # `functools.partial` binds `advance` by keyword regardless of its position in `generate`'s signature — the
 
767
  stage_enabled=False,
768
  target_steps=DEFAULT_TARGET_STEPS,
769
  stage_state=None,
770
+ recondition=True,
771
  progress=gr.Progress(track_tqdm=True),
772
  *,
773
  advance: bool = False,
 
816
  else:
817
  this_stage_steps = int(steps)
818
 
819
+ skip_recondition = advance and stage_state is not None and not recondition
820
+ if skip_recondition:
821
+ # "Re-condition" off: reuses this sequence's cached conditioning verbatim. Safe specifically because
822
+ # nothing sampler/schedule/shift/steps/seed/sharpen/interpolation/LoRA-related is an input to the
823
+ # conditioner at all — only prompt, the two keyframes, canvas, and "Upsample prompt" are. Height/width/
824
+ # num_frames come from that same cached conditioning, so there's nothing new to compare for the
825
+ # shape-consistency check below.
826
+ prompt_embeds = stage_state["prompt_embeds"]
827
+ text_token_tags = stage_state["text_token_tags"]
828
+ metadata = stage_state["metadata"]
829
+ plan = stage_state["plan"]
830
+ condition_seconds = 0.0
831
+ height, width, num_frames = stage_state["height"], stage_state["width"], stage_state["num_frames"]
832
+ refined = stage_state.get("refined") or ""
833
+ else:
834
+ progress(
835
+ 0.0,
836
+ desc=(
837
+ f"Upsampling the prompt on {CONDITIONER_SPACE} ..."
838
+ if upsample
839
+ else f"Conditioning on {CONDITIONER_SPACE} ..."
840
+ ),
841
  )
842
+ conditioned = time.time()
843
+ prompt_embeds, text_token_tags, metadata, plan = encode_remote(
844
+ prompt, first_frame, last_frame, canvas, num_frames, rewrite_prompt=upsample
845
+ )
846
+ condition_seconds = time.time() - conditioned
847
+ height, width, num_frames = (int(metadata[key]) for key in ("height", "width", "num_frames"))
848
+ refined = plan.get("refined_prompt") or ""
849
+
850
+ if advance and (height, width, num_frames) != (
851
+ int(stage_state["height"]), int(stage_state["width"]), int(stage_state["num_frames"])
852
+ ):
853
+ raise gr.Error(
854
+ "Canvas or duration resolved differently than the staged sequence's first stage — both have to "
855
+ "stay fixed across a staged sequence, since they determine the saved latents' shape."
856
+ )
857
 
858
  def keyframe(path):
859
  # The conditioning latents encoded here have to be of the image the conditioner looked at, which it
 
923
  report = (
924
  f"`{width}x{height}`, {num_frames} frames ({num_frames / FPS:.3f} s) -> {out_frames} frames at {fps} fps · "
925
  f"{' · '.join(info)}\n\n"
926
+ f"conditioner {condition_seconds:.0f}s{' (cached)' if skip_recondition else ''} ({plan['num_text_tokens']} tokens"
927
  f"{', upsampled' if refined else ''}) · denoise + decode {denoise_seconds:.0f}s "
928
  f"({denoise_seconds / max(1, this_stage_steps):.1f} s/step) · post {post_seconds:.0f}s · "
929
  f"GPU {gpu_seconds:.0f}s of {booked_seconds}s booked"
 
940
  "width": width,
941
  "num_frames": num_frames,
942
  "steps_done": steps_done_after,
943
+ "prompt_embeds": prompt_embeds,
944
+ "text_token_tags": text_token_tags,
945
+ "metadata": metadata,
946
+ "plan": plan,
947
+ "refined": refined,
948
  }
949
  if stage_enabled
950
  else None
 
1242
  visible=False,
1243
  info="The fixed schedule's total length — 'Steps' above is how many of these one press runs.",
1244
  )
1245
+ recondition = gr.Checkbox(
1246
+ label="Re-condition",
1247
+ value=True,
1248
+ visible=False,
1249
+ info=(
1250
+ "When turned off skips the conditioner on 'Advance' and reuses this sequence's cached prompt/keyframe "
1251
+ "encoding — safe as long as the prompt, keyframes, target dimension, and 'Upsample prompt' haven't "
1252
+ "changed since the first stage."
1253
+ ),
1254
+ )
1255
  advance_btn = gr.Button("Advance", variant="secondary", visible=False)
1256
 
1257
  stage_state = gr.State(None)
 
1272
  )
1273
 
1274
  stage_enabled.change(
1275
+ lambda enabled: tuple(gr.update(visible=enabled) for _ in range(3)),
1276
  stage_enabled,
1277
+ [target_steps, recondition, advance_btn],
1278
  api_name=False,
1279
  )
1280
 
 
1307
  stage_enabled,
1308
  target_steps,
1309
  stage_state,
1310
+ recondition,
1311
  ]
1312
 
1313
  # `functools.partial` binds `advance` by keyword regardless of its position in `generate`'s signature — the