Skip to content

Commit 0e2bce6

Browse files
committed
Update
[ghstack-poisoned]
2 parents 16f0274 + dff96c8 commit 0e2bce6

File tree

99 files changed

+9372
-1311
lines changed

Some content is hidden

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

99 files changed

+9372
-1311
lines changed

.ci/scripts/setup-emscripten.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
set -ex
3+
4+
install_emscripten() {
5+
git clone https://github.com/emscripten-core/emsdk.git
6+
pushd emsdk || return
7+
./emsdk install 4.0.10
8+
./emsdk activate 4.0.10
9+
source ./emsdk_env.sh
10+
popd || return
11+
}
12+
13+
install_emscripten

.github/workflows/android-release-artifacts.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,13 @@ jobs:
4747
name: build-aar
4848
needs: check-if-aar-exists
4949
if: ${{ !github.event.pull_request.head.repo.fork }}
50-
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@release/2.7
50+
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
5151
secrets: inherit
5252
permissions:
5353
id-token: write
5454
contents: read
5555
with:
5656
secrets-env: EXECUTORCH_MAVEN_SIGNING_KEYID EXECUTORCH_MAVEN_SIGNING_PASSWORD EXECUTORCH_MAVEN_CENTRAL_PASSWORD EXECUTORCH_MAVEN_CENTRAL_USERNAME EXECUTORCH_MAVEN_SIGNING_GPG_KEY_CONTENTS
57-
# As this job has access to Maven credential, run this on a fresh ephemeral runner
58-
runner: ephemeral.linux.2xlarge
5957
docker-image: executorch-ubuntu-22.04-clang12-android
6058
submodules: 'recursive'
6159
ref: ${{ github.sha }}

.github/workflows/pull.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,3 +734,31 @@ jobs:
734734
735735
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-openvino.sh
736736
PYTHON_EXECUTABLE=python bash .ci/scripts/test_openvino.sh
737+
738+
test-build-wasm-linux:
739+
name: test-build-wasm-linux
740+
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
741+
permissions:
742+
id-token: write
743+
contents: read
744+
strategy:
745+
fail-fast: false
746+
with:
747+
runner: linux.2xlarge
748+
docker-image: executorch-ubuntu-22.04-clang12
749+
submodules: 'recursive'
750+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
751+
timeout: 90
752+
script: |
753+
# The generic Linux job chooses to use base env, not the one setup by the image
754+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
755+
conda activate "${CONDA_ENV}"
756+
757+
BUILD_TOOL="cmake"
758+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}"
759+
760+
# Install Node.js and Emscripten
761+
source .ci/scripts/setup-emscripten.sh
762+
763+
# Test selective build
764+
PYTHON_EXECUTABLE=python bash examples/wasm/test_build_wasm.sh

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
url = https://github.com/pytorch/cpuinfo.git
2828
[submodule "backends/xnnpack/third-party/pthreadpool"]
2929
path = backends/xnnpack/third-party/pthreadpool
30-
url = https://github.com/Maratyszcza/pthreadpool.git
30+
url = https://github.com/google/pthreadpool.git
3131
[submodule "extension/llm/tokenizers"]
3232
path = extension/llm/tokenizers
3333
url = https://github.com/pytorch-labs/tokenizers.git

