Skip to content

Commit c2e1bb4

Browse files
committed
Update base for Update on "Dont quantize the current token for attention"
Differential Revision: [D63497872](https://our.internmc.facebook.com/intern/diff/D63497872/) [ghstack-poisoned]
2 parents aa90c26 + ee32848 commit c2e1bb4

File tree

673 files changed

+3480
-7407
lines changed

Some content is hidden

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

673 files changed

+3480
-7407
lines changed

.ci/scripts/test_llama.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ echo "Creating tokenizer.bin"
213213
$PYTHON_EXECUTABLE -m extension.llm.tokenizer.tokenizer -t tokenizer.model -o tokenizer.bin
214214

215215

216-
RUNTIME_ARGS="--model_path=${EXPORTED_MODEL_NAME} --tokenizer_path=tokenizer.bin --prompt=Once --temperature=0 --seq_len=10"
216+
RUNTIME_ARGS="--model_path=${EXPORTED_MODEL_NAME} --tokenizer_path=tokenizer.bin --prompt=Once --temperature=0 --seq_len=10 --warmup=1"
217217
# Check build tool.
218218
echo "Running ${EXPORTED_MODEL_NAME} in portable mode"
219219
if [[ "${BUILD_TOOL}" == "buck2" ]]; then

.github/workflows/apple.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ on:
1313
- install_requirements.sh
1414
- backends/apple/**
1515
- build/build_apple_frameworks.sh
16+
- build/build_apple_llm_demo.sh
1617
- build/create_frameworks.sh
1718
- build/test_ios_ci.sh
1819
- examples/demo-apps/apple_ios/**
@@ -215,3 +216,70 @@ jobs:
215216
shasum -a 256 "${FILENAME}"
216217
${AWS_CMD} "${FILENAME}" s3://ossci-ios/executorch/ --acl public-read
217218
done
219+
220+
build-benchmark-app:
221+
name: build-benchmark-app
222+
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
223+
secrets: inherit
224+
with:
225+
runner: macos-latest-xlarge
226+
python-version: '3.11'
227+
submodules: 'true'
228+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
229+
upload-artifact: ios-apps
230+
secrets-env: BUILD_CERTIFICATE_BASE64 EXECUTORCH_BENCHMARK_BUILD_PROVISION_PROFILE_BASE64 KEYCHAIN_PASSWORD
231+
timeout: 90
232+
script: |
233+
set -eux
234+
235+
echo "::group::Setting up CI environment"
236+
.ci/scripts/setup-conda.sh
237+
238+
BUILD_TOOL=cmake
239+
# Setup MacOS dependencies as there is no Docker support on MacOS atm
240+
GITHUB_RUNNER=1 PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
241+
.ci/scripts/setup-macos.sh "${BUILD_TOOL}"
242+
export ARTIFACTS_DIR_NAME=artifacts-to-be-uploaded
243+
244+
# Setup Apple certificate for iOS development
245+
BUILD_PROVISION_PROFILE_BASE64="${SECRET_EXECUTORCH_BENCHMARK_BUILD_PROVISION_PROFILE_BASE64}" \
246+
BUILD_CERTIFICATE_BASE64="${SECRET_BUILD_CERTIFICATE_BASE64}" \
247+
KEYCHAIN_PASSWORD="${SECRET_KEYCHAIN_PASSWORD}" \
248+
.ci/scripts/setup-ios.sh
249+
250+
# Install CoreML Backend Requirements
251+
PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
252+
backends/apple/coreml/scripts/install_requirements.sh
253+
254+
# Install MPS Backend Requirements
255+
PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
256+
backends/apple/mps/install_requirements.sh
257+
echo "::endgroup::"
258+
259+
echo "::group::Build ExecuTorch iOS frameworks"
260+
FRAMEWORKS=(
261+
"executorch"
262+
"backend_coreml"
263+
"backend_mps"
264+
"backend_xnnpack"
265+
"kernels_custom"
266+
"kernels_optimized"
267+
"kernels_portable"
268+
"kernels_quantized"
269+
)
270+
271+
# Build Release iOS Frameworks
272+
PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
273+
build/build_apple_frameworks.sh --coreml --custom --mps --optimized --portable --quantized --xnnpack
274+
275+
mkdir -p extension/apple/Benchmark/Frameworks
276+
for FRAMEWORK in "${FRAMEWORKS[@]}"; do (
277+
cp -r "cmake-out/${FRAMEWORK}.xcframework" extension/apple/Benchmark/Frameworks/
278+
) done
279+
echo "::endgroup::"
280+
281+
echo "::group::Build ExecuTorch benchmark app"
282+
mkdir -p extension/apple/Benchmark/Models
283+
${CONDA_RUN} --no-capture-output \
284+
build/build_apple_llm_demo.sh ${ARTIFACTS_DIR_NAME}
285+
echo "::endgroup::"

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.hypothesis
22
buck-out/
3-
cmake-out/
3+
cmake-out*
4+
.DS_Store
45
cmake-android-out/
56
cmake-out-android/
67
cmake-ios-out/

CMakeLists.txt

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -458,22 +458,22 @@ endif()
458458
add_subdirectory(schema)
459459

460460
#
461-
# executorch_no_prim_ops: Minimal runtime library
461+
# executorch_core: Minimal runtime library
462462
#
463463
# The bare-minimum runtime library, supporting the Program and Method
464464
# interfaces. Does not contain any operators, including primitive ops. Does not
465465
# contain any backends.
466466
#
467467

468468
# Remove any PAL-definition files from the sources.
469-
list(FILTER _executorch_no_prim_ops__srcs EXCLUDE REGEX
469+
list(FILTER _executorch_core__srcs EXCLUDE REGEX
470470
"runtime/platform/default/[^/]*.cpp$"
471471
)
472472

473473
# Add the source file that maps to the requested default PAL implementation.
474474
if(EXECUTORCH_PAL_DEFAULT MATCHES "^(posix|minimal)$")
475475
message(STATUS "executorch: Using PAL default '${EXECUTORCH_PAL_DEFAULT}'")
476-
list(APPEND _executorch_no_prim_ops__srcs
476+
list(APPEND _executorch_core__srcs
477477
"runtime/platform/default/${EXECUTORCH_PAL_DEFAULT}.cpp"
478478
)
479479
else()
@@ -483,45 +483,49 @@ else()
483483
)
484484
endif()
485485

486-
add_library(executorch_no_prim_ops ${_executorch_no_prim_ops__srcs})
487-
target_link_libraries(executorch_no_prim_ops PRIVATE program_schema)
486+
add_library(executorch_core ${_executorch_core__srcs})
487+
488+
# Legacy name alias.
489+
add_library(executorch_no_prim_ops ALIAS executorch_core)
490+
491+
target_link_libraries(executorch_core PRIVATE program_schema)
488492
if(EXECUTORCH_USE_DL)
489493
# Check if dl exists for this toolchain and only then link it.
490494
find_library(DL_LIBRARY_EXISTS NAMES dl)
491495
# Check if the library was found
492496
if(DL_LIBRARY_EXISTS)
493-
target_link_libraries(executorch_no_prim_ops PRIVATE dl) # For dladdr()
497+
target_link_libraries(executorch_core PRIVATE dl) # For dladdr()
494498
endif()
495499
endif()
496500
target_include_directories(
497-
executorch_no_prim_ops PUBLIC ${_common_include_directories}
501+
executorch_core PUBLIC ${_common_include_directories}
498502
)
499-
target_compile_options(executorch_no_prim_ops PUBLIC ${_common_compile_options})
503+
target_compile_options(executorch_core PUBLIC ${_common_compile_options})
500504
if(MAX_KERNEL_NUM)
501505
target_compile_definitions(
502-
executorch_no_prim_ops PRIVATE MAX_KERNEL_NUM=${MAX_KERNEL_NUM}
506+
executorch_core PRIVATE MAX_KERNEL_NUM=${MAX_KERNEL_NUM}
503507
)
504508
endif()
505509

506510
if(EXECUTORCH_BUILD_PYBIND AND APPLE)
507511
# shared version
508512
add_library(
509-
executorch_no_prim_ops_shared SHARED ${_executorch_no_prim_ops__srcs}
513+
executorch_core_shared SHARED ${_executorch_core__srcs}
510514
)
511-
target_link_libraries(executorch_no_prim_ops_shared PRIVATE program_schema)
515+
target_link_libraries(executorch_core_shared PRIVATE program_schema)
512516
if(DL_LIBRARY_EXISTS)
513517
# For dladdr()
514-
target_link_libraries(executorch_no_prim_ops_shared PRIVATE dl)
518+
target_link_libraries(executorch_core_shared PRIVATE dl)
515519
endif()
516520
target_include_directories(
517-
executorch_no_prim_ops_shared PUBLIC ${_common_include_directories}
521+
executorch_core_shared PUBLIC ${_common_include_directories}
518522
)
519523
target_compile_options(
520-
executorch_no_prim_ops_shared PUBLIC ${_common_compile_options}
524+
executorch_core_shared PUBLIC ${_common_compile_options}
521525
)
522526
if(MAX_KERNEL_NUM)
523527
target_compile_definitions(
524-
executorch_no_prim_ops_shared PRIVATE MAX_KERNEL_NUM=${MAX_KERNEL_NUM}
528+
executorch_core_shared PRIVATE MAX_KERNEL_NUM=${MAX_KERNEL_NUM}
525529
)
526530
endif()
527531
endif()
@@ -534,7 +538,7 @@ endif()
534538
# any backends.
535539
#
536540
add_library(executorch ${_executorch__srcs})
537-
target_link_libraries(executorch PRIVATE executorch_no_prim_ops)
541+
target_link_libraries(executorch PRIVATE executorch_core)
538542
target_include_directories(executorch PUBLIC ${_common_include_directories})
539543
target_compile_options(executorch PUBLIC ${_common_compile_options})
540544
target_link_options_shared_lib(executorch)
@@ -570,7 +574,7 @@ endif()
570574
# Install `executorch` library as well as `executorch-config.cmake` under
571575
# ${CMAKE_INSTALL_PREFIX}/
572576
install(
573-
TARGETS executorch executorch_no_prim_ops
577+
TARGETS executorch executorch_core
574578
DESTINATION lib
575579
INCLUDES
576580
DESTINATION ${_common_include_directories}

backends/apple/coreml/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ target_include_directories(
134134
coremldelegate PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/runtime/util
135135
)
136136
target_include_directories(coremldelegate PRIVATE ${EXECUTORCH_ROOT}/..)
137-
target_link_libraries(coremldelegate PRIVATE executorch_no_prim_ops)
137+
target_link_libraries(coremldelegate PRIVATE executorch_core)
138138

139139
if(EXECUTORCH_BUILD_DEVTOOLS)
140140
target_sources(coremldelegate PRIVATE ${SDK_SOURCES} ${PROTOBUF_SOURCES})
@@ -159,7 +159,7 @@ find_library(SQLITE_LIBRARY sqlite3)
159159

160160
target_link_libraries(
161161
coremldelegate
162-
PRIVATE executorch_no_prim_ops ${ACCELERATE_FRAMEWORK} ${COREML_FRAMEWORK}
162+
PRIVATE executorch_core ${ACCELERATE_FRAMEWORK} ${COREML_FRAMEWORK}
163163
${FOUNDATION_FRAMEWORK} ${SQLITE_LIBRARY}
164164
)
165165

@@ -176,7 +176,7 @@ target_compile_options(coremldelegate PRIVATE "-fno-exceptions")
176176

177177
if(EXECUTORCH_BUILD_DEVTOOLS)
178178
target_compile_options(
179-
executorch_no_prim_ops PUBLIC -DET_EVENT_TRACER_ENABLED
179+
executorch_core PUBLIC -DET_EVENT_TRACER_ENABLED
180180
)
181181
target_compile_options(coremldelegate PRIVATE "-frtti")
182182
target_compile_options(libprotobuf-lite PRIVATE "-frtti")

backends/apple/coreml/runtime/workspace/executorchcoreml.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
C9E7D7962AB3F9BF00CCAE5D /* KeyValueStoreTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = C9E7D78E2AB3F9BF00CCAE5D /* KeyValueStoreTests.mm */; };
106106
C9E7D7A22AB3FBB200CCAE5D /* CoreMLBackendDelegateTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = C9E7D7A12AB3FBB200CCAE5D /* CoreMLBackendDelegateTests.mm */; };
107107
C9EC7E1B2BC73B3200A6B166 /* MultiArrayTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = C9EC7E1A2BC73B3200A6B166 /* MultiArrayTests.mm */; };
108-
F24817E52BC655E100E80D98 /* libexecutorch_no_prim_ops.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F24817E42BC655E100E80D98 /* libexecutorch_no_prim_ops.a */; };
108+
F24817E52BC655E100E80D98 /* libexecutorch_core.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F24817E42BC655E100E80D98 /* libexecutorch_core.a */; };
109109
/* End PBXBuildFile section */
110110

