Skip to content

Commit 37e529b

Browse files
committed
Update on "Skip annotate boolean input"
Differential Revision: [D55946526](https://our.internmc.facebook.com/intern/diff/D55946526/) [ghstack-poisoned]
2 parents 88e6051 + ee74466 commit 37e529b

Some content is hidden

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

49 files changed

+1818
-401
lines changed

.ci/scripts/test_llama.sh

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ if [[ -z "${MODE:-}" ]]; then
3737
exit 1
3838
fi
3939

40+
if [[ "${MODE}" =~ xnnpack.* ]]; then
41+
XNNPACK=ON
42+
else
43+
XNNPACK=OFF
44+
fi
45+
46+
if [[ "${MODE}" =~ .*custom.* ]]; then
47+
CUSTOM=ON
48+
else
49+
CUSTOM=OFF
50+
fi
51+
4052
if [[ -z "${BUCK:-}" ]]; then
4153
BUCK=buck2
4254
fi
@@ -47,38 +59,36 @@ fi
4759

4860
which "${PYTHON_EXECUTABLE}"
4961

50-
5162
cmake_install_executorch_libraries() {
5263
echo "Installing libexecutorch.a, libextension_module.so, libportable_ops_lib.a"
5364
rm -rf cmake-out
54-
if [[ "${MODE}" == "xnnpack" ]]; then
55-
XNNPACK=ON
56-
else
57-
XNNPACK=OFF
58-
fi
5965
retry cmake -DBUCK2="$BUCK" \
6066
-DCMAKE_INSTALL_PREFIX=cmake-out \
61-
-DCMAKE_BUILD_TYPE=Release \
67+
-DCMAKE_BUILD_TYPE=Debug \
6268
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
6369
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
70+
-DEXECUTORCH_BUILD_CUSTOM="$CUSTOM" \
6471
-DEXECUTORCH_BUILD_OPTIMIZED=ON \
6572
-DEXECUTORCH_BUILD_XNNPACK="$XNNPACK" \
6673
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
6774
-Bcmake-out .
68-
cmake --build cmake-out -j9 --target install --config Release
75+
cmake --build cmake-out -j9 --target install --config Debug
6976
}
7077

7178
cmake_build_llama_runner() {
7279
echo "Building llama runner"
7380
dir="examples/models/llama2"
7481
retry cmake -DBUCK2="$BUCK" \
7582
-DCMAKE_INSTALL_PREFIX=cmake-out \
76-
-DCMAKE_BUILD_TYPE=Release \
83+
-DCMAKE_BUILD_TYPE=Debug \
84+
-DEXECUTORCH_BUILD_CUSTOM="$CUSTOM" \
85+
-DEXECUTORCH_BUILD_OPTIMIZED=ON \
86+
-DEXECUTORCH_BUILD_XNNPACK="$XNNPACK" \
7787
-DEXECUTORCH_BUILD_OPTIMIZED=ON \
7888
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
7989
-Bcmake-out/${dir} \
8090
${dir}
81-
cmake --build cmake-out/${dir} -j9 --config Release
91+
cmake --build cmake-out/${dir} -j9 --config Debug
8292

8393
}
8494

@@ -117,9 +127,10 @@ fi
117127
EXPORTED_MODEL_NAME="${EXPORTED_MODEL_NAME}.pte"
118128
echo "Exporting ${EXPORTED_MODEL_NAME}"
119129
EXPORT_ARGS="-c stories110M.pt -p ${PARAMS} -d ${DTYPE} -n ${EXPORTED_MODEL_NAME}"
120-
if [[ "${MODE}" == "xnnpack" ]]; then
130+
if [[ "${MODE}" == "xnnpack+kv+custom" ]]; then
121131
EXPORT_ARGS="${EXPORT_ARGS} -kv --use_sdpa_with_kv_cache -X -qmode 8da4w -G 128"
122132
fi
133+
# Add dynamically linked library location
123134
$PYTHON_EXECUTABLE -m examples.models.llama2.export_llama ${EXPORT_ARGS}
124135

125136
# Create tokenizer.bin.

.github/workflows/_unittest.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ jobs:
5757
script: |
5858
set -eux
5959
60-
WORKSPACE=$(pwd)
61-
pushd "${WORKSPACE}/pytorch/executorch"
62-
6360
BUILD_TOOL=${{ matrix.build-tool }}
6461
6562
bash .ci/scripts/setup-conda.sh
@@ -75,5 +72,3 @@ jobs:
7572
${CONDA_RUN} pytest -n auto --cov=./ --cov-report=xml
7673
# Run gtest
7774
${CONDA_RUN} buck2 test runtime/core/... runtime/platform/...
78-
79-
popd

.github/workflows/apple.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ jobs:
3434
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
3535
timeout: 90
3636
script: |
37-
WORKSPACE=$(pwd)
38-
pushd "${WORKSPACE}/pytorch/executorch"
3937
BUILD_TOOL=cmake
4038
4139
.ci/scripts/setup-conda.sh
@@ -48,8 +46,6 @@ jobs:
4846
PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
4947
build/test_ios_ci.sh
5048
51-
popd
52-
5349
build-frameworks-ios:
5450
name: build-frameworks-ios
5551
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
@@ -61,8 +57,6 @@ jobs:
6157
upload-artifact: executorch-frameworks-ios
6258
timeout: 90
6359
script: |
64-
WORKSPACE=$(pwd)
65-
pushd "${WORKSPACE}/pytorch/executorch"
6660
BUILD_TOOL=cmake
6761
VERSION="0.1.0"
6862
FRAMEWORKS=(
@@ -111,8 +105,6 @@ jobs:
111105
zip -r "${RUNNER_TEMP}/artifacts/${FRAMEWORK}_debug-${VERSION}.zip" "${FRAMEWORK}_debug.xcframework"
112106
) done
113107
114-
popd
115-
116108
upload-frameworks-ios:
117109
runs-on: ubuntu-22.04
118110
needs: build-frameworks-ios

.github/workflows/pull.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090
matrix:
9191
dtype: [fp32]
9292
build-tool: [buck2, cmake]
93-
mode: [portable, xnnpack]
93+
mode: [portable, xnnpack+kv+custom]
9494
fail-fast: false
9595
with:
9696
runner: linux.2xlarge

.github/workflows/trunk.yml

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ jobs:
4646
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
4747
timeout: ${{ matrix.timeout }}
4848
script: |
49-
WORKSPACE=$(pwd)
50-
pushd "${WORKSPACE}/pytorch/executorch"
51-
5249
MODEL_NAME=${{ matrix.model }}
5350
BUILD_TOOL=${{ matrix.build-tool }}
5451
BACKEND=${{ matrix.backend }}
@@ -59,7 +56,6 @@ jobs:
5956
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash .ci/scripts/setup-macos.sh "${BUILD_TOOL}"
6057
# Build and test xecutorch
6158
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash .ci/scripts/test.sh "${MODEL_NAME}" "${BUILD_TOOL}" "${BACKEND}" "${DEMO_BACKEND_DELEGATION}"
62-
popd
6359
6460
test-custom-ops-macos:
6561
name: test-custom-ops-macos
@@ -75,17 +71,13 @@ jobs:
7571
submodules: 'true'
7672
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
7773
script: |
78-
WORKSPACE=$(pwd)
79-
pushd "${WORKSPACE}/pytorch/executorch"
80-
8174
BUILD_TOOL=${{ matrix.build-tool }}
8275
8376
bash .ci/scripts/setup-conda.sh
8477
# Setup MacOS dependencies as there is no Docker support on MacOS atm
8578
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash .ci/scripts/setup-macos.sh "${BUILD_TOOL}"
8679
# Build and test custom ops
8780
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash examples/portable/custom_ops/test_custom_ops.sh "${BUILD_TOOL}"
88-
popd
8981
9082
test-selective-build-macos:
9183
name: test-selective-build-macos
@@ -101,17 +93,13 @@ jobs:
10193
submodules: 'true'
10294
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
10395
script: |
104-
WORKSPACE=$(pwd)
105-
pushd "${WORKSPACE}/pytorch/executorch"
106-
10796
BUILD_TOOL=${{ matrix.build-tool }}
10897
10998
bash .ci/scripts/setup-conda.sh
11099
# Setup MacOS dependencies as there is no Docker support on MacOS atm
111100
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash .ci/scripts/setup-macos.sh "${BUILD_TOOL}"
112101
# Build and test selective build
113102
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash examples/selective_build/test_selective_build.sh "${BUILD_TOOL}"
114-
popd
115103
116104
test-demo-backend-delegation:
117105
name: test-demo-backend-delegation
@@ -208,17 +196,13 @@ jobs:
208196
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
209197
timeout: 90
210198
script: |
211-
WORKSPACE=$(pwd)
212-
pushd "${WORKSPACE}/pytorch/executorch"
213-
214199
BUILD_TOOL=cmake
215200
216201
bash .ci/scripts/setup-conda.sh
217202
# Setup MacOS dependencies as there is no Docker support on MacOS atm
218203
GITHUB_RUNNER=1 PYTHON_EXECUTABLE=python ${CONDA_RUN} bash .ci/scripts/setup-macos.sh "${BUILD_TOOL}"
219204
# Build and test coreml delegate
220205
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash backends/apple/coreml/scripts/build_all.sh
221-
popd
222206
223207
test-pybind-build-macos:
224208
name: test-pybind-build-macos
@@ -235,8 +219,6 @@ jobs:
235219
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
236220
timeout: 180
237221
script: |
238-
WORKSPACE=$(pwd)
239-
pushd "${WORKSPACE}/pytorch/executorch"
240222
bash .ci/scripts/setup-conda.sh
241223
242224
# build module for executorch.extension.pybindings.portable_lib
@@ -245,7 +227,6 @@ jobs:
245227
246228
# see if we can import the module successfully
247229
${CONDA_RUN} python -c "from executorch.extension.pybindings import portable_lib; print('success!')"
248-
popd
249230
250231
test-llama-runner-macos:
251232
name: test-llama-runner-mac
@@ -254,7 +235,7 @@ jobs:
254235
matrix:
255236
dtype: [fp32]
256237
build-tool: [buck2, cmake]
257-
mode: [portable, xnnpack]
238+
mode: [portable, xnnpack+kv+custom]
258239
fail-fast: false
259240
with:
260241
runner: macos-m1-stable
@@ -263,8 +244,6 @@ jobs:
263244
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
264245
timeout: 900
265246
script: |
266-
WORKSPACE=$(pwd)
267-
pushd "${WORKSPACE}/pytorch/executorch"
268247
bash .ci/scripts/setup-conda.sh
269248
270249
DTYPE=${{ matrix.dtype }}
@@ -278,4 +257,3 @@ jobs:
278257
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash examples/models/llama2/install_requirements.sh
279258
# Test llama2
280259
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash .ci/scripts/test_llama.sh stories110M.pt "${BUILD_TOOL}" "${DTYPE}" "${MODE}"
281-
popd

CMakeLists.txt

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,20 @@ option(EXECUTORCH_BUILD_VULKAN "Build the Vulkan backend" OFF)
175175
#
176176
# pthreadpool: build pthreadpool library. Disable on unsupported platforms
177177
#
178-
cmake_dependent_option(EXECUTORCH_BUILD_PTHREADPOOL "Build pthreadpool library."
179-
ON "NOT EXECUTORCH_BUILD_ARM_BAREMETAL" OFF)
178+
cmake_dependent_option(
179+
EXECUTORCH_BUILD_PTHREADPOOL "Build pthreadpool library." ON
180+
"NOT EXECUTORCH_BUILD_ARM_BAREMETAL" OFF)
180181

181182
#
182183
# cpuinfo: build cpuinfo library. Disable on unsupported platforms
183184
#
184185
cmake_dependent_option(EXECUTORCH_BUILD_CPUINFO "Build cpuinfo library." ON
185186
"NOT EXECUTORCH_BUILD_ARM_BAREMETAL" OFF)
186187

188+
if(EXECUTORCH_BUILD_CUSTOM)
189+
set(EXECUTORCH_BUILD_OPTIMIZED ON)
190+
endif()
191+
187192
if(EXECUTORCH_BUILD_CPUINFO)
188193
# --- cpuinfo
189194
set(CPUINFO_SOURCE_DIR "backends/xnnpack/third-party/cpuinfo")
@@ -508,24 +513,38 @@ if(EXECUTORCH_BUILD_PYBIND)
508513
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/sdk)
509514
endif()
510515

