Skip to content

Commit 59f4b20

Browse files
authored
Merge branch 'pytorch:main' into dev1/hutton/convert_linear_to_conv2d
2 parents 18ba80a + 3cf9237 commit 59f4b20

40 files changed

+1282
-123
lines changed

.github/workflows/apple-perf.yml

Lines changed: 305 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,305 @@
1+
name: apple-perf
2+
3+
on:
4+
schedule:
5+
- cron: 0 1 * * *
6+
# Note: GitHub has an upper limit of 10 inputs
7+
workflow_dispatch:
8+
inputs:
9+
models:
10+
description: Models to be benchmarked
11+
required: false
12+
type: string
13+
default: stories110M
14+
devices:
15+
description: Target devices to run benchmark
16+
required: false
17+
type: string
18+
default: apple_iphone_15
19+
delegates:
20+
description: Backend delegates
21+
required: false
22+
type: string
23+
default: xnnpack
24+
benchmark_configs:
25+
description: The list of configs used the benchmark
26+
required: false
27+
type: string
28+
test_spec:
29+
description: The test spec to drive the test on AWS devices
30+
required: false
31+
type: string
32+
workflow_call:
33+
inputs:
34+
models:
35+
description: Models to be benchmarked
36+
required: false
37+
type: string
38+
default: stories110M
39+
devices:
40+
description: Target devices to run benchmark
41+
required: false
42+
type: string
43+
default: apple_iphone_15
44+
delegates:
45+
description: Backend delegates
46+
required: false
47+
type: string
48+
default: xnnpack
49+
benchmark_configs:
50+
description: The list of configs used the benchmark
51+
required: false
52+
type: string
53+
test_spec:
54+
description: The test spec to drive the test on AWS devices
55+
required: false
56+
type: string
57+
58+
concurrency:
59+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref_name }}-${{ github.ref_type == 'branch' && github.sha }}-${{ github.event_name == 'workflow_dispatch' }}-${{ github.event_name == 'schedule' }}
60+
cancel-in-progress: true
61+
62+
jobs:
63+
set-parameters:
64+
runs-on: linux.2xlarge
65+
outputs:
66+
models: ${{ steps.set-parameters.outputs.models }}
67+
devices: ${{ steps.set-parameters.outputs.devices }}
68+
delegates: ${{ steps.set-parameters.outputs.delegates }}
69+
steps:
70+
- name: Set parameters
71+
id: set-parameters
72+
shell: bash
73+
env:
74+
# Separate default values from the workflow dispatch. To ensure defaults are accessible
75+
# during scheduled runs and to provide flexibility for different defaults between
76+
# on-demand and periodic benchmarking.
77+
CRON_DEFAULT_MODELS: "stories110M"
78+
CRON_DEFAULT_DEVICES: "apple_iphone_15"
79+
CRON_DEFAULT_DELEGATES: "xnnpack"
80+
run: |
81+
set -ex
82+
MODELS="${{ inputs.models }}"
83+
if [ -z "$MODELS" ]; then
84+
MODELS="$CRON_DEFAULT_MODELS"
85+
fi
86+
DEVICES="${{ inputs.devices }}"
87+
if [ -z "$DEVICES" ]; then
88+
DEVICES="$CRON_DEFAULT_DEVICES"
89+
fi
90+
DELEGATES="${{ inputs.delegates }}"
91+
if [ -z "$DELEGATES" ]; then
92+
DELEGATES="$CRON_DEFAULT_DELEGATES"
93+
fi
94+
95+
# Mapping devices to their corresponding device-pool-arn
96+
declare -A DEVICE_POOL_ARNS
97+
DEVICE_POOL_ARNS[apple_iphone_15]="arn:aws:devicefarm:us-west-2:308535385114:devicepool:02a2cf0f-6d9b-45ee-ba1a-a086587469e6/3b5acd2e-92e2-4778-b651-7726bafe129d"
98+
99+
# Resolve device names with their corresponding ARNs
100+
if [[ ! $(echo "$DEVICES" | jq empty 2>/dev/null) ]]; then
101+
DEVICES=$(echo "$DEVICES" | jq -Rc 'split(",")')
102+
fi
103+
declare -a MAPPED_ARNS=()
104+
for DEVICE in $(echo "$DEVICES" | jq -r '.[]'); do
105+
if [[ -z "${DEVICE_POOL_ARNS[$DEVICE]}" ]]; then
106+
echo "Error: No ARN found for device '$DEVICE'. Abort." >&2
107+
exit 1
108+
fi
109+
MAPPED_ARNS+=("${DEVICE_POOL_ARNS[$DEVICE]}")
110+
done
111+
112+
echo "models=$(echo $MODELS | jq -Rc 'split(",")')" >> $GITHUB_OUTPUT
113+
MAPPED_ARNS_JSON=$(printf '%s\n' "${MAPPED_ARNS[@]}" | jq -R . | jq -s .)
114+
echo "devices=$(echo "$MAPPED_ARNS_JSON" | jq -c .)" >> $GITHUB_OUTPUT
115+
echo "delegates=$(echo $DELEGATES | jq -Rc 'split(",")')" >> $GITHUB_OUTPUT
116+
117+
export-models:
118+
name: export-models
119+
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
120+
needs: set-parameters
121+
strategy:
122+
matrix:
123+
model: ${{ fromJson(needs.set-parameters.outputs.models) }}
124+
delegate: ${{ fromJson(needs.set-parameters.outputs.delegates) }}
125+
fail-fast: false
126+
with:
127+
runner: macos-latest-xlarge
128+
python-version: '3.11'
129+
submodules: 'true'
130+
timeout: 60
131+
upload-artifact: ios-models
132+
script: |
133+
set -eux
134+
135+
echo "::group::Setting up CI environment"
136+
.ci/scripts/setup-conda.sh
137+
138+
BUILD_TOOL=cmake
139+
# Setup MacOS dependencies as there is no Docker support on MacOS atm
140+
GITHUB_RUNNER=1 PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
141+
.ci/scripts/setup-macos.sh "${BUILD_TOOL}"
142+
143+
if [[ ${{ matrix.delegate }} == "coreml" ]]; then
144+
PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
145+
backends/apple/coreml/scripts/install_requirements.sh
146+
fi
147+
148+
if [[ ${{ matrix.delegate }} == "mps" ]]; then
149+
PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
150+
backends/apple/mps/install_requirements.sh
151+
fi
152+
153+
ARTIFACTS_DIR_NAME=artifacts-to-be-uploaded/${{ matrix.model }}_${{ matrix.delegate }}
154+
echo "::endgroup::"
155+
156+
echo "::group::Exporting ${{ matrix.delegate }} model: ${{ matrix.model }}"
157+
BUILD_MODE="cmake"
158+
DTYPE="fp32"
159+
160+
if [[ ${{ matrix.model }} =~ ^stories* ]]; then
161+
# Install requirements for export_llama
162+
PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
163+
bash examples/models/llama2/install_requirements.sh
164+
165+
# Test llama2
166+
if [[ ${{ matrix.delegate }} == "xnnpack" ]]; then
167+
DELEGATE_CONFIG="xnnpack+custom+qe"
168+
fi
169+
PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
170+
bash .ci/scripts/test_llama.sh "${{ matrix.model }}" "${BUILD_MODE}" "${DTYPE}" "${DELEGATE_CONFIG}" "${ARTIFACTS_DIR_NAME}"
171+
else
172+
# TODO (huydhn): Extend the export script here to support other backends such as coreml, mps
173+
PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
174+
bash .ci/scripts/test.sh "${{ matrix.model }}" "${BUILD_MODE}" "${{ matrix.delegate }}" "${ARTIFACTS_DIR_NAME}"
175+
fi
176+
echo "::endgroup::"
177+
178+
upload-models:
179+
needs: export-models
180+
runs-on: linux.2xlarge
181+
steps:
182+
- name: Download the models from GitHub
183+
uses: actions/download-artifact@v3
184+
with:
185+
# The name here needs to match the name of the upload-artifact parameter
186+
name: ios-models
187+
path: ${{ runner.temp }}/artifacts/
188+
189+
- name: Verify the models
190+
shell: bash
191+
working-directory: ${{ runner.temp }}/artifacts/
192+
run: |
193+
ls -lah ./
194+
195+
- name: Upload the models to S3
196+
uses: seemethere/upload-artifact-s3@v5
197+
with:
198+
s3-bucket: gha-artifacts
199+
s3-prefix: |
200+
${{ github.repository }}/${{ github.run_id }}/artifact
201+
retention-days: 1
202+
if-no-files-found: ignore
203+
path: ${{ runner.temp }}/artifacts/
204+
205+
build-llm-demo:
206+
name: build-llm-demo
207+
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
208+
needs:
209+
- set-parameters
210+
secrets: inherit
211+
strategy:
212+
matrix:
213+
tokenizer: [bpe]
214+
with:
215+
runner: macos-latest-xlarge
216+
python-version: '3.11'
217+
submodules: 'true'
218+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
219+
upload-artifact: ios-apps
220+
secrets-env: BUILD_CERTIFICATE_BASE64 BUILD_PROVISION_PROFILE_BASE64 KEYCHAIN_PASSWORD
221+
timeout: 90
222+
script: |
223+
set -eux
224+
225+
echo "::group::Setting up CI environment"
226+
.ci/scripts/setup-conda.sh
227+
228+
BUILD_TOOL=cmake
229+
# Setup MacOS dependencies as there is no Docker support on MacOS atm
230+
GITHUB_RUNNER=1 PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
231+
.ci/scripts/setup-macos.sh "${BUILD_TOOL}"
232+
export ARTIFACTS_DIR_NAME=artifacts-to-be-uploaded
233+
234+
# Setup Apple certificate for iOS development
235+
BUILD_PROVISION_PROFILE_BASE64="${SECRET_BUILD_PROVISION_PROFILE_BASE64}" \
236+
BUILD_CERTIFICATE_BASE64="${SECRET_BUILD_CERTIFICATE_BASE64}" \
237+
KEYCHAIN_PASSWORD="${SECRET_KEYCHAIN_PASSWORD}" \
238+
.ci/scripts/setup-ios.sh
239+
240+
# Install CoreML Backend Requirements
241+
PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
242+
backends/apple/coreml/scripts/install_requirements.sh
243+
244+
# Install MPS Backend Requirements
245+
PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
246+
backends/apple/mps/install_requirements.sh
247+
echo "::endgroup::"
248+
249+
${CONDA_RUN} --no-capture-output \
250+
build/build_apple_llm_demo.sh ${{ matrix.tokenizer }} ${ARTIFACTS_DIR_NAME}
251+
252+
upload-ios-apps:
253+
needs: build-llm-demo
254+
runs-on: linux.2xlarge
255+
steps:
256+
- name: Download the apps from GitHub
257+
uses: actions/download-artifact@v3
258+
with:
259+
# The name here needs to match the name of the upload-artifact parameter
260+
name: ios-apps
261+
path: ${{ runner.temp }}/artifacts/
262+
263+
- name: Verify the apps
264+
shell: bash
265+
working-directory: ${{ runner.temp }}/artifacts/
266+
run: |
267+
ls -lah ./
268+
269+
- name: Upload the apps to S3
270+
uses: seemethere/upload-artifact-s3@v5
271+
with:
272+
s3-bucket: gha-artifacts
273+
s3-prefix: |
274+
${{ github.repository }}/${{ github.run_id }}/artifact
275+
retention-days: 14
276+
if-no-files-found: ignore
277+
path: ${{ runner.temp }}/artifacts/
278+
279+
benchmark-on-device:
280+
needs:
281+
- set-parameters
282+
- upload-ios-apps
283+
- upload-models
284+
permissions:
285+
id-token: write
286+
contents: read
287+
uses: pytorch/test-infra/.github/workflows/mobile_job.yml@main
288+
strategy:
289+
matrix:
290+
model: ${{ fromJson(needs.set-parameters.outputs.models) }}
291+
delegate: ${{ fromJson(needs.set-parameters.outputs.delegates) }}
292+
device: ${{ fromJson(needs.set-parameters.outputs.devices) }}
293+
with:
294+
device-type: ios
295+
# For iOS testing, the runner just needs to call AWS Device Farm, so there is no need to run this on macOS
296+
runner: linux.2xlarge
297+
test-infra-ref: ''
298+
# This is the ARN of ExecuTorch project on AWS
299+
project-arn: arn:aws:devicefarm:us-west-2:308535385114:project:02a2cf0f-6d9b-45ee-ba1a-a086587469e6
300+
device-pool-arn: ${{ matrix.device }}
301+
# Uploaded to S3 from the previous job
302+
ios-ipa-archive: https://gha-artifacts.s3.amazonaws.com/${{ github.repository }}/${{ github.run_id }}/artifact/LLaMAPerfBenchmark.ipa
303+
ios-xctestrun-zip: https://gha-artifacts.s3.amazonaws.com/${{ github.repository }}/${{ github.run_id }}/artifact/LLaMAPerfBenchmark.xctestrun.zip
304+
test-spec: ${{ inputs.test_spec || 'https://ossci-ios.s3.amazonaws.com/executorch/default-ios-device-farm-appium-test-spec.yml' }}
305+
extra-data: https://gha-artifacts.s3.amazonaws.com/${{ github.repository }}/${{ github.run_id }}/artifact/${{ matrix.model }}_${{ matrix.delegate }}/model.zip

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ option(EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL "Build the Runner Util extension"
181181
OFF
182182
)
183183

