Skip to content

Commit b5b40e2

Browse files
committed
[build] Add editable mode unittest
As titled. To do this we need to refactor the arguments being passed into `setup-linux.sh` `setup-macos.sh` and `unittest-linux.sh` `unittest-macos.sh`. ghstack-source-id: a297ee14fb788418c61a45fbb42f7567141eefee Pull Request resolved: #8817
1 parent d48d646 commit b5b40e2

16 files changed

+137
-146
lines changed

.ci/scripts/setup-linux.sh

+7-9
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,17 @@ set -exu
1010
# shellcheck source=/dev/null
1111
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
1212

13-
BUILD_TOOL=$1
14-
if [[ -z "${BUILD_TOOL:-}" ]]; then
15-
echo "Missing build tool (require buck2 or cmake), exiting..."
16-
exit 1
17-
else
18-
echo "Setup Linux for ${BUILD_TOOL} ..."
19-
fi
13+
parse_args "$@"
2014

2115
# As Linux job is running inside a Docker container, all of its dependencies
2216
# have already been installed, so we use PyTorch build from source here instead
2317
# of nightly. This allows CI to test against latest commits from PyTorch
24-
install_executorch "use-pt-pinned-commit"
25-
build_executorch_runner "${BUILD_TOOL}" "${2:-Release}"
18+
if [[ "${EDITABLE:-false}" == "true" ]]; then
19+
install_executorch --use-pt-pinned-commit --editable
20+
else
21+
install_executorch --use-pt-pinned-commit
22+
fi
23+
build_executorch_runner "${BUILD_TOOL}" "${BUILD_MODE}"
2624

2725
if [[ "${GITHUB_BASE_REF:-}" == *main* || "${GITHUB_BASE_REF:-}" == *gh* ]]; then
2826
do_not_use_nightly_on_ci

.ci/scripts/setup-macos.sh

+7-9
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@ set -exu
1010
# shellcheck source=/dev/null
1111
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
1212

13-
BUILD_TOOL=$1
14-
if [[ -z "${BUILD_TOOL:-}" ]]; then
15-
echo "Missing build tool (require buck2 or cmake), exiting..."
16-
exit 1
17-
else
18-
echo "Setup MacOS for ${BUILD_TOOL} ..."
19-
fi
13+
parse_args "$@"
2014