516+
# find pytorch lib, to allow pybind to take at::Tensor as input/output
517+
find_package(Torch CONFIG REQUIRED)
518+
find_library(TORCH_PYTHON_LIBRARY torch_python
519+
PATHS "${TORCH_INSTALL_PREFIX}/lib")
520+
521+
set(_dep_libs
522+
${TORCH_PYTHON_LIBRARY}
523+
bundled_program
524+
etdump
525+
executorch
526+
extension_data_loader
527+
portable_ops_lib
528+
util
529+
torch)
530+
511531
if(EXECUTORCH_BUILD_COREML)
512-
set(PYBIND_LINK_COREML "coremldelegate")
532+
list(APPEND _dep_libs coremldelegate)
513533
endif()
514534

515535
if(EXECUTORCH_BUILD_MPS)
516-
set(PYBIND_LINK_MPS "mpsdelegate")
536+
list(APPEND _dep_libs mpsdelegate)
517537
endif()
518538

519539
if(EXECUTORCH_BUILD_XNNPACK)
520-
# need to explicitly specify XNNPACK here
521-
# otherwise uses XNNPACK symbols from libtorch_cpu
522-
set(PYBIND_LINK_XNNPACK xnnpack_backend XNNPACK)
540+
# need to explicitly specify XNNPACK here otherwise uses XNNPACK symbols
541+
# from libtorch_cpu
542+
list(APPEND _dep_libs xnnpack_backend XNNPACK)
523543
endif()
524544

