Skip to content

Commit 63c3a04

Browse files
Merge branch 'main' into refactor-bitwise-logical-tests
2 parents 614d44b + 8cd1b93 commit 63c3a04

File tree

110 files changed

+1516
-1421
lines changed

Some content is hidden

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

110 files changed

+1516
-1421
lines changed

.ci/scripts/build_android_instrumentation.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ fi
1313
which "${PYTHON_EXECUTABLE}"
1414

1515
build_android_test() {
16-
pushd extension/android_test
17-
ANDROID_HOME="${ANDROID_SDK:-/opt/android/sdk}" ./gradlew testDebugUnitTest
18-
ANDROID_HOME="${ANDROID_SDK:-/opt/android/sdk}" ./gradlew build assembleAndroidTest
16+
mkdir -p extension/android/executorch_android/src/androidTest/resources
17+
cp extension/module/test/resources/add.pte extension/android/executorch_android/src/androidTest/resources
18+
pushd extension/android
19+
ANDROID_HOME="${ANDROID_SDK:-/opt/android/sdk}" ./gradlew :executorch_android:testDebugUnitTest
20+
ANDROID_HOME="${ANDROID_SDK:-/opt/android/sdk}" ./gradlew :executorch_android:assembleAndroidTest
1921
popd
2022
}
2123

