Skip to content

Commit a9e4cdb

Browse files
Merge branch 'main' into fix-unsqueeze-scalar-placeholder-pass
2 parents 5a6cefd + b173722 commit a9e4cdb

File tree

91 files changed

+1961
-1112
lines changed

Some content is hidden

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

91 files changed

+1961
-1112
lines changed

.ci/scripts/test_model.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ test_model() {
8787
bash examples/models/llava/install_requirements.sh
8888
STRICT="--no-strict"
8989
fi
90-
if [[ "$MODEL_NAME" == "llama3_2_vision_encoder" || "$MODEL_NAME" == "llama3_2_text_decoder" ]]; then
91-
# Install requirements for llama vision.
92-
bash examples/models/llama3_2_vision/install_requirements.sh
93-
fi
9490
if [[ "${MODEL_NAME}" == "qwen2_5" ]]; then
9591
# Install requirements for export_llama
9692
bash examples/models/llama/install_requirements.sh

.ci/scripts/unittest-linux.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ if [[ "$BUILD_TOOL" == "cmake" ]]; then
2424
CMAKE_ARGS="-DEXECUTORCH_BUILD_PYBIND=ON -DEXECUTORCH_BUILD_XNNPACK=ON -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON" \
2525
.ci/scripts/setup-linux.sh "$@"
2626

27-
# Install llama3_2_vision dependencies.
28-
PYTHON_EXECUTABLE=python ./examples/models/llama3_2_vision/install_requirements.sh
29-
3027
.ci/scripts/unittest-linux-cmake.sh
3128
elif [[ "$BUILD_TOOL" == "buck2" ]]; then
3229
# Removing this breaks sccache in the Buck build, apparently

.ci/scripts/unittest-macos.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ if [[ "$BUILD_TOOL" == "cmake" ]]; then
2929
# Install llama3_2_vision dependencies.
3030
PYTHON_EXECUTABLE=python \
3131
${CONDA_RUN} --no-capture-output \
32-
./examples/models/llama3_2_vision/install_requirements.sh
3332

3433
.ci/scripts/unittest-macos-cmake.sh
3534
elif [[ "$BUILD_TOOL" == "buck2" ]]; then

.github/workflows/build-presets.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,20 @@ on:
1111
concurrency:
1212
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }}-${{ github.event_name == 'schedule' }}
1313
cancel-in-progress: true
14+
15+
jobs:
16+
apple:
17+
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
18+
strategy:
19+
matrix:
20+
preset: [macos-arm64]
21+
with:
22+
job-name: build
23+
runner: macos-latest-xlarge
24+
python-version: 3.12
25+
submodules: recursive
26+
script: |
27+
set -eux
28+
${CONDA_RUN} ./install_requirements.sh > /dev/null
29+
${CONDA_RUN} cmake --preset ${{ matrix.preset }}
30+
${CONDA_RUN} cmake --build cmake-out --parallel

.github/workflows/pull.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,7 @@ jobs:
434434
output=$(ls -la cmake-out/test/size_test)
435435
arr=($output)
436436
size=${arr[4]}
437-
# threshold=48120 on devserver with gcc11.4
438-
# todo(lfq): update once binary size is below 50kb.
439-
threshold="47552"
437+
threshold="47560"
440438
if [[ "$size" -le "$threshold" ]]; then
441439
echo "Success $size <= $threshold"
442440
else

