Skip to content

Commit 6878f08

Browse files
author
pytorchbot
committed
2024-09-24 nightly release (df72b8c)
1 parent baf0d09 commit 6878f08

File tree

101 files changed

+2138
-706
lines changed

Some content is hidden

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

101 files changed

+2138
-706
lines changed

.ci/scripts/test_phi_3_mini.sh

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
set -exu
9+
10+
BUILD_TYPE=${1:-Debug}
11+
BUILD_DIR=${3:-cmake-out}
12+
MODEL_DIR=examples/models/phi-3-mini
13+
14+
echo "Building with BUILD_TYPE: $BUILD_TYPE, BUILD_DIR: $BUILD_DIR"
15+
16+
if [[ -z "${PYTHON_EXECUTABLE:-}" ]]; then
17+
PYTHON_EXECUTABLE=python3
18+
fi
19+
20+
# Number of processes for a parallel build
21+
NPROC=8
22+
if hash nproc &> /dev/null; then NPROC=$(nproc); fi
23+
24+
cmake_install_executorch_libraries() {
25+
cmake -DPYTHON_EXECUTABLE=python \
26+
-DCMAKE_INSTALL_PREFIX=${BUILD_DIR} \
27+
-DEXECUTORCH_ENABLE_LOGGING=1 \
28+
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
29+
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
30+
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
31+
-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
32+
-DEXECUTORCH_BUILD_XNNPACK=ON \
33+
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
34+
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
35+
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
36+
-B${BUILD_DIR} .
37+
38+
cmake --build ${BUILD_DIR} -j${NPROC} --target install --config ${BUILD_TYPE}
39+
}
40+
41+
cmake_build_phi_3_mini() {
42+
cmake -DPYTHON_EXECUTABLE=$PYTHON_EXECUTABLE \
43+
-DCMAKE_INSTALL_PREFIX=${BUILD_DIR} \
44+
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
45+
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
46+
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
47+
-DEXECUTORCH_BUILD_XNNPACK=ON \
48+
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
49+
-B${BUILD_DIR}/${MODEL_DIR} \
50+
${MODEL_DIR}
51+
52+
cmake --build ${BUILD_DIR}/${MODEL_DIR} -j${NPROC} --config ${BUILD_TYPE}
53+
}
54+
55+
# Download and convert tokenizer.model
56+
prepare_tokenizer() {
57+
echo "Downloading and converting tokenizer.model"
58+
wget -O tokenizer.model "https://huggingface.co/microsoft/Phi-3-mini-128k-instruct/resolve/main/tokenizer.model?download=true"
59+
$PYTHON_EXECUTABLE -m executorch.extension.llm.tokenizer.tokenizer -t tokenizer.model -o tokenizer.bin
60+
}
61+
62+
# Export phi-3-mini model to pte
63+
export_phi_3_mini () {
64+
echo "Exporting phi-3-mini. This will take a few minutes"
65+
$PYTHON_EXECUTABLE -m executorch.examples.models.phi-3-mini.export_phi-3-mini -c "4k" -s 128 -o phi-3-mini.pte
66+
}
67+
68+
run_and_verify() {
69+
NOW=$(date +"%H:%M:%S")
70+
echo "Starting to run phi-3-mini runner at ${NOW}"
71+
if [[ ! -f "phi-3-mini.pte" ]]; then
72+
echo "Export failed. Abort"
73+
exit 1
74+
fi
75+
if [[ ! -f "tokenizer.bin" ]]; then
76+
echo "tokenizer.bin is missing."
77+
exit 1
78+
fi
79+
80+
${BUILD_DIR}/${MODEL_DIR}/phi_3_mini_runner \
81+
--model_path=phi-3-mini.pte \
82+
--tokenizer_path=tokenizer.bin \
83+
--seq_len=128 \
84+
--temperature=0 \
85+
--prompt="<|system|>
86+
You are a helpful assistant.<|end|>
87+
<|user|>
88+
What is the capital of France?<|end|>
89+
<|assistant|>" > result.txt
90+
91+
# verify result.txt
92+
RESULT=$(cat result.txt)
93+
EXPECTED_RESULT="The capital of France is Paris."
94+
if [[ "${RESULT}" == *"${EXPECTED_RESULT}"* ]]; then
95+
echo "Expected result prefix: ${EXPECTED_RESULT}"
96+
echo "Actual result: ${RESULT}"
97+
echo "Success"
98+
exit 0
99+
else
100+
echo "Expected result prefix: ${EXPECTED_RESULT}"
101+
echo "Actual result: ${RESULT}"
102+
echo "Failure; results not the same"
103+
exit 1
104+
fi
105+
}
106+
107+
# Step 1. Build ExecuTorch and phi-3-mini runner
108+
cmake_install_executorch_libraries
109+
cmake_build_phi_3_mini
110+
111+
# Step 2. Export the tokenizer and model
112+
prepare_tokenizer
113+
export_phi_3_mini
114+
115+
# Step 3. Run and verify result
116+
run_and_verify

