Skip to content

Commit c289feb

Browse files
committed
Update on "[executorch][flat_tensor] Serialize flat tensor"
Serialize a flat tensor file. The resulting file looks like: Header with - flatbuffer offset and size - segment data offset and size Flatbuffer Tensor data (in segment) Differential Revision: [D66374253](https://our.internmc.facebook.com/intern/diff/D66374253/) [ghstack-poisoned]
2 parents 7436967 + 836c1cd commit c289feb

File tree

283 files changed

+5553
-3266
lines changed

Some content is hidden

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

283 files changed

+5553
-3266
lines changed

.ci/docker/ci_commit_pins/buck2.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2024-05-15
1+
2024-12-16

.ci/docker/conda-env-ci.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
cmake=3.22.1
22
ninja=1.10.2
3+
libuv
4+
pkg-config
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
# Copyright 2024 Arm Limited and/or its affiliates.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# NB: This function could be used to install Arm dependencies
8+
# Setup arm example environment (including TOSA tools)
9+
git config --global user.email "[email protected]"
10+
git config --global user.name "Github Executorch"
11+
bash examples/arm/setup.sh --i-agree-to-the-contained-eula

.ci/scripts/setup-macos.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,9 @@ if [[ -z "${GITHUB_RUNNER:-}" ]]; then
131131
fi
132132

133133
print_cmake_info
134-
install_executorch
134+
install_pytorch_and_domains
135+
# We build PyTorch from source here instead of using nightly. This allows CI to test against
136+
# the pinned commit from PyTorch
137+
install_executorch "use-pt-pinned-commit"
135138
build_executorch_runner "${BUILD_TOOL}"
139+
do_not_use_nightly_on_ci

.ci/scripts/utils.sh

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,42 @@ install_pip_dependencies() {
4040
popd || return
4141
}
4242

43+
install_domains() {
44+
echo "Install torchvision and torchaudio"
45+
pip install --no-use-pep517 --user "git+https://github.com/pytorch/audio.git@${TORCHAUDIO_VERSION}"
46+
pip install --no-use-pep517 --user "git+https://github.com/pytorch/vision.git@${TORCHVISION_VERSION}"
47+
}
48+
49+
install_pytorch_and_domains() {
50+
pushd .ci/docker || return
51+
TORCH_VERSION=$(cat ci_commit_pins/pytorch.txt)
52+
popd || return
53+
54+
git clone https://github.com/pytorch/pytorch.git
55+
56+
# Fetch the target commit
57+
pushd pytorch || return
58+
git checkout "${TORCH_VERSION}"
59+
git submodule update --init --recursive
60+
61+
export USE_DISTRIBUTED=1
62+
# Then build and install PyTorch
63+
python setup.py bdist_wheel
64+
pip install "$(echo dist/*.whl)"
65+
66+
# Grab the pinned audio and vision commits from PyTorch
67+
TORCHAUDIO_VERSION=$(cat .github/ci_commit_pins/audio.txt)
68+
export TORCHAUDIO_VERSION
69+
TORCHVISION_VERSION=$(cat .github/ci_commit_pins/vision.txt)
70+
export TORCHVISION_VERSION
71+
72+
install_domains
73+
74+
popd || return
75+
# Print sccache stats for debugging
76+
sccache --show-stats || true
77+
}
78+
4379
install_flatc_from_source() {
4480
# NB: This function could be used to install flatbuffer from source
4581
pushd third-party/flatbuffers || return
@@ -59,17 +95,6 @@ install_flatc_from_source() {
5995
popd || return
6096
}
6197

62-
install_arm() {
63-
# NB: This function could be used to install Arm dependencies
64-
# Setup arm example environment (including TOSA tools)
65-
git config --global user.email "[email protected]"
66-
git config --global user.name "Github Executorch"
67-
bash examples/arm/setup.sh --i-agree-to-the-contained-eula
68-
69-
# Test tosa_reference flow
70-
source examples/arm/ethos-u-scratch/setup_path.sh
71-
}
72-
7398
build_executorch_runner_buck2() {
7499
# Build executorch runtime with retry as this step is flaky on macos CI
75100
retry buck2 build //examples/portable/executor_runner:executor_runner

.github/workflows/android-perf.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ jobs:
9898
- uses: actions/checkout@v3
9999

100100
- name: Prepare the spec
101+
id: prepare
101102
shell: bash
102103
env:
103104
BENCHMARK_CONFIG: ${{ toJSON(matrix) }}
@@ -111,7 +112,7 @@ jobs:
111112
# so let's just sed it
112113
sed -i -e 's,{{ model_path }},'"${MODEL_PATH}"',g' android-llm-device-farm-test-spec.yml.j2
113114
114-
BENCHMARK_CONFIG_ID="${{ matrix.model }}_${{ matrix.config }}"
115+
BENCHMARK_CONFIG_ID=$(echo "${{ matrix.model }}_${{ matrix.config }}" | sed -e 's/[^A-Za-z0-9._-]/_/g')
115116
# The config for this benchmark runs, we save it in the test spec so that it can be fetched
116117
# later by the upload script
117118
sed -i -e 's,{{ benchmark_config_id }},'"${BENCHMARK_CONFIG_ID}"',g' android-llm-device-farm-test-spec.yml.j2
@@ -122,6 +123,7 @@ jobs:
122123
123124
# Save the benchmark configs so that we can use it later in the dashboard
124125
echo "${BENCHMARK_CONFIG}" > "${BENCHMARK_CONFIG_ID}.json"
126+
echo "benchmark-config-id=${BENCHMARK_CONFIG_ID}" >> $GITHUB_OUTPUT
125127
126128
- name: Upload the spec
127129
uses: seemethere/upload-artifact-s3@v5
@@ -141,7 +143,7 @@ jobs:
141143
${{ github.repository }}/${{ github.run_id }}/artifacts/benchmark-configs/
142144
retention-days: 1
143145
if-no-files-found: error
144-
path: extension/benchmark/android/benchmark/${{ matrix.model }}_${{ matrix.config }}.json
146+
path: extension/benchmark/android/benchmark/${{ steps.prepare.outputs.benchmark-config-id }}.json
145147

146148
export-models:
147149
name: export-models

.github/workflows/apple-perf.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ jobs:
100100
- uses: actions/checkout@v3
101101

102102
- name: Prepare the spec
103+
id: prepare
103104
shell: bash
104105
env:
105106
BENCHMARK_CONFIG: ${{ toJSON(matrix) }}
@@ -113,7 +114,7 @@ jobs:
113114
# so let's just sed it
114115
sed -i -e 's,{{ model_path }},'"${MODEL_PATH}"',g' default-ios-device-farm-appium-test-spec.yml.j2
115116
116-
BENCHMARK_CONFIG_ID="${{ matrix.model }}_${{ matrix.config }}"
117+
BENCHMARK_CONFIG_ID=$(echo "${{ matrix.model }}_${{ matrix.config }}" | sed -e 's/[^A-Za-z0-9._-]/_/g')
117118
# The config for this benchmark runs, we save it in the test spec so that it can be fetched
118119
# later by the upload script
119120
sed -i -e 's,{{ benchmark_config_id }},'"${BENCHMARK_CONFIG_ID}"',g' default-ios-device-farm-appium-test-spec.yml.j2
@@ -124,6 +125,7 @@ jobs:
124125
125126
# Save the benchmark configs so that we can use it later in the dashboard
126127
echo "${BENCHMARK_CONFIG}" > "${BENCHMARK_CONFIG_ID}.json"
128+
echo "benchmark-config-id=${BENCHMARK_CONFIG_ID}" >> $GITHUB_OUTPUT
127129
128130
- name: Upload the spec
129131
uses: seemethere/upload-artifact-s3@v5
@@ -143,7 +145,7 @@ jobs:
143145
${{ github.repository }}/${{ github.run_id }}/artifacts/benchmark-configs/
144146
retention-days: 1
145147
if-no-files-found: error
146-
path: extension/benchmark/apple/Benchmark/${{ matrix.model }}_${{ matrix.config }}.json
148+
path: extension/benchmark/apple/Benchmark/${{ steps.prepare.outputs.benchmark-config-id }}.json
147149

148150
export-models:
149151
name: export-models

.github/workflows/lint.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,19 @@ jobs:
2020
with:
2121
runner: linux.2xlarge
2222
docker-image: executorch-ubuntu-22.04-linter
23+
submodules: 'true'
2324
fetch-depth: 0
2425
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
2526
timeout: 90
2627
script: |
2728
# The generic Linux job chooses to use base env, not the one setup by the image
2829
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
2930
conda activate "${CONDA_ENV}"
31+
32+
# For mypy linting, we need to first install executorch first so that
33+
# it builds the python package information.
34+
BUILD_TOOL="cmake"
35+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "${BUILD_TOOL}"
3036
3137
CACHE_DIRECTORY="/tmp/.lintbin"
3238
# Try to recover the cached binaries

.github/workflows/pull.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,13 +354,11 @@ jobs:
354354
EXECUTORCH_BUILD_ARM_BAREMETAL=ON \
355355
.ci/scripts/setup-linux.sh "${BUILD_TOOL}"
356356
357-
source .ci/scripts/utils.sh
358357
# Install Arm dependencies
359-
install_arm
360-
361-
# Run pytest with coverage
362-
pytest -c /dev/null -v -n auto --cov=./ --cov-report=xml backends/arm/test
358+
.ci/scripts/setup-arm-baremetal-tools.sh
363359
360+
# Run pytest without simulator
361+
backends/arm/test/test_arm_baremetal.sh test_pytest
364362
365363
test-llama-runner-qnn-linux:
366364
name: test-llama-runner-qnn-linux

.github/workflows/trunk.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,15 @@ jobs:
146146
source .ci/scripts/utils.sh
147147
install_executorch
148148
149-
install_arm
149+
.ci/scripts/setup-arm-baremetal-tools.sh
150150
151151
# Increase number of files user can monitor to bypass buck failures.
152152
# Hopefully this is high enough for this setup.
153153
sudo sysctl fs.inotify.max_user_watches=1048576 # 1024 * 1024
154154
155155
# Test ethos-u delegate examples with run.sh
156-
PYTHON_EXECUTABLE=python bash examples/arm/run.sh examples/arm/ethos-u-scratch/
156+
backends/arm/test/test_arm_baremetal.sh test_run_ethosu_fvp
157+
157158
158159
test-arm-reference-delegation:
159160
name: test-arm-reference-delegation
@@ -172,10 +173,10 @@ jobs:
172173
source .ci/scripts/utils.sh
173174
install_executorch
174175
175-
install_arm
176+
.ci/scripts/setup-arm-baremetal-tools.sh
176177
177-
# Run arm unit tests
178-
pytest -c /dev/null -v -n auto --cov=./ --cov-report=xml backends/arm/test
178+
# Run arm unit tests using the simulator
179+
backends/arm/test/test_arm_baremetal.sh test_pytest_ethosu_fvp
179180
180181
test-coreml-delegate:
181182
name: test-coreml-delegate

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.hypothesis
22
buck-out/
3+
.mypy_cache/
34
buck2-bin/
45
cmake-out*
56
.DS_Store

.lintrunner.toml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,51 @@ command = [
285285
'--',
286286
'@{{PATHSFILE}}',
287287
]
288+
289+
[[linter]]
290+
code = 'MYPY'
291+
include_patterns = [
292+
# TODO(https://github.com/pytorch/executorch/issues/7441): Gradually start enabling all folders.
293+
# 'backends/**/*.py',
294+
'build/**/*.py',
295+
'codegen/**/*.py',
296+
# 'devtools/**/*.py',
297+
'docs/**/*.py',
298+
# 'examples/**/*.py',
299+
# 'exir/**/*.py',
300+
# 'extension/**/*.py',
301+
'kernels/**/*.py',
302+
'profiler/**/*.py',
303+
'runtime/**/*.py',
304+
'scripts/**/*.py',
305+
'test/**/*.py',
306+
'util/**/*.py',
307+
'*.py',
308+
]
309+
exclude_patterns = [
310+
'third-party/**',
311+
'**/third-party/**',
312+
'scripts/check_binary_dependencies.py',
313+
'profiler/test/test_profiler_e2e.py',
314+
]
315+
command = [
316+
'python',
317+
'-m',
318+
'lintrunner_adapters',
319+
'run',
320+
'mypy_linter',
321+
'--config=.mypy.ini',
322+
'--show-disable',
323+
'--',
324+
'--explicit-package-bases',
325+
'@{{PATHSFILE}}'
326+
]
327+
init_command = [
328+
'python',
329+
'-m',
330+
'lintrunner_adapters',
331+
'run',
332+
'pip_init',
333+
'--dry-run={{DRYRUN}}',
334+
'--requirement=requirements-lintrunner.txt',
335+
]

.mypy.ini

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
[mypy]
2+
allow_redefinition = True
3+
warn_unused_configs = True
4+
warn_redundant_casts = True
5+
show_error_codes = True
6+
show_column_numbers = True
7+
disallow_untyped_decorators = True
8+
follow_imports = normal
9+
local_partial_types = True
10+
enable_error_code = possibly-undefined
11+
warn_unused_ignores = False
12+
13+
files =
14+
backends,
15+
codegen,
16+
devtools
17+
examples,
18+
exir,
19+
extension,
20+
kernels,
21+
profiler,
22+
runtime,
23+
scripts,
24+
test,
25+
util
26+
27+
mypy_path = executorch
28+
29+
[mypy-executorch.backends.*]
30+
follow_untyped_imports = True
31+
32+
[mypy-executorch.codegen.*]
33+
follow_untyped_imports = True
34+
35+
[mypy-executorch.devtools.*]
36+
follow_untyped_imports = True
37+
38+
[mypy-executorch.exir.*]
39+
follow_untyped_imports = True
40+
41+
[mypy-executorch.extension.*]
42+
follow_untyped_imports = True
43+
44+
[mypy-executorch.kernels.*]
45+
follow_untyped_imports = True
46+
47+
[mypy-executorch.profiler.*]
48+
follow_untyped_imports = True
49+
50+
[mypy-executorch.runtime.*]
51+
follow_untyped_imports = True
52+
53+
[mypy-executorch.test.*]
54+
follow_untyped_imports = True
55+
56+
[mypy-functorch.*]
57+
follow_untyped_imports = True
58+
59+
[mypy-requests.*]
60+
follow_untyped_imports = True
61+
62+
[mypy-torchgen.*]
63+
follow_untyped_imports = True
64+
65+
[mypy-buck_util]
66+
ignore_missing_imports = True
67+
68+
[mypy-docutils.*]
69+
ignore_missing_imports = True
70+
71+
[mypy-pandas]
72+
ignore_missing_imports = True
73+
74+
[mypy-pytorch_sphinx_theme]
75+
ignore_missing_imports = True
76+
77+
[mypy-ruamel]
78+
ignore_missing_imports = True
79+
80+
[mypy-setuptools.*]
81+
ignore_missing_imports = True
82+
83+
[mypy-sphinx.*]
84+
ignore_missing_imports = True
85+
86+
[mypy-tomllib]
87+
ignore_missing_imports = True
88+
89+
[mypy-yaml]
90+
ignore_missing_imports = True
91+
92+
[mypy-zstd]
93+
ignore_missing_imports = True

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ If it's not clear how to add a test for your PR, take a look at the blame for
197197
the code you're modifying and find an author who has more context. Ask them
198198
for their help in the PR comments.
199199

200-
TODO: Explain how to run tests locally without needing to push and wait for CI.
200+
The `test/run_oss_cpp_tests.sh` script will build and run C++ tests locally.
201201

202202
### Continuous Integration
203203
See https://hud.pytorch.org/hud/pytorch/executorch/main for the current state of

0 commit comments

Comments
 (0)