Oysiyl Claude Sonnet 4.5 commited on
Commit
cb843dd
·
1 Parent(s): aa46d4a

Fix GPU duration calculation and reduce safety margins

Browse files

CRITICAL FIX: ZeroGPU passes image_size as positional argument (args[4]),
not in kwargs. Previous code always used default 512, causing timeouts.

This is why 1024px artistic was getting only 30s (duration for 512px)
instead of proper duration for 1024px.

Changes:
- Extract image_size from args[4] (the actual value passed)
- Reduce safety margins from 40-50% back to 20-25%
- Standard pipeline: 20% margin
- Artistic pipeline: 25% margin

New durations (with corrected image_size extraction):
Standard: 512=12s, 832=24s, 1024=48s (with animation)
Artistic: 512=22s, 768=44s, 832=56s, 1024=94s (without upscale)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +23 -24
app.py CHANGED
@@ -579,54 +579,53 @@ def compile_models_with_aoti():
579
 
580
  def get_dynamic_duration(*args, **kwargs):
581
  """
582
- Calculate GPU duration based on benchmarks with safety margins.
583
  Max duration capped at 120s (unauthenticated user limit).
584
 
585
  Benchmarks (actual measured times):
586
- Standard: 512+anim=10s, 512-anim=7s, 832+anim=20s, 1024=40s (30% safety margin)
587
- Artistic: 640+anim=23s, 832+anim=45s, 832+anim+upscale=57s, 1024+anim+upscale=124s (40-50% safety margin)
588
-
589
- Updated with larger margins for complex examples and to ensure completion of all 30 steps.
590
- 768px artistic with animation requires ~65s to complete all steps.
591
  """
592
  # Debug logging
593
- print(f"[GPU DURATION DEBUG] Called with args={args}, kwargs keys={list(kwargs.keys()) if kwargs else 'None'}")
594
 
595
- # Extract only the parameters we need from kwargs
 
 
 
596
  pipeline = kwargs.get("pipeline", "standard")
597
- image_size = kwargs.get("image_size", 512)
598
  enable_animation = kwargs.get("enable_animation", True)
599
  enable_upscale = kwargs.get("enable_upscale", False)
600
 
601
  print(f"[GPU DURATION DEBUG] Extracted: pipeline={pipeline}, image_size={image_size}, enable_animation={enable_animation}, enable_upscale={enable_upscale}")
602
 
603
  if pipeline == "standard":
604
- # Standard pipeline benchmarks (with 30% safety margin)
605
  if image_size <= 512:
606
- duration = 13 if enable_animation else 10
607
  elif image_size <= 640:
608
- duration = 20 if enable_animation else 15
609
  elif image_size <= 768:
610
- duration = 25 if enable_animation else 18
611
  elif image_size <= 832:
612
- duration = 30 if enable_animation else 22 # Increased for 832px
613
  else: # 1024
614
- duration = 52 if enable_animation else 38
615
  else: # artistic
616
- # Artistic pipeline benchmarks (with 40-50% safety margin for complex prompts)
617
  if image_size <= 512:
618
- # Extrapolated from 640 benchmark
619
- duration = 30 if not enable_upscale else 45
620
  elif image_size <= 640:
621
- duration = 40 if not enable_upscale else 58
622
  elif image_size <= 768:
623
- # Increased for complex examples (poker, rice fields at 704-768) - needs ~65s for 30 steps with animation
624
- duration = 65 if not enable_upscale else 85
625
  elif image_size <= 832:
626
- duration = 75 if not enable_upscale else 95
627
  else: # 1024
628
- # Increased for complex examples (mediterranean garden at 1024)
629
- duration = 100 if not enable_upscale else 120 # Worst case measured at 124s
630
 
631
  # Cap at 120 seconds (unauthenticated user limit)
632
  final_duration = min(duration, 120)
 
579
 
580
  def get_dynamic_duration(*args, **kwargs):
581
  """
582
+ Calculate GPU duration based on benchmarks with 20-25% safety margin.
583
  Max duration capped at 120s (unauthenticated user limit).
584
 
585
  Benchmarks (actual measured times):
586
+ Standard: 512+anim=10s, 512-anim=7s, 832+anim=20s, 1024=40s
587
+ Artistic: 640+anim=23s, 832+anim=45s, 832+anim+upscale=57s, 1024+anim+upscale=124s
 
 
 
588
  """
589
  # Debug logging
590
+ print(f"[GPU DURATION DEBUG] Called with args length={len(args)}, kwargs keys={list(kwargs.keys()) if kwargs else 'None'}")
591
 
592
+ # Extract parameters from correct source (args vs kwargs)
593
+ # Function signature: generate_qr_code_unified(prompt, negative_prompt, text_input, input_type, image_size, ...)
594
+ # ZeroGPU passes some as positional args, some as kwargs
595
+ image_size = args[4] if len(args) > 4 else kwargs.get("image_size", 512)
596
  pipeline = kwargs.get("pipeline", "standard")
 
597
  enable_animation = kwargs.get("enable_animation", True)
598
  enable_upscale = kwargs.get("enable_upscale", False)
599
 
600
  print(f"[GPU DURATION DEBUG] Extracted: pipeline={pipeline}, image_size={image_size}, enable_animation={enable_animation}, enable_upscale={enable_upscale}")
601
 
602
  if pipeline == "standard":
603
+ # Standard pipeline benchmarks (with 20% safety margin)
604
  if image_size <= 512:
605
+ duration = 12 if enable_animation else 9
606
  elif image_size <= 640:
607
+ duration = 18 if enable_animation else 13
608
  elif image_size <= 768:
609
+ duration = 22 if enable_animation else 16
610
  elif image_size <= 832:
611
+ duration = 24 if enable_animation else 17
612
  else: # 1024
613
+ duration = 48 if enable_animation else 34
614
  else: # artistic
615
+ # Artistic pipeline benchmarks (with 25% safety margin)
616
  if image_size <= 512:
617
+ # Extrapolated from 640 benchmark (~18s base)
618
+ duration = 22 if not enable_upscale else 38
619
  elif image_size <= 640:
620
+ duration = 28 if not enable_upscale else 50
621
  elif image_size <= 768:
622
+ # Interpolated between 640 and 832 (~35s base)
623
+ duration = 44 if not enable_upscale else 65
624
  elif image_size <= 832:
625
+ duration = 56 if not enable_upscale else 72
626
  else: # 1024
627
+ # Extrapolated from 832 (~75s base)
628
+ duration = 94 if not enable_upscale else 120 # Worst case measured at 124s
629
 
630
  # Cap at 120 seconds (unauthenticated user limit)
631
  final_duration = min(duration, 120)