525-
# find pytorch lib, to allow pybind to take at::Tensor as input/output
526-
find_package(Torch CONFIG REQUIRED)
527-
find_library(TORCH_PYTHON_LIBRARY torch_python
528-
PATHS "${TORCH_INSTALL_PREFIX}/lib")
545+
if(EXECUTORCH_BUILD_CUSTOM)
546+
list(APPEND _dep_libs custom_ops_lib)
547+
endif()
529548

530549
# compile options for pybind
531550

@@ -548,19 +567,7 @@ if(EXECUTORCH_BUILD_PYBIND)
548567
PUBLIC EXECUTORCH_PYTHON_MODULE_NAME=portable_lib)
549568
target_include_directories(portable_lib PRIVATE ${TORCH_INCLUDE_DIRS})
550569
target_compile_options(portable_lib PUBLIC ${_pybind_compile_options})
551-
target_link_libraries(
552-
portable_lib
553-
PUBLIC ${TORCH_PYTHON_LIBRARY}
554-
bundled_program
555-
etdump
556-
executorch
557-
extension_data_loader
558-
portable_ops_lib
559-
util
560-
torch
561-
${PYBIND_LINK_COREML}
562-
${PYBIND_LINK_MPS}
563-
${PYBIND_LINK_XNNPACK})
570+
target_link_libraries(portable_lib PUBLIC ${_dep_libs})
564571