.github/workflows/pull.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,3 +414,30 @@ jobs:
414414
PYTHON_EXECUTABLE=python bash examples/models/llama2/install_requirements.sh
415415
# Test llama2
416416
PYTHON_EXECUTABLE=python bash .ci/scripts/test_llama.sh stories110M "${BUILD_TOOL}" "${DTYPE}" "${MODE}"
417+
418+
test-phi-3-mini-runner-linux:
419+
name: test-phi-3-mini-runner-linux
420+
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
421+
strategy:
422+
fail-fast: false
423+
with:
424+
runner: linux.24xlarge
425+
docker-image: executorch-ubuntu-22.04-clang12
426+
submodules: 'true'
427+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
428+
timeout: 90
429+
script: |
430+
# The generic Linux job chooses to use base env, not the one setup by the image
431+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
432+
conda activate "${CONDA_ENV}"
433+
434+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "cmake"
435+
436+
# install pybind
437+
bash install_requirements.sh --pybind xnnpack
438+
439+
# install phi-3-mini requirements
440+
bash examples/models/phi-3-mini/install_requirements.sh
441+
442+
# run e2e (export, tokenizer and runner)
443+
PYTHON_EXECUTABLE=python bash .ci/scripts/test_phi_3_mini.sh

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,11 +680,16 @@ if(EXECUTORCH_BUILD_PYBIND)
680680
etdump
681681
executorch
682682
extension_data_loader
683-
portable_ops_lib
684683
util
685684
torch
686685
)
687686

687+
if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
688+
list(APPEND _dep_libs optimized_native_cpu_ops_lib)
689+
else()
690+
list(APPEND _dep_libs portable_ops_lib)
691+
endif()
692+
688693
if(EXECUTORCH_BUILD_COREML)
689694
list(APPEND _dep_libs coremldelegate)
690695
endif()

backends/arm/arm_backend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def __init__(self):
5252
def ethosu_compile_spec(
5353
self,
5454
config: str,
55-
system_config: Optional[str] = None,
56-
memory_mode: Optional[str] = None,
55+
system_config: str,
56+
memory_mode: str,
5757
extra_flags: Optional[str] = None,
5858
config_ini: Optional[str] = "Arm/vela.ini",
5959
) -> "ArmCompileSpecBuilder":

backends/arm/test/models/test_mobilenet_v2_arm.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,18 @@ def test_mv2_u55_BI(self):
102102
tester.run_method_and_compare_outputs(
103103
atol=1.0, qtol=1, inputs=self.model_inputs
104104
)
105+
106+
def test_mv2_u85_BI(self):
107+
(
108+
ArmTester(
109+
self.mv2,
110+
example_inputs=self.model_inputs,
111+
compile_spec=common.get_u85_compile_spec(permute_memory_to_nhwc=True),
112+
)
113+
.quantize()
114+
.export()
115+
.to_edge(config=self._edge_compile_config)
116+
.check(list(self.operators_after_quantization))
117+
.partition()
118+
.to_executorch()
119+
)