.lintrunner.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,13 @@ exclude_patterns = [
220220
'extension/**',
221221
'kernels/optimized/**',
222222
# Justified <functional> include.
223+
'kernels/portable/cpu/op_bitwise*.cpp',
224+
'kernels/portable/cpu/op_eq.cpp',
225+
'kernels/portable/cpu/op_ge.cpp',
226+
'kernels/portable/cpu/op_gt.cpp',
227+
'kernels/portable/cpu/op_le.cpp',
228+
'kernels/portable/cpu/op_lt.cpp',
229+
'kernels/portable/cpu/op_ne.cpp',
223230
'runtime/kernel/thread_parallel_interface.h',
224231
'scripts/**',
225232
'third-party/**',

CMakeLists.txt

Lines changed: 14 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,18 @@ project(executorch)
4848
# MARK: - Start EXECUTORCH_H12025_BUILD_MIGRATION --------------------------------------------------
4949

5050
include(${PROJECT_SOURCE_DIR}/tools/cmake/common/preset.cmake)
51+
52+
load_build_preset()
5153
include(${PROJECT_SOURCE_DIR}/tools/cmake/preset/default.cmake)
5254

55+
# Print all the configs that were called with announce_configured_options.
56+
print_configured_options()
57+
5358
# MARK: - End EXECUTORCH_H12025_BUILD_MIGRATION ----------------------------------------------------
5459

5560
include(tools/cmake/Utils.cmake)
5661
include(CMakeDependentOption)
62+
include(ExternalProject)
5763

5864
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
5965

@@ -175,8 +181,6 @@ option(EXECUTORCH_BUILD_ARM_BAREMETAL
175181
"Build the Arm Baremetal flow for Cortex-M and Ethos-U" OFF
176182
)
177183

178-
option(EXECUTORCH_BUILD_COREML "Build the Core ML backend" OFF)
179-
180184
option(EXECUTORCH_BUILD_KERNELS_CUSTOM "Build the custom kernels" OFF)
181185

182186
option(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT "Build the custom ops lib for AOT"
@@ -239,6 +243,8 @@ option(EXECUTORCH_USE_DL "Use libdl library" ON)
239243

240244
option(EXECUTORCH_BUILD_CADENCE "Build the Cadence DSP backend" OFF)
241245

246+
option(EXECUTORCH_BUILD_CORTEX_M "Build the Cortex-M backend" OFF)
247+
242248
#
243249
# pthreadpool: build pthreadpool library. Disable on unsupported platforms
244250
#
@@ -255,6 +261,8 @@ cmake_dependent_option(
255261
"NOT EXECUTORCH_BUILD_ARM_BAREMETAL" OFF
256262
)
257263

264+
add_subdirectory(third-party)
265+
258266
if(EXECUTORCH_BUILD_EXTENSION_TRAINING)
259267
set(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER ON)
260268
set(EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR ON)
@@ -449,81 +457,6 @@ if(EXECUTORCH_USE_CPP_CODE_COVERAGE)
449457
endif()
450458
endif()
451459

452-
#
453-
# flatc: Flatbuffer commandline tool to generate .h files from .fbs files
454-
#
455-
cmake_dependent_option(
456-
EXECUTORCH_BUILD_FLATC "Build the flatc executable." ON
457-
"NOT FLATC_EXECUTABLE" OFF
458-
)
459-
460-
set(FLATBUFFERS_BUILD_FLATC OFF CACHE BOOL "")
461-
set(FLATBUFFERS_BUILD_FLATHASH OFF CACHE BOOL "")
462-
set(FLATBUFFERS_BUILD_FLATLIB OFF CACHE BOOL "")
463-
set(FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "")
464-
set(FLATBUFFERS_INSTALL OFF CACHE BOOL "")
465-
# exir lets users set the alignment of tensor data embedded in the flatbuffer,
466-
# and some users need an alignment larger than the default, which is typically
467-
# 32.
468-
set(FLATBUFFERS_MAX_ALIGNMENT 1024)
469-
470-
if(EXECUTORCH_BUILD_FLATC)
471-
if(FLATC_EXECUTABLE)
472-
# We could ignore this, but it could lead to confusion about which `flatc`
473-
# is actually being used.
474-
message(
475-
FATAL_ERROR "May not set both EXECUTORCH_BUILD_FLATC and FLATC_EXECUTABLE"
476-
)
477-
endif()
478-
479-
# Build flatc for the *host* to generate files as part of the build step.
480-
include(ExternalProject)
481-
ExternalProject_Add(
482-
flatbuffers
483-
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/third-party/flatbuffers
484-
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/third-party/flatbuffers
485-
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third-party/flatbuffers
486-
CMAKE_ARGS -DFLATBUFFERS_BUILD_FLATC=ON
487-
-DFLATBUFFERS_BUILD_FLATHASH=${FLATBUFFERS_BUILD_FLATHASH}
488-
-DFLATBUFFERS_BUILD_FLATLIB=${FLATBUFFERS_BUILD_FLATLIB}
489-
-DFLATBUFFERS_BUILD_TESTS=${FLATBUFFERS_BUILD_TESTS}
490-
-DFLATBUFFERS_INSTALL=${FLATBUFFERS_INSTALL}
491-
-DCMAKE_CXX_FLAGS="-DFLATBUFFERS_MAX_ALIGNMENT=${FLATBUFFERS_MAX_ALIGNMENT}"
492-
# If building for iOS, "unset" these variables to rely on the host (macOS) defaults.
493-
$<$<AND:$<BOOL:${CMAKE_TOOLCHAIN_IOS}>,$<BOOL:$<FILTER:${PLATFORM},EXCLUDE,^MAC>>>:-DCMAKE_OSX_SYSROOT=>
494-
INSTALL_COMMAND ""
495-
BUILD_BYPRODUCTS <BINARY_DIR>/flatc
496-
)
497-
ExternalProject_Get_Property(flatbuffers BINARY_DIR)
498-
if(WIN32)
499-
# flatbuffers does not use CMAKE_BUILD_TYPE. Internally, the build forces Release
500-
# config, but from CMake's perspective the build type is always Debug.
501-
set(FLATC_EXECUTABLE ${BINARY_DIR}/$<CONFIG>/flatc.exe)
502-
elseif(CMAKE_GENERATOR STREQUAL "Xcode")
503-
set(FLATC_EXECUTABLE ${BINARY_DIR}/$<CONFIG>/flatc)
504-
else()
505-
set(FLATC_EXECUTABLE ${BINARY_DIR}/flatc)
506-
endif()
507-
set(FLATC_EXECUTABLE_BUILT_FROM_SOURCE YES)
508-
endif()
509-
510-
if(NOT FLATC_EXECUTABLE)
511-
message(
512-
WARNING "FLATC_EXECUTABLE not specified, looking for flatc"
513-
)
514-
find_program(FLATC_EXECUTABLE flatc)
515-
516-
if(NOT FLATC_EXECUTABLE)
517-
message(FATAL_ERROR "FLATC_EXECUTABLE must be set when EXECUTORCH_BUILD_FLATC is disabled.")
518-
endif()
519-
endif()
520-
521-
add_executable(flatc IMPORTED GLOBAL)
522-
set_target_properties(flatc PROPERTIES IMPORTED_LOCATION ${FLATC_EXECUTABLE})
523-
524-
if(FLATC_EXECUTABLE_BUILT_FROM_SOURCE)
525-
add_dependencies(flatc flatbuffers)
526-
endif()
527460

528461
#
529462
# program_schema: Generated .h files from schema/*.fbs inputs
@@ -712,6 +645,10 @@ if(EXECUTORCH_BUILD_XNNPACK)
712645
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/xnnpack)
713646
endif()
714647

648+
if(EXECUTORCH_BUILD_CORTEX_M)
649+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/cortex_m)
650+
endif()
651+
715652
if(EXECUTORCH_BUILD_DEVTOOLS)
716653
if(NOT EXECUTORCH_BUILD_ARM_BAREMETAL)
717654
set(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER

CMakePresets.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"version": 10,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 31,
6+
"patch": 0
7+
},
8+
"$comment": "On-device AI across mobile, embedded and edge for PyTorch.",
9+
"configurePresets": [
10+
{
11+
"name": "common",
12+
"hidden": true,
13+
"binaryDir": "${sourceDir}/cmake-out",
14+
"generator": "Unix Makefiles"
15+
},
16+
{
17+
"name": "macos-arm64",
18+
"inherits": ["common"],
19+
"generator": "Xcode",
20+
"cacheVariables": {
21+
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/third-party/ios-cmake/ios.toolchain.cmake",
22+
"EXECUTORCH_BUILD_PRESET_FILE": "${sourceDir}/tools/cmake/preset/macos-arm64.cmake",
23+
"PLATFORM": "MAC_ARM64",
24+
"DEPLOYMENT_TARGET": "10.15"
25+
},
26+
"condition": {
27+
"lhs": "${hostSystemName}",
28+
"type": "equals",
29+
"rhs": "Darwin"
30+
}
31+
}
32+
]
33+
}

