Skip to content

Commit feb2726

Browse files
committed
fix: support MPS device for EdgeTAM
1 parent 4731603 commit feb2726

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

dimos/models/segmentation/edge_tam.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class EdgeTAMProcessor(Detector):
5353
_frame_count: int
5454
_is_tracking: bool
5555
_buffer_size: int
56+
_device: str
5657

5758
def __init__(
5859
self,
@@ -62,8 +63,14 @@ def __init__(
6263
if not local_config_path.exists():
6364
raise FileNotFoundError(f"EdgeTAM config not found at {local_config_path}")
6465

65-
if not torch.cuda.is_available():
66-
raise RuntimeError("EdgeTAM requires a CUDA-capable GPU")
66+
if torch.cuda.is_available():
67+
self._device = "cuda"
68+
elif hasattr(torch.backends, "mps") and torch.backends.mps.is_available():
69+
self._device = "mps"
70+
else:
71+
raise RuntimeError(
72+
"EdgeTAM requires a CUDA-capable GPU or an Apple Silicon MPS/Metal backend."
73+
)
6774

6875
cfg = OmegaConf.load(local_config_path)
6976

@@ -98,7 +105,7 @@ def __init__(
98105
if unexpected_keys:
99106
raise RuntimeError("Unexpected keys in checkpoint")
100107

101-
self._predictor = self._predictor.to("cuda")
108+
self._predictor = self._predictor.to(self._device)
102109
self._predictor.eval()
103110

104111
self._inference_state = None
@@ -124,7 +131,7 @@ def _prepare_frame(self, image: Image) -> torch.Tensor:
124131
img_np /= img_std
125132

126133
img_tensor = torch.from_numpy(img_np).permute(2, 0, 1).float()
127-
img_tensor = img_tensor.cuda()
134+
img_tensor = img_tensor.to(self._device)
128135

129136
return img_tensor
130137

0 commit comments

Comments
 (0)