2115
install_buck() {
2216
if ! command -v zstd &> /dev/null; then
@@ -135,8 +129,12 @@ print_cmake_info
135129
install_pytorch_and_domains
136130
# We build PyTorch from source here instead of using nightly. This allows CI to test against
137131
# the pinned commit from PyTorch
138-
install_executorch "use-pt-pinned-commit"
139-
build_executorch_runner "${BUILD_TOOL}" "${2:-Release}"
132+
if [[ "$EDITABLE" == "true" ]]; then
133+
install_executorch "--use-pt-pinned-commit" "--editable"
134+
else
135+
install_executorch "--use-pt-pinned-commit"
136+
fi
137+
build_executorch_runner "${BUILD_TOOL}" "${BUILD_MODE}"
140138

141139
if [[ "${GITHUB_BASE_REF:-}" == *main* || "${GITHUB_BASE_REF:-}" == *gh* ]]; then
142140
do_not_use_nightly_on_ci

.ci/scripts/unittest-linux.sh

+5-16
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,10 @@
66
# LICENSE file in the root directory of this source tree.
77
set -eux
88

9-
BUILD_TOOL=$1
10-
if [[ $BUILD_TOOL =~ ^(cmake|buck2)$ ]]; then
11-
echo "Running unittests for ${BUILD_TOOL} ..."
12-
else
13-
echo "Missing build tool (require buck2 or cmake), exiting..."
14-
exit 1
15-
fi
9+
# shellcheck source=/dev/null
10+
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
1611

17-
BUILD_MODE=$2
18-
if [[ "${BUILD_MODE:-}" =~ ^(Debug|Release)$ ]]; then
19-
echo "Running tests in build mode ${BUILD_MODE} ..."
20-
else
21-
echo "Unsupported build mode ${BUILD_MODE}, options are Debug or Release."
22-
exit 1
23-
fi
12+
parse_args "$@"
2413

2514
# The generic Linux job chooses to use base env, not the one setup by the image
2615
eval "$(conda shell.bash hook)"
@@ -34,7 +23,7 @@ if [[ "$BUILD_TOOL" == "cmake" ]]; then
3423
PYTHON_EXECUTABLE=python \
3524
EXECUTORCH_BUILD_PYBIND=ON \
3625
CMAKE_ARGS="-DEXECUTORCH_BUILD_XNNPACK=ON -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON" \
37-
.ci/scripts/setup-linux.sh "$BUILD_TOOL" "$BUILD_MODE"
26+
.ci/scripts/setup-linux.sh "$@"
3827

3928
# Install llama3_2_vision dependencies.
4029
PYTHON_EXECUTABLE=python ./examples/models/llama3_2_vision/install_requirements.sh
@@ -45,7 +34,7 @@ elif [[ "$BUILD_TOOL" == "buck2" ]]; then
4534
# because TMPDIR gets messed up? Please feel free to fix this and
4635
# speed up this CI job!
4736
PYTHON_EXECUTABLE=python \
48-
.ci/scripts/setup-linux.sh "$BUILD_TOOL" "$BUILD_MODE"
37+
.ci/scripts/setup-linux.sh "$@"
4938

5039
.ci/scripts/unittest-buck2.sh
5140
else

.ci/scripts/unittest-macos.sh

+4-15
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,10 @@
66
# LICENSE file in the root directory of this source tree.
77
set -eux
88

9-
BUILD_TOOL=$1
10-
if [[ $BUILD_TOOL =~ ^(cmake|buck2)$ ]]; then
11-
echo "Running unittests for ${BUILD_TOOL} ..."
12-
else
13-
echo "Missing build tool (require buck2 or cmake), exiting..."
14-
exit 1
15-
fi
9+
# shellcheck source=/dev/null
10+
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
1611

17-
BUILD_MODE=$2
18-
if [[ $BUILD_MODE =~ ^(Debug|Release)$ ]]; then
19-
echo "Running tests in build mode ${BUILD_MODE} ..."
20-
else
21-
echo "Unsupported build mode ${BUILD_MODE}, options are Debug or Release."
22-
exit 1
23-
fi
12+
parse_args "$@"
2413

2514
bash .ci/scripts/setup-conda.sh
2615
eval "$(conda shell.bash hook)"
@@ -36,7 +25,7 @@ if [[ "$BUILD_TOOL" == "cmake" ]]; then
3625
EXECUTORCH_BUILD_PYBIND=ON \
3726
CMAKE_ARGS="-DEXECUTORCH_BUILD_COREML=ON -DEXECUTORCH_BUILD_MPS=ON -DEXECUTORCH_BUILD_XNNPACK=ON -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON" \
3827
${CONDA_RUN} --no-capture-output \
39-
.ci/scripts/setup-macos.sh "${BUILD_TOOL}" "${BUILD_MODE}"
28+
.ci/scripts/setup-macos.sh "$@"
4029

4130
# Install llama3_2_vision dependencies.
4231
PYTHON_EXECUTABLE=python \

.ci/scripts/utils.sh

+58-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ install_executorch() {
2424
which pip
2525
# Install executorch, this assumes that Executorch is checked out in the
2626
# current directory.
27-
if [[ "${1:-}" == "use-pt-pinned-commit" ]]; then
28-
./install_executorch.sh --pybind xnnpack --use-pt-pinned-commit
29-
else
30-
./install_executorch.sh --pybind xnnpack
31-
fi
27+
./install_executorch.sh --pybind xnnpack "$@"
3228
# Just print out the list of packages for debugging
3329
pip list
3430
}
@@ -166,3 +162,60 @@ do_not_use_nightly_on_ci() {
166162
exit 1
167163
fi
168164
}
165+
166+
167+
parse_args() {
168+
local args=("$@")
169+
local i
170+
local BUILD_TOOL=""
171+
local BUILD_MODE=""
172+
local EDITABLE=""
173+
for ((i=0; i<${#args[@]}; i++)); do
174+
case "${args[$i]}" in
175+
--build-tool)
176+
BUILD_TOOL="${args[$((i+1))]}"
177+
i=$((i+1))
178+
;;
179+
--build-mode)
180+
BUILD_MODE="${args[$((i+1))]}"
181+
i=$((i+1))
182+
;;
183+
--editable)
184+
EDITABLE="${args[$((i+1))]}"
185+
i=$((i+1))
186+
;;
187+
*)
188+
echo "Invalid argument: ${args[$i]}"
189+
exit 1
190+
;;
191+
esac
192+
done
193+
194+
if [[ $BUILD_TOOL =~ ^(cmake|buck2)$ ]]; then
195+
echo "Build tool is ${BUILD_TOOL} ..."
196+
elif [ -z "$BUILD_TOOL" ]; then
197+
echo "Missing build tool (require buck2 or cmake), exiting..."
198+
exit 1
199+
else
200+
echo "Require buck2 or cmake for --build-tool, got ${BUILD_TOOL}, exiting..."
201+
exit 1
202+
fi
203+
BUILD_MODE="${BUILD_MODE:-Release}"
204+
if [[ "$BUILD_MODE" =~ ^(Debug|Release)$ ]]; then
205+
echo "Running tests in build mode ${BUILD_MODE} ..."
206+
else
207+
echo "Unsupported build mode ${BUILD_MODE}, options are Debug or Release."
208+
exit 1
209+
fi
210+
EDITABLE="${EDITABLE:-false}"
211+
if [[ $EDITABLE =~ ^(true|false)$ ]]; then
212+
echo "Editable mode is ${EDITABLE} ..."
213+
else
214+
echo "Require true or false for --editable, got ${EDITABLE}, exiting..."
215+
exit 1
216+
fi
217+
218+
echo "BUILD_TOOL=$BUILD_TOOL"
219+
echo "BUILD_MODE=$BUILD_MODE"
220+
echo "EDITABLE=$EDITABLE"
221+
}