565572
install(TARGETS portable_lib
566573
LIBRARY DESTINATION executorch/extension/pybindings)

backends/qualcomm/builders/op_linear.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ def define_node(
4040
linear_input_tensors.append(input_tensor_wrapper)
4141

4242
weight_node = node.args[1]
43+
if (
44+
quant_attrs := weight_node.meta.get("quant_attrs")
45+
) and "scales" in quant_attrs:
46+
# Dimension of weight is [m, n], per channel quant params is [m]
47+
# Change to [m, 1] to fit the tensor.div(s).add(z)
48+
quant_attrs["scales"] = quant_attrs["scales"].reshape([-1, 1])
49+
quant_attrs["zero_points"] = quant_attrs["zero_points"].reshape([-1, 1])
50+
4351
weight_tensor = get_parameter(weight_node, self.edge_program)
4452
weight_tensor_wrapper = self.define_tensor(
4553
weight_node,
@@ -52,6 +60,12 @@ def define_node(
5260

5361
if len(node.args) >= 3:
5462
bias_node = node.args[2]
63+
64+
# TODO remove this when qnn sdk support
65+
if "scales" in bias_node.meta.get("quant_attrs"):
66+
print(
67+
f"[WARNING] Fallback linear bias, {bias_node}. per channel bias quantization is not support yet."
68+
)
5569
bias_tensor = get_parameter(bias_node, self.edge_program)
5670
bias_tensor_wrapper = self.define_tensor(
5771
bias_node,

0 commit comments

Comments
 (0)