Skip to content

Commit cbc0c95

Browse files
DenisVieriu97facebook-github-bot
authored andcommitted
Add new mps runtime with support for FP16, lifted and unlifted graphs (iOS15+, macOS12+) (#1655)
Summary: This PR changes the MPS Backend runtime to support for **iOS15+/macOS12+** (previous runtime was limited to iOS17/macOS14 only). Additionally, this PR contains changes such as support for both lifted and unlifted graphs, support for torch.export API, optimizations for FP16 and faster model loading during runtime (more information in the summary). **Summary of changes:** - Add support for running the models in FP16 (https://github.com/DenisVieriu97/executorch/pull/7 georgepaw) - Replace the previous MPS runtime from ExecuTorch which was relying on `iOS17` / `macOS` Sonoma APIs for serialization of the MPSGraphExecutable. Instead of creating the MPSGraph nodes and serializing them during AOT, create the corresponding entries of the EdgeIR nodes in the FlatBuffer, and parse them during runtime to construct the graph. This removes any dependency on iOS17 / macOS 14.0 APIs. - Add support for node visitor pattern: - Each node visitor class visits an op and serializes the data into MPSTensors and MPSNodes which get appended in the flatbuffer - The entries from the FlatBuffer are parsed in the runtime and based on them the MPSGraph is constructed (for more info see `MPSGraphBuilder` class and corresponding ops from `operators/` folder. - This method removes the additional read and writes to disk of the MPSGraphExecutable (once during AOT and once during runtime). **Models summary:** | Model | FP16 | FP32 | | :---: | :---: | :---: | mul | <ul><li>- [x] </li> | <ul><li>- [x] </li> | add_mul | <ul><li>- [x] </li> | <ul><li>- [x] </li> | linear | <ul><li>- [x] </li> | <ul><li>- [x] </li> | edsr | <ul><li>- [x] </li> | <ul><li>- [x] </li> | Mobilebert | <ul><li>- [ ] </li> | <ul><li>- [x] </li> | mv2 | <ul><li>- [x] </li> | <ul><li>- [x] </li> | mv3 | <ul><li>- [x] </li> | <ul><li>- [x] </li> | vit | <ul><li>- [x] </li> | <ul><li>- [x] </li> | w2l | <ul><li>- [x] </li> | <ul><li>- [x] </li> | ic3 | <ul><li>- [x] </li> | <ul><li>- [x] </li> | ic4 | <ul><li>- [x] </li> | <ul><li>- [x] </li> | resnet18 | <ul><li>- [x] </li> | <ul><li>- [x] </li> | resnet50 | <ul><li>- [x] </li> | <ul><li>- [x] </li> | Llama2 | <ul><li>- [ ] </li> | <ul><li>- [x] </li> | emformer_join | <ul><li>- [x] </li> | <ul><li>- [x] </li> | emformer_predict | <ul><li>- [ ] </li> | <ul><li>- [ ] </li> | emformer_transcribe | <ul><li>- [x] </li> | <ul><li>- [x] </li> | dl3 | <ul><li>- [ ] </li> | <ul><li>- [ ] </li> | Pull Request resolved: #1655 Reviewed By: cccclai Differential Revision: D52929916 Pulled By: shoumikhin fbshipit-source-id: 8bd2ed124311744ebe19fc17eb0ff508621f974a
1 parent 71aedc5 commit cbc0c95

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+6209
-3652
lines changed

backends/apple/mps/CMakeLists.txt

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,46 @@ if(NOT EXECUTORCH_ROOT)
2020
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
2121
endif()
2222

23+
if(NOT FLATC_EXECUTABLE)
24+
set(FLATC_EXECUTABLE flatc)
25+
endif()
26+
2327
set(_common_compile_options -Wno-deprecated-declarations)
2428
set(_common_include_directories ${EXECUTORCH_ROOT}/..)
2529

30+
set(_mps_schema__include_dir "${CMAKE_BINARY_DIR}/schema/include")
31+
32+
# Paths to headers generated from the .fbs files.
33+
set(_mps_schema__outputs)
34+
foreach(fbs_file ${_mps_schema__srcs})
35+
string(REGEX REPLACE "serialization/([^/]+)[.]fbs$" "\\1_generated.h"
36+
generated "${fbs_file}")
37+
list(APPEND _mps_schema__outputs
38+
"${_mps_schema__include_dir}/executorch/${generated}")
39+
endforeach()
40+
41+
# Generate the headers from the .fbs files.
42+
add_custom_command(
43+
OUTPUT ${_mps_schema__outputs}
44+
COMMAND
45+
${FLATC_EXECUTABLE} --cpp --cpp-std c++11 --scoped-enums -o
46+
"${_mps_schema__include_dir}/executorch/backends/apple/mps"
47+
${_mps_schema__srcs}
48+
WORKING_DIRECTORY ${EXECUTORCH_ROOT}
49+
COMMENT "Generating mps_schema headers"
50+
VERBATIM)
51+
52+
add_library(mps_schema INTERFACE ${_mps_schema__outputs})
53+
set_target_properties(mps_schema PROPERTIES LINKER_LANGUAGE CXX)
54+
target_include_directories(
55+
mps_schema INTERFACE ${_mps_schema__include_dir}
56+
${EXECUTORCH_ROOT}/third-party/flatbuffers/include
57+
${_common_include_directories})
58+
2659
list(TRANSFORM _mps_backend__srcs PREPEND "${EXECUTORCH_ROOT}/")
2760
add_library(mpsdelegate ${_mps_backend__srcs})
28-
target_link_libraries(mpsdelegate PRIVATE baundled_program
61+
target_link_libraries(mpsdelegate PRIVATE baundled_program mps_schema
2962
${_executor_runner_libs})
30-
target_include_directories(mpsdelegate PUBLIC ${_common_include_directories})
3163

3264
install(
3365
TARGETS mpsdelegate

backends/apple/mps/mps_preprocess.py

Lines changed: 152 additions & 753 deletions
Large diffs are not rendered by default.

backends/apple/mps/operations/ActivationOps.mm

Lines changed: 0 additions & 165 deletions
This file was deleted.

backends/apple/mps/operations/BinaryOps.h

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)