Spaces:
Sleeping
Sleeping
Zhen Ye
commited on
Commit
·
0e0cc26
1
Parent(s):
4c39d24
feat: fix multi-gpu visibility and improve logging
Browse files- Unset CUDA_VISIBLE_DEVICES at start of app.py to force visibility of all GPUs
- Change GPU parallelism and distance logs to INFO level for visibility
- app.py +11 -2
- inference.py +4 -4
app.py
CHANGED
|
@@ -1,6 +1,15 @@
|
|
| 1 |
-
import asyncio
|
| 2 |
-
import logging
|
| 3 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import shutil
|
| 5 |
import tempfile
|
| 6 |
import uuid
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import logging
|
| 3 |
+
# Debug/Fix: Unset CUDA_VISIBLE_DEVICES to ensure all GPUs are visible
|
| 4 |
+
# Some environments (like HF Spaces) might set this to "0" by default.
|
| 5 |
+
if "CUDA_VISIBLE_DEVICES" in os.environ:
|
| 6 |
+
# Use print because logging config might not be set yet
|
| 7 |
+
print(f"Found CUDA_VISIBLE_DEVICES={os.environ['CUDA_VISIBLE_DEVICES']}. Unsetting it to enable all GPUs.")
|
| 8 |
+
del os.environ["CUDA_VISIBLE_DEVICES"]
|
| 9 |
+
else:
|
| 10 |
+
print("CUDA_VISIBLE_DEVICES not set. All GPUs should be visible.")
|
| 11 |
+
|
| 12 |
+
import asyncio
|
| 13 |
import shutil
|
| 14 |
import tempfile
|
| 15 |
import uuid
|
inference.py
CHANGED
|
@@ -301,7 +301,7 @@ def infer_frame(
|
|
| 301 |
# Add depth to label, e.g. "car 12m"
|
| 302 |
depth_str = f"{int(det['depth_est_m'])}m"
|
| 303 |
label = f"{label} {depth_str}"
|
| 304 |
-
logging.
|
| 305 |
display_labels.append(label)
|
| 306 |
|
| 307 |
except Exception:
|
|
@@ -468,7 +468,7 @@ def run_inference(
|
|
| 468 |
detector_instance = detectors[gpu_idx]
|
| 469 |
depth_instance = depth_estimators[gpu_idx] if depth_estimators else None
|
| 470 |
|
| 471 |
-
logging.
|
| 472 |
|
| 473 |
# Run depth estimation every 3 frames if configured
|
| 474 |
active_depth_name = depth_estimator_name if (frame_idx % 3 == 0) else None
|
|
@@ -573,7 +573,7 @@ def run_segmentation(
|
|
| 573 |
gpu_idx = frame_idx % len(segmenters)
|
| 574 |
segmenter_instance = segmenters[gpu_idx]
|
| 575 |
|
| 576 |
-
logging.
|
| 577 |
|
| 578 |
processed, _ = infer_segmentation_frame(
|
| 579 |
frame_data,
|
|
@@ -716,7 +716,7 @@ def process_frames_depth(
|
|
| 716 |
gpu_idx = frame_idx % len(estimators)
|
| 717 |
estimator_instance = estimators[gpu_idx]
|
| 718 |
|
| 719 |
-
logging.
|
| 720 |
|
| 721 |
# Use instance lock
|
| 722 |
if hasattr(estimator_instance, "lock"):
|
|
|
|
| 301 |
# Add depth to label, e.g. "car 12m"
|
| 302 |
depth_str = f"{int(det['depth_est_m'])}m"
|
| 303 |
label = f"{label} {depth_str}"
|
| 304 |
+
logging.info("Object '%s' at %s (bbox: %s)", label, depth_str, det['bbox'])
|
| 305 |
display_labels.append(label)
|
| 306 |
|
| 307 |
except Exception:
|
|
|
|
| 468 |
detector_instance = detectors[gpu_idx]
|
| 469 |
depth_instance = depth_estimators[gpu_idx] if depth_estimators else None
|
| 470 |
|
| 471 |
+
logging.info("Processing frame %d on GPU %d (cuda:%d)", frame_idx, gpu_idx, gpu_idx)
|
| 472 |
|
| 473 |
# Run depth estimation every 3 frames if configured
|
| 474 |
active_depth_name = depth_estimator_name if (frame_idx % 3 == 0) else None
|
|
|
|
| 573 |
gpu_idx = frame_idx % len(segmenters)
|
| 574 |
segmenter_instance = segmenters[gpu_idx]
|
| 575 |
|
| 576 |
+
logging.info("Segmenting frame %d on GPU %d (cuda:%d)", frame_idx, gpu_idx, gpu_idx)
|
| 577 |
|
| 578 |
processed, _ = infer_segmentation_frame(
|
| 579 |
frame_data,
|
|
|
|
| 716 |
gpu_idx = frame_idx % len(estimators)
|
| 717 |
estimator_instance = estimators[gpu_idx]
|
| 718 |
|
| 719 |
+
logging.info("Estimating depth for frame %d on GPU %d (cuda:%d)", frame_idx, gpu_idx, gpu_idx)
|
| 720 |
|
| 721 |
# Use instance lock
|
| 722 |
if hasattr(estimator_instance, "lock"):
|