backends/arm/test/ops/test_add.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from executorch.backends.arm.test import common
1414
from executorch.backends.arm.test.tester.arm_tester import ArmTester
1515
from executorch.exir import EdgeCompileConfig
16+
from executorch.exir.backend.compile_spec_schema import CompileSpec
1617
from parameterized import parameterized
1718

1819

@@ -92,16 +93,17 @@ def _test_add_tosa_BI_pipeline(
9293
.run_method_and_compare_outputs(inputs=test_data, qtol=1)
9394
)
9495

95-
def _test_add_u55_BI_pipeline(
96+
def _test_add_ethos_BI_pipeline(
9697
self,
9798
module: torch.nn.Module,
99+
compile_spec: CompileSpec,
98100
test_data: Tuple[torch.Tensor],
99101
):
100102
tester = (
101103
ArmTester(
102104
module,
103105
example_inputs=test_data,
104-
compile_spec=common.get_u55_compile_spec(permute_memory_to_nhwc=True),
106+
compile_spec=compile_spec,
105107
)
106108
.quantize()
107109
.export()
@@ -114,8 +116,7 @@ def _test_add_u55_BI_pipeline(
114116
.serialize()
115117
)
116118

117-
if common.is_option_enabled("corstone300"):
118-
tester.run_method_and_compare_outputs(qtol=1, inputs=test_data)
119+
return tester
119120

120121
@parameterized.expand(Add.test_parameters)
121122
def test_add_tosa_MI(self, test_data: torch.Tensor):
@@ -130,7 +131,22 @@ def test_add_tosa_BI(self, test_data: torch.Tensor):
130131
@parameterized.expand(Add.test_parameters)
131132
def test_add_u55_BI(self, test_data: torch.Tensor):
132133
test_data = (test_data,)
133-
self._test_add_u55_BI_pipeline(self.Add(), test_data)
134+
tester = self._test_add_ethos_BI_pipeline(
135+
self.Add(),
136+
common.get_u55_compile_spec(permute_memory_to_nhwc=True),
137+
test_data,
138+
)
139+
if common.is_option_enabled("corstone300"):
140+
tester.run_method_and_compare_outputs(qtol=1, inputs=test_data)
141+
142+
@parameterized.expand(Add.test_parameters)
143+
def test_add_u85_BI(self, test_data: torch.Tensor):
144+
test_data = (test_data,)
145+
self._test_add_ethos_BI_pipeline(
146+
self.Add(),
147+
common.get_u85_compile_spec(permute_memory_to_nhwc=True),
148+
test_data,
149+
)
134150

135151
@parameterized.expand(Add2.test_parameters)
136152
def test_add2_tosa_MI(self, operand1: torch.Tensor, operand2: torch.Tensor):
@@ -145,4 +161,15 @@ def test_add2_tosa_BI(self, operand1: torch.Tensor, operand2: torch.Tensor):
145161
@parameterized.expand(Add2.test_parameters)
146162
def test_add2_u55_BI(self, operand1: torch.Tensor, operand2: torch.Tensor):
147163
test_data = (operand1, operand2)
148-
self._test_add_u55_BI_pipeline(self.Add2(), test_data)
164+
tester = self._test_add_ethos_BI_pipeline(
165+
self.Add2(), common.get_u55_compile_spec(), test_data
166+
)
167+
if common.is_option_enabled("corstone300"):
168+
tester.run_method_and_compare_outputs(qtol=1, inputs=test_data)
169+
170+
@parameterized.expand(Add2.test_parameters)
171+
def test_add2_u85_BI(self, operand1: torch.Tensor, operand2: torch.Tensor):
172+
test_data = (operand1, operand2)
173+
self._test_add_ethos_BI_pipeline(
174+
self.Add2(), common.get_u85_compile_spec(), test_data
175+
)

backends/arm/test/ops/test_avg_pool.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import torch
1414
from executorch.backends.arm.test import common
1515
from executorch.backends.arm.test.tester.arm_tester import ArmTester
16+
from executorch.exir.backend.backend_details import CompileSpec
1617
from parameterized import parameterized
1718

1819
logger = logging.getLogger(__name__)
@@ -86,14 +87,17 @@ def _test_avgpool2d_tosa_BI_pipeline(
8687
.run_method_and_compare_outputs(inputs=test_data, qtol=1)
8788
)
8889

89-
def _test_avgpool2d_tosa_u55_BI_pipeline(
90-
self, module: torch.nn.Module, test_data: Tuple[torch.tensor]
90+
def _test_avgpool2d_tosa_ethos_BI_pipeline(
91+
self,
92+
module: torch.nn.Module,
93+
compile_spec: CompileSpec,
94+
test_data: Tuple[torch.tensor],
9195
):
9296
(
9397
ArmTester(
9498
module,
9599
example_inputs=test_data,
96-
compile_spec=common.get_u55_compile_spec(permute_memory_to_nhwc=True),
100+
compile_spec=compile_spec,
97101
)
98102
.quantize()
99103
.export()
@@ -141,6 +145,22 @@ def test_avgpool2d_tosa_u55_BI(
141145
test_data: torch.Tensor,
142146
model_params: int | Tuple[int, int],
143147
):
144-
self._test_avgpool2d_tosa_u55_BI_pipeline(
145-
self.AvgPool2d(*model_params), (test_data,)
148+
self._test_avgpool2d_tosa_ethos_BI_pipeline(
149+
self.AvgPool2d(*model_params),
150+
common.get_u55_compile_spec(permute_memory_to_nhwc=True),
151+
(test_data,),
152+
)
153+
154+
@parameterized.expand(test_data_suite)
155+
@unittest.expectedFailure
156+
def test_avgpool2d_tosa_u85_BI(
157+
self,
158+
test_name: str,
159+
test_data: torch.Tensor,
160+
model_params: int | Tuple[int, int],
161+
):
162+
self._test_avgpool2d_tosa_ethos_BI_pipeline(
163+
self.AvgPool2d(*model_params),
164+
common.get_u85_compile_spec(permute_memory_to_nhwc=True),
165+
(test_data,),
146166
)

backends/arm/test/ops/test_bmm.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import torch
1212
from executorch.backends.arm.test import common
1313
from executorch.backends.arm.test.tester.arm_tester import ArmTester
14+
from executorch.exir.backend.compile_spec_schema import CompileSpec
1415
from parameterized import parameterized
1516

1617
torch.manual_seed(1)
@@ -83,14 +84,17 @@ def _test_bmm_tosa_BI_pipeline(
8384
.run_method_and_compare_outputs(inputs=test_data)
8485
)
8586

86-
def _test_bmm_u55_BI_pipeline(
87-
self, module: torch.nn.Module, test_data: Tuple[torch.Tensor, ...]
87+
def _test_bmm_ethosu_BI_pipeline(
88+
self,
89+
module: torch.nn.Module,
90+
compile_spec: CompileSpec,
91+
test_data: Tuple[torch.Tensor, ...],
8892
):
8993
(
9094
ArmTester(
9195
module,
9296
example_inputs=test_data,
93-
compile_spec=common.get_u55_compile_spec(),
97+
compile_spec=compile_spec,
9498
)
9599
.quantize()
96100
.export()
@@ -132,4 +136,13 @@ def test_bmm_u55_BI(self, operand1: torch.Tensor, operand2: torch.Tensor):
132136
@unittest.expectedFailure
133137
def test_bmm_single_input_u55_BI(self, operand1: torch.Tensor):
134138
test_data = (operand1,)
135-
self._test_bmm_u55_BI_pipeline(self.BMMSingleInput(), test_data)
139+
self._test_bmm_ethosu_BI_pipeline(
140+
self.BMMSingleInput(), common.get_u55_compile_spec(), test_data
141+
)
142+
143+
@parameterized.expand(BMMSingleInput.test_parameters)
144+
def test_bmm_single_input_u85_BI(self, operand1: torch.Tensor):
145+
test_data = (operand1,)
146+
self._test_bmm_ethosu_BI_pipeline(
147+
self.BMMSingleInput(), common.get_u85_compile_spec(), test_data
148+
)

0 commit comments

Comments
 (0)