111111
/* Begin PBXCopyFilesBuildPhase section */
@@ -310,7 +310,7 @@
310310
C9EA3FE52B73EF6300B7D7BD /* Accelerate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accelerate.framework; path = System/Library/Frameworks/Accelerate.framework; sourceTree = SDKROOT; };
311311
C9EC7E092BC662A300A6B166 /* objc_array_util.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = objc_array_util.h; path = ../util/objc_array_util.h; sourceTree = "<group>"; };
312312
C9EC7E1A2BC73B3200A6B166 /* MultiArrayTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = MultiArrayTests.mm; path = ../test/MultiArrayTests.mm; sourceTree = "<group>"; };
313-
F24817E42BC655E100E80D98 /* libexecutorch_no_prim_ops.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libexecutorch_no_prim_ops.a; path = ../libraries/libexecutorch_no_prim_ops.a; sourceTree = "<group>"; };
313+
F24817E42BC655E100E80D98 /* libexecutorch_core.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libexecutorch_core.a; path = ../libraries/libexecutorch_core.a; sourceTree = "<group>"; };
314314
/* End PBXFileReference section */
315315

316316
/* Begin PBXFrameworksBuildPhase section */
@@ -319,7 +319,7 @@
319319
buildActionMask = 2147483647;
320320
files = (
321321
C94D510F2ABDF87500AF47FD /* Accelerate.framework in Frameworks */,
322-
F24817E52BC655E100E80D98 /* libexecutorch_no_prim_ops.a in Frameworks */,
322+
F24817E52BC655E100E80D98 /* libexecutorch_core.a in Frameworks */,
323323
C94D510E2ABDF86800AF47FD /* libsqlite3.tbd in Frameworks */,
324324
C94D50D92ABD7B2400AF47FD /* CoreML.framework in Frameworks */,
325325
C99883862B95AD7D000953A3 /* libprotobuf-lite.a in Frameworks */,
@@ -540,7 +540,7 @@
540540
C96560942AABFDCE005F8126 /* libsqlite3.tbd */,
541541
C96560922AABF992005F8126 /* CoreML.framework */,
542542
C96560902AABF982005F8126 /* Accelerate.framework */,
543-
F24817E42BC655E100E80D98 /* libexecutorch_no_prim_ops.a */,
543+
F24817E42BC655E100E80D98 /* libexecutorch_core.a */,
544544
C965608D2AABF72A005F8126 /* libexecutorch.a */,
545545
);
546546
name = "Recovered References";

