Skip to content

Commit 8fee216

Browse files
committed
Update on "[ET-VK][Ops] aten.convolution (SlidingWindow)"
## The Operator `nn.Module` invocations of [`nn.Conv2d`](https://pytorch.org/docs/stable/generated/torch.nn.Conv2d.html#torch.nn.Conv2d) and [`nn.ConvTranspose2d`](https://pytorch.org/docs/stable/generated/torch.nn.ConvTranspose2d.html#torch.nn.ConvTranspose2d) get compiled to `aten.convolution.default` in the Edge Dialect, which carries the signature ``` - func: convolution(Tensor input, Tensor weight, Tensor? bias, int[] stride, SymInt[] padding, int[] dilation, bool transposed, SymInt[] output_padding, int groups) -> Tensor ``` ## Summary (cases handled) We introduce support for the convolution cases covered by [ATen-VK's default SlidingWindow implementation](https://github.com/pytorch/pytorch/blob/09c72eaa3f69f90402c86a30abf4fc621298578c/aten/src/ATen/native/vulkan/ops/Convolution.cpp#L73). This is achieved by - reusing the [existing `conv2d.glsl`](https://github.com/pytorch/pytorch/blob/09c72eaa3f69f90402c86a30abf4fc621298578c/aten/src/ATen/native/vulkan/glsl/conv2d.glsl), and - [moving special weights prepacking from CPU](https://github.com/pytorch/pytorch/blob/09c72eaa3f69f90402c86a30abf4fc621298578c/aten/src/ATen/native/vulkan/ops/Convolution.cpp#L134-L235) to the GPU in `conv2d_prepack_weights.glsl`. We also include resizing support for dynamic shapes. Note that only height and width of the input can vary. ## Cases not handled The implementation is on-par with ATen-VK's SlidingWindow. This means the following cases are missing: 1. **Groups G > 1.** Largely not covered by ATen-VK. `G = in_channels` is covered by ATen-VK's Depthwise impl and will be added soon. 2. **Batch (input) N > 1.** Not covered by ATen-VK. 3. **Padding > 0 while Dilation, Kernel > 1.** Not covered by ATen-VK. ## Coming soon 1. Transpose convolution 2. Depthwise convolution (for completeness) 3. Pointwise convolution (for optimization) 4. Null bias Differential Revision: [D55346778](https://our.internmc.facebook.com/intern/diff/D55346778/) [ghstack-poisoned]
2 parents 9d3b714 + a5e232b commit 8fee216

File tree

144 files changed

+3750
-3414
lines changed

Some content is hidden

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

144 files changed

+3750
-3414
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

.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: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ if(EXECUTORCH_BUILD_PTHREADPOOL)
224224
set(PTHREADPOOL_ALLOW_DEPRECATED_API
225225
ON
226226
CACHE BOOL "")
227+
if(APPLE)
228+
set(PTHREADPOOL_SYNC_PRIMITIVE
229+
"condvar"
230+
CACHE STRING "")
231+
endif()
227232
add_subdirectory("${PTHREADPOOL_SOURCE_DIR}")
228233
endif()
229234

@@ -508,7 +513,9 @@ if(EXECUTORCH_BUILD_PYBIND)
508513
endif()
509514

510515
if(EXECUTORCH_BUILD_XNNPACK)
511-
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)
512519
endif()
513520

514521
# 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": "5bfa35cb5143b4af6840e0e5dd2d40bce93dff331b8eb5798a46274239391a5d",
18+
"sha256" + debug: "1422019da9000f8ff7be597de9e0e3b2482f99cdaa75c2d179835778647be1a6",
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": "2201a61eaf7e06e1937cb73a469fb36cabc219496ba004b85feb2cc7c10f300d",
29+
"sha256" + debug: "3eb6eb97bf0641d2305b0f50ff05a8862d7d65e2491cf4aa05ef1d108649f07c",
30+
],
31+
"executorch": [
32+
"sha256": "2b55cbcff845ab9eaf16a21e520546b2975ef8c55b9e3fbbcc0c375334e40c6f",
33+
"sha256" + debug: "12933cedff6cf21c9d21668779f8d8af8049646fe7d290787b12227ff7abe4a7",
34+
],
35+
"mps_backend": [
36+
"sha256": "510d708361b6ea0692ce5aeb638725d6275824b37bbe744aa876fda24cc2bbbf",
37+
"sha256" + debug: "6a67ba0bf8033f17bd66acb222446df51cd1304e24a4fb2c6d97e15a30fb24f0",
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": "50aaa54901a7cee1059e71cc623f054610406d65ba8fd6edb10b45861be67237",
46+
"sha256" + debug: "3f43f465727c8705432f4bb69260cc9501c519e5da006fc19ee2ab2ea260d1f0",
47+
],
48+
"portable_backend": [
49+
"sha256": "964238e92828665aa598c05b2264faab91fb13ce0f42633cc7d5653300af3e9b",
50+
"sha256" + debug: "d6d85304a4b40f13c9b893e8c264ebdb15307cacf8997494b3818a52e4914b28",
51+
],
52+
"quantized_backend": [
53+
"sha256": "37d31a319f92e26bab2b7ec5e783a8b14457dee0a4638dcdca1d9e17539ee3fb",
54+
"sha256" + debug: "6b45f66f60f6106a41e191418c970bf7b0605df73b9815a06441a5f0809b54e6",
55+
],
56+
"xnnpack_backend": [
57+
"sha256": "03d506243c392e872519ae1335a025ef202319c1db339a753f9d7d74cba226f0",
58+
"sha256" + debug: "3341e89abc99552a6a5bad360003baed194a83e865338bc07afe9e4f171ea169",
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/arm/test/arm_tosa_reference.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040

4141
SUPPORTED_BI_TEST_LIST = [
4242
"simple_add_broadcast",
43-
"block_bottleneck_residual",
4443
]
4544

4645

backends/arm/test/ops/test_add.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
logger = logging.getLogger(__name__)
2020
logger.setLevel(logging.INFO)
2121

22-
torch.manual_seed(42)
23-
2422

2523
class TestSimpleAdd(unittest.TestCase):
2624
class Add(torch.nn.Module):

0 commit comments

Comments
 (0)