MaxNoichl commited on
Commit
3beb81b
·
1 Parent(s): d70966f

Refactor GPU warmup logic by directly calling _warmup function and removing redundant demo.load call in request context.

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +4 -6
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 😻
4
  colorFrom: indigo
5
  colorTo: yellow
6
  sdk: gradio
7
- sdk_version: 5.23.1
8
  app_file: app.py
9
  pinned: true
10
  # hf_oauth: true
 
4
  colorFrom: indigo
5
  colorTo: yellow
6
  sdk: gradio
7
+ sdk_version: 5.42.0
8
  app_file: app.py
9
  pinned: true
10
  # hf_oauth: true
app.py CHANGED
@@ -5,7 +5,6 @@ print(f"Starting up: {time.strftime('%Y-%m-%d %H:%M:%S')}")
5
  # Standard library imports
6
 
7
  import os
8
- os.environ["MPLCONFIGDIR"] = "/tmp/matplotlib" # set BEFORE importing matplotlib
9
 
10
  #Enforce local cching:
11
 
@@ -239,10 +238,12 @@ def no_op_decorator(func):
239
  # decorator_to_use = spaces.GPU() if is_running_in_hf_space() else no_op_decorator
240
  # #duration=120
241
 
242
- @spaces.GPU(duration=1)
243
- def _warmup():
244
  print("Warming up...")
245
 
 
 
246
 
247
  # if is_running_in_hf_space():
248
  @spaces.GPU(duration=30)
@@ -1422,9 +1423,6 @@ with gr.Blocks(theme=theme, css=f"""
1422
  outputs=query_display
1423
  )
1424
 
1425
- # Run a tiny GPU warmup safely inside a request context
1426
- demo.load(fn=_warmup, inputs=None, outputs=None, queue=False)
1427
-
1428
 
1429
  # demo.static_dirs = {
1430
  # "static": str(static_dir)
 
5
  # Standard library imports
6
 
7
  import os
 
8
 
9
  #Enforce local cching:
10
 
 
238
  # decorator_to_use = spaces.GPU() if is_running_in_hf_space() else no_op_decorator
239
  # #duration=120
240
 
241
+ @spaces.GPU(duration=1) # ← forces the detector to see a GPU-aware fn
242
+ def _warmup():
243
  print("Warming up...")
244
 
245
+ _warmup()
246
+
247
 
248
  # if is_running_in_hf_space():
249
  @spaces.GPU(duration=30)
 
1423
  outputs=query_display
1424
  )
1425
 
 
 
 
1426
 
1427
  # demo.static_dirs = {
1428
  # "static": str(static_dir)