CMakeLists.txt

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,12 @@ set(CMAKE_SKIP_BUILD_RPATH OFF)
112112
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
113113
# Automatically add all linked folders that are NOT in the build directory to
114114
# the rpath (per library?)
115-
# TODO: Doesn't work for us right now because we are
116-
# not installing .so's into the correct locations. For example we have
117-
# libcustom_ops_aot_lib.so depending on _portable_lib.so, which was eventually
118-
# put under <site-packages>/executorch/extension/pybindings/ but this rpath is
119-
# not automatically added because at build time it seems `portable_lib` is being
115+
#
116+
# TODO: Doesn't work for us right now because we are not installing .so's into
117+
# the correct locations. For example we have libcustom_ops_aot_lib.so depending
118+
# on _portable_lib.so, which was eventually put under
119+
# <site-packages>/executorch/extension/pybindings/ but this rpath is not
120+
# automatically added because at build time it seems `portable_lib` is being
120121
# built under the same directory, so no extra rpath is being added. To properly
121122
# fix this we need to install `portable_lib` into the correct path.
122123
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)
@@ -321,8 +322,9 @@ if(EXECUTORCH_USE_CPP_CODE_COVERAGE)
321322
" -fprofile-instr-generate -fcoverage-mapping"
322323
)
323324
else()
324-
message(FATAL_ERROR
325-
"Code coverage for compiler ${CMAKE_CXX_COMPILER_ID} is unsupported"
325+
message(
326+
FATAL_ERROR
327+
"Code coverage for compiler ${CMAKE_CXX_COMPILER_ID} is unsupported"
326328
)
327329
endif()
328330
endif()
@@ -633,8 +635,8 @@ if(EXECUTORCH_BUILD_PYBIND)
633635
endif()
634636

635637
if(EXECUTORCH_BUILD_XNNPACK)
636-
# need to explicitly specify XNNPACK and xnnpack-microkernels-prod here otherwise
637-
# uses XNNPACK and microkernel-prod symbols from libtorch_cpu
638+
# need to explicitly specify XNNPACK and xnnpack-microkernels-prod here
639+
# otherwise uses XNNPACK and microkernel-prod symbols from libtorch_cpu
638640
list(APPEND _dep_libs xnnpack_backend XNNPACK xnnpack-microkernels-prod)
639641
endif()
640642

@@ -726,6 +728,17 @@ if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)
726728
endif()
727729
target_link_libraries(executor_runner ${_executor_runner_libs})
728730
target_compile_options(executor_runner PUBLIC ${_common_compile_options})
731+
732+
# Automatically set when using `emcmake cmake` for Wasm build.
733+
if(EMSCRIPTEN)
734+
# Directory of model pte files to embed in the wasm binary.
735+
if(NOT DEFINED WASM_MODEL_DIR)
736+
set(WASM_MODEL_DIR "${CMAKE_SOURCE_DIR}/models/")
737+
endif()
738+
739+
set(CMAKE_EXECUTABLE_SUFFIX ".html")
740+
target_link_options(executor_runner PUBLIC -sALLOW_MEMORY_GROWTH --embed-file "${WASM_MODEL_DIR}@/")
741+
endif()
729742
endif()
730743

731744
if(EXECUTORCH_BUILD_VULKAN)

backends/apple/coreml/CMakeLists.txt

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ if(APPLE)
104104
endif()
105105

