Skip to content

[build] Add editable mode unittest #8817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Feb 28, 2025
Merged
16 changes: 7 additions & 9 deletions .ci/scripts/setup-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@ set -exu
# shellcheck source=/dev/null
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"

BUILD_TOOL=$1
if [[ -z "${BUILD_TOOL:-}" ]]; then
echo "Missing build tool (require buck2 or cmake), exiting..."
exit 1
else
echo "Setup Linux for ${BUILD_TOOL} ..."
fi
read -r BUILD_TOOL BUILD_MODE EDITABLE < <(parse_args "$@")

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

if [[ "${GITHUB_BASE_REF:-}" == *main* || "${GITHUB_BASE_REF:-}" == *gh* ]]; then
do_not_use_nightly_on_ci
Expand Down
16 changes: 7 additions & 9 deletions .ci/scripts/setup-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@ set -exu
# shellcheck source=/dev/null
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"

BUILD_TOOL=$1
if [[ -z "${BUILD_TOOL:-}" ]]; then
echo "Missing build tool (require buck2 or cmake), exiting..."
exit 1
else
echo "Setup MacOS for ${BUILD_TOOL} ..."
fi
read -r BUILD_TOOL BUILD_MODE EDITABLE < <(parse_args "$@")

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

if [[ "${GITHUB_BASE_REF:-}" == *main* || "${GITHUB_BASE_REF:-}" == *gh* ]]; then
do_not_use_nightly_on_ci
Expand Down
21 changes: 5 additions & 16 deletions .ci/scripts/unittest-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,10 @@
# LICENSE file in the root directory of this source tree.
set -eux

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

BUILD_MODE=$2
if [[ "${BUILD_MODE:-}" =~ ^(Debug|Release)$ ]]; then
echo "Running tests in build mode ${BUILD_MODE} ..."
else
echo "Unsupported build mode ${BUILD_MODE}, options are Debug or Release."
exit 1
fi
read -r BUILD_TOOL BUILD_MODE EDITABLE < <(parse_args "$@")

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

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

.ci/scripts/unittest-buck2.sh
else
Expand Down
19 changes: 4 additions & 15 deletions .ci/scripts/unittest-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,10 @@
# LICENSE file in the root directory of this source tree.
set -eux

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

BUILD_MODE=$2
if [[ $BUILD_MODE =~ ^(Debug|Release)$ ]]; then
echo "Running tests in build mode ${BUILD_MODE} ..."
else
echo "Unsupported build mode ${BUILD_MODE}, options are Debug or Release."
exit 1
fi
read -r BUILD_TOOL BUILD_MODE EDITABLE < <(parse_args "$@")

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

# Install llama3_2_vision dependencies.
PYTHON_EXECUTABLE=python \
Expand Down
55 changes: 50 additions & 5 deletions .ci/scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ install_executorch() {
which pip
# Install executorch, this assumes that Executorch is checked out in the
# current directory.
if [[ "${1:-}" == "use-pt-pinned-commit" ]]; then
./install_executorch.sh --pybind xnnpack --use-pt-pinned-commit
else
./install_executorch.sh --pybind xnnpack
fi
./install_executorch.sh --pybind xnnpack "$@"
# Just print out the list of packages for debugging
pip list
}
Expand Down Expand Up @@ -166,3 +162,52 @@ do_not_use_nightly_on_ci() {
exit 1
fi
}


parse_args() {
local args=("$@")
local i
local BUILD_TOOL=""
local BUILD_MODE=""
local EDITABLE=""
for ((i=0; i<${#args[@]}; i++)); do
case "${args[$i]}" in
--build-tool)
BUILD_TOOL="${args[$((i+1))]}"
i=$((i+1))
;;
--build-mode)
BUILD_MODE="${args[$((i+1))]}"
i=$((i+1))
;;
--editable)
EDITABLE="${args[$((i+1))]}"
i=$((i+1))
;;
*)
echo "Invalid argument: ${args[$i]}"
exit 1
;;
esac
done

if [ -z "$BUILD_TOOL" ]; then
echo "Missing build tool (require buck2 or cmake), exiting..."
exit 1
elif ! [[ $BUILD_TOOL =~ ^(cmake|buck2)$ ]]; then
echo "Require buck2 or cmake for --build-tool, got ${BUILD_TOOL}, exiting..."
exit 1
fi
BUILD_MODE="${BUILD_MODE:-Release}"
if ! [[ "$BUILD_MODE" =~ ^(Debug|Release)$ ]]; then
echo "Unsupported build mode ${BUILD_MODE}, options are Debug or Release."
exit 1
fi
EDITABLE="${EDITABLE:-false}"
if ! [[ $EDITABLE =~ ^(true|false)$ ]]; then
echo "Require true or false for --editable, got ${EDITABLE}, exiting..."
exit 1
fi

echo "$BUILD_TOOL $BUILD_MODE $EDITABLE"
}
2 changes: 1 addition & 1 deletion .github/workflows/_android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
# The generic Linux job chooses to use base env, not the one setup by the image
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
conda activate "${CONDA_ENV}"
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh buck2
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool buck2
export ARTIFACTS_DIR_NAME=artifacts-to-be-uploaded