@@ -24,8 +26,7 @@ collect_artifacts_to_be_uploaded() {
2426
# Collect Java library test
2527
JAVA_LIBRARY_TEST_DIR="${ARTIFACTS_DIR_NAME}/library_test_dir"
2628
mkdir -p "${JAVA_LIBRARY_TEST_DIR}"
27-
cp extension/android_test/build/outputs/apk/debug/*.apk "${JAVA_LIBRARY_TEST_DIR}"
28-
cp extension/android_test/build/outputs/apk/androidTest/debug/*.apk "${JAVA_LIBRARY_TEST_DIR}"
29+
cp extension/android/executorch_android/build/outputs/apk/androidTest/debug/*.apk "${JAVA_LIBRARY_TEST_DIR}"
2930
}
3031

3132
main() {

.github/workflows/_android.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ jobs:
2828
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool buck2
2929
export ARTIFACTS_DIR_NAME=artifacts-to-be-uploaded
3030
31+
mkdir -p ${ARTIFACTS_DIR_NAME}/fp32-xnnpack-custom
32+
bash examples/models/llama/install_requirements.sh
33+
bash ".ci/scripts/test_llama.sh" -model stories110M -build_tool cmake -dtype fp16 -mode portable -upload ${ARTIFACTS_DIR_NAME}/fp32-xnnpack-custom
34+
3135
# Build LLM Demo for Android
3236
export BUILD_AAR_DIR=aar-out
37+
mkdir -p $BUILD_AAR_DIR
3338
bash build/build_android_library.sh ${ARTIFACTS_DIR_NAME}
3439
bash .ci/scripts/build_android_instrumentation.sh ${ARTIFACTS_DIR_NAME}
3540
36-
mkdir -p ${ARTIFACTS_DIR_NAME}/fp32-xnnpack-custom
37-
bash ".ci/scripts/test_llama.sh" -model stories110M -build_tool cmake -dtype fp16 -mode portable -upload ${ARTIFACTS_DIR_NAME}/fp32-xnnpack-custom
38-
3941
mkdir -p examples/demo-apps/android/LlamaDemo/app/libs
4042
cp aar-out/executorch.aar examples/demo-apps/android/LlamaDemo/app/libs
4143
pushd examples/demo-apps/android/LlamaDemo
@@ -94,7 +96,6 @@ jobs:
9496
curl -O https://gha-artifacts.s3.amazonaws.com/${{ github.repository }}/${{ github.run_id }}/artifacts/llm_demo/app-debug.apk
9597
curl -O https://gha-artifacts.s3.amazonaws.com/${{ github.repository }}/${{ github.run_id }}/artifacts/llm_demo/app-debug-androidTest.apk
9698
curl -O https://gha-artifacts.s3.amazonaws.com/${{ github.repository }}/${{ github.run_id }}/artifacts/fp32-xnnpack-custom/model.zip
97-
curl -o android-test-debug.apk https://gha-artifacts.s3.amazonaws.com/${{ github.repository }}/${{ github.run_id }}/artifacts/library_test_dir/executorch-debug.apk
9899
curl -o android-test-debug-androidTest.apk https://gha-artifacts.s3.amazonaws.com/${{ github.repository }}/${{ github.run_id }}/artifacts/library_test_dir/executorch-debug-androidTest.apk
99100
unzip model.zip
100101
mv *.pte model.pte

.github/workflows/doc-build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
with:
2727
job-name: Build doc
2828
runner: linux.2xlarge
29-
docker-image: executorch-ubuntu-22.04-clang12
29+
docker-image: executorch-ubuntu-22.04-clang12-android
3030
submodules: 'true'
3131
repository: pytorch/executorch
3232
upload-artifact: docs
@@ -70,8 +70,8 @@ jobs:
7070
7171
# Build javadoc:
7272
cd extension/android
73-
./gradlew javadoc
74-
cp -rf build/docs/javadoc "${RUNNER_DOCS_DIR}"
73+
ANDROID_HOME="${ANDROID_SDK:-/opt/android/sdk}" ./gradlew :executorch_android:javaDocReleaseGeneration
74+
cp -rf executorch_android/build/intermediates/java_doc_dir/release/javaDocReleaseGeneration "${RUNNER_DOCS_DIR}/javadoc"
7575
cd ../..
7676
7777
# If it's main branch, add noindex tag to all .html files to exclude from Google Search indexing.

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ jobs:
7676
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
7777
timeout: 90
7878
script: |
79-
FILES_NEEDS_FORMAT=$(/opt/google-java-format -n extension/android/src/main/java/org/pytorch/executorch/*.java \
80-
examples/demo-apps/android/ExecuTorchDemo/app/src/main/java/com/example/executorchdemo/*.java \
79+
FILES_NEEDS_FORMAT=$(/opt/google-java-format -n \
80+
extension/android/executorch_android/src/main/java/org/pytorch/executorch/*.java \
8181
examples/demo-apps/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/*.java \
8282
extension/benchmark/android/benchmark/app/src/main/java/org/pytorch/minibench/*.java)
8383
if [ -n "$FILES_NEEDS_FORMAT" ]; then

.github/workflows/pull.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
- runner: linux.arm64.2xlarge
6161
docker-image: executorch-ubuntu-22.04-clang12
6262
# TODO: Need to figure out why buck2 doesnt work on Graviton instances.
63-
- runner: linux.arm64.2xlarge
63+
- runner: linux.arm64.2xlarge
6464
build-tool: buck2
6565
fail-fast: false
6666
with:
@@ -420,7 +420,6 @@ jobs:
420420
permissions:
421421
id-token: write
422422
contents: read
423-
needs: test-llama-runner-linux
424423

425424
unittest:
426425
uses: ./.github/workflows/_unittest.yml

backends/qualcomm/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ PRs are always welcome to help improve the codebase in a comprehensive manner. B
124124
- [shewu-quic](https://github.com/shewu-quic)
125125
- [chunit-quic](https://github.com/chunit-quic)
126126
- [winskuo-quic](https://github.com/winskuo-quic)
127+
- [DannyYuyang-quic](https://github.com/DannyYuyang-quic)
127128
- [haowhsu-quic](https://github.com/haowhsu-quic)
128129

129130
Thanks again for your contribution!

backends/qualcomm/_passes/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from .annotate_quant_attrs import AnnotateQuantAttrs
33
from .constant_i64_to_i32 import ConstantI64toI32
44
from .convert_bmm_to_matmul import ConvertBmmToMatmul
5-
from .convert_interpolate_with_upsample2d import ConvertInterpolateWithUpsample2D
65
from .convert_to_linear import ConvertToLinear
76
from .decompose_any import DecomposeAny
87
from .decompose_einsum import DecomposeEinsum
@@ -30,7 +29,6 @@
3029
AnnotateQuantAttrs,
3130
ConstantI64toI32,
3231
ConvertBmmToMatmul,
33-
ConvertInterpolateWithUpsample2D,
3432
RecomposePReLU,
3533
ConvertToLinear,
3634
DecomposeAny,

backends/qualcomm/_passes/annotate_quant_attrs.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from executorch.backends.qualcomm.builders.utils import get_parameter, set_parameter
1111
from executorch.backends.qualcomm.utils.constants import (
1212
QCOM_AXIS,
13+
QCOM_BLOCK_SIZE,
1314
QCOM_DTYPE,
1415
QCOM_ENCODING,
1516
QCOM_QUANT_ATTRS,
@@ -122,13 +123,25 @@ def _dequant_fold_params(self, n, quant_attrs, param):
122123
scales = self._expand(quant_attrs[QCOM_SCALES], dim, axis)
123124
offsets = self._expand(quant_attrs[QCOM_ZERO_POINTS], dim, axis)
124125
param = param.sub(offsets).mul(scales).to(torch.float32).contiguous()
125-
set_parameter(param, n.args[0], self.edge_program)
126+
elif quant_attrs[QCOM_ENCODING] in [
127+
exir_ops.edge.pt2e_quant.dequantize_affine.default
128+
]:
129+
param = torch.ops.pt2e_quant.dequantize_affine(
130+
param,
131+
block_size=quant_attrs[QCOM_BLOCK_SIZE],
132+
scale=quant_attrs[QCOM_SCALE],
133+
zero_point=quant_attrs[QCOM_ZERO_POINT],
134+
input_dtype=quant_attrs[QCOM_DTYPE],
135+
quant_min=quant_attrs[QCOM_QUANT_MIN],
136+
quant_max=quant_attrs[QCOM_QUANT_MAX],
137+
output_dtype=torch.float32,
138+
)
126139
else:
127140
scale = quant_attrs[QCOM_SCALE]
128141
offset = quant_attrs[QCOM_ZERO_POINT]
129142
param = param.sub(offset).mul(scale).to(torch.float32).contiguous()
130-
set_parameter(param, n.args[0], self.edge_program)
131143

144+
set_parameter(param, n.args[0], self.edge_program)
132145
n.args[0].meta["val"] = param
133146

134147
def _annotate_quant_attrs(

backends/qualcomm/_passes/convert_interpolate_with_upsample2d.py

Lines changed: 0 additions & 56 deletions
This file was deleted.

backends/qualcomm/_passes/layout_transform.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class LayoutTransform(ExportPass):
3939
exir_ops.edge.aten.pixel_shuffle.default,
4040
exir_ops.edge.aten.pixel_unshuffle.default,
4141
exir_ops.edge.aten.upsample_bilinear2d.default,
42+
exir_ops.edge.aten.upsample_bilinear2d.vec,
4243
exir_ops.edge.aten.upsample_nearest2d.default,
4344
exir_ops.edge.aten.upsample_nearest2d.vec,
4445
}

backends/qualcomm/_passes/utils.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import torch
88
from executorch.backends.qualcomm.builders.utils import get_parameter
9-
from executorch.backends.qualcomm.utils.constants import QCOM_ENCODING
9+
from executorch.backends.qualcomm.utils.constants import QCOM_DTYPE, QCOM_ENCODING
1010
from executorch.exir.dialects._ops import ops as exir_ops
1111
from torch._subclasses import FakeTensor
1212

@@ -42,6 +42,10 @@ def get_quant_attrs(
4242
value = get_parameter(attr_n, edge_program)
4343
quant_attrs[quant_attr_keys[i - 1]] = value
4444

45+
# remap key for compatibility - block quantization only
46+
if dtype := quant_attrs.get("input_dtype", None):
47+
quant_attrs[QCOM_DTYPE] = dtype
48+
4549
quant_attrs[QCOM_ENCODING] = quant_node.target
4650
return quant_attrs
4751

@@ -62,7 +66,6 @@ def get_passes_dependency_for_capture_program():
6266
AnnotateQuantAttrs,
6367
ConstantI64toI32,
6468
ConvertBmmToMatmul,
65-
ConvertInterpolateWithUpsample2D,
6669
ConvertToLinear,
6770
DecomposeAny,
6871
DecomposeLinalgVectorNorm,
@@ -85,11 +88,9 @@ def get_passes_dependency_for_capture_program():
8588
ConvertToLinear,
8689
RecomposePReLU,
8790
ConvertBmmToMatmul,
88-
ConvertInterpolateWithUpsample2D,
8991
],
90-
ConstantI64toI32: [ConvertInterpolateWithUpsample2D],
92+
ConstantI64toI32: [RemoveRedundancy],
9193
ConvertBmmToMatmul: [ConvertToLinear],
92-
ConvertInterpolateWithUpsample2D: [RemoveRedundancy],
9394
ConvertToLinear: [RecomposePixelUnshuffle],
9495
DecomposeAny: [RemoveRedundancy],
9596
DecomposeLinalgVectorNorm: [RemoveRedundancy],

backends/qualcomm/aot/ir/qcir.fbs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ enum QuantizeType : byte {
5454
AXIS_SCALE_OFFSET,
5555
BW_SCALE_OFFSET,
5656
BW_AXIS_SCALE_OFFSET,
57+
BLOCKWISE_EXPANSION,
58+
UNDEFINED,
59+
}
60+
61+
enum BlockScaleStorageType: byte {
62+
BITWIDTH_SCALE_STORAGE_8 = 0,
63+
BITWIDTH_SCALE_STORAGE_16,
5764
UNDEFINED,
5865
}
5966

@@ -72,6 +79,10 @@ table QuantizeParam {
7279
offsets: [int];
7380
// used by general quantization
7481
data: [ScaleOffset];
82+
// used by block quantization
83+
num_blocks_per_axis: uint;
84+
block_scale_storage_type: BlockScaleStorageType;
85+
block_scale: [ubyte];
7586
}
7687

7788
table Tensor {

0 commit comments

Comments
 (0)