backends/apple/coreml/scripts/build_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ cmake --build "$CMAKE_PROTOBUF_BUILD_DIR_PATH" -j9 -t libprotobuf-lite
5959
echo "ExecuTorch: Copying libraries"
6060
mkdir "$LIBRARIES_DIR_PATH"
6161
cp -f "$CMAKE_EXECUTORCH_BUILD_DIR_PATH/libexecutorch.a" "$LIBRARIES_DIR_PATH"
62-
cp -f "$CMAKE_EXECUTORCH_BUILD_DIR_PATH/libexecutorch_no_prim_ops.a" "$LIBRARIES_DIR_PATH"
62+
cp -f "$CMAKE_EXECUTORCH_BUILD_DIR_PATH/libexecutorch_core.a" "$LIBRARIES_DIR_PATH"
6363
cp -f "$CMAKE_PROTOBUF_BUILD_DIR_PATH/libprotobuf-lite.a" "$LIBRARIES_DIR_PATH"
6464

6565
#Copy ExecuTorch headers

backends/apple/mps/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ target_link_libraries(
7575
mpsdelegate
7676
PRIVATE bundled_program
7777
mps_schema
78-
executorch_no_prim_ops
78+
executorch_core
7979
${FOUNDATION_FRAMEWORK}
8080
${METAL_FRAMEWORK}
8181
${MPS_FRAMEWORK}

backends/arm/arm_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def preprocess( # noqa: C901
217217
# const data directly. Path created and data written only in debug builds.
218218
tosa_graph = ts.TosaSerializer(artifact_path)
219219
graph_module = ArmPassManager().transform_to_backend_pipeline(
220-
graph_module=edge_program.graph_module, compile_spec=compile_spec
220+
exported_program=edge_program, compile_spec=compile_spec
221221
)
222222

223223
node_visitors = get_node_visitors(edge_program)

backends/arm/arm_partitioner.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,15 @@ def is_node_supported(self, submodules, node: torch.fx.Node) -> bool:
5858
exir_ops.edge.aten.mm.default,
5959
exir_ops.edge.aten.repeat.default,
6060
exir_ops.edge.aten.relu.default,
61+
exir_ops.edge.aten.rsqrt.default,
6162
exir_ops.edge.aten._softmax.default,
6263
exir_ops.edge.aten.slice_copy.Tensor,
6364
exir_ops.edge.aten.sub.Tensor,
6465
exir_ops.edge.aten.view_copy.default,
6566
exir_ops.edge.aten.clone.default,
6667
exir_ops.edge.aten.mean.dim,
6768
exir_ops.edge.aten.unsqueeze_copy.default,
69+
exir_ops.edge.aten.squeeze_copy.dims,
6870
operator.getitem,
6971
exir_ops.edge.quantized_decomposed.quantize_per_tensor.default,
7072
exir_ops.edge.quantized_decomposed.dequantize_per_tensor.default,

backends/arm/operators/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@
2828
op_quant,
2929
op_relu,
3030
op_repeat,
31+
op_rsqrt,
3132
op_sigmoid,
3233
op_slice,
3334
op_softmax,
35+
op_squeeze,
3436
op_sub,
3537
op_unsqueeze,
3638
op_view,

backends/arm/operators/op_placeholder.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ def process_inputs(
2828
tosa_graph: ts.TosaSerializer,
2929
):
3030
"""Serialize an input node"""
31+
# inputs need to be in default dim_order (contiguous memory format)
32+
meta = node.meta["val"]
33+
if meta.dim_order() != tuple(range(meta.dim())):
34+
raise RuntimeError(
35+
f"Arm backend only supports contiguous memory format for inputs. "
36+
f"Expected dim_order: {tuple(range(meta.dim()))}, but got: {meta.dim_order()} for node {node.name}"
37+
)
3138
inputs = [TosaArg(node)]
3239
input_shape = inputs[0].shape
3340
input_dim_order = inputs[0].dim_order

0 commit comments

Comments
 (0)