106106
add_library(coreml_util ${UTIL_SOURCES})
107-
target_include_directories(coreml_util PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/runtime/util)
107+
target_include_directories(
108+
coreml_util PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/runtime/util
109+
)
108110
if(APPLE)
109111
target_link_libraries(coreml_util PRIVATE ${FOUNDATION_FRAMEWORK})
110112
endif()
@@ -119,21 +121,25 @@ install(
119121

120122
# CoreML inmemoryfs
121123

122-
set(
123-
INMEMORYFS_SOURCES
124-
runtime/inmemoryfs/inmemory_filesystem.cpp
125-
runtime/inmemoryfs/memory_buffer.cpp
126-
runtime/inmemoryfs/memory_stream.cpp
127-
runtime/inmemoryfs/reversed_memory_stream.cpp
124+
set(INMEMORYFS_SOURCES
125+
runtime/inmemoryfs/inmemory_filesystem.cpp
126+
runtime/inmemoryfs/memory_buffer.cpp runtime/inmemoryfs/memory_stream.cpp
127+
runtime/inmemoryfs/reversed_memory_stream.cpp
128128
)
129129
if(APPLE)
130-
list(APPEND INMEMORYFS_SOURCES runtime/inmemoryfs/inmemory_filesystem_utils.mm)
130+
list(APPEND INMEMORYFS_SOURCES
131+
runtime/inmemoryfs/inmemory_filesystem_utils.mm
132+
)
131133
endif()
132134

133135
add_library(coreml_inmemoryfs ${INMEMORYFS_SOURCES})
134-
target_include_directories(coreml_inmemoryfs PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/runtime/inmemoryfs)
136+
target_include_directories(
137+
coreml_inmemoryfs PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/runtime/inmemoryfs
138+
)
135139
if(APPLE)
136-
target_link_libraries(coreml_inmemoryfs PRIVATE coreml_util ${FOUNDATION_FRAMEWORK})
140+
target_link_libraries(
141+
coreml_inmemoryfs PRIVATE coreml_util ${FOUNDATION_FRAMEWORK}
142+
)
137143
endif()
138144
target_compile_options(coreml_inmemoryfs PUBLIC -fPIC)
139145

@@ -148,17 +154,12 @@ install(
148154

149155
if(EXECUTORCH_BUILD_PYBIND)
150156
pybind11_add_module(
151-
executorchcoreml
152-
SHARED
153-
runtime/inmemoryfs/inmemory_filesystem_py.cpp
154-
runtime/inmemoryfs/inmemory_filesystem_utils.cpp
157+
executorchcoreml SHARED runtime/inmemoryfs/inmemory_filesystem_py.cpp
158+
runtime/inmemoryfs/inmemory_filesystem_utils.cpp
155159
)
156160
target_link_libraries(
157-
executorchcoreml
158-
PRIVATE
159-
coreml_util
160-
coreml_inmemoryfs
161-
nlohmann_json::nlohmann_json
161+
executorchcoreml PRIVATE coreml_util coreml_inmemoryfs
162+
nlohmann_json::nlohmann_json
162163
)
163164
target_compile_options(executorchcoreml PUBLIC -fPIC)
164165
endif()
@@ -179,8 +180,12 @@ if(APPLE)
179180
coremldelegate PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/runtime/delegate
180181
)
181182
target_include_directories(coremldelegate PRIVATE ${PROJECT_SOURCE_DIR}/..)
182-
target_include_directories(coremldelegate PRIVATE ${PROJECT_SOURCE_DIR}/runtime/core/portable_type/c10)
183-
target_compile_definitions(coremldelegate PRIVATE C10_USING_CUSTOM_GENERATED_MACROS)
183+
target_include_directories(
184+
coremldelegate PRIVATE ${PROJECT_SOURCE_DIR}/runtime/core/portable_type/c10
185+
)
186+
target_compile_definitions(
187+
coremldelegate PRIVATE C10_USING_CUSTOM_GENERATED_MACROS
188+
)
184189

185190
if(EXECUTORCH_BUILD_DEVTOOLS)
186191
target_sources(coremldelegate PRIVATE ${SDK_SOURCES} ${PROTOBUF_SOURCES})
@@ -200,13 +205,9 @@ if(APPLE)
200205

201206
target_link_libraries(
202207
coremldelegate
203-
PUBLIC coreml_util
204-
coreml_inmemoryfs
205-
PRIVATE executorch_core
206-
${ACCELERATE_FRAMEWORK}
207-
${COREML_FRAMEWORK}
208-
${FOUNDATION_FRAMEWORK}
209-
${SQLITE_LIBRARY}
208+
PUBLIC coreml_util coreml_inmemoryfs
209+
PRIVATE executorch_core ${ACCELERATE_FRAMEWORK} ${COREML_FRAMEWORK}
210+
${FOUNDATION_FRAMEWORK} ${SQLITE_LIBRARY}
210211
)
211212

212213
target_link_options_shared_lib(coremldelegate)
@@ -218,13 +219,8 @@ if(APPLE)
218219
endif()
219220

220221
target_compile_options(
221-
coremldelegate
222-
PRIVATE
223-
-fobjc-arc
224-
-fno-exceptions
225-
-x objective-c++
226-
-Wno-null-character
227-
-Wno-receiver-expr
222+
coremldelegate PRIVATE -fobjc-arc -fno-exceptions -x objective-c++
223+
-Wno-null-character -Wno-receiver-expr
228224
)
229225

230226
if(EXECUTORCH_BUILD_DEVTOOLS)

backends/arm/scripts/mlsdk_utils.sh

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2025 Arm Limited and/or its affiliates.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
set -euo pipefail
8+
9+
# TODO
10+
mlsdk_manifest_url=""
11+
12+
script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
13+
14+
source ${script_dir}/utils.sh
15+
16+
usage() { echo "Usage: $0 [-u <mlsdk-manifest-url>]" 1>&2; exit 1; }
17+
18+
while getopts ":u:" opt; do
19+
case "${opt}" in
20+
u)
21+
mlsdk_manifest_url=${OPTARG}
22+
;;
23+
*)
24+
usage
25+
;;
26+
esac
27+
done
28+
29+
function download_ai_mlsdk_manifest() {
30+
local _dada_dir="$1"
31+
32+
if [[ -z "${_dada_dir}" ]]; then
33+
echo "Error: _dada_dir parameter missing?"
34+
return 1
35+
fi
36+
37+
if [[ -z "${mlsdk_manifest_url}" ]]; then
38+
echo "Error: mlsdk_manifest_url parameter missing?"
39+
return 1
40+
fi
41+
42+
if [[ ! -d "${_dada_dir}" ]]; then
43+
mkdir -p "$_dada_dir"
44+
pushd "$_dada_dir" || exit 1
45+
46+
curl https://storage.googleapis.com/git-repo-downloads/repo > repo
47+
chmod u+x repo
48+
./repo init --no-repo-verify --depth=1 --manifest-url ${mlsdk_manifest_url} -g model-converter,emulation-layer,vgf-library
49+
./repo sync
50+
51+
popd
52+
fi
53+
}
54+
55+
function setup_model_converter() {
56+
local work_dir="$1"
57+
local manifest_dir="$2"
58+
local enable_vgf_lib="$3"
59+
local enable_emulation_layer="$4"
60+
61+
if [[ -z "$work_dir" ]]; then
62+
echo "Error: work_dir parameter is required."
63+
return 1
64+
fi
65+
66+
if [[ -z "$manifest_dir" ]]; then
67+
echo "Error: manifest_dir parameter is required."
68+
return 1
69+
fi
70+
71+
mkdir -p "$work_dir"
72+
pushd "$work_dir" || exit 1
73+
74+
download_ai_mlsdk_manifest ${manifest_dir}
75+
76+
pushd "$manifest_dir"
77+
78+
# model-converter
79+
# TODO: Remove macOS patch after mlsdk fully supports macOS
80+
if [[ "$(uname)" == "Darwin" ]]; then
81+
sed -i '' '/^ *print(f"Unsupported host platform/ i\
82+
if system == "Darwin":\
83+
# Use default Apple toolchain (Clang) on macOS\
84+
return True\
85+
\
86+
' sw/model-converter/scripts/build.py
87+
fi
88+
python sw/model-converter/scripts/build.py -j$(nproc)
89+
90+
# libvgf
91+
if [[ "${enable_vgf_lib}" -eq 1 ]]; then
92+
# TODO: Remove macOS patch after mlsdk fully supports macOS
93+
if [[ "$(uname)" == "Darwin" ]]; then
94+
sed -i '' '/^ *print(f"ERROR: Unsupported host platform/ i\
95+
if system == "Darwin":\
96+
# Use default Apple toolchain (Clang) on macOS\
97+
return True\
98+
\
99+
' sw/vgf-lib/scripts/build.py
100+
fi
101+
python sw/vgf-lib/scripts/build.py -j$(nproc)
102+
fi
103+
104+
# emu layer
105+
if [[ "${enable_emulation_layer}" -eq 1 ]]; then
106+
pushd sw/emulation-layer
107+
cmake -B build \
108+
-DGLSLANG_PATH=../../dependencies/glslang \
109+
-DSPIRV_CROSS_PATH=../../dependencies/SPIRV-Cross \
110+
-DSPIRV_HEADERS_PATH=../../dependencies/SPIRV-Headers \
111+
-DSPIRV_TOOLS_PATH=../../dependencies/SPIRV-Tools \
112+
-DVULKAN_HEADERS_PATH=../../dependencies/Vulkan-Headers
113+
cmake --build build
114+
popd
115+
fi
116+
117+
popd
118+
}
119+
120+
#setup_model_converter() $1
121+
# `"$manifest_dir"'

