multimodalart HF Staff commited on
Commit
d640927
·
verified ·
1 Parent(s): 76b1547

Tune duration, examples

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -159,16 +159,17 @@ def _extract_answer(texts) -> str:
159
  return ""
160
 
161
 
162
- def _duration(image, question, max_images=3, max_text_tokens=1024, num_timesteps=50, *args, **kwargs):
163
- # ~ text decoding budget + per-image denoising cost (CFG = 3 forward passes / step)
164
- return int(min(300, 45 + int(max_images) * (0.55 * int(num_timesteps) + 6) + int(max_text_tokens) * 0.035))
 
165
 
166
 
167
  @spaces.GPU(duration=_duration)
168
  def reason(
169
  image: Image.Image | None,
170
  question: str,
171
- max_images: int = 3,
172
  max_text_tokens: int = 1024,
173
  num_timesteps: int = 50,
174
  cfg_text_scale: float = 3.0,
@@ -331,7 +332,7 @@ CSS = """
331
 
332
  EXAMPLES = [
333
  ["examples/living_room_blue_couch.jpg",
334
- "Imagine you are standing behind the fireplace looking toward the sofa. Is the TV on your left or your right?"],
335
  ["examples/cafe_interior.jpg",
336
  "Which is closer to the camera: the teapot on the nearest table or the turquoise cabinet? Think about the depth of the scene."],
337
  ["examples/sign_beach.jpg",
@@ -362,7 +363,7 @@ with gr.Blocks(title="ThinkMorph-SSL") as demo:
362
  )
363
  run_btn = gr.Button("Reason", variant="primary")
364
  with gr.Accordion("Advanced settings", open=False):
365
- max_images = gr.Slider(1, 6, value=3, step=1, label="Max generated images")
366
  max_text_tokens = gr.Slider(256, 2048, value=1024, step=64, label="Max text tokens (whole trace)")
367
  num_timesteps = gr.Slider(10, 50, value=50, step=1, label="Denoising steps per image")
368
  cfg_text_scale = gr.Slider(1.0, 8.0, value=3.0, step=0.1, label="CFG text scale")
 
159
  return ""
160
 
161
 
162
+ def _duration(image, question, max_images=2, max_text_tokens=1024, num_timesteps=50, *args, **kwargs):
163
+ # Measured on ZeroGPU: ~0.95 s per denoising step for a ~1024px image (CFG), ~10 s of text decoding.
164
+ est = 15 + int(max_images) * 0.95 * int(num_timesteps) + int(max_text_tokens) * 0.01
165
+ return int(min(300, est * 1.15))
166
 
167
 
168
  @spaces.GPU(duration=_duration)
169
  def reason(
170
  image: Image.Image | None,
171
  question: str,
172
+ max_images: int = 2,
173
  max_text_tokens: int = 1024,
174
  num_timesteps: int = 50,
175
  cfg_text_scale: float = 3.0,
 
332
 
333
  EXAMPLES = [
334
  ["examples/living_room_blue_couch.jpg",
335
+ "Imagine you are standing behind the fireplace looking toward the sofa. Is the TV on your left or your right? Answer with a word, not a letter."],
336
  ["examples/cafe_interior.jpg",
337
  "Which is closer to the camera: the teapot on the nearest table or the turquoise cabinet? Think about the depth of the scene."],
338
  ["examples/sign_beach.jpg",
 
363
  )
364
  run_btn = gr.Button("Reason", variant="primary")
365
  with gr.Accordion("Advanced settings", open=False):
366
+ max_images = gr.Slider(1, 5, value=2, step=1, label="Max generated images")
367
  max_text_tokens = gr.Slider(256, 2048, value=1024, step=64, label="Max text tokens (whole trace)")
368
  num_timesteps = gr.Slider(10, 50, value=50, step=1, label="Denoising steps per image")
369
  cfg_text_scale = gr.Slider(1.0, 8.0, value=3.0, step=0.1, label="CFG text scale")