Spaces:
Running on Zero

ming0531 commited on
Commit
2b2c2a2
·
verified ·
1 Parent(s): 9c46849

Start-up GPU warm-up (Triton kernel build and tuning before the first visitor)

Browse files
Files changed (1) hide show
  1. app.py +16 -0
app.py CHANGED
@@ -107,6 +107,22 @@ def run(state, prompt, start, seconds, long_side, strength, gap, progress=gr.Pro
107
  return path, overlay(frames[first], subject[first]), depth_image(depth), msg
108
 
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  HEADER = """
111
  <div id="header">
112
  <div class="title"><div><h1>FlashReFocus: Video Spotlight</h1><p>Keep one person sharp and blur everyone else, frame
 
107
  return path, overlay(frames[first], subject[first]), depth_image(depth), msg
108
 
109
 
110
+ @spaces.GPU(duration=180)
111
+ def warm_up(frames):
112
+ """Start-up run on the GPU worker: SAM 3, depth and the renderer once (the Triton kernel is built and tuned here),
113
+ so the first visitor does not wait for it."""
114
+ t0 = time.perf_counter()
115
+ engine.process(frames, "person", None, 1.5, 0.6)
116
+ print(f"warm-up done in {time.perf_counter() - t0:.1f} s", flush=True)
117
+
118
+
119
+ try:
120
+ for _side in (768, 512, 960): # the long sides offered, on a 16:9 example clip
121
+ warm_up(engine.read_clip(EXAMPLES[1], 0.5, _side)[0])
122
+ except Exception as e: # never block the start of the Space
123
+ print(f"warm-up skipped ({type(e).__name__}: {e})", flush=True)
124
+
125
+
126
  HEADER = """
127
  <div id="header">
128
  <div class="title"><div><h1>FlashReFocus: Video Spotlight</h1><p>Keep one person sharp and blur everyone else, frame