backends/arm/tosa_quant_utils.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,15 @@ def quantize_value(self, x: torch.Tensor | float) -> Tensor:
146146
x = x.to(torch.float32)
147147
if self.per_channel:
148148
q_op = exir_ops.edge.quantized_decomposed.quantize_per_channel.default
149-
args = (x, self.scale, self.zp, self.axis, self.qmin, self.qmax, self.dtype)
149+
args = (
150+
x,
151+
torch.tensor(self.scale),
152+
torch.tensor(self.zp),
153+
self.axis,
154+
self.qmin,
155+
self.qmax,
156+
self.dtype,
157+
)
150158
else:
151159
q_op = exir_ops.edge.quantized_decomposed.quantize_per_tensor.default
152160
args = (x, self.scale, self.zp, self.qmin, self.qmax, self.dtype) # type: ignore[assignment]
@@ -162,8 +170,8 @@ def dequantize_value(self, qx: torch.Tensor) -> torch.Tensor:
162170
dq_op = exir_ops.edge.quantized_decomposed.dequantize_per_channel.default
163171
args = (
164172
qx,
165-
self.scale,
166-
self.zp,
173+
torch.tensor(self.scale),
174+
torch.tensor(self.zp),
167175
self.axis,
168176
self.qmin,
169177
self.qmax,

0 commit comments

Comments
 (0)