# Build LLM Demo for Android
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/_unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ on:
required: true
type: string
description: Build tool to use, cmake or buck2.
editable:
required: false
type: string
description: Install ExecuTorch in editable mode or not.
python-version:
required: false
type: string
Expand All @@ -34,7 +38,7 @@ jobs:
timeout: 90
script: |
set -eux
.ci/scripts/unittest-linux.sh "${{ inputs.build-tool }}" "${{ inputs.build-mode }}"
.ci/scripts/unittest-linux.sh --build-tool "${{ inputs.build-tool }}" --build-mode "${{ inputs.build-mode }}" --editable "${{ inputs.editable }}"

macos:
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
Expand All @@ -45,4 +49,4 @@ jobs:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
script: |
set -eux
.ci/scripts/unittest-macos.sh "${{ inputs.build-tool }}" "${{ inputs.build-mode }}"
.ci/scripts/unittest-macos.sh --build-tool "${{ inputs.build-tool }}" --build-mode "${{ inputs.build-mode }}" --editable "${{ inputs.editable }}"
4 changes: 2 additions & 2 deletions .github/workflows/android-perf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ jobs:
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-qnn-deps.sh
PYTHON_EXECUTABLE=python bash .ci/scripts/build-qnn-sdk.sh
fi
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "cmake"
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "cmake"
# Install requirements for export_llama
PYTHON_EXECUTABLE=python bash examples/models/llama/install_requirements.sh

Expand Down Expand Up @@ -356,7 +356,7 @@ jobs:
# The generic Linux job chooses to use base env, not the one setup by the image
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
conda activate "${CONDA_ENV}"
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh cmake
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool cmake
export ARTIFACTS_DIR_NAME=artifacts-to-be-uploaded

PYTHON_EXECUTABLE=python bash .ci/scripts/setup-qnn-deps.sh
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/android-release-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
# The generic Linux job chooses to use base env, not the one setup by the image
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
conda activate "${CONDA_ENV}"
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh buck2
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool buck2
export ARTIFACTS_DIR_NAME=artifacts-to-be-uploaded

# Build LLM Demo for Android
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/apple-perf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ jobs:
BUILD_TOOL=cmake
# Setup MacOS dependencies as there is no Docker support on MacOS atm
GITHUB_RUNNER=1 PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
.ci/scripts/setup-macos.sh "${BUILD_TOOL}"
.ci/scripts/setup-macos.sh --build-tool "${BUILD_TOOL}"

if [[ ${{ matrix.config }} == *"coreml"* ]]; then
PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
Expand Down Expand Up @@ -367,7 +367,7 @@ jobs:
BUILD_TOOL=cmake
# Setup MacOS dependencies as there is no Docker support on MacOS atm
GITHUB_RUNNER=1 PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
.ci/scripts/setup-macos.sh "${BUILD_TOOL}"
.ci/scripts/setup-macos.sh --build-tool "${BUILD_TOOL}"
export ARTIFACTS_DIR_NAME=artifacts-to-be-uploaded

# Setup Apple certificate for iOS development
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/apple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:

# Setup MacOS dependencies as there is no Docker support on MacOS atm
GITHUB_RUNNER=1 PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
.ci/scripts/setup-macos.sh "${BUILD_TOOL}"
.ci/scripts/setup-macos.sh --build-tool "${BUILD_TOOL}"

export ARTIFACTS_DIR_NAME=artifacts-to-be-uploaded

Expand Down Expand Up @@ -160,7 +160,7 @@ jobs:

# Setup MacOS dependencies as there is no Docker support on MacOS atm
GITHUB_RUNNER=1 PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
.ci/scripts/setup-macos.sh "${BUILD_TOOL}"
.ci/scripts/setup-macos.sh --build-tool "${BUILD_TOOL}"

# Install CoreML Backend Requirements
PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
Expand Down Expand Up @@ -293,7 +293,7 @@ jobs:
BUILD_TOOL=cmake
# Setup MacOS dependencies as there is no Docker support on MacOS atm
GITHUB_RUNNER=1 PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
.ci/scripts/setup-macos.sh "${BUILD_TOOL}"
.ci/scripts/setup-macos.sh --build-tool "${BUILD_TOOL}"
export ARTIFACTS_DIR_NAME=artifacts-to-be-uploaded

# Setup Apple certificate for iOS development
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/doc-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

BUILD_TOOL=${{ matrix.build-tool }}
# Setup dependencies as there is no Docker support
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "${BUILD_TOOL}"
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}"

if [[(${GITHUB_EVENT_NAME} = 'pull_request' && (${GITHUB_BASE_REF} = 'release'*)) || (${GITHUB_REF} = 'refs/heads/release'*) ]]; then
export CHANNEL=test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
# For mypy linting, we need to first install executorch first so that
# it builds the python package information.
BUILD_TOOL="cmake"
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "${BUILD_TOOL}"
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}"

CACHE_DIRECTORY="/tmp/.lintbin"
# Try to recover the cached binaries
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/periodic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ jobs:
BACKEND=${{ matrix.backend }}
DEMO_BACKEND_DELEGATION=${{ matrix.demo_backend_delegation }}

PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "${BUILD_TOOL}"
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}"
# Build and test ExecuTorch
PYTHON_EXECUTABLE=python bash .ci/scripts/test_model.sh "${MODEL_NAME}" "${BUILD_TOOL}" "${BACKEND}" "${DEMO_BACKEND_DELEGATION}"
Loading
Loading