Skip to content

Commit 41498a5

Browse files
committed
Merge branch 'main' of github.com:pytorch/executorch into hardsigmoid_test
2 parents fd88d97 + 643c628 commit 41498a5

File tree

235 files changed

+13438
-3708
lines changed

Some content is hidden

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

235 files changed

+13438
-3708
lines changed

.ci/docker/ci_commit_pins/pytorch.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a52b4e22571507abc35c2d47de138497190d2e0a
1+
0a038cf0cff2d071b7359ac0491fd2ba7798a438

.ci/scripts/test_llama.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ EXPORTED_MODEL_NAME="${EXPORTED_MODEL_NAME}.pte"
118118
echo "Exporting ${EXPORTED_MODEL_NAME}"
119119
EXPORT_ARGS="-c stories110M.pt -p ${PARAMS} -d ${DTYPE} -n ${EXPORTED_MODEL_NAME}"
120120
if [[ "${MODE}" == "xnnpack" ]]; then
121-
EXPORT_ARGS="${EXPORT_ARGS} --pt2e_quantize xnnpack_dynamic"
121+
EXPORT_ARGS="${EXPORT_ARGS} -kv --use_sdpa_with_kv_cache -X -qmode 8da4w -G 128"
122122
fi
123123
$PYTHON_EXECUTABLE -m examples.models.llama2.export_llama ${EXPORT_ARGS}
124124

.github/workflows/_unittest.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
# Setup MacOS dependencies as there is no Docker support on MacOS atm
3838
PYTHON_EXECUTABLE=python \
3939
EXECUTORCH_BUILD_PYBIND=ON \
40+
EXECUTORCH_BUILD_XNNPACK=ON \
4041
.ci/scripts/setup-linux.sh "${BUILD_TOOL}"
4142
4243
# Run pytest with coverage