backends/apple/mps/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ endforeach()
4242
add_custom_command(
4343
OUTPUT ${_mps_schema__outputs}
4444
COMMAND
45-
${FLATC_EXECUTABLE} --cpp --cpp-std c++11 --scoped-enums -o
45+
flatc --cpp --cpp-std c++11 --scoped-enums -o
4646
"${_mps_schema__include_dir}/executorch/backends/apple/mps"
4747
${_mps_schema__srcs}
4848
WORKING_DIRECTORY ${EXECUTORCH_ROOT}

backends/arm/operators/op_permute.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,26 @@ def permutation_matrix_to_vector(permutation_matrix: torch.Tensor) -> list[int]:
4646
(1,0,2)
4747
"""
4848
N = len(permutation_matrix)
49-
assert N == len(
50-
permutation_matrix[0]
51-
), f"A permutation matrix must be square, got shape {permutation_matrix.shape}"
49+
if N != len(permutation_matrix[0]):
50+
raise ValueError(
51+
f"A permutation matrix must be square, got shape {permutation_matrix.shape}"
52+
)
5253

5354
p = [0] * N
5455
for row_index, row in enumerate(permutation_matrix):
5556
saw_one = False
5657
for col_index, value in enumerate(row):
5758
if value == 1:
58-
assert (
59-
not saw_one
60-
), f"A permutation matrix can only have one 1 per row, got row {row}."
59+
if saw_one:
60+
raise ValueError(
61+
f"A permutation matrix can only have one 1 per row, got {row=}"
62+
)
6163
p[row_index] = col_index
6264
saw_one = True
63-
else:
64-
assert (
65-
value == 0
66-
), f"A permutation matrix only contains 1's and 0's, got value {value}."
65+
elif value != 0:
66+
raise ValueError(
67+
f"A permutation matrix only contains 1's and 0's, got {value=}"
68+
)
6769
return p
6870

6971

0 commit comments

Comments
 (0)