184+
option(EXECUTORCH_BUILD_EXTENSION_TENSOR "Build the Tensor extension" OFF)
185+
184186
option(EXECUTORCH_BUILD_GTESTS "Build googletest based test binaries" OFF)
185187

186188
option(EXECUTORCH_BUILD_MPS "Build the MPS backend" OFF)
@@ -637,6 +639,10 @@ if(EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL)
637639
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/runner_util)
638640
endif()
639641

642+
if(EXECUTORCH_BUILD_EXTENSION_TENSOR)
643+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/tensor)
644+
endif()
645+
640646
if(EXECUTORCH_BUILD_PTHREADPOOL
641647
AND EXECUTORCH_BUILD_CPUINFO
642648
AND CMAKE_CXX_STANDARD GREATER_EQUAL 14

build/Utils.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ function(executorch_print_configuration_summary)
6565
message(STATUS " EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL : "
6666
"${EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL}"
6767
)
68+
message(STATUS " EXECUTORCH_BUILD_EXTENSION_TENSOR : "
69+
"${EXECUTORCH_BUILD_EXTENSION_TENSOR}"
70+
)
6871
message(
6972
STATUS
7073
" EXECUTORCH_BUILD_FLATC : ${EXECUTORCH_BUILD_FLATC}"

build/build_apple_frameworks.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ libexecutorch_no_prim_ops.a,\
3333
libextension_apple.a,\
3434
libextension_data_loader.a,\
3535
libextension_module.a,\
36+
libextension_tensor.a,\
3637
:$HEADERS_PATH"
3738

3839
FRAMEWORK_BACKEND_COREML="backend_coreml:\
@@ -165,6 +166,7 @@ cmake_build() {
165166
-DEXECUTORCH_BUILD_EXTENSION_APPLE=ON \
166167
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
167168
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
169+
-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
168170
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=$CUSTOM \
169171
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=$OPTIMIZED \
170172
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=$QUANTIZED \
@@ -188,6 +190,7 @@ mkdir -p "$HEADERS_PATH"
188190

189191
"$SOURCE_ROOT_DIR"/build/print_exported_headers.py --buck2="$BUCK2" --targets \
190192
//extension/module: \
193+
//extension/tensor: \
191194
| rsync -av --files-from=- "$SOURCE_ROOT_DIR" "$HEADERS_PATH/executorch"
192195

193196
cp "$SOURCE_ROOT_DIR/extension/apple/ExecuTorch/Exported/"*.h "$HEADERS_PATH/executorch"

0 commit comments

Comments
 (0)