Skip to content

Commit 9a7dab9

Browse files
Deprecate MPS backend (#18470)
Differential Revision: D97825833 Co-authored-by: Scott Roy <161522778+metascroy@users.noreply.github.com>
1 parent 4e7261e commit 9a7dab9

File tree

13 files changed

+241
-2
lines changed

13 files changed

+241
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ See [examples/models/llama](examples/models/llama/README.md) for complete workfl
187187
| **Platform** | **Supported Backends** |
188188
|------------------|----------------------------------------------------------|
189189
| Android | XNNPACK, Vulkan, Qualcomm, MediaTek, Samsung Exynos |
190-
| iOS | XNNPACK, MPS, CoreML (Neural Engine) |
190+
| iOS | XNNPACK, CoreML (Neural Engine), MPS *(deprecated)* |
191191
| Linux / Windows | XNNPACK, OpenVINO, CUDA *(experimental)* |
192-
| macOS | XNNPACK, MPS, Metal *(experimental)* |
192+
| macOS | XNNPACK, Metal *(experimental)*, MPS *(deprecated)* |
193193
| Embedded / MCU | XNNPACK, ARM Ethos-U, NXP, Cadence DSP |
194194

195195
See [Backend Documentation](https://docs.pytorch.org/executorch/main/backends-overview.html) for detailed hardware requirements and optimization guides. For desktop/laptop GPU inference with CUDA and Metal, see the [Desktop Guide](desktop/README.md). For Zephyr RTOS integration, see the [Zephyr Guide](zephyr/README.md).

backends/apple/mps/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
cmake_minimum_required(VERSION 3.19)
77

8+
message(
9+
WARNING "[DEPRECATED] The MPS backend is deprecated and will be removed in "
10+
"ExecuTorch 1.4. Please migrate to CoreML or the Metal backend."
11+
)
12+
813
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
914

1015
if(NOT CMAKE_CXX_STANDARD)

backends/apple/mps/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
# Provided subject to the LICENSE file in the top level directory.
44
#
55

6+
import warnings
7+
8+
warnings.warn(
9+
"The executorch.backends.apple.mps package is deprecated and will be "
10+
"removed in ExecuTorch 1.4. Use executorch.backends.apple.coreml instead.",
11+
FutureWarning,
12+
stacklevel=2,
13+
)
14+
615
from .mps_preprocess import MPSBackend
716

817
__all__ = [

backends/apple/mps/mps_preprocess.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
# Provided subject to the LICENSE file in the top level directory.
44
#
55
import logging
6+
import warnings
7+
8+
warnings.warn(
9+
"The MPS backend is deprecated and will be removed in ExecuTorch 1.4. "
10+
"Use the CoreML backend for iOS/macOS GPU acceleration, or the Metal "
11+
"backend for macOS desktop GPU workloads. "
12+
"See https://docs.pytorch.org/executorch/main/backends-overview.html "
13+
"for migration guidance.",
14+
FutureWarning,
15+
stacklevel=2,
16+
)
617
from typing import ClassVar, Dict, final, List, Tuple
718

819
import torch
@@ -27,6 +38,7 @@
2738
convert_to_flatbuffer,
2839
)
2940
from executorch.exir._serialize._program import Cord
41+
from executorch.exir._warnings import deprecated
3042

3143
from executorch.exir.backend.backend_details import (
3244
BackendDetails,
@@ -43,8 +55,24 @@
4355
logging.basicConfig(level=logging.INFO, format=FORMAT)
4456

4557

58+
@deprecated(
59+
"The MPS backend is deprecated and will be removed in ExecuTorch 1.4. "
60+
"Use the CoreML backend for iOS/macOS GPU acceleration, or the Metal "
61+
"backend for macOS desktop GPU workloads. "
62+
"See https://docs.pytorch.org/executorch/main/backends-overview.html "
63+
"for migration guidance.",
64+
category=FutureWarning,
65+
)
4666
@final
4767
class MPSBackend(BackendDetails):
68+
"""MPS backend for Apple GPU acceleration via MPSGraph.
69+
70+
.. warning::
71+
72+
``MPSBackend`` is deprecated and will be removed in ExecuTorch 1.4.
73+
Use ``CoreMLBackend`` (iOS/macOS) or the Metal backend (macOS) instead.
74+
"""
75+
4876
@staticmethod
4977
def slice_len_max(s):
5078
assert s.start is not None

backends/apple/mps/partition/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
# Provided subject to the LICENSE file in the top level directory.
44
#
55

6+
import warnings
7+
8+
warnings.warn(
9+
"The executorch.backends.apple.mps.partition package is deprecated and will "
10+
"be removed in ExecuTorch 1.4. Use "
11+
"executorch.backends.apple.coreml.partition instead.",
12+
FutureWarning,
13+
stacklevel=2,
14+
)
15+
616
from .mps_partitioner import MPSPartitioner
717

818
__all__ = [

backends/apple/mps/partition/mps_partitioner.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,23 @@
44
#
55

66
import logging
7+
import warnings
8+
9+
warnings.warn(
10+
"The MPS partitioner is deprecated and will be removed in ExecuTorch 1.4. "
11+
"Use CoreMLPartitioner for iOS/macOS GPU acceleration instead. "
12+
"See https://docs.pytorch.org/executorch/main/backends-overview.html "
13+
"for migration guidance.",
14+
FutureWarning,
15+
stacklevel=2,
16+
)
717
from typing import Any, cast, Dict, List, Union
818

919
import torch
1020
from executorch.backends.apple.mps import MPSBackend
1121
from executorch.backends.apple.mps.operators.node_visitor import get_node_visitors
1222
from executorch.backends.transforms import get_shape
23+
from executorch.exir._warnings import deprecated
1324
from executorch.exir.backend.backend_details import CompileSpec
1425
from executorch.exir.backend.canonical_partitioners.pattern_op_partitioner import (
1526
generate_partitions_from_list_of_nodes,
@@ -51,7 +62,22 @@ def is_node_supported(self, submodules, node: torch.fx.Node) -> bool:
5162
return True
5263

5364

65+
@deprecated(
66+
"The MPS partitioner is deprecated and will be removed in ExecuTorch 1.4. "
67+
"Use CoreMLPartitioner for iOS/macOS GPU acceleration instead. "
68+
"See https://docs.pytorch.org/executorch/main/backends-overview.html "
69+
"for migration guidance.",
70+
category=FutureWarning,
71+
)
5472
class MPSPartitioner(Partitioner):
73+
"""Partitioner for the MPS backend.
74+
75+
.. warning::
76+
77+
``MPSPartitioner`` is deprecated and will be removed in ExecuTorch 1.4.
78+
Use ``CoreMLPartitioner`` instead.
79+
"""
80+
5581
def __init__(self, compile_specs: List[CompileSpec]) -> None:
5682
self.compile_specs = compile_specs
5783
self.delegation_spec = DelegationSpec(MPSBackend.__name__, compile_specs)

backends/apple/mps/runtime/MPSBackend.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ bool is_available() const override {
4444
BackendInitContext& context,
4545
FreeableBuffer* processed,
4646
ArrayRef<CompileSpec> compile_specs) const override {
47+
ET_LOG(
48+
Info,
49+
"The MPS backend is deprecated and will be removed in ExecuTorch 1.4. "
50+
"Please migrate to CoreML or the Metal backend.");
51+
4752
auto executor = context.get_runtime_allocator()->allocateInstance<mps::delegate::MPSExecutor>();
4853
if (executor == nullptr) {
4954
return Error::MemoryAllocationFailed;

backends/apple/mps/setup.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Building and Running ExecuTorch with MPS Backend
22

3+
> **⚠️ Deprecated:** The MPS backend is deprecated as of ExecuTorch 1.2 and will
4+
> be removed in ExecuTorch 1.4. Please migrate to the
5+
> [CoreML backend](../coreml/) for iOS/macOS GPU acceleration, or the
6+
> [Metal backend](../../../desktop/) for macOS desktop GPU workloads.
7+
38
In this tutorial we will walk you through the process of getting setup to build the MPS backend for ExecuTorch and running a simple model on it.
49

510
The MPS backend device maps machine learning computational graphs and primitives on the [MPS Graph](https://developer.apple.com/documentation/metalperformanceshadersgraph/mpsgraph?language=objc) framework and tuned kernels provided by [MPS](https://developer.apple.com/documentation/metalperformanceshaders?language=objc).
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#
2+
# Copyright (c) 2023 Apple Inc. All rights reserved.
3+
# Provided subject to the LICENSE file in the top level directory.
4+
#
5+
6+
import sys
7+
import unittest
8+
import warnings
9+
10+
11+
class TestMPSDeprecation(unittest.TestCase):
12+
"""Tests that MPS backend deprecation warnings are properly emitted."""
13+
14+
def setUp(self) -> None:
15+
# Clear cached MPS modules so module-level warnings fire again on each test
16+
for key in [
17+
k for k in sys.modules if k.startswith("executorch.backends.apple.mps")
18+
]:
19+
del sys.modules[key]
20+
21+
def test_mps_package_import_warns(self) -> None:
22+
with warnings.catch_warnings(record=True) as w:
23+
warnings.simplefilter("always")
24+
import executorch.backends.apple.mps # noqa: F401
25+
26+
future_warnings = [
27+
warning
28+
for warning in w
29+
if issubclass(warning.category, FutureWarning)
30+
and "deprecated" in str(warning.message).lower()
31+
and "mps" in str(warning.message).lower()
32+
]
33+
self.assertTrue(
34+
len(future_warnings) > 0,
35+
"Importing executorch.backends.apple.mps should emit a FutureWarning",
36+
)
37+
38+
def test_mps_partition_package_import_warns(self) -> None:
39+
with warnings.catch_warnings(record=True) as w:
40+
warnings.simplefilter("always")
41+
import executorch.backends.apple.mps.partition # noqa: F401
42+
43+
future_warnings = [
44+
warning
45+
for warning in w
46+
if issubclass(warning.category, FutureWarning)
47+
and "deprecated" in str(warning.message).lower()
48+
and "mps" in str(warning.message).lower()
49+
]
50+
self.assertTrue(
51+
len(future_warnings) > 0,
52+
"Importing executorch.backends.apple.mps.partition should emit a FutureWarning",
53+
)
54+
55+
def test_mps_backend_class_warns(self) -> None:
56+
with warnings.catch_warnings(record=True) as w:
57+
warnings.simplefilter("always")
58+
from executorch.backends.apple.mps.mps_preprocess import ( # noqa: F401
59+
MPSBackend,
60+
)
61+
62+
future_warnings = [
63+
warning
64+
for warning in w
65+
if issubclass(warning.category, FutureWarning)
66+
and "MPS backend is deprecated" in str(warning.message)
67+
]
68+
self.assertTrue(
69+
len(future_warnings) > 0,
70+
"Importing MPSBackend should emit a FutureWarning about deprecation",
71+
)
72+
73+
def test_mps_partitioner_class_warns(self) -> None:
74+
with warnings.catch_warnings(record=True) as w:
75+
warnings.simplefilter("always")
76+
from executorch.backends.apple.mps.partition.mps_partitioner import ( # noqa: F401
77+
MPSPartitioner,
78+
)
79+
80+
future_warnings = [
81+
warning
82+
for warning in w
83+
if issubclass(warning.category, FutureWarning)
84+
and "MPS partitioner is deprecated" in str(warning.message)
85+
]
86+
self.assertTrue(
87+
len(future_warnings) > 0,
88+
"Importing MPSPartitioner should emit a FutureWarning about deprecation",
89+
)
90+
91+
def test_deprecation_message_mentions_alternative(self) -> None:
92+
with warnings.catch_warnings(record=True) as w:
93+
warnings.simplefilter("always")
94+
from executorch.backends.apple.mps.mps_preprocess import ( # noqa: F401
95+
MPSBackend,
96+
)
97+
98+
future_warnings = [
99+
warning for warning in w if issubclass(warning.category, FutureWarning)
100+
]
101+
self.assertTrue(len(future_warnings) > 0)
102+
message = str(future_warnings[-1].message)
103+
self.assertIn(
104+
"CoreML",
105+
message,
106+
"Deprecation warning should mention CoreML as an alternative",
107+
)
108+
109+
def test_deprecation_message_mentions_removal_version(self) -> None:
110+
with warnings.catch_warnings(record=True) as w:
111+
warnings.simplefilter("always")
112+
from executorch.backends.apple.mps.mps_preprocess import ( # noqa: F401
113+
MPSBackend,
114+
)
115+
116+
future_warnings = [
117+
warning for warning in w if issubclass(warning.category, FutureWarning)
118+
]
119+
self.assertTrue(len(future_warnings) > 0)
120+
message = str(future_warnings[-1].message)
121+
self.assertIn(
122+
"1.4",
123+
message,
124+
"Deprecation warning should mention the removal version (1.4)",
125+
)

docs/source/backends/mps/mps-overview.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# MPS Backend
22

3+
:::{warning}
4+
**Deprecated:** The MPS backend is deprecated as of ExecuTorch 1.2 and will be
5+
removed in ExecuTorch 1.4. Please migrate to the
6+
[CoreML backend](../coreml/coreml-overview.md) for iOS/macOS GPU acceleration,
7+
or the [Metal backend](../../../../desktop/README.md) for macOS desktop GPU
8+
workloads.
9+
:::
10+
311
MPS delegate is the ExecuTorch solution to take advantage of Apple's GPU for on-device ML using the [MPS Graph](https://developer.apple.com/documentation/metalperformanceshadersgraph/mpsgraph?language=objc) framework and tuned kernels provided by [MPS](https://developer.apple.com/documentation/metalperformanceshaders?language=objc).
412

513
## Target Requirements

0 commit comments

Comments
 (0)