Skip to content

Commit fe76cc1

Browse files
Merge pull request #1436 from roboflow/feature/proper-mps-handling-for-macos
Apply changes such that MPS is correctly supported for `rfdetr`, yet still remain non-default for MacOS
2 parents e05ae18 + 500325f commit fe76cc1

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

.github/workflows/integration_tests_inference_experimental_gpu.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ name: INTEGRATION TESTS - inference_experimental (GPU)
22
permissions:
33
contents: read
44
on:
5-
pull_request:
6-
branches: [main]
75
push:
86
branches: [main]
97
workflow_dispatch:

inference_experimental/inference_exp/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import os
2+
3+
if os.environ.get("PYTORCH_ENABLE_MPS_FALLBACK") is None:
4+
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
5+
16
from inference_exp.entities import ColorFormat
27
from inference_exp.models.auto_loaders.core import AutoModel
38
from inference_exp.models.base.classification import (

inference_experimental/inference_exp/models/common/onnx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ def run_session_via_iobinding(
196196
)
197197
device = get_input_device(inputs=inputs)
198198
if device.type != "cuda":
199-
inputs_np = {name: value.numpy() for name, value in inputs.items()}
199+
inputs_np = {name: value.cpu().numpy() for name, value in inputs.items()}
200200
results = session.run(None, inputs_np)
201-
return [torch.from_numpy(element) for element in results]
201+
return [torch.from_numpy(element).to(device=device) for element in results]
202202
try:
203203
import pycuda.driver as cuda
204204
from inference_exp.models.common.cuda import use_primary_cuda_context

inference_experimental/tests/integration_tests/models/test_clip_predictions.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
import torch.nn.functional as F
88
from clip import clip
99
from filelock import FileLock
10+
from inference_exp.configuration import DEFAULT_DEVICE
1011
from PIL.Image import Image
1112
from torch import nn
1213

13-
EXPECTED_DOG_IMAGE_EMBEDDING = torch.Tensor(
14+
EXPECTED_DOG_IMAGE_EMBEDDING = torch.tensor(
1415
[
1516
[
1617
-0.031097251921892166,
@@ -1038,7 +1039,8 @@
10381039
0.006933738477528095,
10391040
-0.0005487799644470215,
10401041
]
1041-
]
1042+
],
1043+
device=DEFAULT_DEVICE,
10421044
)
10431045

10441046

inference_experimental/tests/integration_tests/models/test_perception_encoder_predictions.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import numpy as np
22
import pytest
33
import torch
4+
from inference_exp.configuration import DEFAULT_DEVICE
45

5-
EXPECTED_DOG_IMAGE_EMBEDDING = torch.Tensor(
6+
EXPECTED_DOG_IMAGE_EMBEDDING = torch.tensor(
67
[
78
[
89
-0.04075119271874428,
@@ -1030,7 +1031,8 @@
10301031
0.027445748448371887,
10311032
0.03301752358675003,
10321033
]
1033-
]
1034+
],
1035+
device=DEFAULT_DEVICE,
10341036
)
10351037

10361038

0 commit comments

Comments
 (0)