.github/workflows/_android.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
# The generic Linux job chooses to use base env, not the one setup by the image
2626
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
2727
conda activate "${CONDA_ENV}"
28-
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh buck2
28+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool buck2
2929
export ARTIFACTS_DIR_NAME=artifacts-to-be-uploaded
3030
3131
# Build LLM Demo for Android

.github/workflows/_unittest.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ on:
1515
required: true
1616
type: string
1717
description: Build tool to use, cmake or buck2.
18+
editable:
19+
required: false
20+
type: string
21+
description: Install ExecuTorch in editable mode or not.
1822
python-version:
1923
required: false
2024
type: string
@@ -34,7 +38,7 @@ jobs:
3438
timeout: 90
3539
script: |
3640
set -eux
37-
.ci/scripts/unittest-linux.sh "${{ inputs.build-tool }}" "${{ inputs.build-mode }}"
41+
.ci/scripts/unittest-linux.sh --build-tool "${{ inputs.build-tool }}" --build-mode "${{ inputs.build-mode }}" --editable "${{ inputs.editable }}"
3842
3943
macos:
4044
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
@@ -45,4 +49,4 @@ jobs:
4549
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
4650
script: |
4751
set -eux
48-
.ci/scripts/unittest-macos.sh "${{ inputs.build-tool }}" "${{ inputs.build-mode }}"
52+
.ci/scripts/unittest-macos.sh --build-tool "${{ inputs.build-tool }}" --build-mode "${{ inputs.build-mode }}" --editable "${{ inputs.editable }}"

.github/workflows/android-perf.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ jobs:
181181
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-qnn-deps.sh
182182
PYTHON_EXECUTABLE=python bash .ci/scripts/build-qnn-sdk.sh
183183
fi
184-
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "cmake"
184+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "cmake"
185185
# Install requirements for export_llama
186186
PYTHON_EXECUTABLE=python bash examples/models/llama/install_requirements.sh
187187
@@ -356,7 +356,7 @@ jobs:
356356
# The generic Linux job chooses to use base env, not the one setup by the image
357357
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
358358
conda activate "${CONDA_ENV}"
359-
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh cmake
359+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool cmake
360360
export ARTIFACTS_DIR_NAME=artifacts-to-be-uploaded
361361
362362
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-qnn-deps.sh

