MoraxCheng commited on
Commit
457d8df
·
1 Parent(s): a092fd7

Enhance Zero GPU support with environment variable control and improved error handling

Browse files
Files changed (1) hide show
  1. app.py +32 -6
app.py CHANGED
@@ -18,13 +18,28 @@ import shutil
18
  import uuid
19
  import gc
20
 
 
 
 
21
  # Try to import spaces for Zero GPU support
22
- try:
23
- import spaces
24
- SPACES_AVAILABLE = True
25
- except ImportError:
26
  SPACES_AVAILABLE = False
27
- print("Warning: spaces module not available. Running without Zero GPU support.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
  # Add current directory to path
30
  sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
@@ -341,7 +356,18 @@ def score_and_create_matrix_all_singles_impl(sequence,mutation_range_start=None,
341
 
342
  # Apply Zero GPU decorator if available
343
  if SPACES_AVAILABLE:
344
- score_and_create_matrix_all_singles = spaces.GPU(duration=300)(score_and_create_matrix_all_singles_impl)
 
 
 
 
 
 
 
 
 
 
 
345
  else:
346
  score_and_create_matrix_all_singles = score_and_create_matrix_all_singles_impl
347
 
 
18
  import uuid
19
  import gc
20
 
21
+ # Check if Zero GPU should be disabled via environment variable
22
+ DISABLE_ZERO_GPU = os.environ.get('DISABLE_ZERO_GPU', 'false').lower() == 'true'
23
+
24
  # Try to import spaces for Zero GPU support
25
+ if DISABLE_ZERO_GPU:
 
 
 
26
  SPACES_AVAILABLE = False
27
+ print("Zero GPU disabled via environment variable")
28
+ else:
29
+ try:
30
+ import spaces
31
+ SPACES_AVAILABLE = True
32
+ # Check if we're actually running on Hugging Face Spaces with Zero GPU
33
+ if hasattr(spaces, 'config') and hasattr(spaces.config, 'Config'):
34
+ print("Zero GPU support detected and available")
35
+ else:
36
+ print("Spaces module imported but Zero GPU may not be fully configured")
37
+ except ImportError:
38
+ SPACES_AVAILABLE = False
39
+ print("Warning: spaces module not available. Running without Zero GPU support.")
40
+ except Exception as e:
41
+ SPACES_AVAILABLE = False
42
+ print(f"Warning: Error importing spaces module: {e}. Running without Zero GPU support.")
43
 
44
  # Add current directory to path
45
  sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
 
356
 
357
  # Apply Zero GPU decorator if available
358
  if SPACES_AVAILABLE:
359
+ try:
360
+ # Try with explicit duration
361
+ score_and_create_matrix_all_singles = spaces.GPU(duration=300)(score_and_create_matrix_all_singles_impl)
362
+ except Exception as e:
363
+ print(f"Warning: Failed to apply Zero GPU decorator with duration: {e}")
364
+ try:
365
+ # Try without duration parameter
366
+ score_and_create_matrix_all_singles = spaces.GPU()(score_and_create_matrix_all_singles_impl)
367
+ except Exception as e2:
368
+ print(f"Warning: Failed to apply Zero GPU decorator: {e2}")
369
+ print("Falling back to CPU mode")
370
+ score_and_create_matrix_all_singles = score_and_create_matrix_all_singles_impl
371
  else:
372
  score_and_create_matrix_all_singles = score_and_create_matrix_all_singles_impl
373