.github/workflows/apple.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ jobs:
100100
zip -r "${RUNNER_TEMP}/artifacts/${FRAMEWORK}-${VERSION}.zip" "${FRAMEWORK}.xcframework"
101101
) done
102102
103+
# Build Debug iOS Frameworks
104+
PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
105+
build/build_apple_frameworks.sh --coreml --custom --mps --optimized --portable --quantized --xnnpack --Debug
106+
107+
# Bundle Debug iOS Frameworks
108+
for FRAMEWORK in "${FRAMEWORKS[@]}"; do (
109+
cd cmake-out && \
110+
mv "${FRAMEWORK}.xcframework" "${FRAMEWORK}_debug.xcframework" && \
111+
zip -r "${RUNNER_TEMP}/artifacts/${FRAMEWORK}_debug-${VERSION}.zip" "${FRAMEWORK}_debug.xcframework"
112+
) done
113+
103114
popd
104115
105116
upload-frameworks-ios:
@@ -146,5 +157,6 @@ jobs:
146157
147158
for FILENAME in "${RUNNER_TEMP}"/frameworks-ios/*.zip; do
148159
[ -e "${FILENAME}" ] || continue
160+
shasum -a 256 "${FILENAME}"
149161
${AWS_CMD} "${FILENAME}" s3://ossci-ios/executorch/ --acl public-read
150162
done

.github/workflows/pull.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ jobs:
232232
# build module for executorch.extension.pybindings.portable_lib
233233
BUILD_TOOL=${{ matrix.build-tool }}
234234
PYTHON_EXECUTABLE=python \
235+
EXECUTORCH_BUILD_XNNPACK=ON \
235236
EXECUTORCH_BUILD_PYBIND=ON \
236237
bash .ci/scripts/setup-linux.sh "${BUILD_TOOL}"
237238

.github/workflows/trunk.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ jobs:
159159
git config --global user.name "Github Executorch"
160160
bash examples/arm/setup.sh --i-agree-to-the-contained-eula
161161
162+
# Increase number of files user can monitor to bypass buck failures.
163+
# Hopefully this is high enough for this setup.
164+
sudo sysctl fs.inotify.max_user_watches=1048576 # 1024 * 1024
165+
162166
# Test ethos-u delegate examples with run.sh
163167
source examples/arm/ethos-u-scratch/setup_path.sh
164168
PYTHON_EXECUTABLE=python bash examples/arm/run.sh examples/arm/ethos-u-scratch/ buck2

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@
3737
[submodule "third-party/flatcc"]
3838
path = third-party/flatcc
3939
url = https://github.com/dvidelabs/flatcc.git
40-
[submodule "examples/third-party/llama"]
41-
path = examples/third-party/llama
42-
url = https://github.com/facebookresearch/llama.git
4340
[submodule "examples/third-party/fbjni"]
4441
path = examples/third-party/fbjni
4542
url = https://github.com/facebookincubator/fbjni.git

.swift/coreml_backend_debug/dummy.swift

Whitespace-only changes.

.swift/custom_backend_debug/dummy.swift

Whitespace-only changes.

.swift/executorch_debug/dummy.swift

Whitespace-only changes.

.swift/mps_backend_debug/dummy.swift

Whitespace-only changes.

.swift/optimized_backend_debug/dummy.swift

Whitespace-only changes.

.swift/portable_backend_debug/dummy.swift

Whitespace-only changes.

.swift/quantized_backend_debug/dummy.swift

Whitespace-only changes.

.swift/xnnpack_backend_debug/dummy.swift

Whitespace-only changes.

CMakeLists.txt

Lines changed: 63 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -56,45 +56,6 @@ if(NOT CMAKE_BUILD_TYPE)
5656
set(CMAKE_BUILD_TYPE Debug)
5757
endif()
5858

59-
# --- cpuinfo
60-
set(CPUINFO_SOURCE_DIR "backends/xnnpack/third-party/cpuinfo")
61-
set(CPUINFO_BUILD_TOOLS
62-
OFF
63-
CACHE BOOL "")
64-
set(CPUINFO_BUILD_UNIT_TESTS
65-
OFF
66-
CACHE BOOL "")
67-
set(CPUINFO_BUILD_MOCK_TESTS
68-
OFF
69-
CACHE BOOL "")
70-
set(CPUINFO_BUILD_BENCHMARKS
71-
OFF
72-
CACHE BOOL "")
73-
set(CPUINFO_LIBRARY_TYPE
74-
"static"
75-
CACHE STRING "")
76-
set(CPUINFO_LOG_LEVEL
77-
"error"
78-
CACHE STRING "")
79-
set(CLOG_SOURCE_DIR "${CPUINFO_SOURCE_DIR}/deps/clog")
80-
add_subdirectory("${CPUINFO_SOURCE_DIR}")
81-
82-
# --- pthreadpool
83-
set(PTHREADPOOL_SOURCE_DIR "backends/xnnpack/third-party/pthreadpool")
84-
set(PTHREADPOOL_BUILD_TESTS
85-
OFF
86-
CACHE BOOL "")
87-
set(PTHREADPOOL_BUILD_BENCHMARKS
88-
OFF
89-
CACHE BOOL "")
90-
set(PTHREADPOOL_LIBRARY_TYPE
91-
"static"
92-
CACHE STRING "")
93-
set(PTHREADPOOL_ALLOW_DEPRECATED_API
94-
ON
95-
CACHE BOOL "")
96-
add_subdirectory("${PTHREADPOOL_SOURCE_DIR}")
97-
9859
# ------------------------------ OPTIONS -------------------------------------
9960
# WARNING: Please don't add example specific options in this CMakeLists.txt.
10061
# Instead please use `find_package(executorch REQUIRED)` in the example
@@ -211,6 +172,66 @@ option(EXECUTORCH_BUILD_XNNPACK "Build the XNNPACK backend" OFF)
211172

212173
option(EXECUTORCH_BUILD_VULKAN "Build the Vulkan backend" OFF)
213174

175+
#
176+
# pthreadpool: build pthreadpool library. Disable on unsupported platforms
177+
#
178+
cmake_dependent_option(EXECUTORCH_BUILD_PTHREADPOOL "Build pthreadpool library."
179+
ON "NOT EXECUTORCH_BUILD_ARM_BAREMETAL" OFF)
180+
181+
#
182+
# cpuinfo: build cpuinfo library. Disable on unsupported platforms
183+
#
184+
cmake_dependent_option(EXECUTORCH_BUILD_CPUINFO "Build cpuinfo library." ON
185+
"NOT EXECUTORCH_BUILD_ARM_BAREMETAL" OFF)
186+
187+
if(EXECUTORCH_BUILD_CPUINFO)
188+
# --- cpuinfo
189+
set(CPUINFO_SOURCE_DIR "backends/xnnpack/third-party/cpuinfo")
190+
set(CPUINFO_BUILD_TOOLS
191+
OFF
192+
CACHE BOOL "")
193+
set(CPUINFO_BUILD_UNIT_TESTS
194+
OFF
195+
CACHE BOOL "")
196+
set(CPUINFO_BUILD_MOCK_TESTS
197+
OFF
198+
CACHE BOOL "")
199+
set(CPUINFO_BUILD_BENCHMARKS
200+
OFF
201+
CACHE BOOL "")
202+
set(CPUINFO_LIBRARY_TYPE
203+
"static"
204+
CACHE STRING "")
205+
set(CPUINFO_LOG_LEVEL
206+
"error"
207+
CACHE STRING "")
208+
set(CLOG_SOURCE_DIR "${CPUINFO_SOURCE_DIR}/deps/clog")
209+
add_subdirectory("${CPUINFO_SOURCE_DIR}")
210+
endif()
211+
212+
if(EXECUTORCH_BUILD_PTHREADPOOL)
213+
# --- pthreadpool
214+
set(PTHREADPOOL_SOURCE_DIR "backends/xnnpack/third-party/pthreadpool")
215+
set(PTHREADPOOL_BUILD_TESTS
216+
OFF
217+
CACHE BOOL "")
218+
set(PTHREADPOOL_BUILD_BENCHMARKS
219+
OFF
220+
CACHE BOOL "")
221+
set(PTHREADPOOL_LIBRARY_TYPE
222+
"static"
223+
CACHE STRING "")
224+
set(PTHREADPOOL_ALLOW_DEPRECATED_API
225+
ON
226+
CACHE BOOL "")
227+
if(APPLE)
228+
set(PTHREADPOOL_SYNC_PRIMITIVE
229+
"condvar"
230+
CACHE STRING "")
231+
endif()
232+
add_subdirectory("${PTHREADPOOL_SOURCE_DIR}")
233+
endif()
234+
214235
if(NOT PYTHON_EXECUTABLE)
215236
resolve_python_executable()
216237
endif()
@@ -492,7 +513,9 @@ if(EXECUTORCH_BUILD_PYBIND)
492513
endif()
493514

494515
if(EXECUTORCH_BUILD_XNNPACK)
495-
set(PYBIND_LINK_XNNPACK "xnnpack_backend")
516+
# need to explicitly specify XNNPACK here
517+
# otherwise uses XNNPACK symbols from libtorch_cpu
518+
set(PYBIND_LINK_XNNPACK xnnpack_backend XNNPACK)
496519
endif()
497520

498521
# find pytorch lib, to allow pybind to take at::Tensor as input/output

Package.swift

Lines changed: 75 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -9,95 +9,93 @@
99

1010
import PackageDescription
1111

12-
let url = "https://ossci-ios.s3.amazonaws.com/executorch"
1312
let version = "0.1.0"
14-
let coreml_sha256 = "78d853d87be478696e56e658aa4ff17d47ae185a9a6a36316c821fa8b2d3aacd"
15-
let custom_sha256 = "f059f6716298403dff89a952a70e323c54911be140d05f2467bd5cc61aaefae3"
16-
let executorch_sha256 = "ba9a0c2b061afaedbc3c5454040a598b1371170bd9d9a30b7163c20e23339841"
17-
let mps_sha256 = "39542a8671cca1aa627102aa47785d0f6e2dfe9a40e2c22288a755057b00fbfa"
18-
let optimized_sha256 = "1d84fa16197bb6f0dec01aaa29d2a140c0e14d8e5e92630a7b4dd6f48012506d"
19-
let portable_sha256 = "4993904f89ecb4476677ff3c072ed1a314a608170f10d364cfd23947851ccbf3"
20-
let quantized_sha256 = "8d35ee0e7ca77c19782eaea07a1888f576cda679f8a4a5edb03d80ebe858047e"
21-
let xnnpack_sha256 = "380e5185c4c48ede7cc0d0f0657ffb26df83cd9f55813d78593aea8a93942caf"
22-
23-
struct Framework {
24-
let name: String
25-
let checksum: String
26-
var frameworks: [String] = []
27-
var libraries: [String] = []
28-
29-
func target() -> Target {
30-
.binaryTarget(
31-
name: name,
32-
url: "\(url)/\(name)-\(version).zip",
33-
checksum: checksum
34-
)
35-
}
36-
37-
func dependencies() -> Target {
38-
.target(
39-
name: "\(name)_dependencies",
40-
dependencies: [.target(name: name)],
41-
path: ".swift/\(name)",
42-
linkerSettings:
43-
frameworks.map { .linkedFramework($0) } +
44-
libraries.map { .linkedLibrary($0) }
45-
)
46-
}
47-
}
48-
49-
let frameworks = [
50-
Framework(
51-
name: "coreml_backend",
52-
checksum: coreml_sha256,
53-
frameworks: [
13+
let url = "https://ossci-ios.s3.amazonaws.com/executorch/"
14+
let debug = "_debug"
15+
let deliverables = [
16+
"coreml_backend": [
17+
"sha256": "0e5973bbc547e3a39f988f9a7a68b47bda0a6a17b04516fff6957fd527f8cd48",
18+
"sha256" + debug: "c63773f0098625f884fecb11b4a5f6318b97d566329fef8b013444829cd7c421",
19+
"frameworks": [
5420
"Accelerate",
5521
"CoreML",
5622
],
57-
libraries: [
23+
"libraries": [
5824
"sqlite3",
59-
]
60-
),
61-
Framework(
62-
name: "custom_backend",
63-
checksum: custom_sha256
64-
),
65-
Framework(
66-
name: "executorch",
67-
checksum: executorch_sha256
68-
),
69-
Framework(
70-
name: "mps_backend",
71-
checksum: mps_sha256,
72-
frameworks: [
25+
],
26+
],
27+
"custom_backend": [
28+
"sha256": "c8405e21324262cd6590046096ddeb3ac33a598f88afc817a2f2fdee821da150",
29+
"sha256" + debug: "a08a6aa15ddce61a76cd1bf2206d017cc4ac7dcb9ca312ad7750a36814448eaa",
30+
],
31+
"executorch": [
32+
"sha256": "57269f9b81d56a3d96ece2012e2ece3af24174846abd98de9a3bee07f3b9583d",
33+
"sha256" + debug: "66975caf3d9c1238d29945288f23ddb6e07e16386d4dedf429c0f2d81cfbe0cc",
34+
],
35+
"mps_backend": [
36+
"sha256": "bb7531172252b6535429fbde429de208665f933d0f509982872eada86839e734",
37+
"sha256" + debug: "6d41437e40cb794b4b7a0d971931773de263370463b38a014f38e99bd1c5d52b",
38+
"frameworks": [
7339
"Metal",
7440
"MetalPerformanceShaders",
7541
"MetalPerformanceShadersGraph",
76-
]
77-
),
78-
Framework(
79-
name: "optimized_backend",
80-
checksum: optimized_sha256
81-
),
82-
Framework(
83-
name: "portable_backend",
84-
checksum: portable_sha256
85-
),
86-
Framework(
87-
name: "quantized_backend",
88-
checksum: quantized_sha256
89-
),
90-
Framework(
91-
name: "xnnpack_backend",
92-
checksum: xnnpack_sha256
93-
)
94-
]
42+
],
43+
],
44+
"optimized_backend": [
45+
"sha256": "bdab593fb49c9000291dbf691ad578d771883745ed2851f00492e828d089d1ea",
46+
"sha256" + debug: "8316ad259d6aafecf2e9abc91a04fc1fa3e0398597e043119b4c29c21e9f2029",
47+
],
48+
"portable_backend": [
49+
"sha256": "38ebdad7d5cd24ca44cd950d561dcf9a9b883dff626c167bc6f5f28f041b8406",
50+
"sha256" + debug: "9e68b3e92e5c920875845f59821ee984b87486d05c1bf8a461b011530e02dd55",
51+
],
52+
"quantized_backend": [
53+
"sha256": "245a3acbf06c6afe9cfb6b03eddfa015390e582ffdfb76efd23b7c810f080f10",
54+
"sha256" + debug: "134d759fe708a4ffbf7efbd25c6020186e1a13abc0dac0a897e2fe13aac3e76a",
55+
],
56+
"xnnpack_backend": [
57+
"sha256": "a1c9cf8347c17f3e50e45d7f37f64ee040f0a1b0a40fa4748d90b45c4150e3b2",
58+
"sha256" + debug: "e92a15c2982630951e5ae5e927d548049db25d89e8b639e8901c5f4650f3a7d0",
59+
],
60+
].reduce(into: [String: [String: Any]]()) {
61+
$0[$1.key] = $1.value
62+
$0[$1.key + debug] = $1.value
63+
}
64+
.reduce(into: [String: [String: Any]]()) {
65+
var newValue = $1.value
66+
if $1.key.hasSuffix(debug) {
67+
$1.value.forEach { key, value in
68+
if key.hasSuffix(debug) {
69+
newValue[String(key.dropLast(debug.count))] = value
70+
}
71+
}
72+
}
73+
$0[$1.key] = newValue.filter { key, _ in !key.hasSuffix(debug) }
74+
}
9575

9676
let package = Package(
9777
name: "executorch",
9878
platforms: [
9979
.iOS(.v15),
10080
],
101-
products: frameworks.map { .library(name: $0.name, targets: ["\($0.name)_dependencies"]) },
102-
targets: frameworks.flatMap { [$0.target(), $0.dependencies()] }
81+
products: deliverables.keys.map { key in
82+
.library(name: key, targets: ["\(key)_dependencies"])
83+
}.sorted { $0.name < $1.name },
84+
targets: deliverables.flatMap { key, value -> [Target] in
85+
[
86+
.binaryTarget(
87+
name: key,
88+
url: "\(url)\(key)-\(version).zip",
89+
checksum: value["sha256"] as? String ?? ""
90+
),
91+
.target(
92+
name: "\(key)_dependencies",
93+
dependencies: [.target(name: key)],
94+
path: ".swift/\(key)",
95+
linkerSettings:
96+
(value["frameworks"] as? [String] ?? []).map { .linkedFramework($0) } +
97+
(value["libraries"] as? [String] ?? []).map { .linkedLibrary($0) }
98+
),
99+
]
100+
}
103101
)

backends/apple/mps/operators/constant_ops.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ def define_node(
5555
elif node.target == exir_ops.edge.aten.empty.memory_format:
5656
fill_value = 0
5757
elif node.target == exir_ops.edge.aten.scalar_tensor.default:
58-
fill_value = float(node.args[0])
58+
fill_value = cast(float, node.args[0])
59+
60+
if fill_value == float("-inf"):
61+
fill_value = "-inf"
62+
elif fill_value == float("inf"):
63+
fill_value = "inf"
5964

6065
dtype = MPSDataType.mps_data_type_float32
6166
if node.kwargs and "dtype" in node.kwargs and node.kwargs["dtype"] is not None:

backends/apple/mps/operators/node_visitor.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,9 @@ def define_scalar(
157157
"""
158158
assert isinstance(val, int) or isinstance(val, float)
159159

160-
if val in self.tensor_to_id:
161-
return self.tensor_to_id[val]
160+
id = len(mps_graph.mps_values)
161+
self.tensor_to_id[val] = id
162162

163-
id = self.get_serialized_id(val, mps_graph)
164163
tensor = torch.tensor(val)
165164
constant_buffer_size, constant_buffer, mps_data_type = self.get_serialized_data(
166165
tensor, mps_graph, mps_data_type, id

0 commit comments

Comments
 (0)