raylim commited on
Commit
875e616
·
unverified ·
1 Parent(s): 0a746ad

Fix ZeroGPU detection and increase workers for non-ZeroGPU environments

Browse files

- Check ZERO_GPU env var instead of just spaces package presence
- Automatically increase num_workers to minimum of 8 when not on ZeroGPU
- Apply to all GPU operations (CTransPath, Optimus, Aeon, Paladin)
- Keep num_workers=0 on ZeroGPU to avoid multiprocessing issues

Files changed (1) hide show
  1. src/mosaic/analysis.py +26 -8
src/mosaic/analysis.py CHANGED
@@ -5,12 +5,18 @@ feature extraction, and model inference for cancer subtype and biomarker predict
5
  """
6
 
7
  # Import spaces first before any CUDA-related imports
 
 
8
  try:
9
  import spaces
10
 
11
  HAS_SPACES = True
 
 
 
12
  except ImportError:
13
  HAS_SPACES = False
 
14
 
15
  # Create a no-op decorator if spaces is not available
16
  class spaces:
@@ -46,9 +52,12 @@ def _extract_ctranspath_features(coords, slide_path, attrs, num_workers):
46
  Returns:
47
  tuple: (ctranspath_features, coords)
48
  """
49
- if HAS_SPACES:
50
  num_workers = 0
51
- logger.info("Running CTransPath on Zero GPU: setting num_workers=0")
 
 
 
52
 
53
  start_time = pd.Timestamp.now()
54
  logger.info("Extracting CTransPath features")
@@ -89,9 +98,12 @@ def _extract_optimus_features(filtered_coords, slide_path, attrs, num_workers):
89
  Returns:
90
  Optimus features
91
  """
92
- if HAS_SPACES:
93
  num_workers = 0
94
- logger.info("Running Optimus on Zero GPU: setting num_workers=0")
 
 
 
95
 
96
  start_time = pd.Timestamp.now()
97
  logger.info("Extracting Optimus features")
@@ -131,9 +143,12 @@ def _run_aeon_inference(features, site_type, num_workers):
131
  Returns:
132
  Aeon results DataFrame
133
  """
134
- if HAS_SPACES:
135
  num_workers = 0
136
- logger.info("Running Aeon on Zero GPU: setting num_workers=0")
 
 
 
137
 
138
  start_time = pd.Timestamp.now()
139
  logger.info("Running Aeon for cancer subtype inference")
@@ -172,9 +187,12 @@ def _run_paladin_inference(features, aeon_results, site_type, num_workers):
172
  Returns:
173
  Paladin results DataFrame
174
  """
175
- if HAS_SPACES:
176
  num_workers = 0
177
- logger.info("Running Paladin on Zero GPU: setting num_workers=0")
 
 
 
178
 
179
  start_time = pd.Timestamp.now()
180
  logger.info("Running Paladin for biomarker inference")
 
5
  """
6
 
7
  # Import spaces first before any CUDA-related imports
8
+ import os
9
+
10
  try:
11
  import spaces
12
 
13
  HAS_SPACES = True
14
+ # Check if we're actually running on ZeroGPU
15
+ # The ZERO_GPU env var is set when running on ZeroGPU
16
+ IS_ZEROGPU = os.environ.get("ZERO_GPU") == "true"
17
  except ImportError:
18
  HAS_SPACES = False
19
+ IS_ZEROGPU = False
20
 
21
  # Create a no-op decorator if spaces is not available
22
  class spaces:
 
52
  Returns:
53
  tuple: (ctranspath_features, coords)
54
  """
55
+ if IS_ZEROGPU:
56
  num_workers = 0
57
+ logger.info("Running CTransPath on ZeroGPU: setting num_workers=0")
58
+ else:
59
+ num_workers = max(num_workers, 8)
60
+ logger.info(f"Running CTransPath with num_workers={num_workers}")
61
 
62
  start_time = pd.Timestamp.now()
63
  logger.info("Extracting CTransPath features")
 
98
  Returns:
99
  Optimus features
100
  """
101
+ if IS_ZEROGPU:
102
  num_workers = 0
103
+ logger.info("Running Optimus on ZeroGPU: setting num_workers=0")
104
+ else:
105
+ num_workers = max(num_workers, 8)
106
+ logger.info(f"Running Optimus with num_workers={num_workers}")
107
 
108
  start_time = pd.Timestamp.now()
109
  logger.info("Extracting Optimus features")
 
143
  Returns:
144
  Aeon results DataFrame
145
  """
146
+ if IS_ZEROGPU:
147
  num_workers = 0
148
+ logger.info("Running Aeon on ZeroGPU: setting num_workers=0")
149
+ else:
150
+ num_workers = max(num_workers, 8)
151
+ logger.info(f"Running Aeon with num_workers={num_workers}")
152
 
153
  start_time = pd.Timestamp.now()
154
  logger.info("Running Aeon for cancer subtype inference")
 
187
  Returns:
188
  Paladin results DataFrame
189
  """
190
+ if IS_ZEROGPU:
191
  num_workers = 0
192
+ logger.info("Running Paladin on ZeroGPU: setting num_workers=0")
193
+ else:
194
+ num_workers = max(num_workers, 8)
195
+ logger.info(f"Running Paladin with num_workers={num_workers}")
196
 
197
  start_time = pd.Timestamp.now()
198
  logger.info("Running Paladin for biomarker inference")