Azan commited on
Commit ·
91de477
1
Parent(s): 6352295
Fix: Monkeypatch torch.cuda to prevent crash on non-NVIDIA CPU systems
Browse files
ylff/utils/model_loader.py
CHANGED
|
@@ -234,6 +234,12 @@ def load_da3_model(
|
|
| 234 |
else:
|
| 235 |
logger.warning("MPS requested but not available. Falling back to CPU.")
|
| 236 |
device = "cpu"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
|
| 238 |
logger.info(f"Loading DA3 model: {model_name} on {device}")
|
| 239 |
model = DepthAnything3.from_pretrained(model_name)
|
|
|
|
| 234 |
else:
|
| 235 |
logger.warning("MPS requested but not available. Falling back to CPU.")
|
| 236 |
device = "cpu"
|
| 237 |
+
|
| 238 |
+
# Monkeypatch torch.cuda.is_bf16_supported to avoid initializing CUDA on CPU machines
|
| 239 |
+
# This prevents "Found no NVIDIA driver" error in depth_anything_3/api.py
|
| 240 |
+
if hasattr(torch.cuda, "is_bf16_supported"):
|
| 241 |
+
logger.info("Patching torch.cuda.is_bf16_supported to prevent CUDA initialization on CPU")
|
| 242 |
+
torch.cuda.is_bf16_supported = lambda: False
|
| 243 |
|
| 244 |
logger.info(f"Loading DA3 model: {model_name} on {device}")
|
| 245 |
model = DepthAnything3.from_pretrained(model_name)
|