multimodalart HF Staff commited on
Commit
afdca01
Β·
verified Β·
1 Parent(s): 795963b

Simpler: let the ZeroGPU allocator queue GPU calls (concurrency_limit=None), parallel CPU events

Browse files

Per review: no Gradio-level GPU gate at all. Generate events get concurrency_limit=None β€” the ZeroGPU allocator queues GPU allocation per call with its own 'Waiting for a GPU' UI, and the composer LLM call at the start of simple_generate now starts the moment the user clicks. Explicit None matters: unset falls back to Gradio's default of 1 per function. CPU events (assist 8, video 4, examples None) keep their bumps since the default serialized them across users. The compose/sing split from the previous commit is dropped β€” not needed under this model.

Files changed (1) hide show
  1. app.py +14 -21
app.py CHANGED
@@ -1533,21 +1533,19 @@ def compose_assist(raw_state, duration):
1533
  return state, "Lyrics & structured prompt ready β€” review and tweak them, then press Generate."
1534
 
1535
 
1536
- def simple_compose(state, duration):
1537
- # Composing is a plain LLM API call, so it runs OUTSIDE the GPU queue: it starts the moment the user
1538
- # clicks instead of waiting behind every queued song. The singing step chains after it on the GPU queue.
1539
  state = _normalize_state(state)
1540
  description = _composed_description(state)
1541
  title = state["title"] or state["description"]
1542
- yield gr.skip(), "writing lyrics & structured prompt...", gr.skip(), title
1543
  lyr, gm, vd, arr = compose_song(description, duration)
1544
  state.update(lyrics=lyr, global_meta=gm, vocals=vd, arrangement=arr)
1545
- yield (
1546
- {"cmd": "status", "text": "Lyrics ready β€” waiting for a GPU slot..."},
1547
- "lyrics ready β€” waiting for a GPU slot...",
1548
- state,
1549
- gr.skip(),
1550
- )
1551
 
1552
 
1553
  def studio_generate(state, duration, seed, randomize_seed, headroom, steps, guidance):
@@ -1620,15 +1618,10 @@ with gr.Blocks(theme=gr.themes.Citrus(), css=CSS) as demo:
1620
 
1621
  _knobs = [duration, seed, randomize_seed, headroom, steps, guidance]
1622
 
1623
- ev_compose = composer.submit(lambda: ({"cmd": "reset", "loader": True, "status": "Writing lyrics & structured prompt with MiniMax-M3...", "nonce": random.random()}, None), None, [player, video_out]).then(
1624
- simple_compose, [composer, duration],
1625
- [player, stats, composer, video_title],
1626
- concurrency_limit=8, show_progress="minimal",
1627
- )
1628
- ev_simple = ev_compose.success(
1629
- studio_generate, [composer] + _knobs,
1630
- [player, stats, wav_state, seed, video_title],
1631
- concurrency_limit=1, concurrency_id="gpu", show_progress="minimal",
1632
  )
1633
  ev_simple.then(render_video, [wav_state, video_title], video_out, concurrency_limit=4).then(
1634
  lambda s: s.replace(" β€” rendering share video...", " β€” share video ready."), stats, stats
@@ -1637,7 +1630,7 @@ with gr.Blocks(theme=gr.themes.Citrus(), css=CSS) as demo:
1637
  ev_studio = composer.click(lambda: ({"cmd": "reset", "loader": True, "status": "Acquiring ZeroGPU...", "nonce": random.random()}, "", None), None, [player, stats, video_out]).then(
1638
  studio_generate, [composer] + _knobs,
1639
  [player, stats, wav_state, seed, video_title],
1640
- concurrency_limit=1, concurrency_id="gpu", show_progress="minimal",
1641
  )
1642
  ev_studio.then(render_video, [wav_state, video_title], video_out, concurrency_limit=4).then(
1643
  lambda s: s.replace(" β€” rendering share video...", " β€” share video ready."), stats, stats
@@ -1645,7 +1638,7 @@ with gr.Blocks(theme=gr.themes.Citrus(), css=CSS) as demo:
1645
 
1646
  player.stop(
1647
  lambda: "stopped β€” kept the part that was already streamed.", None, stats,
1648
- cancels=[ev_compose, ev_simple, ev_studio], show_progress="hidden",
1649
  )
1650
 
1651
  composer.edit(compose_assist, [composer, duration], [composer, stats], concurrency_limit=8, show_progress="minimal")
 
1533
  return state, "Lyrics & structured prompt ready β€” review and tweak them, then press Generate."
1534
 
1535
 
1536
+ def simple_generate(state, duration, seed, randomize_seed, headroom, steps, guidance):
1537
+ # One event so the output components engage (spinner) from the first click, through composing and singing.
 
1538
  state = _normalize_state(state)
1539
  description = _composed_description(state)
1540
  title = state["title"] or state["description"]
1541
+ yield gr.skip(), "writing lyrics & structured prompt...", gr.skip(), gr.skip(), gr.skip(), title
1542
  lyr, gm, vd, arr = compose_song(description, duration)
1543
  state.update(lyrics=lyr, global_meta=gm, vocals=vd, arrangement=arr)
1544
+ yield {"cmd": "status", "text": "Lyrics ready β€” acquiring ZeroGPU..."}, "lyrics ready β€” acquiring ZeroGPU...", gr.skip(), gr.skip(), state, gr.skip()
1545
+ for audio, status, wav, used_seed in generate(
1546
+ description, lyr, gm, vd, arr, duration, seed, randomize_seed, headroom, steps, guidance
1547
+ ):
1548
+ yield audio, status, wav, used_seed, gr.skip(), gr.skip()
 
1549
 
1550
 
1551
  def studio_generate(state, duration, seed, randomize_seed, headroom, steps, guidance):
 
1618
 
1619
  _knobs = [duration, seed, randomize_seed, headroom, steps, guidance]
1620
 
1621
+ ev_simple = composer.submit(lambda: ({"cmd": "reset", "loader": True, "status": "Writing lyrics & structured prompt with MiniMax-M3...", "nonce": random.random()}, None), None, [player, video_out]).then(
1622
+ simple_generate, [composer] + _knobs,
1623
+ [player, stats, wav_state, seed, composer, video_title],
1624
+ concurrency_limit=None, show_progress="minimal",
 
 
 
 
 
1625
  )
1626
  ev_simple.then(render_video, [wav_state, video_title], video_out, concurrency_limit=4).then(
1627
  lambda s: s.replace(" β€” rendering share video...", " β€” share video ready."), stats, stats
 
1630
  ev_studio = composer.click(lambda: ({"cmd": "reset", "loader": True, "status": "Acquiring ZeroGPU...", "nonce": random.random()}, "", None), None, [player, stats, video_out]).then(
1631
  studio_generate, [composer] + _knobs,
1632
  [player, stats, wav_state, seed, video_title],
1633
+ concurrency_limit=None, show_progress="minimal",
1634
  )
1635
  ev_studio.then(render_video, [wav_state, video_title], video_out, concurrency_limit=4).then(
1636
  lambda s: s.replace(" β€” rendering share video...", " β€” share video ready."), stats, stats
 
1638
 
1639
  player.stop(
1640
  lambda: "stopped β€” kept the part that was already streamed.", None, stats,
1641
+ cancels=[ev_simple, ev_studio], show_progress="hidden",
1642
  )
1643
 
1644
  composer.edit(compose_assist, [composer, duration], [composer, stats], concurrency_limit=8, show_progress="minimal")