.github/workflows/android-release-artifacts.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
# The generic Linux job chooses to use base env, not the one setup by the image
5050
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
5151
conda activate "${CONDA_ENV}"
52-
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh buck2
52+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool buck2
5353
export ARTIFACTS_DIR_NAME=artifacts-to-be-uploaded
5454
5555
# Build LLM Demo for Android

.github/workflows/apple-perf.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ jobs:
181181
BUILD_TOOL=cmake
182182
# Setup MacOS dependencies as there is no Docker support on MacOS atm
183183
GITHUB_RUNNER=1 PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
184-
.ci/scripts/setup-macos.sh "${BUILD_TOOL}"
184+
.ci/scripts/setup-macos.sh --build-tool "${BUILD_TOOL}"
185185
186186
if [[ ${{ matrix.config }} == *"coreml"* ]]; then
187187
PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
@@ -367,7 +367,7 @@ jobs:
367367
BUILD_TOOL=cmake
368368
# Setup MacOS dependencies as there is no Docker support on MacOS atm
369369
GITHUB_RUNNER=1 PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
370-
.ci/scripts/setup-macos.sh "${BUILD_TOOL}"
370+
.ci/scripts/setup-macos.sh --build-tool "${BUILD_TOOL}"
371371
export ARTIFACTS_DIR_NAME=artifacts-to-be-uploaded
372372
373373
# Setup Apple certificate for iOS development

.github/workflows/apple.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
7070
# Setup MacOS dependencies as there is no Docker support on MacOS atm
7171
GITHUB_RUNNER=1 PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
72-
.ci/scripts/setup-macos.sh "${BUILD_TOOL}"
72+
.ci/scripts/setup-macos.sh --build-tool "${BUILD_TOOL}"
7373
7474
export ARTIFACTS_DIR_NAME=artifacts-to-be-uploaded
7575
@@ -160,7 +160,7 @@ jobs:
160160
161161
# Setup MacOS dependencies as there is no Docker support on MacOS atm
162162
GITHUB_RUNNER=1 PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
163-
.ci/scripts/setup-macos.sh "${BUILD_TOOL}"
163+
.ci/scripts/setup-macos.sh --build-tool "${BUILD_TOOL}"
164164
165165
# Install CoreML Backend Requirements
166166
PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
@@ -293,7 +293,7 @@ jobs:
293293
BUILD_TOOL=cmake
294294
# Setup MacOS dependencies as there is no Docker support on MacOS atm
295295
GITHUB_RUNNER=1 PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
296-
.ci/scripts/setup-macos.sh "${BUILD_TOOL}"
296+
.ci/scripts/setup-macos.sh --build-tool "${BUILD_TOOL}"
297297
export ARTIFACTS_DIR_NAME=artifacts-to-be-uploaded
298298
299299
# Setup Apple certificate for iOS development

.github/workflows/doc-build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
3939
BUILD_TOOL=${{ matrix.build-tool }}
4040
# Setup dependencies as there is no Docker support
41-
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "${BUILD_TOOL}"
41+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}"
4242
4343
if [[(${GITHUB_EVENT_NAME} = 'pull_request' && (${GITHUB_BASE_REF} = 'release'*)) || (${GITHUB_REF} = 'refs/heads/release'*) ]]; then
4444
export CHANNEL=test

.github/workflows/lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
# For mypy linting, we need to first install executorch first so that
3636
# it builds the python package information.
3737
BUILD_TOOL="cmake"
38-
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "${BUILD_TOOL}"
38+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}"
3939
4040
CACHE_DIRECTORY="/tmp/.lintbin"
4141
# Try to recover the cached binaries

.github/workflows/periodic.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ jobs:
6363
BACKEND=${{ matrix.backend }}
6464
DEMO_BACKEND_DELEGATION=${{ matrix.demo_backend_delegation }}
6565
66-
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "${BUILD_TOOL}"
66+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}"
6767
# Build and test ExecuTorch
6868
PYTHON_EXECUTABLE=python bash .ci/scripts/test_model.sh "${MODEL_NAME}" "${BUILD_TOOL}" "${BACKEND}" "${DEMO_BACKEND_DELEGATION}"

0 commit comments

Comments
 (0)